Define positioning properties from a scene node

Started by Jérémy, November 07, 2019, 05:35:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jérémy

I would like to know how to set position, rotation, and scale values from a SceneNode. I have already ask this question when i'm working with KS7.3 but now i have KS8.
Morten Kristensen tell me i can get the transformation matrix in KS8 with getTransform() (and after getTransformation then applyTransform() ).
I try to use this first function but node.getTransform() return different values i see in KeyShot for the children node ? It works for the father node.

Here is a simple code for example:

# AUTHOR Jérémy BAUCHEREL
# VERSION 0.0.0
import os, math
from math import cos, sin, pi


root = lux.getSceneTree()
for node in root.find(name = "Hexapode2"):
    node_pere = node

matrice = node_pere.getTransform().val()       

ROTX = math.degrees(math.atan(matrice[6]/matrice[10]))
ROTY = math.degrees(-math.asin(matrice[2]))
ROTZ = math.degrees(math.atan(matrice[1]/matrice[0]))

# works
print("Node:")
print("Trans X: "+str(matrice[12]))
print("Trans Y: "+str(matrice[13]))
print("Trans Z: "+str(matrice[14]))

print("Rot X: "+str(ROTX))
print("Rot Y: "+str(ROTY))
print("Rot Z: "+str(ROTZ))



print("\nChildren:")

for ch in node_pere.getChildren():
    # On récupère la matrice de transformation du noeud
    matrice = ch.getTransform().val()         
    ROTX = math.degrees(math.atan(matrice[6]/matrice[10]))
    ROTY = math.degrees(-math.asin(matrice[2]))
    ROTZ = math.degrees(math.atan(matrice[1]/matrice[0]))

    # does not works
    print("Children: "+ch.getName())
    print("Trans X: "+str(matrice[12]))
    print("Trans Y: "+str(matrice[13]))
    print("Trans Z: "+str(matrice[14]))

    print("Rot X: "+str(ROTX))
    print("Rot Y: "+str(ROTY))
    print("Rot Z: "+str(ROTZ))