PDA

View Full Version : get Position on face, by faceNum and Bary


JHN
02-22-2009, 06:41 PM
I have a face I want to track like the attachment controller does, but then by script.
So I have a faceNumber and a barycentric coord. from the hit ray and now I want to know what position in worldspace it is at a certain time, and a normal direction would be great too.

If it's not easy I can always bake out an attachment controller, but I would like to know if it can be done programmaticly, and by what code, I don't see a lot of methods beside pointPos like functions... Any pointers would be great, but I'm getting the feeling it's going to be by the faceverts and going from there.

Thanks!
-Johan

Bobo
02-22-2009, 07:07 PM
I have a face I want to track like the attachment controller does, but then by script.
So I have a faceNumber and a barycentric coord. from the hit ray and now I want to know what position in worldspace it is at a certain time, and a normal direction would be great too.

If it's not easy I can always bake out an attachment controller, but I would like to know if it can be done programmaticly, and by what code, I don't see a lot of methods beside pointPos like functions... Any pointers would be great, but I'm getting the feeling it's going to be by the faceverts and going from there.

Thanks!
-Johan

The position is easy:

theFace = getFace theMesh theFaceIndex --gives a Point3 with 3 vertex indices
theVert1 = getVert theMesh theFace.x --get the position of vertex 1
theVert2 = getVert theMesh theFace.y --get the position of vertex 2
theVert3 = getVert theMesh theFace.z --get the position of vertex 3
--now calculate the point by multiplying each position by the Bary and adding the values:
thePos = theVert1*theBary.x + theVert2*theBary.y + theVert3*theBary.z

The intersectRayEx will give you the FACE normal, but if you want to average the vertex normals, you can do exactly the same as above, but read the 3 vertex normals, multiply by the bary components and add together. The trouble is taking into account smoothing groups, since the point might be influenced by face or vertex normals depending on what groups that face shares with its neighbors.

JHN
02-23-2009, 08:28 AM
Bobo,

Thanks for that! It makes sense, and retrieving the normal by the 3 vertex normals should be enough for my needs, tracking a null overtime over a surface, I just need the general direction, probably going to reduce the resulting keyframes as well.

Many thanks!
-Johan

JHN
02-24-2009, 07:29 PM
Hmm, it seems the manual tracking of a face normal is not as accurate as the attachment controller is. It probably uses some more advanced logic. If a face is rotated by bend for example more then, I think, 90 degrees it starts to return flipped values for the normal.


How does the attachment controller calculate it's position on the face, since it seems to stick to the surface just right (so now I wrote my script around a temporary attachment controller baking the transform values back). I'd interested in pseudo code or real code, to see what I'm missing.

Thanks!
-Johan

CGTalk Moderation
02-24-2009, 07:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.