Copy Vertices Normal to Vertices Color
color per ver normal map applied normal map

This simple MEL script iterate through the selected polygonal model vertices queries each vertex normal and applies respectively the XYZ values after normalization to the RGB values of the same vertex. After which the user bakes the color value to an image and process that image the Photoshope to be used as Normal Map.

  • Script:

    // Usage select a single polygonal model and run the script
    // Create to float arrays to hold the vert color and normal,
    // Maya float is actually a double
    float $xyz2RGB[],$norm_xyz[];

    // Create a string array to hold the selected model list
    string $polyname[]=`ls -sl`;

    // Clear the selection
    select -cl;

    // Get the vert count of the selected model,
    // polyEvaluate returns an array
    int $polyCurrentVert[]=`polyEvaluate -v $polyname[0]`;

    // Initialize current vert
    int $currentVert = 0;

    // Iterate through the selected model verts
    for (; $currentVert < $polyCurrentVert [0]; $currentVert++)
    {
        // select a vertex
        select -r ($polyname[0]+".vtx["+$currentVert+"]");

        // Query the vertex normal xyz value
        $norm_xyz = `polyNormalPerVertex -q -xyz`;

        // Shift each normal value from (1,1) to (0 through 1)
        $xyz2RGB[0] = (($norm_xyz[0] * .5)+.5);
        $xyz2RGB[1] = (($norm_xyz[1] * .5)+.5);
        $xyz2RGB[2] = (($norm_xyz[2] * .5)+.5);

        // Set the selecte vert color with the new value
        polyColorPerVertex -nun -rgb $xyz2RGB[0] $xyz2RGB[1] $xyz2RGB[2];

        // Clear the selection
        select -cl;
    }