WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   problem with yield statement and animation path (https://forum.worldviz.com/showthread.php?t=5705)

jelly 04-27-2016 11:15 AM

problem with yield statement and animation path
 
Hello!

I have an animation that goes through a maze in a loop (4 times).

I also have a yield statement that waits for an arrow key (see code below in red) but whenever I have it inside the function, it offsets everything, the animation seems to play twice before waiting for the arrow key and then it offsets all coordinates.

Why does that happen?



Code:

import viz                                                                                                                       
import viztask                                                                                                       

viz.clearcolor(viz.BLACK)

viz.go()

#Set the start position:
startPos = [-6.4,1.4,-8]

### Add all the resources. ###############

maze1 = viz.add('Objects/Maze_1.dae')
maze1.visible(viz.OFF)

view = viz.MainView

view.eyeheight(1.4)
view.setPosition(startPos)

view.collision(viz.ON)
viz.collisionbuffer(.8)

##Animation path
pathMaze1 = viz.addAnimationPath()

#Add control points to the path, along with their time stamp.
pathMaze1.addControlPoint(2, pos=startPos,euler=(0,0,0),scale=(2,2,2))
pathMaze1.addControlPoint(4, pos=startPos,euler=(90,0,0),scale=(2,2,2))
pathMaze1.addControlPoint(6, pos=(0,1.4,-8),euler=(0,0,0),scale=(2,2,2))
pathMaze1.addControlPoint(8, pos=(0,1.4,5),euler=(0,0,0),scale=(2,2,2))

#Duation of animation
pathMaze1Duration = pathMaze1.getDuration()

def animation():

        link = viz.link(pathMaze1,view)
        pathMaze1.play()
        yield viztask.waitTime(pathMaze1Duration)
        pathMaze1.reset()

def maze1trial():
        print 'now'
        view.setPosition(startPos)
        maze1.visible(viz.ON)
        yield animation()
        #yield viztask.waitKeyDown([viz.KEY_LEFT,viz.KEY_RIGHT])
        maze1.visible(viz.OFF)

def masterFunction():       
        for x in range(4):
                yield maze1trial()
viztask.schedule(masterFunction())


Jeff 04-29-2016 02:19 AM

In order to run the code, I changed the model to the piazza. However, I didn't notice a coordinate offset from one trial to another. If you have viewpoint collision enabled and depending on the stepsize, the viewpoint can get bumped up on collisions with the scene. If you want to wait until the path is finished playing before doing something else, wait for a path end event:

Code:

import viz                                                                                                                       
import viztask                                                                                                       

viz.go()

startPos = [-6.4,1.4,-8]
view = viz.MainView
view.eyeheight(1.4)

maze1 = viz.add('piazza.osgb')

pathMaze1 = viz.addAnimationPath()
pathMaze1.addControlPoint(2, pos=startPos,euler=(0,0,0),scale=(2,2,2))
pathMaze1.addControlPoint(4, pos=startPos,euler=(90,0,0),scale=(2,2,2))
pathMaze1.addControlPoint(6, pos=(0,1.4,-8),euler=(0,0,0),scale=(2,2,2))
pathMaze1.addControlPoint(8, pos=(0,1.4,5),euler=(0,0,0),scale=(2,2,2))
pathMaze1.addEventAtEnd('maze_end')

link = viz.link(pathMaze1,view)

def trials():
       
        for x in range(4):
               
                print 'trial',x
                pathMaze1.play()
                yield viztask.waitPathEvent(pathMaze1, 'maze_end')
                yield viztask.waitKeyDown([viz.KEY_LEFT,viz.KEY_RIGHT])
                pathMaze1.reset()
       
viztask.schedule( trials() )


jelly 05-05-2016 09:13 AM

Thank you very much! Indeed, this version seems fine. I really need to troubleshoot my scripts usign that maze more in detail. Not sure why I get these resetting problems that I have been writing about. For now I solved the issue by not using animation paths but by using the goTo.


All times are GMT -7. The time now is 02:21 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC