-
Notifications
You must be signed in to change notification settings - Fork 20
Scripting
Scripting is the way to add logic, interaction and animations to the virtual scene. All features of PolyVR are accessible from scripts, including scene graph operations, content import or creation, physics, lightning, cameras and many more. The module is called 'VR', it is documented, just click on the button with the question mark.
import VR
print VR.getVersion()
Scripts are written in python, this allows to import any module installed on your system. This also allows to import your own python modules. The path to place your modules is the folder where your project lies. If you want to add more paths you can do this in an init script:
import sys
sys.path.append("my/module/path/myMod")
from myMod import mymod
reload(mymod) # only needed when the module code changed
# help(mymod) # print all members of your module
mymod.test()
this code starts the test function defined in mymod.py in the folder my/module/path/myMod. For this to work, an empty file names init.py has to be placed in my/module/path/myMod.
Scripts can be triggered by pressing the button with the gears. This is only meant for testing! The trigger types are:
- on_scene_load
- Triggers the script right after the scene loaded
- on_timeout
- Triggers the script each X ms (max once per frame), X must be passed as parameter
- Set parameter to 0 to trigger each frame
- on_device
- Triggers the script when receiving a signal from a device
- set the device to listen to
- set the key and key state to listen to, setting the key to -1 makes the script trigger for any key.