Transform — Aspose.3D FOSS for Java

Package: com.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.getTransform().

public class Transform extends A3DObject

Accessing a Node’s Transform

import com.aspose.threed.Scene;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");
Transform t = node.getTransform();

Properties

PropertyTypeGetterSetterDescription
translationVector3getTranslation()setTranslation(Vector3)Position offset from the parent node’s origin. Default Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Non-uniform scale factor per axis. Default Vector3(1, 1, 1).
rotationQuaterniongetRotation()setRotation(Quaternion)Rotation as a unit quaternion. Setting this also updates Euler angles.
eulerAnglesVector3getEulerAngles()setEulerAngles(Vector3)Rotation in degrees as (X, Y, Z) Euler angles. Setting this also updates the quaternion rotation.
preRotationVector3getPreRotation()setPreRotation(Vector3)Euler angles applied before the main rotation (used in FBX rigs).
postRotationVector3getPostRotation()setPostRotation(Vector3)Euler angles applied after the main rotation.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)Local-only translation: affects geometry but not child nodes.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)Local-only scale: affects geometry but not child nodes.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)Local-only rotation: affects geometry but not child nodes.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)The full combined 4x4 transformation matrix. Cached; recomputed when any component changes. Setting it decomposes back to translation/scaling/rotation.

Fluent Setter Methods

All setters return this, enabling chaining:

MethodParametersDescription
setTranslation(double tx, double ty, double tz)double, double, doubleSet position.
setScale(double sx, double sy, double sz)double, double, doubleSet scale.
setEulerAngles(double rx, double ry, double rz)double, double, doubleSet rotation in degrees.
setRotation(double rx, double ry, double rz, double rw)double, double, double, doubleSet rotation as a quaternion (x, y, z, w).
setPreRotation(double rx, double ry, double rz)double, double, doubleSet pre-rotation in degrees.
setPostRotation(double rx, double ry, double rz)double, double, doubleSet post-rotation in degrees.
setGeometricTranslation(double x, double y, double z)double, double, doubleSet geometric translation.
setGeometricScaling(double sx, double sy, double sz)double, double, doubleSet geometric scale.
setGeometricRotation(double rx, double ry, double rz)double, double, doubleSet geometric rotation in degrees.

Usage Examples

Position a Node

import com.aspose.threed.Scene;
import com.aspose.threed.*;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");

// Using fluent setters
node.getTransform().setTranslation(5.0, 0.0, -3.0);

// Or via property setter
node.getTransform().setTranslation(new Vector3(5.0, 0.0, -3.0));

Rotate with Euler Angles

import com.aspose.threed.Scene;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("rotated");

// Rotate 45 degrees around Y axis
node.getTransform().setEulerAngles(0.0, 45.0, 0.0);

// Chain multiple operations
node.getTransform()
    .setTranslation(2.0, 0.0, 0.0)
    .setScale(2.0, 2.0, 2.0);

Rotate with a Quaternion

import com.aspose.threed.Scene;
import com.aspose.threed.*;
import com.aspose.threed.*;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("q-rotated");

// 90 degrees rotation around the Y axis
double halfAngle = Math.toRadians(45);   // half the total rotation
Quaternion q = new Quaternion(Math.cos(halfAngle), 0.0, Math.sin(halfAngle), 0.0);
node.getTransform().setRotation(q);

System.out.println("Euler: " + node.getTransform().getEulerAngles());   // synced automatically

Scale and Position Together

import com.aspose.threed.Scene;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("big-offset");

node.getTransform()
    .setTranslation(10.0, 0.0, 0.0)
    .setScale(3.0, 3.0, 3.0)
    .setEulerAngles(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:

import com.aspose.threed.Scene;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("centered-mesh");

// Shift the mesh half a unit down so its base sits at y=0
node.getTransform().setGeometricTranslation(0.0, -0.5, 0.0);

Read the Combined Transform Matrix

import com.aspose.threed.Scene;
import com.aspose.threed.*;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("m");
node.getTransform().setTranslation(1.0, 2.0, 3.0);
node.getTransform().setEulerAngles(0.0, 45.0, 0.0);

Matrix4 m = node.getTransform().getTransformMatrix();
System.out.println(m.getClass().getName());   // com.aspose.threed.Matrix4

See Also