CGTalk > Software Specific Forums > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 02-22-2009, 07:41 PM   #1
JHN
maxscript/c# lover
 
JHN's Avatar
Johan Boekhoven
Technical Artist
nmtrix.com
Netherlands
 
Join Date: Apr 2002
Posts: 1,714
get Position on face, by faceNum and Bary

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
__________________
Online: LinkedIn | blog | nmtrix.com
Code: mxs+.net | c# | mb-python | php | html+js | mysql | python
 
Old 02-22-2009, 08:07 PM   #2
Bobo
Krakatoa Guy
 
Bobo's Avatar
Borislav Petrov
Product Specialist
Thinkbox Software
Vancouver, Canada
 
Join Date: Mar 2002
Posts: 5,317
Quote:
Originally Posted by JHN
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.
__________________
Bobo
 
Old 02-23-2009, 09:28 AM   #3
JHN
maxscript/c# lover
 
JHN's Avatar
Johan Boekhoven
Technical Artist
nmtrix.com
Netherlands
 
Join Date: Apr 2002
Posts: 1,714
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
__________________
Online: LinkedIn | blog | nmtrix.com
Code: mxs+.net | c# | mb-python | php | html+js | mysql | python
 
Old 02-24-2009, 08:29 PM   #4
JHN
maxscript/c# lover
 
JHN's Avatar
Johan Boekhoven
Technical Artist
nmtrix.com
Netherlands
 
Join Date: Apr 2002
Posts: 1,714
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
__________________
Online: LinkedIn | blog | nmtrix.com
Code: mxs+.net | c# | mb-python | php | html+js | mysql | python
 
Old 02-24-2009, 08:29 PM   #5
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:20 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.