Transform — Aspose.3D FOSS for Java

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

Transform beheert de positie, oriëntatie en schaal van een Node in de 3D‑scène. Elke node heeft precies één Transform, toegankelijk via node.getTransform().

public class Transform extends A3DObject

Toegang tot de Transform van een Node

import com.aspose.threed.Scene;

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

Example

ExampleExampleExampleExampleExample
translationVector3getTranslation()setTranslation(Vector3)Positie‑offset ten opzichte van de oorsprong van de bovenliggende node. Standaard Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Niet‑uniforme schaalfactor per as. Standaard Vector3(1, 1, 1).
rotationQuaterniongetRotation()setRotation(Quaternion)Rotatie als een eenheidsquaternion. Het instellen hiervan werkt ook de Euler‑hoeken bij.
eulerAnglesVector3getEulerAngles()setEulerAngles(Vector3)Rotatie in graden als (X, Y, Z) Euler‑hoeken. Het instellen hiervan werkt ook de quaternion‑rotatie bij.
preRotationVector3getPreRotation()setPreRotation(Vector3)Euler‑hoeken toegepast vóór de hoofdrotatie (gebruikt in FBX‑rigs).
postRotationVector3getPostRotation()setPostRotation(Vector3)Euler‑hoeken toegepast na de hoofdrotatie.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)Alleen lokale translatie: beïnvloedt de geometrie maar niet de kindnodes.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)Alleen lokale schaal: beïnvloedt de geometrie maar niet de kindnodes.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)Alleen lokale rotatie: beïnvloedt de geometrie maar niet de kindnodes.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)De volledige gecombineerde 4x4‑transformatie matrix. In cache; opnieuw berekend wanneer een component verandert. Het instellen hiervan ontleedt terug naar translatie/schaal/rotatie.

Fluente setter-methoden

Alle setters retourneren this, waardoor chaining mogelijk is:

ExampleExampleExample
setTranslation(double tx, double ty, double tz)double, double, doublePositie instellen.
setScale(double sx, double sy, double sz)double, double, doubleSchaal instellen.
setEulerAngles(double rx, double ry, double rz)double, double, doubleRotatie instellen in graden.
setRotation(double rx, double ry, double rz, double rw)double, double, double, doubleRotatie instellen als een quaternion (x, y, z, w).
setPreRotation(double rx, double ry, double rz)double, double, doublePre-rotatie instellen in graden.
setPostRotation(double rx, double ry, double rz)double, double, doublePost-rotatie instellen in graden.
setGeometricTranslation(double x, double y, double z)double, double, doubleGeometrische translatie instellen.
setGeometricScaling(double sx, double sy, double sz)double, double, doubleGeometrische schaal instellen.
setGeometricRotation(double rx, double ry, double rz)double, double, doubleGeometrische rotatie instellen in graden.

Gebruikvoorbeeld

Node positioneren

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

Roteren met Euler-hoeken

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

Roteren met een 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

Schaal en positie samen

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

Geometrische offset (pivot-offset)

Geometrische transformaties verschuiven de geometrie ten opzichte van de pivot van de node zonder de kindnodes te beïnvloeden; handig om een mesh binnen zijn node te centreren:

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

Lees de gecombineerde Transform-matrix

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

Zie ook

 Nederlands