Transform — Aspose.3D FOSS for Java
Example: com.aspose.threed (aspose-3d-foss)
Transform ovláda polohu, orientáciu a mierku Node v 3D scéne. Každý uzol má presne jeden Transform, prístupný cez node.getTransform().
public class Transform extends A3DObjectZískanie Transform uzla
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) | Posun polohy od pôvodu rodičovského uzla. Predvolená Vector3(0, 0, 0). |
scaling | Vector3 | getScaling() | setScaling(Vector3) | Nerovnomerný faktor mierky na os. Predvolený Vector3(1, 1, 1). |
rotation | Quaternion | getRotation() | setRotation(Quaternion) | Rotácia ako jednotkový kvaternion. Nastavením tohto sa tiež aktualizujú Eulerove uhly. |
eulerAngles | Vector3 | getEulerAngles() | setEulerAngles(Vector3) | Rotácia v stupňoch ako Eulerove uhly (X, Y, Z). Nastavením tohto sa tiež aktualizuje rotácia kvaternionu. |
preRotation | Vector3 | getPreRotation() | setPreRotation(Vector3) | Eulerove uhly aplikované pred hlavnou rotáciou (používané v FBX rigoch). |
postRotation | Vector3 | getPostRotation() | setPostRotation(Vector3) | Eulerove uhly aplikované po hlavnej rotácii. |
geometricTranslation | Vector3 | getGeometricTranslation() | setGeometricTranslation(Vector3) | Lokálny posun: ovplyvňuje geometriu, ale nie podriadené uzly. |
geometricScaling | Vector3 | getGeometricScaling() | setGeometricScaling(Vector3) | Lokálna mierka: ovplyvňuje geometriu, ale nie podriadené uzly. |
geometricRotation | Vector3 | getGeometricRotation() | setGeometricRotation(Vector3) | Lokálna rotácia: ovplyvňuje geometriu, ale nie podriadené uzly. |
transformMatrix | Matrix4 | getTransformMatrix() | setTransformMatrix(Matrix4) | Celá kombinovaná 4x4 transformačná matica. Uložená v cache; prepočítaná, keď sa zmení akákoľvek zložka. Nastavením sa rozloží späť na posun/mierku/rotáciu. |
Plynulé metódy nastavenia
Všetky settery vracajú this, čo umožňuje reťazenie:
| Example | Example | Example |
|---|---|---|
setTranslation(double tx, double ty, double tz) | double, double, double | Nastaviť polohu. |
setScale(double sx, double sy, double sz) | double, double, double | Nastaviť mierku. |
setEulerAngles(double rx, double ry, double rz) | double, double, double | Nastaviť rotáciu v stupňoch. |
setRotation(double rx, double ry, double rz, double rw) | double, double, double, double | Nastaviť rotáciu ako kvaternion (x, y, z, w). |
setPreRotation(double rx, double ry, double rz) | double, double, double | Nastavte predrotáciu v stupňoch. |
setPostRotation(double rx, double ry, double rz) | double, double, double | Nastavte postrotáciu v stupňoch. |
setGeometricTranslation(double x, double y, double z) | double, double, double | Nastavte geometrický posun. |
setGeometricScaling(double sx, double sy, double sz) | double, double, double | Nastavte geometrickú mierku. |
setGeometricRotation(double rx, double ry, double rz) | double, double, double | Nastavte geometrickú rotáciu v stupňoch. |
Príklady použitia
Pozícia uzla
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));Rotácia pomocou Eulerových uhlov
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);Rotácia pomocou 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 automaticallyMierka a pozícia spoločne
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);Geometrický posun (Pivot Offset)
Geometrické transformácie posúvajú geometriu vzhľadom na pivot uzla bez ovplyvnenia podriadených uzlov; užitočné pre vycentrovanie siete v rámci jej uzla:
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);Prečítajte kombinovanú transformačnú maticu
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