# Polynormalpervertex

**URL:** https://forum.highend3d.com/t/polynormalpervertex/2130
**Category:** Maya
**Tags:** mel
**Created:** [June 28, 2007, 6:30pm UTC](https://forum.highend3d.com/t/polynormalpervertex/2130 "2007-06-28T18:30:43Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![glenpoo](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/g/a8b319/32.png) [@glenpoo](https://forum.highend3d.com/u/glenpoo)
#### Post date: [June 28, 2007, 6:30pm UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/1 "2007-06-28T18:30:43Z")

</div>

The goal of this script is to make a tool that will move all normals with individual offsets relative to their position. currently moving batch normals (with the maya tool) results in all normals facing the exact same direction. This is not good for spheres or pretty much anything else with a curve to it. The problem i have is when i put a slider for each axis and pass that variable into the "polyNormalPerVertex" for the axis it only registers on the 0 or 180 degrees. here is the script:

window -h 50 -w 50 -s true -t normalEdit;  
columnLayout;

string $xSlider = `floatSliderGrp -dc "xSet(`floatSliderGrp -q -v $xSlider`)" //slider that sends its float to proc xSet -cc "xSet(`floatSliderGrp -q -v $xSlider`)" -min -1.0 -max 1.0 -f true -l X -pre 4`;

string $ySlider = `floatSliderGrp -dc "ySet(`floatSliderGrp -q -v $ySlider`)" //slider that sends its float to proc ySet -cc "ySet(`floatSliderGrp -q -v $ySlider`)" -min -1.0 -max 1.0 -f true -l Y -pre 4`;

string $zSlider = `floatSliderGrp -dc "zSet(`floatSliderGrp -q -v $zSlider`)" //slider that sends its float to proc zSet -cc "zSet(`floatSliderGrp -q -v $zSlider`)" -min -1.0 -max 1.0 -f true -l Z -pre 4`;

showWindow;

proc xSet(float $xOffSet){  
 //string $verts[] = `filterExpand -selectionMask 31`; //store object's verts in an array  
 //$numVerts = `size $verts`; //sore how many verts in array  
 polyNormalPerVertex -rel -x $xOffSet; //todo loop through verts and adjust them individually  
 print $xOffSet;  
 };  
proc ySet(float $yOffSet){  
 //string $verts[] = `filterExpand -selectionMask 31`;  
 //$numVerts = `size $verts`;  
 polyNormalPerVertex -rel -y $yOffSet;  
 print $yOffSet;  
 };  
proc zSet(float $zOffSet){  
 //string $verts[] = `filterExpand -selectionMask 31`;  
 //$numVerts = `size $verts`;  
 polyNormalPerVertex -rel -z $zOffSet;  
 print $zOffSet;  
 };

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [June 29, 2007, 10:31am UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/2 "2007-06-29T10:31:15Z")

</div>

hmm.. before I assemble a script to do that with -relative, I'd checked if if works manually ;]  
And I see: Doesn't seem so!

eg: polyNormalPerVertex -rel -y 0.1; just turns all normals up. As if the "-rel"-flag has no meaning at all.

But I'd love to have such a script as well!!! But I doubt the slider-version is handy enough for my high requisitions ![]() !!

I thought about clustering al concerned vertices, but clusters don't change normals.  
Seems the only reliable thing would be to query the normal values and reasign a fresh calculated ones per vertex (or even per vertex face)

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [June 29, 2007, 10:36am UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/3 "2007-06-29T10:36:50Z")

</div>

well you cant actually do enything usefull with this in animation. since the normals get recalculated on each deform so...

Good for statics. (but especialy usefull is the ability to push one faces normals out to meet the next faces normal!)

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [June 29, 2007, 11:39am UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/4 "2007-06-29T11:39:26Z")

</div>

Hi Joojaa!  
What u mean? the clusters?

Do you have a cool idea how one could turn vertexnormals relatively?

And don't tell me via APi ;]

---

<div class="post-metadata">

### Author: ![glenpoo](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/g/a8b319/32.png) [@glenpoo](https://forum.highend3d.com/u/glenpoo)
#### Post date: [June 29, 2007, 2:02pm UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/5 "2007-06-29T14:02:34Z")

</div>

no it doen't work manually. that's the point of making the script. eventually i will have to query each vertex for its position do some math based on that vector to move it accordingly. but the main problem i'm worried about at the moment is why the sliders variable doesn't move the normal correctly. try the script as it sits. the normal jumps from 1 to -1 with no intermediate. also it overides the other two degrees of freedom even though the -x -y -z flags are set.

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [June 29, 2007, 5:55pm UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/6 "2007-06-29T17:55:31Z")

</div>

Nah! If it doesn't work manually, why do you expect it to work in a script? :]

I managed to make it work with a given offset like  
[b]rotateMyVertexNormals 10 0 0;

[/b]but I gotta go now. I show you later.

---

<div class="post-metadata">

### Author: ![glenpoo](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/g/a8b319/32.png) [@glenpoo](https://forum.highend3d.com/u/glenpoo)
#### Post date: [June 29, 2007, 9:43pm UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/7 "2007-06-29T21:43:19Z")

</div>

it works fine on individual vertex normals manually, not batch.

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [July 2, 2007, 8:48am UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/8 "2007-07-02T08:48:14Z")

</div>

really? Not here! Doesn't on one neither on many.  
Can you show me how?

btw: here is my attempt:

I just take the vector, rotate it, apply it! Simple as that:

CODE  
global proc ezNormalTool\_relRotNormals(float $rx, float $ry, float $rz)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;// get vertices flattened with ls -fl  
&nbsp;&nbsp;&nbsp;&nbsp;string $sel[] = `ls -sl`;  
&nbsp;&nbsp;&nbsp;&nbsp;string $vtxs[] = ls("-fl",`polyListComponentConversion -tv`);  
&nbsp;&nbsp;&nbsp;&nbsp;select -d;  
&nbsp;&nbsp;&nbsp;&nbsp;for ($vtx in $vtxs)  
&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// if the vertex' normals are splitted handle each vertexFace for itself  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (`ez\_IsNormalSplitted $vtx`)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $vtxFs[] = ls("-fl",polyListComponentConversion("-toVertexFace", $vtx));  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for ($vtxF in $vtxFs)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float $normal[] = `polyNormalPerVertex -q -xyz $vtxF`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float $newNormal[] = ezRotateVector($normal[0], $normal[1], $normal[2], $rx, $ry, $rz);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;polyNormalPerVertex -xyz $newNormal[0] $newNormal[1] $newNormal[2] $vtxF;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// else do the whole vertex  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float $normal[3] = `polyNormalPerVertex -q -xyz $vtx`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float $newNormal[] = ezRotateVector($normal[0], $normal[1], $normal[2], $rx, $ry, $rz);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;polyNormalPerVertex -xyz $newNormal[0] $newNormal[1] $newNormal[2] $vtx;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;select $sel;  
}

// you gonna need these as well:

global proc int ez\_IsNormalSplitted(string $vertex)  
 {  
&nbsp;&nbsp;&nbsp;&nbsp; // get all vertexFaces from this vertex  
&nbsp;&nbsp;&nbsp;&nbsp; string $vtxFs[] = ls("-fl",polyListComponentConversion("-toVertexFace",$vertex));  
&nbsp;&nbsp;&nbsp;&nbsp; int $numVFs = size($vtxFs);

&nbsp;&nbsp;&nbsp;&nbsp; // loop them all but the last  
&nbsp;&nbsp;&nbsp;&nbsp; for($i1 = 0; $i1 \< ($numVFs - 1); $i1++)  
&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for($i2 = ($i1 + 1); $i2 \< $numVFs; $i2++)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vector $vVtxF1 = `polyNormalPerVertex -q -xyz $vtxFs[$i1]`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vector $vVtxF2 = `polyNormalPerVertex -q -xyz $vtxFs[$i2]`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // if their vectors match  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($vVtxF1 != $vVtxF2)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp; return 0;  
 }

global proc float[] ez\_RotateVector(float $vx, float $vy, float $vz, float $rx, float $ry, float $rz)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;float $temp, $sx, $cx, $sy, $cy, $sz, $cz;

&nbsp;&nbsp;&nbsp;&nbsp;$rx = deg\_to\_rad($rx);  
&nbsp;&nbsp;&nbsp;&nbsp;$ry = deg\_to\_rad($ry);  
&nbsp;&nbsp;&nbsp;&nbsp;$rz = deg\_to\_rad($rz);

&nbsp;&nbsp;&nbsp;&nbsp;$sx = sin($rx);  
&nbsp;&nbsp;&nbsp;&nbsp;$cx = cos($rx);  
&nbsp;&nbsp;&nbsp;&nbsp;$sy = sin($ry);  
&nbsp;&nbsp;&nbsp;&nbsp;$cy = cos($ry);  
&nbsp;&nbsp;&nbsp;&nbsp;$sz = sin($rz);  
&nbsp;&nbsp;&nbsp;&nbsp;$cz = cos($rz);

&nbsp;&nbsp;&nbsp;&nbsp;$temp = $vy \* $cx - $vz \* $sx;  
&nbsp;&nbsp;&nbsp;&nbsp;$vz&nbsp;&nbsp; = $vy \* $sx + $vz \* $cx;  
&nbsp;&nbsp;&nbsp;&nbsp;$vy&nbsp;&nbsp; = $temp;

&nbsp;&nbsp;&nbsp;&nbsp;$temp = $vz \* $sy + $vx \* $cy;  
&nbsp;&nbsp;&nbsp;&nbsp;$vz&nbsp;&nbsp; = $vz \* $cy - $vx \* $sy;  
&nbsp;&nbsp;&nbsp;&nbsp;$vx&nbsp;&nbsp; = $temp;

&nbsp;&nbsp;&nbsp;&nbsp;$temp = $vx \* $cz - $vy \* $sz;  
&nbsp;&nbsp;&nbsp;&nbsp;$vy&nbsp;&nbsp; = $vx \* $sz + $vy \* $cz;  
&nbsp;&nbsp;&nbsp;&nbsp;$vx&nbsp;&nbsp; = $temp;

&nbsp;&nbsp;&nbsp;&nbsp;float $resV[] = {$vx, $vy, $vz};  
&nbsp;&nbsp;&nbsp;&nbsp;normalize($resV);  
&nbsp;&nbsp;&nbsp;&nbsp;return $resV;  
}

now ezNormalTool\_relRotNormals 10 0 0; rotates all your vertices normals in the selection by 10 degrees on x-axis.

The problem with the slider is also: A slider is a absolute control its hard to make it do relative changes. You'd need to compare the last and the current value to make a valid change. And so you,d need to store your value somehow. maybe in the ui as well not in global vars.

---

<div class="post-metadata">

### Author: ![dbiggs](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/d/eb9ed0/32.png) [@dbiggs](https://forum.highend3d.com/u/dbiggs)
#### Post date: [July 2, 2007, 9:29am UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/9 "2007-07-02T09:29:56Z")

</div>

QUOTE(ewerybody @ 07/02/07, 12:48 AM) [snapback]269032[/snapback]  
The problem with the slider is also: A slider is a absolute control its hard to make it do relative changes. You'd need to compare the last and the current value to make a valid change. And so you,d need to store your value somehow. maybe in the ui as well not in global vars.

Just make a copy of your mesh and refer to that, it's the perfect backup of the normals.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [July 2, 2007, 10:23am UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/10 "2007-07-02T10:23:04Z")

</div>

or write it to blind data?

---

<div class="post-metadata">

### Author: ![ewerybody](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewerybody](https://forum.highend3d.com/u/ewerybody)
#### Post date: [July 2, 2007, 11:08am UTC](https://forum.highend3d.com/t/polynormalpervertex/2130/11 "2007-07-02T11:08:57Z")

</div>

QUOTE  
Just make a copy of your mesh and refer to that, it's the perfect backup of the normals.

what?!? at every drag as I slide? for a simple float value?

But backing up the mesh is a valuable option! As polyNormalPervertex crashes your Normals sometimes. Do you have similar experiences?
