Jump to content
ron2812

How to convert the rotation of transform node to a Point orient attribute?

Recommended Posts

Hey!

I work on a kitbash tool where you can combine multiple meshes and export a point cloud,  ready for instancing assets in e.g. Unreal Engine. 

So far this works fine. I use a Transform node to place/rotate/scale the mesh and transfer the attributes required for instancing to a point. (like scale, P etc.)
I exposed the Transform handle to my HDA.
My problem is to get the rotation right. 

I calculated yaw, roll and pitch using the following code, using the Transform's rx, ry and rz:

matrix3 m = maketransform(@N,@up);
@orient = quaternion(m);

vector4 pitch = quaternion({1,0,0}*radians(ch("../transform/rx"))); 
vector4 yaw = quaternion({0,1,0}*radians(ch("../transform/ry")));
vector4 roll = quaternion({0,0,1}*radians(ch("../transform/rz"))); 

@orient = qmultiply(@orient, pitch);
@orient = qmultiply(@orient, yaw);
@orient = qmultiply(@orient, roll);

This works fine as long as you only rotate along a single axis.

When I rotate along multiple axis simultaneously things get weird and  the handly doesn't match the point's orientation at all.

Is there a better way to simply convert a Transform's rx, ry and rz to a Point orient attribute

Thanks for your help in advance!

Best,
Ron

 

Share this post


Link to post
Share on other sites

Hey Ronald !

The easiest way I found to handle rotation like you want is to create an initial orient attribute on your points before any transformation. And that's it !

The awesome thing with this is that the transform node has an awesome feature that not only transforms the P, but also any other attributes it can, based on their type.
So if there is, for instance, an existing orient attribute, the transform node will modify it accordingly, without you having to do any matrix math ! And you can daisy-chain multiple transforms without having to bother re-computing the orient each time :)

 

In this gif, I show exactly this. The extract_smth_smth wrangle is superfluous, only to have the x y z attributes extracted from the orient, to be able to visualize them with the visualize node. (also - I just found out that I could have used orient directly in the visualize node instead of the x y z like I did. So that wrangle really is superfluous)

transformOrient.thumb.gif.a7bf9641843d0a84729c0bef5f7b7e5c.gif

Edited by Alain2131
  • Like 2

Share this post


Link to post
Share on other sites

Ha!
Awesome! You just saved me a lot of headache fiddling with quaterions!

Thank you so much! Works like a charm!

Best,
Ron

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×