Node3D

The base of all objects which can be aggregated to describe a 3D scene. Every Node3D element contains the local and world transformations in 3D space. Every node has one parent node and a list of child nodes. Every transformation such as, position, rotation, or scale, also affects the child objects of a node.

The following code example shows how nodes can be created and combined to describe a simple scene with the following node hierarchy:

Create Hierarchy
#     root
#     /  \
#   c_1, c_2
#       /   \
#    c_2_1  c_2_2

root = Node3D("root")
c_1 = Node3D("child_1")
c_2 = Node3D("child_2")
c_2_1 = Node3D("child_2_1")
c_2_2 = Node3D("child_2_2")
root.add(c_1)
root.add(c_2)
c_2.add(c_2_1)
c_2.add(c_2_2)

All Node3D objects can now be individually transformed in 3D space.

Change position of root node
root.local_position = Vector([2,1,1])

After executing the code above, all child nodes and the root node itself are moved to the position of the root node.

Change child node local position
c_2.local_position += Vector([1,0,0])

The root node and node c_1 are still at position [2,1,1] since they are not affected by the transforms of the c_2 child node. Both child nodes c_2_1 and c_2_2 and node c_2 itself are shifted 1 unit towards the local x-axis away from the root node. This means that these nodes are now at world coordinates [3,1,1].

class pysg.node_3d.Node3D(name: str = 'New Node')

Node element of scene graph (tree structure).

Parameters:name – Name for string representation.
add(node_3d: pysg.node_3d.Node3D) → None

Adds another node as child of this node. It is important to note, that the world position and rotation will remain the same of the added child, but all its local transforms will be updated relative to the new parent.

Parameters:node_3d (Node3D) – The child node which shall be added to the scene graph.
get_leaf_nodes() → list

Recursively iterate over all children and return list with all leaf Node3Ds (no more children).

Returns:List of all children with no more child nodes. Type of list elements is Node3D.
Return type:list
local_euler_angles

Local rotation in euler angle representation as Vector of length 3. Internally quaternions are used. The used rotation order is YZX.

See also

Please have a look at the rotations section for more details.

local_matrix

Local translation matrix (read only).

Returns:4x4 local translation matrix of the current node.
Return type:Matrix44
local_position

The local position is relative to the transform of the parent node.

Note

The return value is a copy of the original vector and can not be edited directly. This means that code like node.local_position.x += 2 will not work as you might expect it to!

Returns:Position of node relative to parent node.
Return type:Vector3
local_quaternion

The local rotation as quaternion.

Note

The return value is a copy of the original quaternion and can not be edited directly. Use the quaternion setter instead.

Returns:Quaternion rotation relative to parent node.
Return type:Quaternion
parent

The parent of the current node element.

Returns:Parent node.
Return type:Node3D
remove(node_3d: pysg.node_3d.Node3D) → None

Remove a child from the scene graph.

Parameters:node_3d (Node3D) – The child node which shall be removed from the scene graph.
rotate_x(angle: float, local_space: bool = True) → None

Rotate object around its x-axis.

Parameters:
  • angle – The rotation angle in degrees.
  • local_space – If True rotate in local coordinate system. Otherwise in world space.
rotate_y(angle: float, local_space: bool = True) → None

Rotate object around its y-axis.

Parameters:
  • angle – The rotation angle in degrees.
  • local_space – If True rotate in local coordinate system. Otherwise in world space.
rotate_z(angle: float, local_space: bool = True) → None

Rotate object around its z-axis.

Parameters:
  • angle – The rotation angle in degrees.
  • local_space – If True rotate in local coordinate system. Otherwise in world space.
scale

Local scale of current node.

Returns:X, Y and Z scale as Vector3.
Return type:Vector3
update_world_matrix() → None

Updates the world matrix for a given node in the render scene graph.

world_euler_angles()

World rotation in euler angle representation as Vector of length 3. Internally quaternions are used. The used rotation order is YZX.

See also

Please have a look at the rotations section for more details.

world_matrix

World translation matrix (read only).

Returns:4x4 translation matrix of the current node in world space.
Return type:Matrix44
world_position

The world position of a node.

Note

The return value is a copy of the original vector and can not be edited directly. This means that code like node.world_position.x += 2 will not work as you might expect it to!

Returns:Position of node in world space.
Return type:Vector3
world_quaternion

The world rotation as quaternion.

Note

The return value is a copy of the original quaternion and can not be edited directly. Use the quaternion setter instead.

Returns:Rotation in world space as quaternion.
Return type:Quaternion