-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultiple_objects_animation.py
89 lines (64 loc) · 2.1 KB
/
multiple_objects_animation.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
import math
import time
import random
import logging
import os.path
import itertools as it
logging.basicConfig(level=logging.INFO)
from freemoovr.proxy.base_zmq import ServerBaseZMQ
from freemoovr.proxy.stimulus_osg import StimulusOSG2Controller
from lutil import PathIter, TimedTrue
p = '1_object_1_animation_osgexp0130.osgt' # relative paths are in the compilation data directory
vr = StimulusOSG2Controller(server_ids=['default-id'])
vr.set_animation_duration(1.0)
vr.wait_for_servers()
nodes = {'original': vr.load_osg(p)}
paths = {'original': PathIter(0.5, 0.5, 0.05).walk()}
for i in range(2):
name = 'copy%d' % i
nodes[name] = nodes['original'].clone(name)
paths[name] = PathIter(1 + (i * 0.5), 1 + (i * 0.7), 0.05).walk()
vr.wait_for_servers()
for node in nodes.values():
node.hide()
vr.wait_for_servers()
visible = {n: False for n in nodes}
started = {n: False for n in nodes}
observer_path = PathIter(0, dt=0.1).walk()
every_2s = TimedTrue.new_every(seconds=2)
for j in it.count():
opos = next(observer_path)
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_2s:
name = random.choice(nodes.keys())
choices = []
if visible[name]:
choices.append('fade_out')
if started[name]:
choices.append('anim_stop')
else:
choices.append('anim_start')
else:
choices.append('fade_in')
what = random.choice(choices)
node = nodes[name]
if what == 'fade_out':
node.fade_out()
visible[name] = False
elif what == 'fade_in':
node.fade_in()
visible[name] = True
elif what == 'anim_stop':
node.animation_stop('ArmatureAction_O1')
started[name] = False
elif what == 'anim_start':
node.animation_start('ArmatureAction_O1')
started[name] = True
print name, what
vr.set_position(*opos)
time.sleep(0.05)