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 A3DObject

Accesarea Transform-ului unui nod

import com.aspose.threed.Scene;

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

Example

ExampleExampleExampleExampleExample
translationVector3getTranslation()setTranslation(Vector3)Deplasare de poziție față de originea nodului părinte. Implicit Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Factor de scară neuniform pe axă. Implicit Vector3(1, 1, 1).
rotationQuaterniongetRotation()setRotation(Quaternion)Rotație ca un quaternion unitate. Setarea acesteia actualizează și unghiurile Euler.
eulerAnglesVector3getEulerAngles()setEulerAngles(Vector3)Rotație în grade ca unghiuri Euler (X, Y, Z). Setarea acesteia actualizează și rotația quaternion.
preRotationVector3getPreRotation()setPreRotation(Vector3)Unghiurile Euler aplicate înainte de rotația principală (utilizate în rig-urile FBX).
postRotationVector3getPostRotation()setPostRotation(Vector3)Unghiurile Euler aplicate după rotația principală.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)Translație doar locală: afectează geometria, dar nu nodurile copil.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)Scalare doar locală: afectează geometria, dar nu nodurile copil.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)Rotire doar locală: afectează geometria, dar nu nodurile copil.
transformMatrixMatrix4getTransformMatrix()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:

ExampleExampleExample
setTranslation(double tx, double ty, double tz)double, double, doubleSetează poziția.
setScale(double sx, double sy, double sz)double, double, doubleSetează scalarea.
setEulerAngles(double rx, double ry, double rz)double, double, doubleSetează rotirea în grade.
setRotation(double rx, double ry, double rz, double rw)double, double, double, doubleSetează rotirea ca un quaternion (x, y, z, w).
setPreRotation(double rx, double ry, double rz)double, double, doubleSetează pre-rotirea în grade.
setPostRotation(double rx, double ry, double rz)double, double, doubleSetează post-rotirea în grade.
setGeometricTranslation(double x, double y, double z)double, double, doubleSetați translația geometrică.
setGeometricScaling(double sx, double sy, double sz)double, double, doubleSetați scala geometrică.
setGeometricRotation(double rx, double ry, double rz)double, double, doubleSetaț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 automatically

Scalare ș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

Vezi și

 Română