Re: Scripting : Align along normal

Date : Tue, 1 Nov 2005 15:23:42 +0100
To : XSI(at)Softimage.COM
From : guillaume laforge <guillaume.laforge.3d(at)gmail.com>
Subject : Re: Scripting : Align along normal
Thanks a lot Raffaele for the nice explanations :-)
 
>to create a 3x3 matrix you need 9 numbers, and that's it :D
I know that ;-). I was thinking about orthogonal 3x3 matrix.
All those concepts are new in my mind so I keep things rather vague ;-).
 
>and after you get a normal from your own operations always normalize it
>in place...
Good to know to avoïd the "matric creep" ;-) . I read it is possible to "othogonalize" a slightly out of orthogonality matrix ( because of floating point error). It is an other thing I need to find how to do in XSI :-p.
 
Cheers,
 
Guillaume Laforge
Cg Artist | Jr Td

 


 
2005/11/1, Raffaele Fragapane <jaco(at)thejaco.com>:
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 >> //-------------------------------------------------------
>
> 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 >> 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


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.