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
| Example | Example | Example | Example | Example |
|---|---|---|---|---|
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) | זוויות אוילר מיושמות לפני הסיבוב הראשי (משמשות במערכות 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 רהוטות
כל ה‑setters מחזירים this, מאפשרים שרשור:
| Example | Example | Example |
|---|---|---|
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