-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo_osg2.py
70 lines (55 loc) · 2.26 KB
/
demo_osg2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import time
import os.path
import threading
from replay import ReplayExperiment as ExperimentBase
# these are the original locations of the cylinders in the
# osgt used in demo_osg1 - however for OSG2 they should be loaded
# from individual OSG files and controlled individually
OFFSETS = {
'Cylinder': (0.0, 0.0, 0),
'Cylinder_001': (0.56862, 0.0, 0),
'Cylinder_002': (-1.47691, 0.62461, 0),
'Cylinder_003': (-0.3971, -1.7441, 0)
}
class MyExperiment(ExperimentBase):
def __init__(self, *args, **kwargs):
ExperimentBase.__init__(self, *args, **kwargs)
self._models = {}
for m in OFFSETS:
p = os.path.abspath(os.path.join('demo_world_v2.osgt.parts', '%s.osgt' % m))
if not os.path.isfile(p):
raise Exception('must be run from sample_code directory')
self._models[m] = self.load_osg(p)
self._models[m].move(*OFFSETS[m])
# the base class calls this with the current integrated position of
# the observer in the world
def do_move_world(self, x, y, z):
# but because there is no API to move all objects in OSG2,
# do what was equivalent and move all objects in the world
# to a constant position relative to the observer
#
# this effectively recreates the behavior of demo_osg1.py
#
for m in OFFSETS:
ox, oy, oz = OFFSETS[m]
self._models[m].move(ox + x, oy + y, oz + z)
def run_forever(self):
t0 = time.time()
try:
while 1:
time.sleep(0.1)
except KeyboardInterrupt:
self.stop()
if __name__ == '__main__':
import logging
import argparse
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--server-ids', metavar='default-id,server-2', default='default-id',
help="comma separated display server ids (default='default-id'")
parser.add_argument('logfile', nargs=1, help='yaml position log file')
args = parser.parse_args()
e = MyExperiment.new_osg2(servers=[n.strip() for n in args.server_ids.strip().split(',')],
replay_filename=args.logfile[0])
e.start(record=True)
e.run_forever()