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

ExampleExampleExampleExampleExample
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)זוויות אוילר מיושמות לפני הסיבוב הראשי (משמשות במערכות FBX).
postRotationVector3getPostRotation()setPostRotation(Vector3)זוויות אוילר מיושמות אחרי הסיבוב הראשי.
geometricTranslationVector3getGeometricTranslation()setGeometricTranslation(Vector3)תרגום מקומי בלבד: משפיע על הגאומטריה אך לא על צמתים צאצאים.
geometricScalingVector3getGeometricScaling()setGeometricScaling(Vector3)קנה מידה מקומי בלבד: משפיע על הגאומטריה אך לא על צמתים צאצאים.
geometricRotationVector3getGeometricRotation()setGeometricRotation(Vector3)סיבוב מקומי בלבד: משפיע על הגאומטריה אך לא על צמתים צאצאים.
transformMatrixMatrix4getTransformMatrix()setTransformMatrix(Matrix4)מטריצת ההמרה המשולבת 4x4 המלאה. נשמרת במטמון; מחושבת מחדש כאשר כל רכיב משתנה. הגדרת המטריצה מפצלת חזרה לתרגום/קנה מידה/סיבוב.

שיטות Setter רהוטות

כל ה‑setters מחזירים this, מאפשרים שרשור:

ExampleExampleExample
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);

סיבוב עם קווטרניון

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

ראה גם

 עברית