Home Technical Talk

[Maya] Mel command for convertLightmap

greentooth
Offline / Send Message
Froyok greentooth
Hello guys,

I'm trying to make little and simple script for baking the lighting in my scene.
Nothing complicated, but I stuck on an error that I can't understand.

Here is my little code :
global proc RenderToVertex()
{
    //create backset ?
    $bakeSet = "ParadiseBackSet";
    
    if(!`objExists $bakeSet`)
    {
        $bakeSet = `createNode -n "ParadiseBackSet" vertexBakeSet`;
    }
    
    //setup backset
    setAttr ($bakeSet+".bakeColor") 1;
    setAttr ($bakeSet+".bakeAlpha") 0;
    setAttr ($bakeSet+".colorMode") 2; //only Global Illumination
    setAttr ($bakeSet+".normalDirection") 1; //Surface front
    setAttr ($bakeSet+".scaleRgba") 1.0;
    setAttr ($bakeSet+".colorBlending") 3; //Multiply
    //setAttr ($bakeSet+".colorSetName") ""; //none, use default selected on mesh

    string $sel[] = `ls -sl`;
    string $list = "";
    
    if(size($sel) != 0)
    {
        //get shape per object and add them to the list
        for($obj in $sel)
        {
            // get the shading engine of current geometry
            string $temp = ParadiseGetShapes($obj);
            
            string $conn[] = `listConnections -type "shadingEngine" $temp`;
            string $shadingEngine = $conn[0];

            $base = ($shadingEngine + " " + $temp);
            
            //string $material = $HH[0];
            
            //print ($material + " " + $obj + "\n");
            
            $list = ($list + " " + $base);
        }
        
        //apply the GI
        convertLightmap  
            -camera persp 
            -sh -vm //shadow and vertices
            -bakeSetOverride $bakeSet //backset defined before
            $list;
        
    }
}
Unfortunately, the step with my $list variable doesn't work. I got this error :
// Error: (Mayatomr) : at least one shading group and one dag object expected, command not executed //
My shapes listed before ARE dag objects, they are listed with the initialShadingGroup (I believe this is what Maya find as a non-dag object).

But how to send a list of shapes to this command without using a string variable ? The purpose is to send all the shapes at once to execute the computation of the lighting only once. The command works fine if I repeat the convertLightmap per shapes (but this increase the time of computation unfortunately). Also what I don't understand is that if I use the "Mental Ray Baking Options" window with multiple shapes, it works fine, and the command is exactly as the one in my code.


I'm totally lost (and soon I will be mad).

Replies

  • Froyok
    Options
    Offline / Send Message
    Froyok greentooth
    Looks like :
    convertLightmapSetup  -camera persp -sh -vm -bakeSetOverride $bakeSet -showcpv;
    
    works fine.

    Why ? I don't know, the command is undocumented. :facepalm:
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Froyok, I think the problem from browsing the code is that Maya thinks your $list is one DAG object (which when concatenated together doesn't exist). Something that would be interesting to check is the execution time between doing it that way and for loop. I think Maya behind the scenes is doing it per shape.
Sign In or Register to comment.