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/3c6281d056e6dd0beb75f018816218e7 to your computer and use it in GitHub Desktop.
Save killiantimsit/3c6281d056e6dd0beb75f018816218e7 to your computer and use it in GitHub Desktop.
Houdini - Attribute Wrangle VEX - Delete small floating pieces by number of primitives (Assemble SOP)
// Houdini - Assemble 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 geometry must be assembled first using an Assemble SOP
// with the "Create Packed Geometry" option disabled
// and the "Output Prefix" set or linked to assemble_output_prefix.
//string assemble_output_prefix = chs('../assemble1/outside_group');
string assemble_output_prefix = 'piece';
// List all of the unique 'name' values in the geo (e.g. piece0, piece1, etc.)
string pieces_names[];
for (int piece_num = 0; piece_num < nuniqueval(0, 'primitive', 'name'); piece_num++) {
string piece_name = sprintf('%s%d', assemble_output_prefix, piece_num);
append(pieces_names, piece_name);
}
// Find the "largest" piece (i.e. the one with the most primitives) in the list
int max_count = 0;
int largest_piece_id;
foreach (int piece_id; string piece_name; pieces_names) {
int uniq_count = findattribvalcount(0, 'primitive', 'name', piece_name);
if (uniq_count > max_count) {
max_count = uniq_count;
largest_piece_id = piece_id;
}
}
// Delete all of the primitives that are not part of the largest piece
removeindex(pieces_names, largest_piece_id);
foreach (int piece_id; string piece_name; pieces_names) {
int total_prim_in_piece = findattribvalcount(0, 'primitive', 'name', piece_name);
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', 'name', piece_name, 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