Skip to content
Alessandro Febretti edited this page Apr 28, 2015 · 5 revisions

[[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

Methods

Method(s)

Description

Basic

create(string name) static

Creates a scene node with the specified name.

string getName(), setName(string name)

Gets or sets the node name.

Transformation

setPosition(Vector3 pos), setPosition(float x, float y, float z), Vector3 getPosition()

Gets or sets the node position relative to its parent. The value can be specified as 3 floats or as a 3 object.

translate(Vector3 position, Space space), translate(float x, float y, float z, Space space)

Moves the node by the specified amount, using the reference frame specified in Space (see the Space subsection for details). The amount can be specified as 3 floats or as a 3 object.

setScale(Vector3 pos), setScale(float x, float y, float z), Vector3 getScale()

Gets and sets the node scale. The value can be specified as 3 floats or as a 3 object.

Quaternion getOrientation(), setOrientation(Quaternion orientation)

Gets and sets the node orientation (see ).

rotate(Vector3 axis, float angle, Space space)

Rotates the node around the specified 3 axis by angle radians, using the reference frame specified in Space (see the Space subsection for details).

yaw(float rads), pitch(float rads), roll(float rads)

Applies a yaw, pitch or roll to the node (in radians).

resetOrientation()

Resets the node orientation to identity (i.e. zero) orientation.

lookAt(Vector3 position, Vector3 upvector)

Makes the node face the specified position and orients the node Y axis to correspond to the passed up vector. See 3.

Reference Frame

Vector3 convertLocalToWorldPosition(Vector3 position)

Converts a 3 position from the local node reference frame to the global reference frame.

Vector3 convertWorldToLocalPosition(Vector3 position)

Converts a 3 position from the global reference frame to the local node reference frame.

Quaternion convertLocalToWorldOrientation(Quaternion orientation)

Converts a orientation from the local node reference frame to the global reference frame.

Quaternion convertWorldToLocalOrientation(Quaternion orientation)

Converts a orientation from the global reference frame to the local node reference frame.

Hierarchy

int numChildren()

Gets the number of children of this node.

SceneNode getChildByName(string name)

Finds a child by name.

SceneNode getChildByIndex(int index)

Gets a child by index. Note there is no guarantee the objects will be returned back in the same order they were added. If you need precise ordering, consider adding scene nodes to your own list.

addChild(SceneNode node)

Adds a child to this node.

removeChildByRef(SceneNode node)

Removes a child by reference.

removeChildByName(string name)

Removes a child by its name.

removeChildByIndex(int index)

Removes a child by its index.

SceneNode getParent()

Gets the node parent.

Visibility

bool isVisible(), setVisible(bool value)

Gets or sets the node visibility status. A node visibility does not influence children of the node, but only scene objects attached to the node itself. To change children visibility use setChildrenVisible instead.

setChildrenVisible(bool value)

Recursively sets the visibility of descendants of this node.

Bounding box

bool isBoundingBoxVisible(), setBoundingBoxVisible(bool value)

Vector3 getBoundMinimum(), Vector3 getBoundMaximum()

Gets the bounding box minimum or maximum points (as 3 points).

Vector3 getBoundCenter()

Gets the bounding box center as a 3 point.

float getBoundRadius()

Gets the bounding box radius.

Selection control

bool isSelected(), setSelected(bool value)

isSelectable(), setSelectable(bool value)

Camera

setFacingCamera(Camera camera) Camera getFacingCamera()

Makes the node face the specified (billboard mode). Pass None to disable billboard mode.

bool isFacingCameraFixedY(), setFacingCameraFixedY(bool value)

When set to True, Y axis for nodes facing camera will be fixed to the world Y axis. When set to false, the Y axis will follow the camera Y axis (This is the default mode).

Motion Capture

followTrackable(int trackabeId)

Starts following the motion-captured trackable trackableId.

setFollowOffset(Vector3 offset, Quaternion orientationOffset)

Sets the tracking position and orientation offset applied to this object, with respect to the motion captured trackable. (see 3, ).

unfollow()

Stops following a motion-captured trackable.

User Data

string getTag(), setTag(string tag)

Gets or sets the string tag for the node.

(v5.1) setFlag(uint bit)

Sets a custom flag bit on the node. NOTE: Flags from 1 << 16 to 1 << 31 are reserved for C++ modules.

(v5.1) unsetFlag(uint bit)

Unsets a custom flag bit on the node.

(v5.1) bool isFlagSet(uint bit)

Checks if a custom flag is set on the node.

Global functions

The following is a list of useful global functions related to scene node management # SceneNode getScene() # Returns the root of the scene.

querySceneRay(Vector3 origin, Vector3 dir, callback, [flags])

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.

hitNode(SceneNode node, Vector3 origin, Vector3 direction)

Computes a ray / scene node interesction. Returns a tuple with two elements: - Elements 0 is a boolean set to true if the ray interescts the node - Element 1 is a Vector3 storing the intersection position

The Space Enumeration

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

Examples

Basic

# 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)

Hierarchy, relative position, rotation around another node

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))

Simple node hit callback

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)

Picking and moving objects

# 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)

The hitNode function

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)
Clone this wiki locally