Normal direction to quaternion?

   14213   11   2
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
I'm trying to come up with a way, where I can do a packed geo sim with instances, then turn those into instances that Octane can see.

so I scatter points, with random scales, and normals, and then copy an object to those points useing pack and instance. this goes into a DOP setup no problem.

Then I take an instance node, and bring in those points. I have to delete the pivot, and them object merge in the scale from the original points and wrangle those onto my dopimport points.

That all works, I have the same scaling as before, however the rotation doesn't match. the dopimport has an orient attribute, It seems like I need to add the rotation from the original normals, to the orient attribute. However it is a quaternion, and I can't for the life of me figure out how to go from normals direction to quaternion.

I've attached a simplified scene, maybe that will explain it better.

Thanks
Chris

Attachments:
instanceDynamicObjects.hip (325.6 KB)

User Avatar
Member
1737 posts
Joined: May 2006
Online
Not at Houdini atm so I haven't opened your scene, but it should be something like this:

http://www.tokeru.com/cgwiki/?title=HoudiniVex#Convert_N_and_Up_to_Orient_with_maketransform [www.tokeru.com]
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
Thank you mestela, that has gotten me a lot closer, I'm still missing something,

I took the example that was on that forum, and essentially tried to make a test that worked,

do an attribute random, and randomize the N

then do a wrangle that sets the up vector, v@up = set(0,1,0);
then do a wrangle that has the example code:

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

and that works, when I toggle off and on that last wrangle the angel of the copies stays the same, so it seems like I am correctly converting N to quaternion,

however on my scene, I do the same thing to set the up vector,

but then do a wrangle with:

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

thinking that adding the existing orient, to the new orient would line them up, and it's closeish, but not exact?
keep in mind I don't know anything about quaternions, so thought that must not be how you combine quaternions, so found qmultiply, and tried:

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

well that is a lot closer… but not exact, also as you play through the sim, they aren't linked up to eachother, so I dont' know what to do at this point. how does one add 2 quaternions together?

Thanks
User Avatar
Member
1737 posts
Joined: May 2006
Online
Heh, I only barely understand quaternions too, I have a few tricks I know by rote, that's about it.

But yes, qmultiply should be how you combine them. Order is important, so if it doesn't work one way, try swapping it from

@orient = qmultiply(quaternion(m), @orient);

to

@orient = qmultiply(@orient, quaternion(m));
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
Thanks mestela, switching the order makes it so they are linked up, and their orientation is very close I don't know what I"m doing wrong that it's not exact, some parts are closer than others, it's so weird that it is close but not exact, I'm not putting in any values, so I would think that I either line them up and it's right or it's not, close but off doesn't make sense, but I am in over my head so who knows.

Attachments:
instanceDynamicObjects.hip (329.3 KB)

User Avatar
Member
1737 posts
Joined: May 2006
Online
As it happens I only learned about this last week!

A co-worker showed me that the orient and whatnot directly from packed rbd can't be trusted; it's best to directly access the packed prim intrinsics ‘packedfulltransform’ (matrix4) and ‘pivot’ (vector), and pull those apart to get your correct orient/scale/pivot:

matrix m4 = primintrinsic(0,'packedfulltransform',@ptnum);
matrix3 m3 = matrix3(m4);
@orient = quaternion(m3);
@scale = cracktransform(0,0,2,0,m4);
v@pivot = primintrinsic(0,'pivot',@ptnum);

Maybe there's a sop/method to do this without getting so fiddly; I was using the transform pieces sop and getting similar subtle shifts like your setup. Be curious if anyone knows a way (cough sidefx cough), but this worked well for me.

Attached an update to your scene with the above wrangle (had to change the dopIO sop to make sure it was pulling in the full packed prim, not just points within the instance object).
Edited by mestela - Dec. 23, 2017 09:13:42

Attachments:
instanceDynamicObjects_me.hiplc (334.4 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
wow, I never would have figured that out, thanks so much! there's some gems in that wrangle I'll be trying to understand,
User Avatar
Member
620 posts
Joined: Nov. 2013
Offline
Why not unpack the packed geo directly?
Edited by jerry7 - Dec. 24, 2017 05:37:29
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
Hey Jerry, I don't understand what unpacking the packed geo directly adds? could you explain?

Thanks
User Avatar
Member
620 posts
Joined: Nov. 2013
Offline
chris wells
Hey Jerry, I don't understand what unpacking the packed geo directly adds? could you explain?

Thanks

The Unpack SOP can do it.
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
yeah but I don't understand how that would be better? If you unpack them and just use the geo, Octane can render it, but it's not instanced anymore taking up more ram. Am I missing something? And actually newest octane, seems to be able to render packed geo, it seems to just unpack it internally, as it uses the same number of polys/memory. But of course instanced is a lot less.
User Avatar
Member
620 posts
Joined: Nov. 2013
Offline
I haven't used Octane. But in you scene, the instance1 OBJ is not real instance. The internal geometry is just plain polygon.
  • Quick Links