Transform
Methods: aspose.threed (aspose-3d-foss)
Transform kontrolē pozīciju, orientāciju un mērogu Node 3D ainas ietvaros. Katram mezglam ir tieši viens Transform, piekļūst caur node.transform.
class Transform(A3DObject):Node Transform piekļuve
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 | Pozīcijas nobīde no vecā mezgla izcelsmes. Noklusējums Vector3(0, 0, 0). |
scaling | Vector3 | Nekonsekvents mēroga koeficients katrai asij. Noklusējums Vector3(1, 1, 1). |
rotation | Quaternion | Rotācija kā vienības kvaternions. Iestatot šo, tiek atjaunināts arī euler_angles. |
euler_angles | Vector3 | Rotācija grādos kā (X, Y, Z) Eilera leņķi. Iestatot šo, tiek atjaunināts arī rotation. |
pre_rotation | Vector3 | Eilera leņķi, kas piemēroti pirms galvenās rotācijas (izmanto FBX rigos). |
post_rotation | Vector3 | Eilera leņķi, kas piemēroti pēc galvenās rotācijas. |
geometric_translation | Vector3 | Lokāls pārvietojums: ietekmē ģeometriju, bet ne bērnu mezglus. |
geometric_scaling | Vector3 | Lokāls mērogs: ietekmē ģeometriju, bet ne bērnu mezglus. |
geometric_rotation | Vector3 | Lokāla tikai rotācija: ietekmē ģeometriju, bet ne bērnu mezglus. |
transform_matrix | Matrix4 | Pilna kombinētā 4×4 transformācijas matrica. Kešota; pārrēķināta, kad mainās jebkurš komponents. Iestatot to, tas tiek sadalīts atpakaļ translācijas/mērogošanas/rotācijas komponentēs. |
Plūstošas iestatīšanas metodes
Visu setteri atgriež self, ļaujot ķēdēšanu:
| Methods | Methods | Methods |
|---|---|---|
set_translation(tx, ty, tz) | float, float, float | Iestatīt pozīciju. |
set_scale(sx, sy, sz) | float, float, float | Iestatīt mērogu. |
set_euler_angles(rx, ry, rz) | float, float, float | Iestatīt rotāciju grādos. |
set_rotation(rw, rx, ry, rz) | float, float, float, float | Iestatīt rotāciju kā kvaterniona (w, x, y, z). |
set_pre_rotation(rx, ry, rz) | float, float, float | Iestatīt priekšrotāciju grādos. |
set_post_rotation(rx, ry, rz) | float, float, float | Iestatīt pēcroto rotāciju grādos. |
set_geometric_translation(x, y, z) | float, float, float | Iestatīt ģeometrisko translāciju. |
set_geometric_scaling(sx, sy, sz) | float, float, float | Iestatīt ģeometrisko mērogu. |
set_geometric_rotation(rx, ry, rz) | float, float, float | Iestatīt ģeometrisko rotāciju grādos. |
Lietošanas piemēri
Pozicionēt mezglu
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)Rotēt ar Eilera leņķiem
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)Rotēt ar kvaternionu
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 automaticallyMērogot un pozicionēt kopā
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))Ģeometriska nobīde (Pivota nobīde)
Ģeometriskie transformācijas pārvieto ģeometriju attiecībā pret mezgla pivotu, neietekmējot bērnu mezglus; noderīgi, lai centrētu režģi mezgla ietvaros:
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)Nolasīt kombinēto Transform matricu
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'>