Last active
April 10, 2023 18:48
-
-
Save skyburchard/405edc75b8c0fbcfc1648971b1dbada4 to your computer and use it in GitHub Desktop.
houdini vex snippets
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
/////////////////////// | |
// houdini vex snippets | |
/////////////////////// | |
// get angle between two vectors ( 0 - 360 dergees ) | |
float angleBetween ( vector v1; vector v2 ) { | |
// define up vector | |
vector up = {0.0, 1.0, 0.0}; | |
float angle = acos(dot(v1, v2)); | |
int firstHalf = sign(dot(v2, cross(up, v1))) >= 0; | |
angle = firstHalf ? angle : 2 * PI - angle; | |
return degrees(angle); | |
} | |
// get nearest point on a finite line | |
vector nearestPointOnFiniteLine ( vector start; vector end; vector pnt ) { | |
vector line = (end - start); | |
float lineLength = length(line); | |
line = normalize(line); | |
vector v = pnt - start; | |
float d = dot(v, line); | |
d = clamp(d, 0.0, lineLength); | |
return start + line * d; | |
} | |
// get array of attribute names, useful for iterating over all attributes | |
// it can only get attributes that already exist, not attributes created in current wrangle | |
string pointattributes[] = detailintrinsic(0, "pointattributes"); | |
///////////////////////// | |
// unique values of array | |
///////////////////////// | |
// src: https://www.sidefx.com/forum/topic/59111/?page=1#post-322116 | |
function int[] fn_arrayuniqueval (int arr[]) | |
{ | |
int tmp[] = {}; | |
foreach(int src; arr) | |
{ | |
int i =0; | |
foreach(int itm; tmp) if (src == itm) i++ ; | |
if (i == 0) append(tmp, src); | |
} | |
return arr = tmp; | |
} | |
// Custom Code | |
i[]@List = {1,8,8,2,7,3,8,4,8,6,7,1,1}; | |
@List = fn_arrayuniqueval(@List); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment