RE: Scripting : Align along normal
| Date : Mon, 31 Oct 2005 13:02:30 -0000 |
| To : <XSI(at)Softimage.COM> |
| From : "kim aldis" <kim(at)cg-soup.com> |
| Subject : RE: Scripting : Align along normal |
var vp1 = XSIMath.CreateVector3();
var vp2 = XSIMath.CreateVector3();
vDir.NormalizeInPlace();
vp1.Cross( vDir , vUp );
vp2 .Cross( vp1, vDir );
vp1.NormalizeInPlace();
vp2 .NormalizeInPlace();
vMat3.Set(
vp1.x, vp1.y, vp1.z,
vDir .x, vDir .y, vDir.z,
vp2.x, vp2.y, vp2.z
);
oRotation= XSIMath.CreateRotation();
oRotation.SetFromMatrix3( vMat3 );
oRotation.GetXYZAngles( vp1 );
return vp1
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf Of guillaume laforge
Sent: 31-October-2005 12:34
To: XSI(at)Softimage.COM
Subject: Scripting : Align along normalHi list :-)I'm learning XSIMath and I can't find how to align an object along the POLYGON normal ? My script seems to work but it doesn't align perfectly along polygon normal :-/. As I'm new to those things I'm wondering if I miss something in the 3d math logic or if in XSI the polygon normal is a special case (compared to normals on points ).Here is my script ://AlignAlongNormal.js
//Select one polygon, run the script and pick an object.
//-----------------------------------------------------//Get the selected polygon
var polySel = Selection.item(0).subcomponent.componentcollection;
var oPolygonFace = polySel(0);
//Get the Polygon Normal
var oPolygonNode = oPolygonFace.Nodes(0);
var >
//Get the Polygon points
1 );
//-----------------------------------------
//Find the Position.
var oPos = XSIMath.CreateVector3();
for ( var i = 0 ; i < oNborsPoints.count ; i++ )
{
oPos.x = oPos.x+oNborsPoints(i).Position.x;
oPos.y = oPos.y+oNborsPoints(i).Position.y;
oPos.z = oPos.z +oNborsPoints(i).Position.z;
}
oPos.x = oPos.x/oNborsPoints.count;
oPos.y = oPos.y/oNborsPoints.count;
oPos.z = oPos.z /oNborsPoints.count;//-------------Align the picked object------------------
//Pick session
var oPicked = PickObject ("Please pick an object") ;
var buttonChoice = oPicked.Value( "ButtonPressed" ) ;
var MyObj = oPicked.item(2);
//Rotation
MyObj.kinematics.global.transform = RotationFromPoly(oNormal) ;//Position
MyObj.Kinematics.Global.Parameters("posx").value = oPos.x;
MyObj.Kinematics.Global.Parameters("posy").value = oPos.y;
MyObj.Kinematics.Global.Parameters("posz").value = oPos.z;//**********From Ray-T Function**********
function RotationFromPoly(polyNormal)
{
var upVec = XSIMath.CreateVector3();
upVec.set(0, 1, 0);
var axis = XSIMath.CreateVector3();
axis.cross(upVec, polyNormal);
var angle = Math.acos(upVec.dot(polyNormal));
var rot = XSIMath.CreateRotation();
rot.SetFromAxisAngle(axis, angle);
var transfo = XSIMath.CreateTransform();
transfo.SetRotation(rot);
return transfo;
}Any advice from experienced user is welcome !
Cheers,
Guillaume Laforge
CG artist | Jr td :)
- Follow-Ups:
- Re: Scripting : Align along normal
- From: guillaume laforge <guillaume.laforge.3d(at)gmail.com>
- Re: Scripting : Align along normal
- References:
- Scripting : Align along normal
- From: guillaume laforge <guillaume.laforge.3d(at)gmail.com>
- Scripting : Align along normal
| DATE: | << | >> | THREAD: | << | >> | INDEX: | Main | Thread |
|---|
- Previous by Date: Re: constant pass
- Next by Date: Re: constant pass
- Previous by Thread: Re: constant pass
- Next by Thread: Re: constant pass
- Index(es):
| Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available. |