coren
10-07-2009, 05:03 PM
Hi
my problem is to reproduce the autogrid function using maxscript(applied to a face center).
I created a small script to show you my problem.
here it is:
fn createAPlane theName=(
thePlane=plane width:150 length:150 lengthsegs:1 widthsegs:1 name:theName
convertToPoly thePlane
thePlane
)
fn fingAngleFrom3Points A B C =
(
n1=normalize(B-A)
n2=normalize(C-A)
--return
acos(dot n1 n2)
)
fn findZorientation norm =
(
A=[0,0,0]
B=[0,-1,0]
C=norm
C.z=0
C=normalize C
X=C.x
if X!=0 then
((fingAngleFrom3Points A B C)*(X/abs X))
else
(fingAngleFrom3Points A B C)
)
fn generateTransformationMat obj =
(
theNormal=polyop.getFaceNormal obj 1
Zorientation=findZorientation (copy theNormal)
theNormalMatrix=matrixFromNormal theNormal
theFaceCenter=polyOp.getFaceCenter obj 1
theMat=matrix3 1
--ZORIENTATION
rotateZ theMat (Zorientation)
--INCLINATION
rotate theMat (theNormalMatrix.rotationpart )
--TRASLATION
translate theMat theFaceCenter
-- RETURN
theMat
)
theFirstPlane=createAPlane "first plane"
theSecondPlane=createAPlane "Second plane"
move theFirstPlane [200,0,0]
rotate theFirstPlane (eulerangles 40 0 0)
rotate theSecondPlane(eulerangles 40 0 20)
theFirstBox=box name:"first box" width:14 lenght:25 height:12 transform:(generateTransformationMat theFirstPlane)
theSecondBox=box name:"second box" width:14 lenght:25 height:12 transform:(generateTransformationMat theSecondPlane)
execute the script, it create two planes with two boxes in the center(their orientation should be like the one obtained with the autogrid)
If you manually create a box in each plane(with the autogrid function) you should notice that the one on the plane named "second plane" has a different orientation than the one created by script.
I need do replicate the exact autogrid function ad I can't find were I am wrong.
Someone could help me?
Thanks
p.s. sorry for my english
my problem is to reproduce the autogrid function using maxscript(applied to a face center).
I created a small script to show you my problem.
here it is:
fn createAPlane theName=(
thePlane=plane width:150 length:150 lengthsegs:1 widthsegs:1 name:theName
convertToPoly thePlane
thePlane
)
fn fingAngleFrom3Points A B C =
(
n1=normalize(B-A)
n2=normalize(C-A)
--return
acos(dot n1 n2)
)
fn findZorientation norm =
(
A=[0,0,0]
B=[0,-1,0]
C=norm
C.z=0
C=normalize C
X=C.x
if X!=0 then
((fingAngleFrom3Points A B C)*(X/abs X))
else
(fingAngleFrom3Points A B C)
)
fn generateTransformationMat obj =
(
theNormal=polyop.getFaceNormal obj 1
Zorientation=findZorientation (copy theNormal)
theNormalMatrix=matrixFromNormal theNormal
theFaceCenter=polyOp.getFaceCenter obj 1
theMat=matrix3 1
--ZORIENTATION
rotateZ theMat (Zorientation)
--INCLINATION
rotate theMat (theNormalMatrix.rotationpart )
--TRASLATION
translate theMat theFaceCenter
-- RETURN
theMat
)
theFirstPlane=createAPlane "first plane"
theSecondPlane=createAPlane "Second plane"
move theFirstPlane [200,0,0]
rotate theFirstPlane (eulerangles 40 0 0)
rotate theSecondPlane(eulerangles 40 0 20)
theFirstBox=box name:"first box" width:14 lenght:25 height:12 transform:(generateTransformationMat theFirstPlane)
theSecondBox=box name:"second box" width:14 lenght:25 height:12 transform:(generateTransformationMat theSecondPlane)
execute the script, it create two planes with two boxes in the center(their orientation should be like the one obtained with the autogrid)
If you manually create a box in each plane(with the autogrid function) you should notice that the one on the plane named "second plane" has a different orientation than the one created by script.
I need do replicate the exact autogrid function ad I can't find were I am wrong.
Someone could help me?
Thanks
p.s. sorry for my english
