I found a great post from a brilliant TD Marco Giordano working some normal magic.
http://www.marcogiordanotd.com/blog/cg-general/houdini-otl-normals-on-curve [marcogiordanotd.com]
He was kind enough to share is otl, which I promptly dissected to get a little more knowledge about the dark arts of vector math. My plan was to rebuild it using a Wrangle SOP…because…vex.
I streamlined the Python code he was using and converted it to vex and ended up getting troublesomely different results. See the attached hip file to see the steps I took and the results. Hopefully someone can illuminate and correct the issue. The speed difference between the two is remarkable. But it doesn't really matter if it doesn't work!
cross product: VEX vs Python
4503 2 1- northupfox
- Member
- 15 posts
- Joined: May 2014
- Offline
- tamte
- Member
- 8582 posts
- Joined: July 2007
- Offline
to just fix your code to compute with correct values you need to specify that @tan is vector using v@tan directly:
vector firstVec = {1,0,0};
vector cross1 = cross(firstVec,v@tan);
vector cross2 = cross(v@tan,cross1);
@N = normalize(cross2);
however if you want to have exactly the same result as that python code you have to iterate over points sequentially to avoid flipping (as next N depends on previous)
so change your AttribWrangle to Detail mode and use:
vector firstVec = {1,0,0};
for (int i=0;i<npoints(0);i++)
{
vector tan = point(0, “tan”, i);
vector cross1 = cross(firstVec,tan);
vector cross2 = cross(tan,cross1);
firstVec = normalize(cross2);
setpointattrib(0, “N”, i, firstVec);
}
considering that N attrib already exists, otherwise you would need to create it before or use addattribute to create it within wrangle;
vector firstVec = {1,0,0};
vector cross1 = cross(firstVec,v@tan);
vector cross2 = cross(v@tan,cross1);
@N = normalize(cross2);
however if you want to have exactly the same result as that python code you have to iterate over points sequentially to avoid flipping (as next N depends on previous)
so change your AttribWrangle to Detail mode and use:
vector firstVec = {1,0,0};
for (int i=0;i<npoints(0);i++)
{
vector tan = point(0, “tan”, i);
vector cross1 = cross(firstVec,tan);
vector cross2 = cross(tan,cross1);
firstVec = normalize(cross2);
setpointattrib(0, “N”, i, firstVec);
}
considering that N attrib already exists, otherwise you would need to create it before or use addattribute to create it within wrangle;
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- northupfox
- Member
- 15 posts
- Joined: May 2014
- Offline
-
- Quick Links