-
Notifications
You must be signed in to change notification settings - Fork 26
SceneNode
[[module omega | Python-Reference#module-omega]] wraps [omega::SceneNode](http://omegalib.googlecode.com/svn/refdocs/trunk/html/classomega_1_1_scene_node.html)
Last revision: ver. 5.1 - 10 December 2013
Base class for nodes in the scene graph
The following is a list of useful global functions related to scene node management
# SceneNode getScene()
#
Returns the root of the scene.
Performs a query on the scene using a ray defined by the origin
and dir
3 parameters. For each hit node, it invokes a callback function taking the node reference and distance to the origin as parameters.
The function accepts optional flags that control the query:
- QueryFlags.QuerySort
sorts the result nodes from closest to farthest.
- QueryFlags.QueryFirst
returns only one result.
Multiple flags can be used together, i.e. querySceneRay(a, b, func, QueryFlags.QuerySort | QueryFlags.QueryFirst)
NOTE: only nodes tagged as selectable (see Node.setSelectable
) will be considered for the query.
The Space
enumeration is used by some of the node methods to indicate what is the reference of the applied transformation. Space
specifies three values:
- Local
: the transformation is applied relative to the node current reference frame
- Parent
: the transformation is applied relative to the node parent reference frame
- World
: the transformation is applied relative to the world reference frame
# gets the root scene node
root = getEngine().getScene()
# prints the node position
print(root.getPosition()
root.setPosition(Vector3(0, 2, -2))
# scale is returned as a Vector3
scale = root.getScale()
scale.x = 0.1
root.setScale(scale)
# orientation is of Quaternion type
print(root.getOrientation())
# yaw, pitch roll are in radians
root.yaw(1)
from omega import *
from euclid import *
# needed for radians()
from math import *
a = SceneNode.create('a')
b = SceneNode.create('b')
a.addChild(b)
# set position of a relative to b
b.setPosition(Vector3(0,1,0))
# set position of a: after this, world position of b will be (1,1,0)
a.setPosition(Vector3(1,0,0))
# apply 90 degrees yaw to a: b will rotate around a's center (1,0,0)
a.yaw(radians(90))
node = SceneNode.create('node')
getScene().addChild(node)
node.setSelectable(true)
# attach some stuff to the node...
# [ ... ]
def queryCallback(node distance):
print("Node " + node.getName() + " hit at " + distance)
querySceneRay(Vector3f(0, 0, 0), Vector3f(0, 0, -1), queryCallback)
# Create multiple objects, do setSelectable(True) on them
# to make them selectable in ray queries
# [...] Skipping code
# Create an interactor, this will be used to move objects once they
# are selected
interactor = ToolkitUtils.setupInteractor('config/interactor')
# This function is called when an object is picked.
# Just set the object as the active movable object by passing it
# to the interactor
def onObjectSelected(node, distance):
interactor.setSceneNode(node)
# Event function: on pointer events when the left button is pressed,
# do picking.
def onEvent():
e = getEvent()
if(e.getServiceType() == ServiceType.Pointer):
# When the confirm button is pressed:
if(e.isButtonDown(EventFlags.Button1)):
r = getRayFromEvent(e)
if(r[0]): querySceneRay(r[1], r[2], onObjectSelected)
setEventFunction(onEvent)
cube = BoxShape(1,1,1)
# This event handler changes a cube color when it's clicked.
def onEvent():
e = getEvent()
if(e.isButtonDown(EventFlags.Button2)):
r = getRayFromEvent(e)
hitData = hitNode(cube, r[1], r[2])
if(hitData[0]):
cube.setEffect('colored -e red')
setEventFunction(onEvent)