VRED 2024 - Python vrdTransformNode.setTranslation local mode

VRED 2024 - Python vrdTransformNode.setTranslation local mode

andreasK3K4G
Enthusiast Enthusiast
552 Views
6 Replies
Message 1 of 7

VRED 2024 - Python vrdTransformNode.setTranslation local mode

andreasK3K4G
Enthusiast
Enthusiast

Hello,

 

is there a way to set vrdTransformNode.setTranslation

with the option we have in the editor to use "local mode"?

So we can move along the groups orientation?

0 Likes
Accepted solutions (1)
553 Views
6 Replies
Replies (6)
Message 2 of 7

Christian_Garimberti
Advisor
Advisor

Hi, like written in the help. vrdTransformNode.setTranslation is in Local Mode.

Instead, vrdTransformNode.setWorldTranslation(translation)

Is for World Space

 

vrdTransformNode.setTranslation(translation)

Sets the translation in local space.

 

Best

Chris

 

 

 

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

0 Likes
Message 3 of 7

andreasK3K4G
Enthusiast
Enthusiast

Hi,

setTranslation is in local space.

But i mean the option to switch to local mode, like the option in the GUI Transform Button.

So when the group has an modified rotation pivot, that i can put setTranslation(10,0,0) and

the group get moved along the modified x-axis. 

0 Likes
Message 4 of 7

Christian_Garimberti
Advisor
Advisor

Sorry but maybe i didn't understand...

The "Local Mode" Switch is to manage the transform manipulator while working in render window.

It doesn't change the transformation of the object. i suppose only change the behavior the user interact while  graphically move objects.

Via Api you should use vrdTransformNode.setTranslation(translation) if you want to set a transform on a specific node, so it inherits transforms from the parent tree (it follow the parents transformation).

Instead, if you need to input a global transformation, no matter the parent tree, you should use vrdTransformNode.setWorldTranslation(translation)

 

otherwise... i didn't understand what you need...

 

Best

Chris

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

0 Likes
Message 5 of 7

andreasK3K4G
Enthusiast
Enthusiast

Hi Christian,

thanks for the fast response. No worry, sometimes it is hard to describe.

The idea is to save me some line of code, cause i guess it is already inside of VRED.

 

Lets start from zero:

1. I have a line in VRED which present my direction vector. This line should be the new rotation axis.

2. My script is calculating the direction vector and set the rotation pivot orientation for the group the user wants to animate.

3. The user can now put in a value and choose the axis, and the group gets rotated around the new axis.
    The script can directly use anim_group.setRotationAsEuler(QVector3D(0,0,33))  (for example)

4. The user wants to move the group along the new axis, just typing in a value an choosing the axis.

5. Now it would be nice, to directly use anim_group.setTranslation(QVector3D(50,0,0)) (for example)

But for sure, it takes the local space and not along the custom axis.

 

I can write a function to get the new position with a given vector and a distance. I guess this is what happens anyway internal when the user use local mode in viewport. So it calculates the direction vector from the rotation pivot orientation values? and sets the new postion x,y,z with a proper math function.

 

So at the end it is just the question or as far i can imagine from your answers, more like a "nice to have", setRotationAsEuler takes the rotation pivot orientation into account, is setTranslation able to do aswell?

 

Maybe it is just me who needs this to save some line of code. 😉

 

translate_mode_.png

0 Likes
Message 6 of 7

sinje_thiedemann
Autodesk
Autodesk
Accepted solution

Hi @andreasK3K4G 

yes, in local mode the translation vector is essentially rotated. We can use the quaternion (QQuaternion) representation of the rotation and pivot rotation to get the rotated vector:

b = vrScenegraphService.getSelectedNode()
qr = b.getRotationAsQuaternion()
qro = b.getRotationOrientationAsQuaternion()
tr = (qr * qro).rotatedVector( QVector3D(100,0,0))
t = b.getTranslation()
b.setTranslation( tr + t) # or just tr

Using this, the object moves along its "local" x-axis, for example.

 

Message 7 of 7

andreasK3K4G
Enthusiast
Enthusiast

Thank you, works perfect!

0 Likes