RE: [script] Normals - not understanding

Date : Wed, 18 Oct 2006 15:27:47 -0400
To : <XSI(at)Softimage.COM>
From : "Mathieu Leclaire" <mleclair(at)hybride.com>
Subject : RE: [script] Normals - not understanding
You are assigning the normal x,y,z to the nulls local x,y,z rotation
values... of course you'll have weird result. If what you are looking for is
to orient the nulls positive Z axis in the direction of the normal and the Y
axis towards the global Y axis, what you should do is something more along
the lines of this:

vZ = ovGlobalNormal;
vY.Set(0, 1, 0);
vX.Cross(vY, vZ);
vY.Cross(vZ, vX);
var t1 = XSIMath.CreateTransform();
vX.NormalizeInPlace();
vY.NormalizeInPlace();
vZ.NormalizeInPlace();
t1.SetRotationFromXYZAxes( vX, vY, vZ);
oNull.kinematics.global.Transform = t1;

Of course, this is in java so I'll let you the pleasure to convert it to
which ever language best fits you.

Hope this is what you where looking for.

Mathieu Leclaire
R&D Programmer
Hybride technologies

-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM]On Behalf
Of Bernard Lebel
Sent: Wednesday, October 18, 2006 3:00 PM
To: XSI(at)Softimage.COM
Subject: [script] Normals - not understanding


Hi,

I'm writing a script that extracts the normal vector of every point of
a mesh. Then these vectors are mapped to world space. Finally, for
each point, a null is created and the world vector is applied to its
rotation.

For a minority of normals, it works well, the null ends up with the
right orientation. But for a majority of them, the null has an
orientation that I have a hard time to figure out.

If you create a sphere and run the code below, you'll see what I mean:


import win32com

xsi = Application
xsimath = win32com.client.Dispatch( 'XSI.Math' )

oMesh = xsi.selection(0)
oMeshTransform = oMesh.kinematics.local.transform

for oPoint in oMesh.activeprimitive.geometry.points:

	# Get global point normal direction
	ovGlobalNormal = xsimath.mapobjectorientationtoworldspace(
oMeshTransform, oPoint.normal )

	# Get New point position
	ovGlobalPosition = xsimath.mapobjectpositiontoworldspace(
oMeshTransform, oPoint.position )

	# create null
	oNull = xsi.activesceneroot.addnull()

	oNull.kinematics.local.rotx.value = xsimath.radianstodegrees(
ovGlobalNormal.x )
	oNull.kinematics.local.roty.value = xsimath.radianstodegrees(
ovGlobalNormal.y )
	oNull.kinematics.local.rotz.value = xsimath.radianstodegrees(
ovGlobalNormal.z )

	oNull.kinematics.local.posx.value = ovGlobalPosition.x
	oNull.kinematics.local.posy.value = ovGlobalPosition.y
	oNull.kinematics.local.posz.value = ovGlobalPosition.z



Any idea?


Using XSI 5.11


Thanks
Bernard
---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi



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