-
Notifications
You must be signed in to change notification settings - Fork 20
CreateScene
To create an empty scene just click the first toolbar button, choose a place to save it and start authoring!
Go to the Scene tab and then on Scripting, there you can start scripting you application logic in Python.
A new scene comes with a script called init which contains:
def init():
import VR
if hasattr(VR, 'scene'): VR.scene.destroy()
VR.scene = VR.Object('scene', 'light')
Appart from those two lines there is nothing special about this script. To add or remove scripts use the small toolbar above the editor.
Back to the initial script.
The first line import VR
is added to every new script, you can remove it if you want to.
The VR module contains the python bindings to every feature of PolyVR.
All available bindings are described in a documentation widget available through the toolbar ('?' icon).
The other two lines are quite useful for every application.
When executed, the last line creates an object called scene
.
This object is not just a local variable, but it is added to the global VR context.
This allows other scripts to access it directly.
The line before checks if the VR modules already has an object called scene
and destroys it if true.
This is a simple mechanism to fully reset and rebuild your scene, a typical init script.
To launch the script on startup just add a on_scene_load
trigger
To create your first object, create a geometry, define it as a box primitive and position it in space:
g = VR.Geometry('myFirstBox') # create a new geometry
VR.scene.addChild(g) # attach the geometry to the scene object
g.setPrimitive('Box 2 2 2 1 1 1') # width, height, depth, subdivisions in x y z
g.setTransform([0,0,0], [0,0,-1], [0,1,0]) # position, direction (local -z), up (local y)
Every new object has to be attached to another node of the scenegraph.
A full list of available primitives and their parameters can be found in the documentation of setPrimitive
.
You can play around with the parameters and the object transformation.
Add more objects to make your scene more complex
To quickly add some color use:
g.setColor('red') # shortcut to add a new colored material.
More advanced styling of the object surface is addressed in the material guide
To enable a simple interaction with your object you can set it as pickable. This allows the user to drag and drop it with any pointing device (mouse or VR controller).
g.setPickable(True)
For more complex interactions with your scene take a look at device triggered scripts. Or you can add animations to your scene. If you are new to Application Programming we recommend continuing with the basic concepts of a scene-graph, the core data structure of your virtual scene.
Here follows a script that summarizes the above:
def init():
import VR
if hasattr(VR, 'scene'): VR.scene.destroy()
VR.scene = VR.Object('scene', 'light')
def addObject(name, color, position):
g = VR.Geometry(name) # create a new geometry
VR.scene.addChild(g) # attach the geometry to the scene object
g.setPrimitive('Box 2 2 2 1 1 1') # width, height, depth, subdivisions in x y z
g.setTransform(position, [0,0,-1], [0,1,0]) # position, direction (local -z), up (local y)
g.setPickable(True)
g.setColor(color) # shortcut to add a new colored material.
return g
addObject('box1', 'red', [-3,0,-3])
addObject('box2', 'green', [0,0,-3])
addObject('box3', 'blue', [3,0,-3])