Transform — Aspose.3D FOSS for Java

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

Transform kontrolē pozīciju, orientāciju un mērogu Node 3D ainas. Katram mezglam ir tieši viens Transform, piekļūst caur node.getTransform().

public class Transform extends A3DObject

Mezgla Transform piekļuve

import com.aspose.threed.Scene;

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

Methods

MethodsMethodsMethodsMethodsMethods
translationVector3getTranslation()setTranslation(Vector3)Pozīcijas nobīde no vecāka mezgla izcelsmes. Noklusējuma Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Nehomogēns mēroga koeficients katrai asij. Noklusējuma Vector3(1, 1, 1).
rotationQuaterniongetRotation()setRotation(Quaternion)Rotācija kā vienības kvaternions. Iestatot šo, tiek atjaunināti arī Eilera leņķi.
eulerAnglesVector3getEulerAngles()setEulerAngles(Vector3)Rotācija grādos kā (X, Y, Z) Eilera leņķi. Iestatot šo, tiek atjaunināta arī kvaterniona rotācija.
preRotationVector3getPreRotation()setPreRotation(Vector3)Eilera leņķi, kas tiek piemēroti pirms galvenās rotācijas (izmanto FBX struktūrās).
postRotationVector3getPostRotation()setPostRotation(Vector3)Eilera leņķi, kas tiek piemēroti pēc galvenās rotācijas.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)Tikai lokāla translācija: ietekmē ģeometriju, bet ne bērnu mezglus.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)Tikai lokāls mērogs: ietekmē ģeometriju, bet ne bērnu mezglus.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)Tikai lokāla rotācija: ietekmē ģeometriju, bet ne bērnu mezglus.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)Pilna kombinētā 4x4 transformācijas matrica. Kešota; pārskaitīta, kad mainās jebkurš komponents. Iestatot to, tas tiek sadalīts atpakaļ translācijā/mērogā/rotācijā.

Plūstošas iestatīšanas metodes

Visi iestatītāji atgriež this, ļaujot ķēdēt:

MethodsMethodsMethods
setTranslation(double tx, double ty, double tz)double, double, doubleIestatīt pozīciju.
setScale(double sx, double sy, double sz)double, double, doubleIestatīt mērogu.
setEulerAngles(double rx, double ry, double rz)double, double, doubleIestatīt rotāciju grādos.
setRotation(double rx, double ry, double rz, double rw)double, double, double, doubleIestatīt rotāciju kā kvaterniona (x, y, z, w).
setPreRotation(double rx, double ry, double rz)double, double, doubleIestatīt priekšrotāciju grādos.
setPostRotation(double rx, double ry, double rz)double, double, doubleIestatīt pēcrotošanu grādos.
setGeometricTranslation(double x, double y, double z)double, double, doubleIestatīt ģeometrisko translāciju.
setGeometricScaling(double sx, double sy, double sz)double, double, doubleIestatīt ģeometrisko mērogu.
setGeometricRotation(double rx, double ry, double rz)double, double, doubleIestatīt ģeometrisko rotāciju grādos.

Lietojuma piemēri

Pozicionēt mezglu

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ēt ar Eilera leņķiem

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ēt ar kvaterniona

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

Mērogot un pozicionēt kopā

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

Ģeometriska nobīde (Pivota nobīde)

Ģeometriskie transformācijas pārvieto ģeometriju attiecībā pret mezgla pivotu, neietekmējot bērnu mezglus; noderīgi, lai centrētu režģi mezgla ietvaros:

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

Nolasīt kombinēto Transformācijas matricu

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

Skatīt arī

 Latviešu