View Full Version : Unlocking normal script
01-15-2004, 01:50 PM
I'm trying to make a small script that unlocks vertex normals without destroying all the painfully made tweaks.
The idea is simple:
-get normal B from vertex.face
- unlock normal (this sets the normal to the vertex normal)
- set normal B to vertex.face
However, it doesn't work and I haven't got a clue why. The script simply resets the normals to the vertex normal. Maybe it isn't possible to query and set normals on vertex.faces?
// get selection from scene
string $zelection = `ls -sl -fl`;
// convert to vertex faces
string $vertsFaces = `polyListComponentConversion -toVertexFace $zelection`;
// reselect vertexFaces in scene to flatten selection
select -r $vertsFaces;
$vertFaces = `ls -sl -fl`;
int $numberOfVertexFaces = size($vertFaces);
for($i=0; $i<$numberOfVertexFaces; $i++)
// get normal
float $currentNormal = `polyNormalPerVertex -q -xyz $vertFaces[$i]`;
// unlock normal
polyNormalPerVertex -ufn true $vertFaces[$i];
// set normal
polyNormalPerVertex -xyz $currentNormal $currentNormal $currentNormal $vertFaces[$i];
01-16-2004, 07:49 PM
I'm getting to the core of the problem...the apply normal to vertex faces doesn't seem to work correctly, try this:
Create a sphere
Delete all but four faces so that you end up with a curved square
Go to vertex-face mode and select one vertex-face that is in the middle.
Execute this line in the script editor:
float $normal = `polyNormalPerVertex -q -xyz`;
polyNormalPerVertex -xyz $normal $normal $normal;
The get/set normal should result in exactly the same normal on the vertex-face, but as you can see the normal is not the same. Also, normals on other vertex-faces (top and side of the face) change, even though I don't even have them selected!
Anybody got a clue why this is happening? I know that the query part (first line) is correct, I've used this function in an geometry exporter without problems.
01-16-2004, 10:25 PM
Is there a way to do this manualy. And if so, does that work well.
I will try if i can come up with some solution. There must be a way to get this going right.
By the way, did you check the Forum on Highend3d.
:: Galactor ::
01-17-2004, 09:38 AM
You can unlock them manually with 'set vertex normal' with the unlock option on, but that will destroy all the normal data (normals set to vertex). That's why I want to write this script :)
I don't read the Highend3d forums, was there anything related to this problem over there? Could you give me a link?
01-17-2004, 10:37 PM
I looked in the docs to see what "polyNormalPerVertex" is all about. And this was the discription of the function.
Command associates normal(x, y, z) with vertices on polygonal objects. When used with the query flag, it returns the normal associated with the specified components. However, when queried, the command returns all normals (all vtx-face combinations) on the vertex, regardless of whether they ar shared or not.
So i wonder, doesn't the "However" part of the discription tell why it is not working.
And here is the forum of Highend. It even has a special game section. The forum on Highend hosts a lot of proffesional users.
:: Galactor ::
01-18-2004, 10:34 AM
One vertex can consist of multiple vertex-faces. So what it is saying is that one vertex can have more than one normal, in which case it outputs them all. Since I select only one vertex-face I avoid this problem, a vertex-face can have only one normal.
I am quite sure that the value I get from the vertex-face is correct, since I have used it in an exporter and all normals turned out fine.That would mean that it is not possible to set normals on individual vertex-faces...which would suck :shrug:
The face vertex normals are initially shared. When you change one individually, you split them all forcing them to be re-computed. I'm guessing if you save all the values first, then unfreeze and set them, it would work.
01-19-2004, 02:58 PM
It works, brilliant!
I'll post the script this week, after I do a little more testing...
05-17-2004, 07:32 AM
Here is the unlock normals script. I've had a few nasty crashes in the beginning, that's why I didn't post it yet. I haven't had any problems after that, but do backup your work before using :)
05-17-2004, 07:54 AM
Here is a related script. It is a script for averaging normals between multiple objects. For example, making the normals of a leg of a characters seamless with the pelvis but still having seperate objects.
It's really slow, so it is probably only usefull for game stuff. If it doesn't work correctly you need to use the unlock normal script I've posted in the message above.
05-18-2004, 09:28 AM
The average normal script doesn't take the scaling of the object into account, so if the object is scaled you need to freeze transformations on the object for it to work correctly.
01-17-2006, 04:00 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.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.