Transform — Aspose.3D FOSS for Java
Example: com.aspose.threed (aspose-3d-foss)
Transform controlează poziția, orientarea și scară unui Node în scena 3D. Fiecare nod are exact unul Transform, accesat prin node.getTransform().
public class Transform extends A3DObjectAccesarea Transform-ului unui nod
import com.aspose.threed.Scene;
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");
Transform t = node.getTransform();Example
| Example | Example | Example | Example | Example |
|---|---|---|---|---|
translation | Vector3 | getTranslation() | setTranslation(Vector3) | Deplasare de poziție față de originea nodului părinte. Implicit Vector3(0, 0, 0). |
scaling | Vector3 | getScaling() | setScaling(Vector3) | Factor de scară neuniform pe axă. Implicit Vector3(1, 1, 1). |
rotation | Quaternion | getRotation() | setRotation(Quaternion) | Rotație ca un quaternion unitate. Setarea acesteia actualizează și unghiurile Euler. |
eulerAngles | Vector3 | getEulerAngles() | setEulerAngles(Vector3) | Rotație în grade ca unghiuri Euler (X, Y, Z). Setarea acesteia actualizează și rotația quaternion. |
preRotation | Vector3 | getPreRotation() | setPreRotation(Vector3) | Unghiurile Euler aplicate înainte de rotația principală (utilizate în rig-urile FBX). |
postRotation | Vector3 | getPostRotation() | setPostRotation(Vector3) | Unghiurile Euler aplicate după rotația principală. |
geometricTranslation | Vector3 | getGeometricTranslation() | setGeometricTranslation(Vector3) | Translație doar locală: afectează geometria, dar nu nodurile copil. |
geometricScaling | Vector3 | getGeometricScaling() | setGeometricScaling(Vector3) | Scalare doar locală: afectează geometria, dar nu nodurile copil. |
geometricRotation | Vector3 | getGeometricRotation() | setGeometricRotation(Vector3) | Rotire doar locală: afectează geometria, dar nu nodurile copil. |
transformMatrix | Matrix4 | getTransformMatrix() | setTransformMatrix(Matrix4) | Matricea completă combinată 4x4 a transformării. Stocată în cache; recalculată când se modifică orice componentă. Setarea ei o descompune înapoi în translație/scalare/rotire. |
Metode Setter fluent
Toți setatorii returnează this, permițând înlănțuirea:
| Example | Example | Example |
|---|---|---|
setTranslation(double tx, double ty, double tz) | double, double, double | Setează poziția. |
setScale(double sx, double sy, double sz) | double, double, double | Setează scalarea. |
setEulerAngles(double rx, double ry, double rz) | double, double, double | Setează rotirea în grade. |
setRotation(double rx, double ry, double rz, double rw) | double, double, double, double | Setează rotirea ca un quaternion (x, y, z, w). |
setPreRotation(double rx, double ry, double rz) | double, double, double | Setează pre-rotirea în grade. |
setPostRotation(double rx, double ry, double rz) | double, double, double | Setează post-rotirea în grade. |
setGeometricTranslation(double x, double y, double z) | double, double, double | Setați translația geometrică. |
setGeometricScaling(double sx, double sy, double sz) | double, double, double | Setați scala geometrică. |
setGeometricRotation(double rx, double ry, double rz) | double, double, double | Setați rotația geometrică în grade. |
Exemple de utilizare
Poziționează un nod
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));Rotează cu unghiuri Euler
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);Rotează cu un 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 automaticallyScalare și poziționare împreună
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);Compensare geometrică (Offset pivot)
Transformările geometrice mută geometria în raport cu pivotul nodului fără a afecta nodurile copil; util pentru centrare unui mesh în interiorul nodului său:
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);Citește matricea Transform combinată
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