Jump to content

# Primitive group center positions

## Recommended Posts

What's the best method to put a point into the center of each primitive group in a geo?

I was wondering if scatter can [somehow] do it?

#### Share this post

##### Share on other sites

You can do this with an assemble sop. Just use it on all groups and transfer the groups also. Create packed geo and delete the points which are not grouped. I think there are also slicker methods but this one was the first I came up with.

pointsOnPrimitiveGroups.hip

#### Share this post

##### Share on other sites

there is an actual vex function for this

you can give it a group as input.

running the following code in a wrangle (Run Over: Detail (only once))

```string grps[] = detailintrinsic(0, "primitivegroups");
foreach(string grp; grps)
{
int groupCenterPt = addpoint(0,getbbox_center(0, grp));
}```

should do the trick for you

• 3

#### Share this post

##### Share on other sites

problem i see with bbox is it is flawed that it's not always truely 'centre'....ie. for a 'quad'...the centre is same as bbox centre...easy...but say you are dealing with the 2 tris making up that quad...the centre of each tri is somewhere inside the tri...not at the centre of its bbox.

here's the illustration....group shape resembles a triangle...its centre should be inside that triangle...not on its hypotenuse/bbox centre

bboxflaw.hipnc

Edited by Noobini

#### Share this post

##### Share on other sites

Thank you for the answers,

@acey195 very nice use of bbox centers, indeed!

@jon3de I've checked your file however after the packed geo assemble, blast and delete has nothing in them, 0 prims, points, vertices, etc.

Edited by pak

#### Share this post

##### Share on other sites

file is ok here. Check if you have some primitve groups for the assemble sop. Also make sure that you transfer your groups if you create the packed geo in the assemble sop. Than it should work.

#### Share this post

##### Share on other sites

there is no "transfer_groups" parameter for the assemble obj here, that may be the reason. I'm not connecting your file to my content, opening it up directly gives me the above error/popup.

H16 here

#### Share this post

##### Share on other sites

One way I've used before is scale it to 0 on a per primitive basis and then fuse all the points, so that you get the center point of each one. Hope it helps :-)

#### Share this post

##### Share on other sites

Is it something like this?, I am doing it inside a for each, maybe is not what you are looking for, but have a look.

Edited by moneitor
redaction

#### Share this post

##### Share on other sites

No I misunderstood the question, I am gonna prepare something else. Sorry about that.

#### Share this post

##### Share on other sites

This is probably more like that.

pointsOnPrimitiveGroups.hip

#### Share this post

##### Share on other sites
3 hours ago, violalyu said:

One way I've used before is scale it to 0 on a per primitive basis and then fuse all the points, so that you get the center point of each one. Hope it helps :-)

That would solve for "primitives" - but I'm looking for "prim group centers" ~ I believe this method wouldn't work in that case?

#### Share this post

##### Share on other sites

@pak yes sorry I wasn't reading the title carefully! I went from @jon3de 's file and added a (very roundabout) way to get the group name as an attribute on the newly created centroid points, I'm sure there are better ways, but I'll just post it here in case this could be of any inspiration :-)

pointsOnPrimitiveGroups_viola.hipnc

#### Share this post

##### Share on other sites

@violalyuthank you for this nice addition, there are some good vex solutions to this problem indeed, one of the things I'm wondering is - how to solve this without vex

for me, the file @jon3de provided does not work (as described above)

#### Share this post

##### Share on other sites

Hi @pak, I didn't have the error message, but it is basically the same for me, it might be Houdini version difference? I'm using Houdini16.0.633, something might changed from 15.5 to 16?
Also it seems you need the group attribute on the points for some later operation? Maybe there are other ways to directly achieve that, like instead of using group name as the "marker", there might be other attributes that could be used?

#### Share this post

##### Share on other sites

mmm...still wrong to me...because everyone's using BBox logic...if my prim groups are 'triangles' like these in the corners...their prim group center....well...they don't look very centered do they ?

However if all your prim groups are 'rectangular'...well ignore me...all's fine and dandy...

Edited by Noobini

#### Share this post

##### Share on other sites

here's my take on things...look at the classic case in the top left corner, a piece that is a triangular shape, imagine if BBox logic was applied to get the 'center'...it would have been ON the hypotenuse (right angle triangle, basic trig)....WRONG !!!

But with my simple CoM logic (I won't claim it's foolproof, I'm wondering how it works on an L shape)..it's on the inside of the tri itself...

Edited by Noobini
• 3

#### Share this post

##### Share on other sites

FYI, if you load the sample file CentroidPoints, you'll get this Detail Wrangle:

```int nprims = nprimitives(1);
for(int i = 0; i < nprims; ++i)
{
int nvtx = primintrinsic(1, "vertexcount", i);
vector pos = { 0, 0, 0 };
if(nvtx > 0)
{
for(int j = 0; j < nvtx; ++j)
{
int ptidx = vertexpoint(1, vertexindex(1, i, j));
pos += point(1, "P", ptidx);
}
pos /= nvtx;
}
int pt = addpoint(geoself(), pos);
}```

which was my initial idea to solve this problem...while it would work fine if your prim verts were 'evenly' distributed...it falls down when the verts distribution is skewed. so if your prim (or prim group) has this vert distribution, using the wrangle above you'd get the center incorrectly pulled to the highest vert concentration...so I decided to use scatter to even out my sample size so I don't care how 'dodgy' the orig geometry is...

#### Share this post

##### Share on other sites

That's such a clever way to work @Noobini, thank you for this detailed step by step share!

@violalyu I am on 16.0.705 - maybe it's a version difference.. However, I don't have the option "transfer groups" anywhere in that node. Here, check out this brand new assemble node I've placed.

Edit: Just checked help for the node through right click menu, indeed in H16, there is no "transfer groups" option in assemble node. Maybe that's why.

Edited by pak

#### Share this post

##### Share on other sites

Hi @pak thanks for the update! Good to know

## 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

×
• Donations

• Leaderboard