Transform — Aspose.3D FOSS for Python API Reference

Package: aspose.threed (aspose-3d-foss)

Transform controls the position, orientation, and scale of a Node in the 3D scene. Every node has exactly one Transform, accessed via node.transform.

class Transform(A3DObject):

Accessing a Node’s Transform

from aspose.threed import Scene

scene = Scene()
node = scene.root_node.create_child_node("box")
t = node.transform     # Transform object

Properties

PropertyTypeDescription
translationVector3Position offset from the parent node’s origin. Default Vector3(0, 0, 0).
scalingVector3Non-uniform scale factor per axis. Default Vector3(1, 1, 1).
rotationQuaternionRotation as a unit quaternion. Setting this also updates euler_angles.
euler_anglesVector3Rotation in degrees as (X, Y, Z) Euler angles. Setting this also updates rotation.
pre_rotationVector3Euler angles applied before the main rotation (used in FBX rigs).
post_rotationVector3Euler angles applied after the main rotation.
geometric_translationVector3Local-only translation: affects geometry but not child nodes.
geometric_scalingVector3Local-only scale: affects geometry but not child nodes.
geometric_rotationVector3Local-only rotation: affects geometry but not child nodes.
transform_matrixMatrix4The full combined 4×4 transformation matrix. Cached; recomputed when any component changes. Setting it decomposes back to translation/scaling/rotation.

Fluent Setter Methods

All setters return self, enabling chaining:

MethodParametersDescription
set_translation(tx, ty, tz)float, float, floatSet position.
set_scale(sx, sy, sz)float, float, floatSet scale.
set_euler_angles(rx, ry, rz)float, float, floatSet rotation in degrees.
set_rotation(rw, rx, ry, rz)float, float, float, floatSet rotation as a quaternion (w, x, y, z).
set_pre_rotation(rx, ry, rz)float, float, floatSet pre-rotation in degrees.
set_post_rotation(rx, ry, rz)float, float, floatSet post-rotation in degrees.
set_geometric_translation(x, y, z)float, float, floatSet geometric translation.
set_geometric_scaling(sx, sy, sz)float, float, floatSet geometric scale.
set_geometric_rotation(rx, ry, rz)float, float, floatSet geometric rotation in degrees.

Usage Examples

Position a Node

from aspose.threed import Scene

scene = Scene()
node = scene.root_node.create_child_node("box")

# Using fluent setters
node.transform.set_translation(5.0, 0.0, -3.0)

# Or via property assignment
from aspose.threed.utilities import Vector3
node.transform.translation = Vector3(5.0, 0.0, -3.0)

Rotate with Euler Angles

from aspose.threed import Scene

scene = Scene()
node = scene.root_node.create_child_node("rotated")

# Rotate 45° around Y axis
node.transform.set_euler_angles(0.0, 45.0, 0.0)

# Chain multiple operations
node.transform.set_translation(2.0, 0.0, 0.0).set_scale(2.0, 2.0, 2.0)

Rotate with a Quaternion

from aspose.threed import Scene
from aspose.threed.utilities import Quaternion, Vector3
import math

scene = Scene()
node = scene.root_node.create_child_node("q-rotated")

# 90° rotation around the Y axis
half_angle = math.radians(45)   # half the total rotation
q = Quaternion(math.cos(half_angle), 0.0, math.sin(half_angle), 0.0)
node.transform.rotation = q

print(f"Euler: {node.transform.euler_angles}")   # synced automatically

Scale and Position Together

from aspose.threed import Scene

scene = Scene()
node = scene.root_node.create_child_node("big-offset")

(node.transform
    .set_translation(10.0, 0.0, 0.0)
    .set_scale(3.0, 3.0, 3.0)
    .set_euler_angles(0.0, 90.0, 0.0))

Geometric Offset (Pivot Offset)

Geometric transforms shift the geometry relative to the node’s pivot without affecting child nodes; useful for centering a mesh within its node:

from aspose.threed import Scene

scene = Scene()
node = scene.root_node.create_child_node("centered-mesh")

# Shift the mesh half a unit down so its base sits at y=0
node.transform.set_geometric_translation(0.0, -0.5, 0.0)

Read the Combined Transform Matrix

from aspose.threed import Scene

scene = Scene()
node = scene.root_node.create_child_node("m")
node.transform.set_translation(1.0, 2.0, 3.0).set_euler_angles(0.0, 45.0, 0.0)

m = node.transform.transform_matrix
print(type(m))  # <class 'aspose.threed.utilities.Matrix4'>

See Also