Transform — Aspose.3D FOSS for Java
Properties: com.aspose.threed (aspose-3d-foss)
Transform kiểm soát vị trí, hướng và tỉ lệ của một Node trong cảnh 3D. Mỗi nút có đúng một Transform, được truy cập qua node.getTransform().
public class Transform extends A3DObjectTruy cập Transform của Node
import com.aspose.threed.Scene;
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");
Transform t = node.getTransform();Properties
| Properties | Properties | Properties | Properties | Properties |
|---|---|---|---|---|
translation | Vector3 | getTranslation() | setTranslation(Vector3) | Độ dịch vị trí so với gốc của nút cha. Mặc định Vector3(0, 0, 0). |
scaling | Vector3 | getScaling() | setScaling(Vector3) | Hệ số tỉ lệ không đồng nhất theo mỗi trục. Mặc định Vector3(1, 1, 1). |
rotation | Quaternion | getRotation() | setRotation(Quaternion) | Xoay dưới dạng quaternion đơn vị. Thiết lập này cũng sẽ cập nhật các góc Euler. |
eulerAngles | Vector3 | getEulerAngles() | setEulerAngles(Vector3) | Xoay tính bằng độ dưới dạng các góc Euler (X, Y, Z). Thiết lập này cũng sẽ cập nhật quaternion xoay. |
preRotation | Vector3 | getPreRotation() | setPreRotation(Vector3) | Các góc Euler được áp dụng trước phép xoay chính (được dùng trong rig FBX). |
postRotation | Vector3 | getPostRotation() | setPostRotation(Vector3) | Các góc Euler được áp dụng sau phép xoay chính. |
geometricTranslation | Vector3 | getGeometricTranslation() | setGeometricTranslation(Vector3) | Dịch chuyển chỉ cục bộ: ảnh hưởng đến hình học nhưng không ảnh hưởng đến các nút con. |
geometricScaling | Vector3 | getGeometricScaling() | setGeometricScaling(Vector3) | Tỉ lệ chỉ cục bộ: ảnh hưởng đến hình học nhưng không ảnh hưởng đến các nút con. |
geometricRotation | Vector3 | getGeometricRotation() | setGeometricRotation(Vector3) | Xoay chỉ cục bộ: ảnh hưởng đến hình học nhưng không ảnh hưởng đến các nút con. |
transformMatrix | Matrix4 | getTransformMatrix() | setTransformMatrix(Matrix4) | Ma trận biến đổi 4x4 kết hợp đầy đủ. Được lưu trong bộ nhớ đệm; tính lại khi bất kỳ thành phần nào thay đổi. Thiết lập nó sẽ phân tách lại thành dịch chuyển/tỉ lệ/xoay. |
Các phương thức Setter dạng fluent
Tất cả các hàm setter trả về this, cho phép chuỗi lệnh:
| Properties | Properties | Properties |
|---|---|---|
setTranslation(double tx, double ty, double tz) | double, double, double | Đặt vị trí. |
setScale(double sx, double sy, double sz) | double, double, double | Đặt tỉ lệ. |
setEulerAngles(double rx, double ry, double rz) | double, double, double | Đặt góc quay tính bằng độ. |
setRotation(double rx, double ry, double rz, double rw) | double, double, double, double | Đặt góc quay dưới dạng quaternion (x, y, z, w). |
setPreRotation(double rx, double ry, double rz) | double, double, double | Đặt góc quay trước tính bằng độ. |
setPostRotation(double rx, double ry, double rz) | double, double, double | Đặt góc quay sau tính bằng độ. |
setGeometricTranslation(double x, double y, double z) | double, double, double | Đặt phép dịch hình học. |
setGeometricScaling(double sx, double sy, double sz) | double, double, double | Đặt tỉ lệ hình học. |
setGeometricRotation(double rx, double ry, double rz) | double, double, double | Đặt góc quay hình học tính bằng độ. |
Ví dụ sử dụng
Đặt vị trí cho Node
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));Xoay bằng góc Euler
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);Xoay bằng 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 automaticallyTỉ lệ và Vị trí cùng lúc
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);Độ dịch hình học (Pivot Offset)
Các biến đổi hình học di chuyển hình học so với pivot của node mà không ảnh hưởng đến các node con; hữu ích để căn giữa một mesh trong node của nó:
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);Đọc ma trận Transform kết hợp
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