Transform — Aspose.3D FOSS for Java

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

Transform valdo padėtį, orientaciją ir mastelį Node 3D scenoje. Kiekvienas mazgas turi lygiai vieną Transform, pasiekiamą per node.getTransform().

public class Transform extends A3DObject

Mazgo Transform prieiga

import com.aspose.threed.Scene;

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

Example

ExampleExampleExampleExampleExample
translationVector3getTranslation()setTranslation(Vector3)Padėties poslinkis nuo tėvo mazgo pradžios. Numatyta Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Nelygus mastelio koeficientas pagal ašį. Numatyta Vector3(1, 1, 1).
rotationQuaterniongetRotation()setRotation(Quaternion)Sukimas kaip vienetinis kvaternionas. Nustatant šį parametrą taip pat atnaujinami Eulerio kampai.
eulerAnglesVector3getEulerAngles()setEulerAngles(Vector3)Sukimas laipsniais kaip (X, Y, Z) Eulerio kampai. Nustatant šį parametrą taip pat atnaujinamas kvaternioninis sukimas.
preRotationVector3getPreRotation()setPreRotation(Vector3)Eulerio kampai taikomi prieš pagrindinį sukimą (naudojama FBX rig’uose).
postRotationVector3getPostRotation()setPostRotation(Vector3)Eulerio kampai taikomi po pagrindinio sukimo.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)Tik vietinis perkėlimas: veikia geometriją, bet ne vaikų mazgus.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)Tik vietinis mastelis: veikia geometriją, bet ne vaikų mazgus.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)Tik vietinis sukimas: veikia geometriją, bet ne vaikų mazgus.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)Visas sujungtas 4x4 transformacijos matricos. Talpinama podėlyje; perskaičiuojama, kai bet kuris komponentas pasikeičia. Nustatant ją, ji išskaidoma atgal į perkėlimą/mastelį/sukimą.

Sklandūs nustatymo metodai

Visi nustatymo metodai grąžina this, leidžiant grandinti:

ExampleExampleExample
setTranslation(double tx, double ty, double tz)double, double, doubleNustatyti poziciją.
setScale(double sx, double sy, double sz)double, double, doubleNustatyti mastelį.
setEulerAngles(double rx, double ry, double rz)double, double, doubleNustatyti sukimosi kampą laipsniais.
setRotation(double rx, double ry, double rz, double rw)double, double, double, doubleNustatyti sukimą kaip kvaternioną (x, y, z, w).
setPreRotation(double rx, double ry, double rz)double, double, doubleNustatykite priešrotaciją laipsniais.
setPostRotation(double rx, double ry, double rz)double, double, doubleNustatykite po rotaciją laipsniais.
setGeometricTranslation(double x, double y, double z)double, double, doubleNustatykite geometrinį perkėlimą.
setGeometricScaling(double sx, double sy, double sz)double, double, doubleNustatykite geometrinį mastelį.
setGeometricRotation(double rx, double ry, double rz)double, double, doubleNustatykite geometrinę rotaciją laipsniais.

Naudojimo pavyzdys

Nustatyti mazgo padėtį

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

Sukti naudojant Eulerio kampus

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

Sukti naudojant kvaternioną

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

Mastelis ir padėtis kartu

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

Geometrinis poslinkis (Pivot poslinkis)

Geometriniai transformavimai perkelia geometriją santykinai su mazgo pivotu nepaveikdami vaikų mazgų; naudinga centruoti tinklą jo mazge:

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

Skaityti sujungtą Transform matricą

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

Žr. taip pat

 Lietuvių