Last active
January 3, 2017 17:17
-
-
Save melMass/d967a7ee01f0480644f22a6e94b96656 to your computer and use it in GitHub Desktop.
Simple normalize node in VEX for Houdini (Points)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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