Transform — Aspose.3D FOSS for Java

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

Transform контролира позицията, ориентацията и мащаба на Node в 3D сцената. Всеки възел има точно един Transform, достъпен чрез node.getTransform().

public class Transform extends A3DObject

Достъп до Transform на възел

import com.aspose.threed.Scene;

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

Example

ExampleExampleExampleExampleExample
translationVector3getTranslation()setTranslation(Vector3)Отместване на позицията от произхода на родителския възел. По подразбиране Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Нееднороден фактор на мащабиране за всяка ос. По подразбиране Vector3(1, 1, 1).
rotationQuaterniongetRotation()setRotation(Quaternion)Въртене като единичен кватернион. Задаването му също актуализира Ейлеровите ъгли.
eulerAnglesVector3getEulerAngles()setEulerAngles(Vector3)Въртене в градуси като (X, Y, Z) Ейлерови ъгли. Задаването му също актуализира въртенето като кватернион.
preRotationVector3getPreRotation()setPreRotation(Vector3)Ейлерови ъгли, приложени преди главната ротация (използвани в FBX rigs).
postRotationVector3getPostRotation()setPostRotation(Vector3)Ейлерови ъгли, приложени след главната ротация.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)Локална само транслация: засяга геометрията, но не и дъщерните възли.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)Локален само мащаб: засяга геометрията, но не и дъщерните възли.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)Локална само ротация: засяга геометрията, но не и дъщерните възли.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)Пълната комбинирана 4x4 трансформационна матрица. Кеширана; пресмята се отново, когато се промени който и да е компонент. При задаване се декомпозира обратно към транслация/мащаб/ротация.

Fluent методи за задаване

Всички сетъри връщат this, позволявайки верижно извикване:

ExampleExampleExample
setTranslation(double tx, double ty, double tz)double, double, doubleЗадайте позиция.
setScale(double sx, double sy, double sz)double, double, doubleЗадайте мащаб.
setEulerAngles(double rx, double ry, double rz)double, double, doubleЗадайте завъртане в градуси.
setRotation(double rx, double ry, double rz, double rw)double, double, double, doubleЗадайте завъртане като кватернион (x, y, z, w).
setPreRotation(double rx, double ry, double rz)double, double, doubleЗадайте предварително завъртане в градуси.
setPostRotation(double rx, double ry, double rz)double, double, doubleЗадайте последващо завъртане в градуси.
setGeometricTranslation(double x, double y, double z)double, double, doubleЗадайте геометрично преместване.
setGeometricScaling(double sx, double sy, double sz)double, double, doubleЗадайте геометричен мащаб.
setGeometricRotation(double rx, double ry, double rz)double, double, doubleЗадайте геометрично завъртане в градуси.

Примери за употреба

Позициониране на възел

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

Въртене с Ейлерови ъгли

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

Въртене с 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

Мащабиране и позициониране заедно

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

Геометрично отместване (Pivot Offset)

Геометричните трансформации преместват геометрията спрямо pivot-а на възела, без да засягат дъщерните възли; полезно е за центриране на mesh в неговия възел:

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

Прочетете комбинираната матрица Transform

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

Вижте също

 Български