Transform — Aspose.3D FOSS for Java

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

Transform ovláda polohu, orientáciu a mierku Node v 3D scéne. Každý uzol má presne jeden Transform, prístupný cez node.getTransform().

public class Transform extends A3DObject

Získanie Transform uzla

import com.aspose.threed.Scene;

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

Example

ExampleExampleExampleExampleExample
translationVector3getTranslation()setTranslation(Vector3)Posun polohy od pôvodu rodičovského uzla. Predvolená Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Nerovnomerný faktor mierky na os. Predvolený Vector3(1, 1, 1).
rotationQuaterniongetRotation()setRotation(Quaternion)Rotácia ako jednotkový kvaternion. Nastavením tohto sa tiež aktualizujú Eulerove uhly.
eulerAnglesVector3getEulerAngles()setEulerAngles(Vector3)Rotácia v stupňoch ako Eulerove uhly (X, Y, Z). Nastavením tohto sa tiež aktualizuje rotácia kvaternionu.
preRotationVector3getPreRotation()setPreRotation(Vector3)Eulerove uhly aplikované pred hlavnou rotáciou (používané v FBX rigoch).
postRotationVector3getPostRotation()setPostRotation(Vector3)Eulerove uhly aplikované po hlavnej rotácii.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)Lokálny posun: ovplyvňuje geometriu, ale nie podriadené uzly.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)Lokálna mierka: ovplyvňuje geometriu, ale nie podriadené uzly.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)Lokálna rotácia: ovplyvňuje geometriu, ale nie podriadené uzly.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)Celá kombinovaná 4x4 transformačná matica. Uložená v cache; prepočítaná, keď sa zmení akákoľvek zložka. Nastavením sa rozloží späť na posun/mierku/rotáciu.

Plynulé metódy nastavenia

Všetky settery vracajú this, čo umožňuje reťazenie:

ExampleExampleExample
setTranslation(double tx, double ty, double tz)double, double, doubleNastaviť polohu.
setScale(double sx, double sy, double sz)double, double, doubleNastaviť mierku.
setEulerAngles(double rx, double ry, double rz)double, double, doubleNastaviť rotáciu v stupňoch.
setRotation(double rx, double ry, double rz, double rw)double, double, double, doubleNastaviť rotáciu ako kvaternion (x, y, z, w).
setPreRotation(double rx, double ry, double rz)double, double, doubleNastavte predrotáciu v stupňoch.
setPostRotation(double rx, double ry, double rz)double, double, doubleNastavte postrotáciu v stupňoch.
setGeometricTranslation(double x, double y, double z)double, double, doubleNastavte geometrický posun.
setGeometricScaling(double sx, double sy, double sz)double, double, doubleNastavte geometrickú mierku.
setGeometricRotation(double rx, double ry, double rz)double, double, doubleNastavte geometrickú rotáciu v stupňoch.

Príklady použitia

Pozícia uzla

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ácia pomocou Eulerových uhlov

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ácia pomocou 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

Mierka a pozícia spoločne

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

Geometrický posun (Pivot Offset)

Geometrické transformácie posúvajú geometriu vzhľadom na pivot uzla bez ovplyvnenia podriadených uzlov; užitočné pre vycentrovanie siete v rámci jej uzla:

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

Prečítajte kombinovanú transformačnú maticu

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

Pozri tiež

 Slovenčina