PDA

View Full Version : Simultaneous Actions on Multiple Objects


javadi
07-18-2013, 10:37 PM
Hi,

I am wondering how I can run actions on multiple objects at the same time. It is a very basic task, but I cannot find any solution to it. The structure of my code is as follows: I have a scheduler that calls function MainProcedure. There I want to for example spin two objects ('Object1' & 'Object2') simultaneously. A part of my code goes below

if __name__ == "__main__":
...
viztask.schedule(MainProcedure())
...

def MainProcedure():
...

TempActionSpinObject1 = vizact.spinTo(euler = [90, 0, 0], speed = SpeedTurn)
TempActionSpinObject2 = vizact.spinTo(euler = [0, 90, 0], speed = SpeedTurn)

yield viztask.addAction(Object1, TempActionSpinObject1)
yield viztask.addAction(Object2, TempActionSpinObject2)

...


The code as it stands now, first spins the first object and then the second one. I tried the following code (removing 'yield') to test whether the objects spins together, but it turned out that the first objects doesn't spin at all, but the second object spins fine.


viztask.addAction(Object1, TempActionSpinObject1)
yield viztask.addAction(Object2, TempActionSpinObject2)


I thought perhaps it has something to do with 'pool' numbers. I thought perhaps the 2nd action overwrites the first one, if the pool numbers are both set to default (zero). so, I tried the following code, but again no luck.


viztask.addAction(Object1, TempActionSpinObject1, pool = 0)
yield viztask.addAction(Object2, TempActionSpinObject2, pool = 1)


I know about vizact.sequence and vizact.parallel. As far as I understand they act on one object. Any idea how to solve this problem? Very many thanks.

Greetings
Amir

farshizzo
07-19-2013, 09:43 AM
You can use viztask.waitAll to wait for a specified set of actions to complete. Here is an example:
import viz
import vizact
import viztask
viz.go()

Object1 = viz.add('beachball.osgb',pos=(-1,2,5))
Object2 = viz.add('soccerball.osgb',pos=(1,2,5))

def MainTask():

yield viztask.waitKeyDown(' ')

spin1 = vizact.spinTo(euler=[90,0,0], speed=45)
spin2 = vizact.spinTo(euler=[0,90,0], speed=45)

waitSpin1 = viztask.waitTask( viztask.addAction(Object1, spin1) )
waitSpin2 = viztask.waitTask( viztask.addAction(Object2, spin2) )

yield viztask.waitAll( [waitSpin1, waitSpin2] )

print 'finished'

viztask.schedule( MainTask() )

javadi
07-19-2013, 03:54 PM
Hi,

Very many thanks for your detailed reply. Very helpful.

Greetings
Amir