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
| Example | Example | Example | Example | Example |
|---|---|---|---|---|
translation | Vector3 | getTranslation() | setTranslation(Vector3) | Отместване на позицията от произхода на родителския възел. По подразбиране Vector3(0, 0, 0). |
scaling | Vector3 | getScaling() | setScaling(Vector3) | Нееднороден фактор на мащабиране за всяка ос. По подразбиране Vector3(1, 1, 1). |
rotation | Quaternion | getRotation() | setRotation(Quaternion) | Въртене като единичен кватернион. Задаването му също актуализира Ейлеровите ъгли. |
eulerAngles | Vector3 | getEulerAngles() | setEulerAngles(Vector3) | Въртене в градуси като (X, Y, Z) Ейлерови ъгли. Задаването му също актуализира въртенето като кватернион. |
preRotation | Vector3 | getPreRotation() | setPreRotation(Vector3) | Ейлерови ъгли, приложени преди главната ротация (използвани в FBX rigs). |
postRotation | Vector3 | getPostRotation() | setPostRotation(Vector3) | Ейлерови ъгли, приложени след главната ротация. |
geometricTranslation | Vector3 | getGeometricTranslation() | setGeometricTranslation(Vector3) | Локална само транслация: засяга геометрията, но не и дъщерните възли. |
geometricScaling | Vector3 | getGeometricScaling() | setGeometricScaling(Vector3) | Локален само мащаб: засяга геометрията, но не и дъщерните възли. |
geometricRotation | Vector3 | getGeometricRotation() | setGeometricRotation(Vector3) | Локална само ротация: засяга геометрията, но не и дъщерните възли. |
transformMatrix | Matrix4 | getTransformMatrix() | setTransformMatrix(Matrix4) | Пълната комбинирана 4x4 трансформационна матрица. Кеширана; пресмята се отново, когато се промени който и да е компонент. При задаване се декомпозира обратно към транслация/мащаб/ротация. |
Fluent методи за задаване
Всички сетъри връщат this, позволявайки верижно извикване:
| Example | Example | Example |
|---|---|---|
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