Transform — Aspose.3D FOSS for Java
Overview: com.aspose.threed (aspose-3d-foss)
Transform ควบคุมตำแหน่ง, การวางแนว, และสเกลของ Node ในฉาก 3D. โหนดแต่ละอันมีอย่างแม่นยำหนึ่ง Transform, เข้าถึงผ่าน node.getTransform().
public class Transform extends A3DObjectการเข้าถึง Transform ของ Node
import com.aspose.threed.Scene;
Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");
Transform t = node.getTransform();Overview
| Overview | Overview | Overview | Overview | Overview |
|---|---|---|---|---|
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) | มุมออยเลอร์ที่ใช้ก่อนการหมุนหลัก (ใช้ใน rig ของ FBX). |
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 ที่รวมเต็มรูปแบบ. ถูกแคช; คำนวณใหม่เมื่อส่วนประกอบใดเปลี่ยนแปลง. การตั้งค่าจะทำการแยกกลับเป็นการแปล/สเกล/การหมุน. |
เมธอด Setter แบบ Fluent
ตัวตั้งค่าทั้งหมดจะคืนค่า this, ทำให้สามารถเชื่อมต่อกันได้:
| Overview | Overview | Overview |
|---|---|---|
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 | ตั้งการหมุนเชิงเรขาคณิตเป็นองศา. |
ตัวอย่างการใช้งาน
กำหนดตำแหน่งให้ 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));หมุนด้วยมุมออยเลอร์
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);หมุนด้วยควอเทอร์เนียน
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)
การแปลงเชิงเรขาคณิตจะย้ายรูปทรงสัมพันธ์กับจุดหมุนของโหนดโดยไม่กระทบโหนดลูก; มีประโยชน์สำหรับการจัดศูนย์เมชภายในโหนดของมัน:
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