How to find center of mass

   3340   7   3
User Avatar
Member
67 posts
Joined: 11月 2017
Offline
I often have an issue when I want to animate an object rotating around it's Y axis such as a propeller or a fan.
Sometimes object is not perfectly on world axis and it doesn't rotate properly. I am trying to have a gun rotate around itself while shooting.
I tried everything. $CEX thing, $XMIN thing. $BBX thing. I tried to extract centroid with a bounding box. I can't get this object to spin on axis. Before I did it by hand painstakingly for helicopters but I want to find out if there is any procedural way to do this. Is there any method to get a perfect centroid of an object that is not in perfect alignment with the world ?
Thank you

Attachments:
Capture.JPG (801.6 KB)

User Avatar
Member
4528 posts
Joined: 2月 2012
Offline
Hi,

You can use Measure SOP's Centroid option that computes the center of mass:
https://www.sidefx.com/docs/houdini/nodes/sop/measure.html [www.sidefx.com]

"The centroid of a piece of geometry is the center of mass of the its entire surface and not just the average position of its points. Although for a single triangle the two coincide, for more complex geometry the areas of the triangles incident to each point affect its contribution to the average."
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
8595 posts
Joined: 7月 2007
Offline
Extract Centroid in Center Of Mass mode seems to produce the same result as Measure Centroid so it may be another option if such result works for you
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
67 posts
Joined: 11月 2017
Offline
Hey guys thank you so much for both useful responses. @tamte I probably didn't use Rxtract Centroid correctly as once I have centroid attribute I wasn't sure what to do next. @animatrix_ I just tried using Measure SOP and that gives me a @Centroid attribute but as I said, I am not sure how to proceed after that.
My setup is simple I have a .gtlf model imported from Sketchfab, I blasted a GUN that I need, imported it with OBJ MERGE in different GEO node and then expected to use $F*5 on Z rotational axis to make it spin around itself. This is where I start having issues with centroid. I tried adding it to a group and than trying to affect just that group in TRANSFORM SOP but I am not sure how to use this @centroid to make it spin around itself.
Thank you for all your help I am truly grateful.
Edited by Nikodim Fomich - 2021年10月30日 14:47:06

Attachments:
C2.JPG (867.6 KB)
Editor[31].mp4 (6.0 MB)

User Avatar
Member
143 posts
Joined: 10月 2015
Offline
Hello
I think in this case you want more the axis of rotation that could be defined by the face the gun is touching than the Center of mass.....
then you could just create a ident() matrix and rotate it around this axe ...you will have to get also the centroid of the base of the gun .... selecting both the machine face and the base gun you could have something semi procedural ....
I have made a demo scene , check

Benjamin

Attachments:
Rotate_axis.hiplc (263.9 KB)

User Avatar
Member
67 posts
Joined: 11月 2017
Offline
Benjamin Lemoine
Hello
I think in this case you want more the axis of rotation that could be defined by the face the gun is touching than the Center of mass.....
then you could just create a ident() matrix and rotate it around this axe ...you will have to get also the centroid of the base of the gun .... selecting both the machine face and the base gun you could have something semi procedural ....
I have made a demo scene , check

Benjamin


WOW, Thank you so much for explaining it and providing a hip file because there is just no way I would understand what ident matrix is without an example. I don't even get it now. I don't know why simple things have to be this complicated in Houdini. I just want to spin thing around. Usually there is an option in other programs I used before to snap the object to be able to spin around itself. I wasn't gonna go elaborate like in your example in terms of movement I was just gonna have it in same place spinning around like a fan. I didn't realize it takes a page of coding for that simple task. Thank you for your effort and making this file. Gotta save this as an HDA for future because I have no clue what's going on in that Att Wrangle. Also I will for sure ask Side FX to implement fix for this in some update of Houdini. They are redoing already existing nodes (while making them much worse) like FILE CACHE and they don't have a node to do this which is a no brainer.
Again thank you. Will save this as a shelf tool so I can spin things around in the future.
User Avatar
Member
143 posts
Joined: 10月 2015
Offline
Hello
I'm sorry it look complicated
But if you are importing an object with arbitrary orientation it's not possible for the machine by itself to decide what would be the correct orientation...
If you were building the stuff yourself in Houdini you could animate it in a very simple way at obj level like in my screenshot
You will find many other way of doing it in Houdini , that's the beauty of the software it will let you find your own solution for a task .

I wish you a good learning in Houdini

Benjamin

Attachments:
SharedScreenshot.jpg (182.9 KB)

User Avatar
Member
4528 posts
Joined: 2月 2012
Offline
Hi,

If you are looking to rotate objects around their longest axis you can also perform PCA (Principal Component Analysis) on your geometry. I don't know if there are other simpler ways other than using Bound SOP with OBB (Oriented Bounding Box) then perform some deductions to find the longest oriented axis, then rotate around that axis.

Here is an off axis Tommy firing some machine guns:



I used a predefined PCA HDA and used this code to rotate the geometry around its longest axis:

float angle = radians ( ch("amount") );

vector p = point ( 1, "P", 0 );
vector4 q = point ( 1, "orient", 0 );
matrix3 m = qconvert ( q );
vector axis = point ( 1, "x", 0 );

@P -= p;
@P *= invert ( m );
rotate ( m, angle, axis );
@P *= m;
@P += p;

Possibly not the easiest method but it's just another way depending on your requirements.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
  • Quick Links