resetting object transforms

Started by jbeau, July 22, 2019, 12:27:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jbeau

How do I compare matrices and apply?
If I don't compare, I have success but I don't see any changes applied.

root = lux.getSceneTree()
for node in root.find("test"):
     noTrans = luxmath.Matrix.makeIdentity().val()
     #compare object matrix to default matrix
     if node.getTransform() != noTrans:
          #if object matrix is not default, apply default transforms
          node.applyTransform(noTrans)
     else:
          print('transform set to default already:', node)


Is there a way to use the reset transform, similar to the button option in position?
I can't seem to split the result of getTransform() to return the matrix only for comparison.
Thanks,
J

jbeau

#1
Just doing some quick testing...
"externalShell_grp" has an X- transform of 10 units.

root = lux.getSceneTree()
val = luxmath.Matrix().makeIdentity().val()
print('val:', val)
for node in root.find(name = "externalShell_grp"):
     name = node.getName()
     print('nodeName:', name)
     print('/n')

     print('node:', node)
     print('/n')

     getTrans = node.getTransform()
     print('getTrans:', getTrans) 
     print('/n')

     Matrix = luxmath.Matrix(val).makeIdentity()
     print('Matrix:', Matrix) 
     
     node.applyTransform(Matrix)


returns:
val: (1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0)
nodeName: externalShell_grp
/n
node: <lux.SceneNode object at 0x12c808768, name: "externalShell_grp", kind: Group>
/n
getTrans: <luxmath.Matrix object at 0x12c808840>
(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 10.0, 0.0, 0.0, 1.0)
/n
Matrix: <luxmath.Matrix object at 0x12c808708>
(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0)

If val() is just a tuple, maybe I can use that to compare?
It prints successful but the transforms don't get updated. What am I doing wrong?

jbeau

#2
Comparing tuples worked using val() :)


root = lux.getSceneTree()
val = luxmath.Matrix().makeIdentity().val()
print('val:', val)
for node in root.find(name = "externalShell_grp"):
     getTrans = node.getTransform().val()
     if getTrans == val:
          print(node.getName(), "has default transforms.")
     else:
          print(node.getName(), "does not have default transforms")


Now how to apply them...

jbeau

#3
Boom 8) working reset for translate only:

root = lux.getSceneTree()
for node in root.find(name = "replaceObjectNameHere"):
     #get transformations for scale, rotation and translate
     getTrans = node.getTransform().getTransformation()

     #isolate translations
     translation = list(getTrans)[-1].val()

     #not sure if .mul() is the best way to reset, any ideas? maybe .invert()
     Matrix = luxmath.Matrix().makeIdentity().translate(luxmath.Vector(translation).mul(-1))
     node.applyTransform(Matrix)

jbeau

Are there any flags for resetting local transforms?
Similar to scene/object/position/reset.
I've been able to get position and scale, but absolute rotate values are converted to something completely different:(

Jérémy

I'm trying to reset object to his initial position without success...
I tested with setTransformation only and with Rotate then Translate but none of this works.

How can i code the reset button?


root = lux.getSceneTree()
for ch in root.find(name = "test_node"):
    # Get the transformation matrix of node
    matrice = ch.getTransform()

    # Get the scale vector, rotation and translation of matrix
    tup_vector = matrice.getTransformation()

    scale_vector = tup_vector[0].mul(-1).val()
    rotation_vector = tup_vector[1].mul(-1).val()
    transformation_vector = tup_vector[2].mul(-1).val()
                           
    #print(scale_vector)
    #print(rotation_vector)
    #print(transformation_vector)
                           
    Matrix = luxmath.Matrix().makeIdentity().setTransformation(scale_vector, rotation_vector, transformation_vector)
    ch.applyTransform(Matrix)
                       
    #Matrix = luxmath.Matrix().makeIdentity().rotate(rotation_vector)
    #ch.applyTransform(Matrix)
                           
    #Matrix = luxmath.Matrix().makeIdentity().translate(transformation_vector)
    #ch.applyTransform(Matrix)