Align object to face (stick)

Hello, I need to correct a problem in a script that I need

I need an object stuck in the face of a normal

my code in ScriptController in transform for de face 76 in sphere02

dependsOn $Sphere02
(
Pos= polyop.getFaceCenter $sphere02 76
Norm = (polyop.getFaceNormal $sphere02 76)

worldUpVector = [0,0,1]

rightVector = normalize(cross worldUpVector Norm)
upVector = normalize(cross rightVector Norm)
matrix3 rightVector upVector Norm Pos
)

In principle it works, but there are problems in the rotation of the object aligned....obviously not well

any suggestions?
(attach my example 3ds max 2009)

thank you!!!
(sorry for my bad inglish)

AttachmentSize
orient.max232 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Leandro Salerno's picture

what we needed was that

what we needed was that attached to the center of the face selected...
$sphere02.dir produces an incorrect rotation in the object attached...

I could solve it with help from Cesar Saez in http://www.foro3d.com/f115/maxscript-orientar-objeto-a-normal-de-66833.html
two faces were used to calculate a vector from worldUpVector...

dependsOn $Teapot01
(
Pos= polyop.getFaceCenter $Teapot01 858
 
Pos2= polyop.getFaceCenter $Teapot01 844
 
Norm =  (polyop.getFaceNormal  $Teapot01 858)
 
worldUpVector = (pos - pos2)/Length(pos - pos2)
 
rightVector = normalize(cross worldUpVector Norm)
 
upVector = normalize(cross rightVector Norm)   
 
matrix3 rightVector upVector Norm Pos
)

thanks anyway!!!

KaSa's picture

Do you want to keep the

Do you want to keep the attached object from rotating on its z axis? If that is the case, use an axis of the base object instead of worldUpVector. For example, use $sphere02.dir instead of [0,0,1].

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.