-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultiple_objects.py
123 lines (93 loc) · 3.37 KB
/
multiple_objects.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import math
import time
import logging
import os.path
import collections
import random
import itertools as it
logging.basicConfig(level=logging.WARNING)
from freemoovr.proxy.base_zmq import ServerBaseZMQ
from freemoovr.proxy.stimulus_osg import StimulusOSG2Controller
from lutil import PathIter, TimedTrue
########
# a demo which compares the performance of different clone types
# when duplicating a loaded model. in auto/deep clone mode the
# models are faded in and then sequentially started to animate
#
# in shallow clone mode, because the models are linked and not
# independently animateable and fadeable, they are not faded or
# animated individually
########
# if true, expects 'locust diffuse2.jpg' and 'locust_lp_120.osgt' in this directory
TRY_USE_LOCUST = True
# how to clone the model. in normal operation use only 'auto' or 'shallow'. deep is
# mostly used during engine development to validate the auto clone mode does the right
# thing
HOW = 'auto'
assert HOW in ('shallow', 'deep', 'auto')
# sequentially fade in all the models, 1 per second. With a lot of models (see DUPLICATES)
# this can take a long time. Is automatically disabled if using a shallow clone as that creates
# 1000 models
CAN_HIDE = False
p = os.path.abspath('locust_lp_120.osgt')
ANIMATION = 'ArmatureAction'
if (not os.path.exists(p)) or (not TRY_USE_LOCUST):
p = '1_object_1_animation_osgexp0130.osgt' # relative paths are in the compilation data directory
ANIMATION = 'ArmatureAction_O1'
print "to use a locust model, put 'locust diffuse2.jpg' and 'locust_lp_120.osgt' in this directory"
vr = StimulusOSG2Controller(server_ids=['default-id'])
# how many clones
DUPLICATES = 1000 if HOW == 'shallow' else 100
DT = 1/30.
nodes = {'_original': vr.load_osg(p)}
paths = {'_original': PathIter(0.5, 0.5, DT).walk()}
visible = {}
for i in range(DUPLICATES):
name = 'copy%d' % i
nodes[name] = nodes['_original'].clone(name, how=HOW)
paths[name] = PathIter(1 + (i * 0.5), 1 + (i * 0.01), DT).walk()
vr.wait_for_servers()
if (HOW != 'shallow') and CAN_HIDE:
print "hiding all"
for node in nodes.values():
node.move(hidden=True)
else:
print "not hiding all"
visible = {n: True for n in nodes}
vr.wait_for_servers()
# wait for 5s to give you a chance to set the camera
time.sleep(5)
observer_path = PathIter(0, dt=DT).walk()
started = {}
every_1s = TimedTrue(hz=1)
for j in it.count():
opos = next(observer_path)
# move them all
for idx, name in enumerate(sorted(nodes)):
node = nodes[name]
path = paths[name]
pos = next(path)
if visible.get(name):
node.move(*pos)
if every_1s:
if HOW == 'shallow':
name = '_original'
else:
# randomly start an animation
name = random.choice(nodes.keys())
node = nodes[name]
already_visible = (not CAN_HIDE) or (HOW == 'shallow') or visible.get(name)
if already_visible:
if not started.get(name):
node.animation_start(ANIMATION)
started[name] = True
print "start", name
elif (HOW != 'shallow') and CAN_HIDE:
if not visible.get(name):
node.fade_in()
visible[name] = True
print "fade_in", name
vr.set_position(*opos)
time.sleep(DT)
if (j % 20) == 0:
print "fps", vr.get_framerate()