Home Technical Talk

GetVertNormalsFromFace script for maya

passerby
polycounter lvl 12
Offline / Send Message
passerby polycounter lvl 12
Wondering if there is a script with the same functionality as this for maya.

http://wiki.polycount.com/VertexNormal?action=show&redirect=Vertex+Normal#GetVertNormalsFromFace_MAXScript


iv been able to accomplish the same thing using mig normals tools, but it is a more involved process than just selecting some faces and running a script.

since i got to select a face, get the face normal from it, than covert to vertices, and set there normals to the face normal, than repeat for each face.

Replies

  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Your looking for transfer attributes -> Normals. No need for a script :)
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    where is that tool?

    also i would need to do 1 face at a time that way, so ideal i want find a way to copy the faces normal vector, into the normal vectors of the verts the face shares, than if i have a selection if multiple faces, have it loop right through and repeat in each selected face.

    edit: found it in the mesh menu, it dosnt do what i want, im not trying to transfer normals from 1 mesh to a other, im trying to take face the normal of a face, and put it into the normals of the faces 4 verts.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    alright i managed to get something that partially works like i want.
    global proc pbFacetoVertNRM() {
    
    	string $normals[] = `polyInfo -faceNormals`;
    	string $buffer[];
    	tokenize $normals[0] $buffer;
    
    	if (size($buffer) < 5) {
    		warning "Select a face!";
    		return;
    	}
    
    	float $plane[3];
    	$plane[0] = $buffer[2];
    	$plane[1] = $buffer[3];
    	$plane[2] = $buffer[4];
    	PolySelectConvert 3;
        	polyNormalPerVertex -xyz $plane[0] $plane[1] $plane[2];
    }
    

    it does what i want if i got 1 face selected at a time, no i just need to stop sucking at scripting, and find a way to make it loop and run on 1 face at a time, if there is a selection of multiple faces.
  • sinistergfx
    Options
    Offline / Send Message
    sinistergfx polycounter lvl 18
    Try 'fillet outside' in mig's with a face selection.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    Try 'fillet outside' in mig's with a face selection.

    that doesn't do what i want, it splits the normal and i end up with 2 normals on 1 vertex.

    i just need to know how to make the above code iterate through all the faces in a face selection, than i have exactly what i need.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    i really dont understand how loops work in mel.

    i tried that but it still does everything as 1, instead of iterating through faces.
    global proc pbFacetoVertNRMTEST() {
    
    	string $Faces[] = `filterExpand -sm 34`;
    
    
    	for ($Face in $Faces)
    	{
    		string $normals[] = `polyInfo -faceNormals`;
    		string $buffer[];
    		tokenize $normals[0] $buffer;
    
    		if (size($buffer) < 5) {
    			warning "Select a face!";
    			return;
    		}
    
    		float $plane[3];
    		$plane[0] = $buffer[2];
    		$plane[1] = $buffer[3];
    		$plane[2] = $buffer[4];
    		PolySelectConvert 3;
        		polyNormalPerVertex -xyz $plane[0] $plane[1] $plane[2];
    		PolySelectConvert 10;
    	}
    }
    
    pbFacetoVertNRMTEST();
    
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Hey passerby you mind illustrating this with an example?
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    ok well the code i have posted in post #4 of this thread, takes a face selection, gets the faces normal, than coverts to verts, and applies that normals to those verts so they have the exact same normal facing as the face.

    the problem with that is that it only works on a selection of 1 face at a time, or it will make all the normals it edits face the same direction, no matter which verts they are.

    more or less want to take that script, and have it work with selections of multiple faces, but work on them 1 at a time.

    busy with other stuff atm, but later i can take screen-shots to what im trying to do, id that description wasn't enough.


    EDIT:

    ok this is what i want it to do.

    facenormalstovertnormals.jpg

    simple takeing the face normal of the selected face, than applying it to the 4 vertices's on that face.

    and the reason why this is useful to me is for normal-map baking.

    the left image is, with out editing the vertex normals like this, and hte one on the right is with the edit vertex normals.

    normalbakes.jpg

    this vertex normal tweak give better and flatter shading, on the flat parts of the cube in the normalmap, which compresses a lot better when brought into udk, since i don't got a big gradient going over the whole thing.

    all im trying ti accomplish with the script is a faster and more efficient way to edit the vertex normals like this, since currently i got to do it all by hand, or use the script i have in post #4, which is still slow, since i need to run that on 1 face at a time.
  • Pola
    Options
    Offline / Send Message
    Pola polycounter lvl 6
    While not the best solution, if you wanted to automate it for now you could perhaps have a script that has a function to iterate through each face in your selection one at a time so that you call it via mouse click and then have the mouse click the necessary buttons in migNormalTools using an autoclicker script to do all the clicks on the screen. Still pretty much doing it manually just with less effort on your end.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    done and working as expected now!
    global proc FaceNRMtoVert() {
    
    
        string $Fs[] = `filterExpand -sm 34`;
        select -cl;
        for ($F in $Fs) {
            select -r $F;
            string $normals[] = `polyInfo -faceNormals`;
            string $buffer[];
            tokenize $normals[0] $buffer;
            
            float $plane[3];
            $plane[0] = $buffer[2];
            $plane[1] = $buffer[3];
            $plane[2] = $buffer[4];  
            PolySelectConvert 3;
            polyNormalPerVertex -xyz $plane[0] $plane[1] $plane[2];
            }
    }
    
  • Eric Chadwick
    Options
    Online / Send Message
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
  • Fingus
    Options
    Offline / Send Message
    Fingus polycounter lvl 11
    Nice, this seems really useful!

    But I can't get it to work. I tried it on a simple cube, both beveled and not beveled, and with one face selected and multiple. It just does nothing. :(
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    how are you running it, and do you got vertex normal view on so you can see what is happening?

    if you just copy and run that code it won't do anything untill you run

    FaceNRMtoVert();

    beat way to use it world be to place it in a file called FaceNRMtoVert.mel in your scripts folder than add FaceNRMtoVert(); to your shelf.

    edit: and what Maya version, I wrote it while on 2012 and I believe froyk has it working on 2013. but I have never tested for older versions of maya since 2012 is the only version I own.
  • Froyok
    Options
    Offline / Send Message
    Froyok greentooth
    Yeah, I got it working as is in Maya 2013, I didn't touch the code in any way.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    ya i think he just ran the code as is with out calling the procedure after.

    since the code only defines the procedure, but dosnt call it.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Tried it on 2011 and worked.
  • Fingus
    Options
    Offline / Send Message
    Fingus polycounter lvl 11
    Indeed I did run it without calling the proc. Was late at night so I didn't look through the code before posting, derp. :s
  • jul_lef
    Options
    Offline / Send Message
    jul_lef polycounter lvl 9
    So I see it works fine on cube type geo but anyone had issues with Cylinder geo ? Can't find a tool around that works well no luck with AMT normal tools LT too :(
Sign In or Register to comment.