Transform — Aspose.3D FOSS for Java

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

Transform kontroliše položaj, orijentaciju i skalu Node u 3D sceni. Svaki čvor ima tačno jedan Transform, pristupa se putem node.getTransform().

public class Transform extends A3DObject

Pristup Transformu čvora

import com.aspose.threed.Scene;

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

Example

ExampleExampleExampleExampleExample
translationVector3getTranslation()setTranslation(Vector3)Pomak položaja u odnosu na poreklo roditeljskog čvora. Podrazumevano Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Neravnomerna skala po osi. Podrazumevano Vector3(1, 1, 1).
rotationQuaterniongetRotation()setRotation(Quaternion)Rotacija kao jedinični kvaternion. Postavljanje ove vrednosti takođe ažurira Eulerove uglove.
eulerAnglesVector3getEulerAngles()setEulerAngles(Vector3)Rotacija u stepenima kao (X, Y, Z) Eulerovi uglovi. Postavljanje ove vrednosti takođe ažurira rotaciju kvaternionom.
preRotationVector3getPreRotation()setPreRotation(Vector3)Eulerovi uglovi primenjeni pre glavne rotacije (koristi se u FBX rigovima).
postRotationVector3getPostRotation()setPostRotation(Vector3)Eulerovi uglovi primenjeni posle glavne rotacije.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)Lokalni prevod: utiče na geometriju, ali ne i na podređene čvorove.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)Lokalna skala: utiče na geometriju, ali ne i na podređene čvorove.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)Lokalna rotacija: utiče na geometriju, ali ne i na podređene čvorove.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)Kompletna kombinovana 4x4 matrica transformacije. Keširana; ponovo izračunata kada se bilo koja komponenta promeni. Postavljanje je dekomponuje nazad u translation/scaling/rotation.

Fluent metode postavljanja

Svi seteri vraćaju this, omogućavajući lančanje:

ExampleExampleExample
setTranslation(double tx, double ty, double tz)double, double, doublePostavi poziciju.
setScale(double sx, double sy, double sz)double, double, doublePostavi skalu.
setEulerAngles(double rx, double ry, double rz)double, double, doublePostavi rotaciju u stepenima.
setRotation(double rx, double ry, double rz, double rw)double, double, double, doublePostavi rotaciju kao kvaternion (x, y, z, w).
setPreRotation(double rx, double ry, double rz)double, double, doublePostavi pre‑rotaciju u stepenima.
setPostRotation(double rx, double ry, double rz)double, double, doublePostavi post‑rotaciju u stepenima.
setGeometricTranslation(double x, double y, double z)double, double, doublePostavi geometrijski pomeraj.
setGeometricScaling(double sx, double sy, double sz)double, double, doublePostavi geometrijsku skalu.
setGeometricRotation(double rx, double ry, double rz)double, double, doublePostavi geometrijsku rotaciju u stepenima.

Primeri upotrebe

Pozicioniranje čvora

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

Rotacija pomoću Eulerovih uglova

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

Rotacija pomoću 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

Skaliranje i pozicioniranje zajedno

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

Geometrijski pomeraj (Pivot pomeraj)

Geometrijske transformacije pomeraju geometriju u odnosu na pivot čvora, a da ne utiču na podređene čvorove; korisno za centriranje mreže unutar njenog čvora:

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

Pročitajte kombinovanu matricu transformacije

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

Vidi takođe

 Српски