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

OverviewOverviewOverviewOverviewOverview
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)มุมออยเลอร์ที่ใช้ก่อนการหมุนหลัก (ใช้ใน rig ของ FBX).
postRotationVector3getPostRotation()setPostRotation(Vector3)มุมออยเลอร์ที่ใช้หลังการหมุนหลัก.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)การแปลที่ใช้เฉพาะในระดับโลคัล: มีผลต่อรูปทรงเรขาคณิตแต่ไม่กระทบโหนดลูก.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)สเกลที่ใช้เฉพาะในระดับโลคัล: มีผลต่อรูปทรงเรขาคณิตแต่ไม่กระทบโหนดลูก.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)การหมุนที่ใช้เฉพาะในระดับโลคัล: มีผลต่อรูปทรงเรขาคณิตแต่ไม่กระทบโหนดลูก.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)เมทริกซ์การแปลง 4x4 ที่รวมเต็มรูปแบบ. ถูกแคช; คำนวณใหม่เมื่อส่วนประกอบใดเปลี่ยนแปลง. การตั้งค่าจะทำการแยกกลับเป็นการแปล/สเกล/การหมุน.

เมธอด Setter แบบ Fluent

ตัวตั้งค่าทั้งหมดจะคืนค่า this, ทำให้สามารถเชื่อมต่อกันได้:

OverviewOverviewOverview
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

ดูเพิ่มเติม

 ภาษาไทย