September 17, 2018

Quick Tip #2

For many a simple one but still worth mentioning. 

If you have a geometry with primitives and you want to get the center of each primitive positions and place a point there... you have multiple options - I give you four of them. All of the examples shown below have the result you see in the title.

Option 1  Fuse-Shuffle (more fun with names)

First you use a fuse node to give each primitive unique points. (also possible with a facet node) Then you scale the primitive down to zero with a prim node. Now all points of the prim have the same position and you can use a fuse again to get rid of the duplicated points.

Option 2 Block the Pivot

This variant has two differences. First instead of handling all primitives at once you create a foreach block. That allows you to create different logic for specific primitives. 

The 2nd difference - instead of the prim node you can also use a transform node. But you would have to change the pivot for the scale by providing the center of the axis. Those expressions are called $CEX, $CEY and $CEZ.

Option 3 Code "Brute Force" Nerd

The third option involves VEX. Many would say that it is crazy to put in that many code where you can easily create 3 nodes like in option 1 BUT I think it is at least important to understand that you can do it this way. And even more important to understand the vector math behind this. 

So the wrangle is set to primitive which will do a loop foreach one. I fill an array with all the points and loop over said array with the foreach loop. 

By adding each position to one vector I can divide that vector by the amount of points I gathered. This will give me the center point of the primitive or to be more precise the average Position of all points. Add the point and get rid of the primitive with it's original points.

Option 4 The lazy Coder

A simple trick to get that average point position would be to put an attribute promote in between. You take the P attribute from point and promote to a vector attribute on primitives. All you have to do now is to add the point and remove the original primitive.

I think I like this one the most nowadays. It's a bit more elegant and allows you to switch to a different behaviour simply by saving the new attribute to detail. That will create the points at the geometry center instead of the single primitives.

--------------------------

The Patreon Section Add-Ins

Since I like to write VEX I often forget that you of course also can use a VOP to apply the same effect.

Option 5 The Voppler by Olaf Finkbeiner

This one just lets me bite my toungue... I used that not that long ago... but still forgot it. But for those cases there is a Farmfield around.

By feeding the source data into the 2nd input of a wrangle you don't need to remove the prim. Only the points you add come out of the wrangle. For the center position you can also simply use the getbbox function.

Option 6 Sneaky Backdoor by Farmfield

Cheers 

Dave

Leave a Reply

Your email address will not be published. Required fields are marked *

David Kahl VFX

a Software Developer, Nerd and VFX Artist based in Germany
Visit Patreon
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram