WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Newbie - Trouble using loops (https://forum.worldviz.com/showthread.php?t=5119)

lawry2 07-30-2014 11:49 AM

Newbie - Trouble using loops
 
Hi all,

I'm new to using Vizard and am having difficulty using loops. My issue is that when I use a loop, it blocks the environment from being rendered. I thought that this was OK as I was using the same method I saw in the Vizard documentation.

Code:

import viz
import viztask

env = viz.add('../models/environment.OSGB')

viz.go()

def run():
       
        while True:
                # Something simple
                print viz.MainView.getPosition()
                print viz.MainView.getEuler()

viztask.schedule(run())

What I get here is just a black window. The model is never seen but the output window shows the camera Euler and position. I'm aware that the loop is blocking but how do I get around this?

Jeff 07-30-2014 01:35 PM

Functions scheduled with viztask must contain a yield command. The following should work:

Code:

import viz
import viztask

env = viz.add('dojo.osgb')

viz.go()

def run():
       
        while True:
                # Something simple
                yield viztask.waitTime(1)
                print viz.MainView.getPosition()
                print viz.MainView.getEuler()

viztask.schedule(run())


lawry2 07-30-2014 01:38 PM

Thanks for the quick reply.

Yep, that worked. I must ask though, why is this?

Using what you said, I have put the print statements in another function and I call that using a yield statement.

Jeff 07-30-2014 01:51 PM

Vizard's task functions are implemented using Python generators which use yield statements.


All times are GMT -7. The time now is 11:20 AM.

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