Skip to content

Instantly share code, notes, and snippets.

@melMass

melMass/MTB_normalize.c

Last active Jan 3, 2017
Embed
What would you like to do?
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