View Full Version : How aim polyNormal to an Object center ?

10 October 2005, 12:37 PM
Look at this little sketch who explain What I want to do .. with a mel command.

I have created several yellow polyplane, and it around the sphere shape with the MakeLive function. I doesn't search to orient the plane // to the surface of the blue sphere ! So I want to modify all the face normal of the Yellow shape to get it look at the outer space of the Blue sphere center. As you can see the blue sphere was correctly smooth, and all the normal face of the sphere look perfectly at the opposite of the Center pivot of the sphere.

I want to do that Because .. I want to get a correct light effect on the shape of the yellow plane,as if he look like a sphere.. for good illumination.

How can I do this process in a mel script ?

10 October 2005, 08:30 AM
nobody can help me .... or maybe you work hard to resolve tha problem...:thumbsup:

10 October 2005, 12:19 PM
have you try constraint normal?

should work to fit your plane to the sphere, then delete the constraint if you don't want it anymore..done.


10 October 2005, 08:33 PM
The sphere shape is just here to explain what I want to do with the Normal of the yellow shape..

I would like to orient ( aim ) every normal of the yellow shape to look out of the center of the Yellow shape ( as well as the center of the Blue sphere ). the sphere is just a notice, to understand how I would ike to turn all the normal of the Yellow shape

10 October 2005, 08:46 PM
Will the polyPlanes and the sphere be animated?

10 October 2005, 09:46 PM
Here's a quick script I wrote to orient the normals to have a common
intersection point (sphere's center point in this case).

The usage is as follows:
1) Create a locator and move it to mark the given center point.
(Move the locator's transform-node, not the locator's "Local position" etc. attributes)
2) Select the locator and the geometry to apply the effect on to.
3) Execute the script.

Here's a picture to illustrate the resulting normals.
The individual planes no longer have a faceted look, but
are smoothly Gouraud-shaded to better model the shading
on a sphere.

And the code...

global proc savingSmoluck() {

string $transforms[] = `ls -sl -type "transform"`;
if(size($transforms) < 1) error "Please select a locator!";

int $locatorFound = false;
vector $locator;
for($transform in $transforms) {
string $shapes[] = `listRelatives -children $transform`;
for($shape in $shapes)
if (`nodeType $shape` == "locator")
$locatorFound = true;
$locator = `xform -q -ws -t $transform`;

if($locatorFound) break;
if(!$locatorFound) error "Please select a locator!";

print ("Locator with coordinates: ("+$locator+")\n");

string $objects[] = `filterExpand -sm 12`;
if(size($objects) < 1) error "Please select at least one poly object!";
for($object in $objects) {

int $i; int $numVs[] = `polyEvaluate -vertex $object`;
for($i=0; $i<$numVs[0]; $i++) {

string $V = $object+".vtx["+$i+"]";
vector $point = `xform -q -ws -t $V`;

vector $normal = $point - $locator;
if(normalize($normal) != 1) continue;

polyNormalPerVertex -xyz ($normal.x) ($normal.y) ($normal.z) $V;

10 October 2005, 07:34 AM
Here the mb file With the locator and one shape. I have tested with Maya 6 and 7 , and the script seems to have a problem.. Or it's my mistake..

Please help...And Many Thanks you can resolve that.

10 October 2005, 07:56 AM
but if you just want the plane to orient in a specific direction then just create a locator and aimConstraint your plane to it..what's the probleme with that?.

Or maybe i don't get it.


Ok my bad didn't really understand what you where doing.
I guess the above script sould work then.

10 October 2005, 08:04 AM
To Thematt:

I explain what I want not fairly well as I need maybe.. but I doesn't want to Aim the different plane Shape.. But the "Normal" of the different plane shape. That the Big Difference !

Migugi understood my question, but it seems that the script dosen't work for me. Should I have missed something ?

10 October 2005, 08:13 AM
The thing is, a polygonal face has face normals and vertex normals.
Now if you apply the script straight ahead to the scene you posted
there are a few faces that have a face normal pointing towards the
locator (highlighted red in the picture 1) and cause shading errors when
the script applies the vertex normals to them (in picture 2 the faces are
rendered black). This is because the face normals are facing the opposite
direction than the vertex normals.

What you have to do before executing the script is to flip the direction of the
problematic face normals to point away from the locator.
(Using just the Maya's Edit Polygons -> Normals -> Reverse).

Once all the face normals are facing away from the locator, you can apply the
script, which works on the vertex-normal level. The resulting geometry can then be seen in
picture 3. There are a few faces that are rendered black, but that is due to the
cameras point of view. If you rotate the camera, some other faces are facing the
other way. You can use the Shading -> Back face culling, to toggle the rendering
of back faced polygons. In picture 4 the shading should be fine.

Also, you might want to check out a MEL-tool collection I've written for
manipulating vertex normals

10 October 2005, 08:52 AM
:rolleyes: So I will really thing That I'm from another planet... Test that corrected maya binary file. I've reverse some of the face who in the past looked into the locator.

So now .. if I follow you procedure, I'll have to:

1. Verify if there is quads who look into the locator, and correct it by a reverse command on these face.
2. Select the locator first and the polyshape finally.
3. Execute the mel script... and it's done.

But for me nothing appens...:cry:

Take that new .mb file ( to test it. I have put the mel Script in comment window of the Locator.

And Thanks a lot for your MEL-tool collection , it's very usefull for Lowpoly modeling especialy for gaming. I will show you later why I want to InvertOrient Normal To Locator.

You will see that very usefull in most case, like in a lowpoly tree modeling/rendering ...oups :rolleyes: !

10 October 2005, 10:09 AM
3. Execute the mel script... and it's done.

But for me nothing appens...:cry:

Ahh, so you have trouble executing the script. Here's a few ways you can do it:

Save the whole script as
Documents and Settings\[user name]\My Documents\maya\[version]\scripts\savingSmoluck.mel
Now you can write
in your script editor and execute it. (hilight the script and press Ctrl+Enter)
Or highlight the code and drag it to your shelf with the middle mouse button
to make a shelf button.

Copy the whole script to your script editor and add the line
to the end of the script and execute the whole thing.

See, you can't just execute the script as I pasted it, but you must call the
function defined in the script. Sorry for the inconvenience.

10 October 2005, 10:21 AM
Yes Thanks... I've forget that Point ....Crazy ! :banghead:

So Now , you can Add that little script to your Normal Tool Component You've done all the devellopement...I'm just the Dady of the idea... :bowdown:

CGTalk Moderation
10 October 2005, 10:21 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.