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 A3DObject

Truy 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

PropertiesPropertiesPropertiesPropertiesProperties
translationVector3getTranslation()setTranslation(Vector3)Độ dịch vị trí so với gốc của nút cha. Mặc định Vector3(0, 0, 0).
scalingVector3getScaling()setScaling(Vector3)Hệ số tỉ lệ không đồng nhất theo mỗi trục. Mặc định Vector3(1, 1, 1).
rotationQuaterniongetRotation()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.
eulerAnglesVector3getEulerAngles()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.
preRotationVector3getPreRotation()setPreRotation(Vector3)Các góc Euler được áp dụng trước phép xoay chính (được dùng trong rig FBX).
postRotationVector3getPostRotation()setPostRotation(Vector3)Các góc Euler được áp dụng sau phép xoay chính.
geometricTranslationVector3getGeometricTranslation()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.
geometricScalingVector3getGeometricScaling()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.
geometricRotationVector3getGeometricRotation()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.
transformMatrixMatrix4getTransformMatrix()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:

PropertiesPropertiesProperties
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 automatically

Tỉ 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

Xem thêm

 Tiếng Việt