ScriptSpot

Forum topic · General Scripting

Align object to face (stick)

By Leandro Salerno · 2008-10-13

Downloads
Description

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)

Comments (2)

Leandro Salerno · 2008-10-15

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.h…
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 · 2008-10-14

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].