Transform
Methods: aspose.threed (aspose-3d-foss)
Transform שולט במיקום, בכיוון ובקנה מידה של Node בסצנת ה‑3D. לכל צומת יש בדיוק אחד Transform, נגיש דרך node.transform.
class Transform(A3DObject):גישה ל‑Transform של Node
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("box")
t = node.transform # Transform objectMethods
| Methods | Methods | Methods |
|---|---|---|
translation | Vector3 | היסט מיקום ממקור הצומת ההורה. ברירת מחדל Vector3(0, 0, 0). |
scaling | Vector3 | גורם קנה מידה לא אחיד לכל ציר. ברירת מחדל Vector3(1, 1, 1). |
rotation | Quaternion | סיבוב כקוואטרניון יחידה. הגדרת זאת גם מעדכנת euler_angles. |
euler_angles | Vector3 | סיבוב במעלות כזוויות אוילר (X, Y, Z). הגדרת זאת גם מעדכנת rotation. |
pre_rotation | Vector3 | זוויות אוילר המיושמות לפני הסיבוב הראשי (משמשות במערכות FBX). |
post_rotation | Vector3 | זוויות אוילר המיושמות אחרי הסיבוב הראשי. |
geometric_translation | Vector3 | תרגום מקומי בלבד: משפיע על הגאומטריה אך לא על צמתים צאצאים. |
geometric_scaling | Vector3 | קנה מידה מקומי בלבד: משפיע על הגאומטריה אך לא על צמתים צאצאים. |
geometric_rotation | Vector3 | סיבוב מקומי בלבד: משפיע על הגאומטריה אך לא על צמתים צאצאים. |
transform_matrix | Matrix4 | מטריצת ההמרה המשולבת המלאה בגודל 4×4. נשמרת במטמון; מחושבת מחדש כאשר כל רכיב משתנה. הגדרת אותה מפצלת חזרה לתרגום/קנה מידה/סיבוב. |
שיטות Setter רהוטות
כל ה‑setters מחזירים self, מאפשרים שרשור:
| Methods | Methods | Methods |
|---|---|---|
set_translation(tx, ty, tz) | float, float, float | הגדר מיקום. |
set_scale(sx, sy, sz) | float, float, float | הגדר קנה מידה. |
set_euler_angles(rx, ry, rz) | float, float, float | הגדר סיבוב במעלות. |
set_rotation(rw, rx, ry, rz) | float, float, float, float | הגדר סיבוב כקוואטרניון (w, x, y, z). |
set_pre_rotation(rx, ry, rz) | float, float, float | הגדר סיבוב מקדים במעלות. |
set_post_rotation(rx, ry, rz) | float, float, float | הגדר סיבוב לאחרי במעלות. |
set_geometric_translation(x, y, z) | float, float, float | הגדר תרגום גאומטרי. |
set_geometric_scaling(sx, sy, sz) | float, float, float | הגדר קנה מידה גאומטרי. |
set_geometric_rotation(rx, ry, rz) | float, float, float | הגדר סיבוב גאומטרי במעלות. |
דוגמאות שימוש
מיקום צומת
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("box")
# Using fluent setters
node.transform.set_translation(5.0, 0.0, -3.0)
# Or via property assignment
from aspose.threed.utilities import Vector3
node.transform.translation = Vector3(5.0, 0.0, -3.0)סיבוב עם זוויות אוילר
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("rotated")
# Rotate 45° around Y axis
node.transform.set_euler_angles(0.0, 45.0, 0.0)
# Chain multiple operations
node.transform.set_translation(2.0, 0.0, 0.0).set_scale(2.0, 2.0, 2.0)סיבוב עם קוואטורניון
from aspose.threed import Scene
from aspose.threed.utilities import Quaternion, Vector3
import math
scene = Scene()
node = scene.root_node.create_child_node("q-rotated")
# 90° rotation around the Y axis
half_angle = math.radians(45) # half the total rotation
q = Quaternion(math.cos(half_angle), 0.0, math.sin(half_angle), 0.0)
node.transform.rotation = q
print(f"Euler: {node.transform.euler_angles}") # synced automaticallyקנה מידה ומיקום יחד
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("big-offset")
(node.transform
.set_translation(10.0, 0.0, 0.0)
.set_scale(3.0, 3.0, 3.0)
.set_euler_angles(0.0, 90.0, 0.0))הזחה גאומטרית (הזחה סביב ציר)
ההטרנספורמציות הגאומטריות מזיזות את הגאומטריה ביחס לציר של הצומת מבלי להשפיע על צמתים צאצאים; שימושי למרכז רשת בתוך הצומת שלו:
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("centered-mesh")
# Shift the mesh half a unit down so its base sits at y=0
node.transform.set_geometric_translation(0.0, -0.5, 0.0)קרא את מטריצת ה‑Transform המשולבת
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("m")
node.transform.set_translation(1.0, 2.0, 3.0).set_euler_angles(0.0, 45.0, 0.0)
m = node.transform.transform_matrix
print(type(m)) # <class 'aspose.threed.utilities.Matrix4'>