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 A3DObjectAccessing a Node’s Transform
import com.aspose.threed.Scene;
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");
Transform t = node.getTransform();Properties
| Property | Type | Getter | Setter | Description |
|---|---|---|---|---|
translation | Vector3 | getTranslation() | setTranslation(Vector3) | Position offset from the parent node’s origin. Default Vector3(0, 0, 0). |
scaling | Vector3 | getScaling() | setScaling(Vector3) | Non-uniform scale factor per axis. Default Vector3(1, 1, 1). |
rotation | Quaternion | getRotation() | setRotation(Quaternion) | Rotation as a unit quaternion. Setting this also updates Euler angles. |
eulerAngles | Vector3 | getEulerAngles() | setEulerAngles(Vector3) | Rotation in degrees as (X, Y, Z) Euler angles. Setting this also updates the quaternion rotation. |
preRotation | Vector3 | getPreRotation() | setPreRotation(Vector3) | Euler angles applied before the main rotation (used in FBX rigs). |
postRotation | Vector3 | getPostRotation() | setPostRotation(Vector3) | Euler angles applied after the main rotation. |
geometricTranslation | Vector3 | getGeometricTranslation() | setGeometricTranslation(Vector3) | Local-only translation: affects geometry but not child nodes. |
geometricScaling | Vector3 | getGeometricScaling() | setGeometricScaling(Vector3) | Local-only scale: affects geometry but not child nodes. |
geometricRotation | Vector3 | getGeometricRotation() | setGeometricRotation(Vector3) | Local-only rotation: affects geometry but not child nodes. |
transformMatrix | Matrix4 | getTransformMatrix() | 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:
| Method | Parameters | Description |
|---|---|---|
setTranslation(double tx, double ty, double tz) | double, double, double | Set position. |
setScale(double sx, double sy, double sz) | double, double, double | Set scale. |
setEulerAngles(double rx, double ry, double rz) | double, double, double | Set rotation in degrees. |
setRotation(double rx, double ry, double rz, double rw) | double, double, double, double | Set rotation as a quaternion (x, y, z, w). |
setPreRotation(double rx, double ry, double rz) | double, double, double | Set pre-rotation in degrees. |
setPostRotation(double rx, double ry, double rz) | double, double, double | Set post-rotation in degrees. |
setGeometricTranslation(double x, double y, double z) | double, double, double | Set geometric translation. |
setGeometricScaling(double sx, double sy, double sz) | double, double, double | Set geometric scale. |
setGeometricRotation(double rx, double ry, double rz) | double, double, double | Set 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 automaticallyScale 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