Transform — Aspose.3D FOSS for Java
Enumerations: com.aspose.threed (aspose-3d-foss)
Transform controlla la posizione, l’orientamento e la scala di un Node nella scena 3D. Ogni nodo ha esattamente uno Transform, accessibile tramite node.getTransform().
public class Transform extends A3DObjectAccesso al Transform di un Node
import com.aspose.threed.Scene;
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");
Transform t = node.getTransform();Enumerations
| Enumerations | Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|---|
translation | Vector3 | getTranslation() | setTranslation(Vector3) | Offset di posizione dall’origine del nodo genitore. Predefinito Vector3(0, 0, 0). |
scaling | Vector3 | getScaling() | setScaling(Vector3) | Fattore di scala non uniforme per asse. Predefinito Vector3(1, 1, 1). |
rotation | Quaternion | getRotation() | setRotation(Quaternion) | Rotazione come quaternion unitario. Impostare questo aggiorna anche gli angoli di Eulero. |
eulerAngles | Vector3 | getEulerAngles() | setEulerAngles(Vector3) | Rotazione in gradi come angoli di Eulero (X, Y, Z). Impostare questo aggiorna anche la rotazione quaternion. |
preRotation | Vector3 | getPreRotation() | setPreRotation(Vector3) | Angoli di Eulero applicati prima della rotazione principale (usati nei rig FBX). |
postRotation | Vector3 | getPostRotation() | setPostRotation(Vector3) | Angoli di Eulero applicati dopo la rotazione principale. |
geometricTranslation | Vector3 | getGeometricTranslation() | setGeometricTranslation(Vector3) | Traslazione solo locale: influisce sulla geometria ma non sui nodi figli. |
geometricScaling | Vector3 | getGeometricScaling() | setGeometricScaling(Vector3) | Scala solo locale: influisce sulla geometria ma non sui nodi figli. |
geometricRotation | Vector3 | getGeometricRotation() | setGeometricRotation(Vector3) | Rotazione solo locale: influisce sulla geometria ma non sui nodi figli. |
transformMatrix | Matrix4 | getTransformMatrix() | setTransformMatrix(Matrix4) | La matrice di trasformazione 4x4 completa combinata. Messa in cache; ricalcolata quando qualsiasi componente cambia. Impostarla la decompone nuovamente in traslazione/scalatura/rotazione. |
Metodi setter fluent
Tutti i setter restituiscono this, consentendo il chaining:
| Enumerations | Enumerations | Enumerations |
|---|---|---|
setTranslation(double tx, double ty, double tz) | double, double, double | Imposta posizione. |
setScale(double sx, double sy, double sz) | double, double, double | Imposta scala. |
setEulerAngles(double rx, double ry, double rz) | double, double, double | Imposta rotazione in gradi. |
setRotation(double rx, double ry, double rz, double rw) | double, double, double, double | Imposta rotazione come quaternione (x, y, z, w). |
setPreRotation(double rx, double ry, double rz) | double, double, double | Imposta pre-rotazione in gradi. |
setPostRotation(double rx, double ry, double rz) | double, double, double | Imposta post-rotazione in gradi. |
setGeometricTranslation(double x, double y, double z) | double, double, double | Imposta traslazione geometrica. |
setGeometricScaling(double sx, double sy, double sz) | double, double, double | Imposta scala geometrica. |
setGeometricRotation(double rx, double ry, double rz) | double, double, double | Imposta rotazione geometrica in gradi. |
Esempi di utilizzo
Posizionare un 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));Ruotare con angoli di Eulero
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);Ruotare con 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 automaticallyScala e posizione insieme
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);Offset geometrico (Offset del pivot)
Le trasformazioni geometriche spostano la geometria rispetto al pivot del nodo senza influenzare i nodi figli; utile per centrare una mesh all’interno del suo nodo:
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);Leggi la matrice Transform combinata
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