Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killiantimsit/ddfef8b357289d884f774cdcf890c3d2 to your computer and use it in GitHub Desktop.
Save killiantimsit/ddfef8b357289d884f774cdcf890c3d2 to your computer and use it in GitHub Desktop.
Houdini - Attribute Wrangle VEX - Delete small floating pieces by number of primitives (Connectivity SOP)
// Houdini - Connectivity SOP > Attribute Wrangle SOP
// Delete small floating pieces by number of primitives
//
// To be used inside the VEXpression parameter of an Attribute Wrangle SOP
// with the "Run Over" mode set to "Detail (only once)".
// The Attribute Wrangle SOP must be placed after a Connectivity SOP
// with the "Connectivity Type" set to "Primitive"
// and the "Attribute" set or linked to connect_attr.
//string connect_attr = chs('../connectivity1/attribname');
string connect_attr = 'class';
int uniq_connect_ids[];
int max_count = 0;
int largest_piece_id;
for (int connect_id = 0; connect_id < nuniqueval(0, 'primitive', connect_attr); connect_id++) {
// List all of the unique values of the connectivity attribute
append(uniq_connect_ids, connect_id);
// Find the "largest" piece (i.e. the one with the most primitives) in the list
int uniq_count = findattribvalcount(0, 'primitive', connect_attr, connect_id);
if (uniq_count > max_count) {
max_count = uniq_count;
largest_piece_id = connect_id;
}
}
// Delete all of the primitives that are not part of the largest piece
removeindex(uniq_connect_ids, largest_piece_id);
foreach (int connect_id; uniq_connect_ids) {
int total_prim_in_piece = findattribvalcount(0, 'primitive', connect_attr, connect_id);
for (int prim_id_in_piece = 0; prim_id_in_piece < total_prim_in_piece; prim_id_in_piece++) {
int prim_to_del_id = findattribval(0, 'primitive', connect_attr, connect_id, prim_id_in_piece);
removeprim(0, prim_to_del_id, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment