Re: Scripting : Align along normal
| Date : Tue, 01 Nov 2005 23:59:24 +1030 |
| To : XSI(at)Softimage.COM |
| From : Raffaele Fragapane <jaco(at)thejaco.com> |
| Subject : Re: Scripting : Align along normal |
to create a 3x3 matrix you need 9 numbers, and that's it :D
however, what you want to do (orienting an object without shearing or non-uniform scaling) requires an orthogonal 3x3 matrix.
that is what you need to create a set of 3 axis that define an orientation.
to do that you need 3 normalized vectors orthogonal to each other.
a cross product performed on any 2 non aligned vectors, returns a 3rd that is orthogonal to both, which is at the base of the double cross product system I pimped in previous emails and posts on other sites.
given one vector (the poly normal, which is what you want to align the Y axis to), another vector to up vector this one(safest upvector to use is a unit vector aligned along the smallest absolute value of your initial vector), and 2 cross products, the result is a set that is guaranteed to create an orthogonal matrix.
as for your script, afaik the polygon node collection is meant to represent edge junctions in your polygon, therefore the normal of the first node you retrieve won't be the same of the polygon's, unless you have a completely flat subsection there.
so either use the old geometry2D (which I don't like nor reccomend, but everytime I neglected it I got told off :P) or use facets or the normalsArray if you want a polygon's normal without the overhead of extrapolating it yourself from the points' normals.
and after you get a normal from your own operations always normalize it in place, even if it shouldn't be a problem when you operate on already normalized vectors and a set number of operands, precision errors creeping in at any point in transformations are always pesky to track if they cascade down.
****************************** | Raffaele Fragapane | | Rising Sun Pictures | | "Remember, TD is for TopDog" | ******************************
guillaume laforge wrote:
Thanks for the help Kim. Raf function gives me a clearer vision of matrix use with XSI :-). So two vector cross products are needed to create the 3X3 matrix ? Not so complicated :-)
However, I found my problem. It came from a wrong normal vector. Maybe some users on this list learn 3d math like me so here is the answer : In my previous script the polygon normal is :
//---------------------------------------------------------
var polySel = Selection.item(0).subcomponent.componentcollection;
var oPolygonFace = polySel(0);
//Get the Polygon Normal
var oPolygonNode = oPolygonFace.Nodes(0);
var oNormal = oPolygonNode.Normal;
//-------------------------------------------------------
In fact it returns a point normal.
So I use this snipet to find the polygon normal :
//--------------------------------------------------------- //Get the selected polygon var polySel = Selection.item(0).subcomponent.componentcollection; var oPolygonFace = polySel(0); nbPoints = oPolygonFace.NeighborVertices (1); var oNormal = XSIMath.CreateVector3(); for(i=0;i<nbPoints.count;i++) { oNormal.AddInPlace(nbPoints.item(i).normal); } oNormal.ScaleInPlace(1/nbPoints.count); //---------------------------------------------------------
Thanks to Heldge Mathee for his scripting tutorials (Getting Started with Scripting in SOFTIMAGE|XSI ). It helps a lot !
Cheers,
Guillaume Laforge Cg Artist | Jr Td
--- Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body: unsubscribe xsi
- Follow-Ups:
- Re: Scripting : Align along normal
- From: guillaume laforge <guillaume.laforge.3d(at)gmail.com>
- Re: Scripting : Align along normal
| DATE: | << | >> | THREAD: | << | >> | INDEX: | Main | Thread |
|---|
- Previous by Date: RE: XSI 5.01 available
- Next by Date: RE: XSI 5.01 available
- Previous by Thread: RE: XSI 5.01 available
- Next by Thread: RE: XSI 5.01 available
- Index(es):
| Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available. |