Hello everybody and thanks for your attention.
On the one hand I have a Maya scene which contains complex nodal materials.
Example :
On the other hand I have a personnal OpenGL rendering application. In order to interpret these complex materials in my application, I want to bake them using "Mentalray Batch Bake".
I can do it manually, by :
1) Select the material and the related mesh
2) Go to panel Rendering --> Lighting/Shading --> Batch Bake (mental ray)
3) Fix the baking parameters and "Convert"
This operation creates a new simpler material that I can deal with :
Now, what is the problem ?
It turns out that I fact, I don't have 1 complex material but several, and I don't have only 1 scene but several. So I have a lot a complex materials in different scenes. I want to write a script that do the previous process automatically.
Operation 1) is easy to reproduce, but I'm having trouble for operation 2). In order to do this, I looked the command output an try to reproduce these :
Command output :
select -r MyUberMesh1 MyUberMesh2; select -tgl myUberShader ; convertLightmapSetup -camera persp -bakeSetOverride tmpTextureBakeSet -showcpv; // Baking 2 maps // // Cmd: convertLightmap -camera persp -bo tmpTextureBakeSet shadingEngine myUberMesh1 shadingEngine myUberMesh2 // // Baked 2 maps. 0 maps failed //
My script to reproduce it :
# Create a baked set maya.mel.eval("createNode textureBakeSet -n "myUberBakedTexture"") maya.mel.eval("setAttr ...") # Set baked set attributes as needed # Select the material and the related meshes cmds.select("myUberMaterial") cmds.hyperShade(objects="") selected_meshes = cmds.ls(sl=True, l=True) cmds.select("myUberMaterial", add=True) # Because the hyperShade command unselected it # Do Batch baking using converLightmap command shading_engine = get_shading_engine("myUberMaterial") # Personnal function melcmd = "convertLightmap -camera persp -bo "myUberBakedTexture"" for msh in selected_meshes : melcmd += " " + shading_engine + " " + str(msh)
maya.mel.eval(melcmd)
Finaly, the command I call is like :
convertLightmap -camera perp -bo myUberBakedTexture shadEngine Mesh1 shadEngine Mesh2 ...
The problem is that the command has not the same effect that the one I want to reproduce. The one I want to reproduce create a new simple material and attach the related meshes to it, and the command I write myself do not create a new material, and do not attach related meshes to it.
Is someone who has already used this command could help me on this way ?
Thank you and sorry for my long post.