Jump to content

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


ron2812

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

 

Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...