Transform — Aspose.3D FOSS for Java

Methods: com.aspose.threed (aspose-3d-foss)

Transform steuert die Position, Orientierung und Skalierung eines Node in der 3D‑Szene. Jeder Knoten hat genau einen Transform, zugegriffen über node.getTransform().

public class Transform extends A3DObject

Zugriff auf das Transform eines Knotens

import com.aspose.threed.Scene;

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

Methods

MethodsMethodsMethodsMethodsMethods
translationVector3getTranslation()setTranslation(Vector3)Positionsversatz vom Ursprung des übergeordneten Knotens. Standard Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Nicht-uniformer Skalierungsfaktor pro Achse. Standard Vector3(1, 1, 1).
rotationQuaterniongetRotation()setRotation(Quaternion)Rotation als Einheitsquaternion. Das Setzen aktualisiert auch die Euler-Winkel.
eulerAnglesVector3getEulerAngles()setEulerAngles(Vector3)Rotation in Grad als (X, Y, Z) Euler-Winkel. Das Setzen aktualisiert auch die Quaternion-Rotation.
preRotationVector3getPreRotation()setPreRotation(Vector3)Euler-Winkel, die vor der Hauptrotation angewendet werden (verwendet in FBX‑Rigs).
postRotationVector3getPostRotation()setPostRotation(Vector3)Euler-Winkel, die nach der Hauptrotation angewendet werden.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)Nur lokale Translation: wirkt sich auf die Geometrie aus, nicht jedoch auf Kindknoten.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)Nur lokale Skalierung: wirkt sich auf die Geometrie aus, nicht jedoch auf Kindknoten.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)Nur lokale Rotation: wirkt sich auf die Geometrie aus, nicht jedoch auf Kindknoten.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)Die vollständige kombinierte 4x4-Transformationsmatrix. Gepuffert; wird neu berechnet, wenn sich irgendeine Komponente ändert. Beim Setzen wird sie wieder in Translation/Skalierung/Rotation zerlegt.

Fluent-Setter-Methoden

Alle Setter geben zurück this, was Verkettung ermöglicht:

MethodsMethodsMethods
setTranslation(double tx, double ty, double tz)double, double, doublePosition setzen.
setScale(double sx, double sy, double sz)double, double, doubleSkalierung setzen.
setEulerAngles(double rx, double ry, double rz)double, double, doubleRotation in Grad setzen.
setRotation(double rx, double ry, double rz, double rw)double, double, double, doubleRotation als Quaternion setzen (x, y, z, w).
setPreRotation(double rx, double ry, double rz)double, double, doubleStellen Sie die Vorrotation in Grad ein.
setPostRotation(double rx, double ry, double rz)double, double, doubleStellen Sie die Nachrotation in Grad ein.
setGeometricTranslation(double x, double y, double z)double, double, doubleStellen Sie die geometrische Translation ein.
setGeometricScaling(double sx, double sy, double sz)double, double, doubleStellen Sie die geometrische Skalierung ein.
setGeometricRotation(double rx, double ry, double rz)double, double, doubleStellen Sie die geometrische Rotation in Grad ein.

Anwendungsbeispiele

Einen Knoten positionieren

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));

Rotation mit Euler-Winkeln

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);

Rotation mit einem 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

Skalierung und Position gemeinsam

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);

Geometrischer Offset (Pivot-Offset)

Geometrische Transformationen verschieben die Geometrie relativ zum Pivot des Knotens, ohne die Kindknoten zu beeinflussen; nützlich, um ein Mesh innerhalb seines Knotens zu zentrieren:

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);

Die kombinierte Transformationsmatrix auslesen

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

Siehe auch

 Deutsch