Skip to content

Instantly share code, notes, and snippets.

@melMass
Last active January 3, 2017 17:17
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 melMass/d967a7ee01f0480644f22a6e94b96656 to your computer and use it in GitHub Desktop.
Save melMass/d967a7ee01f0480644f22a6e94b96656 to your computer and use it in GitHub Desktop.
Simple normalize node in VEX for Houdini (Points)
// NORMALIZE in VEX for Houdini
// Normalize input mesh (resize it to 1 unit) and centers it.
//INIT
vector min, max;
getbbox(min, max);
vector center = (min+max)/2;
vector size = set(max.x - min.x,max.y -min.y,max.z - min.z);
// DEBUG
/*
adddetailattrib(0,"Size",{0,0,0});
setdetailattrib(0,"Size",size);
adddetailattrib(0,"AxisRatio","axis");
float max_axis = max(size);
string max_axis_name;
// Simple if case to check which axis are equal max.
if (size.x == max_axis){
max_axis_name += "X";
}
else if (size.y == max_axis){
max_axis_name += "Y";
}
else if (size.z == max_axis){
max_axis_name += "Z";
}
setdetailattrib(0,"AxisRatio",max_axis_name);
*/
matrix3 sm = ident();
float scale_factor = (1 / max_axis) * ch("scale");
scale(sm,scale_factor);
@P *= sm;
@P.x -= center.x*scale_factor;
@P.y -= (center.y- size.y/2) * scale_factor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment