Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killiantimsit/6901f0c97afbe2e9e7ec03d9b44ff313 to your computer and use it in GitHub Desktop.
Save killiantimsit/6901f0c97afbe2e9e7ec03d9b44ff313 to your computer and use it in GitHub Desktop.
Houdini - Attribute Wrangle VEX - Delete small floating pieces by bounding box sizes (Assemble SOP)
// Houdini - Assemble SOP > Attribute Wrangle SOP
// Delete small floating pieces by bounding box sizes
//
// 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,
// "Create groups" option enabled,
// 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 biggest bounding box) in the list
// making use of the groups created by the Assemble SOP
float max_size = 0;
int largest_piece_id;
foreach (int piece_id; string piece_name; pieces_names) {
float piece_length = length(getbbox_size(0, piece_name));
if (piece_length > max_size) {
max_size = piece_length;
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);
}
}
@chrsmlls333
Copy link

You are a lifesaver. +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment