[Python + Maya] Baking using Surface Sampler / file location questions-

Hi Tech-Artists!

I guess I’d like to introduce myself quickly:
I’m a student and independent game developer from Vermont. I’m focused on developing tools for Maya at the moment using Python. I feel pretty entry level to the world of tech art, but I am enthusiastic and determined to do my best.

My Question(s):
Has anyone baked using cmds.surfaceSampler? I have been unable to find any concrete examples of using this on the internet so far.
I have been able to output the file to the scene folder in the Maya project directory by simply typing:

fn = cmd.workspace( q=True, dir=True)+"N_"

What would be a good way to have it save in the project folder’s images folder?
What method would work for baking both the Normal map and the Ambient Occlusion together and outputting both as files? How could i return these to connect to the shader?

Sorry if these are a lot of questions! Any amount of advice or pointers is appreciated-

//Robin

Welcome aboard. You picked a tricky set of problems to start with!

Workspace is a really lame command :frowning:


image_folder = cmds.workspace("images", q=True, fre= True)
disk_location = cmds.workspace(en=image_folder)

gives the disk location of the images folder; you can also add the name of the output file if you want before calling -en:


image_folder = cmds.workspace("images", q=True, fre= True)
file_name = "test.dds"
file_path = cmds.workspace(en=image_folder + "/" + file_name)

Baking is pretty straightforward; for a given map it looks like


cmds.surfaceSampler( mapOutput='normal', filename='C:/test', fileFormat='dds', source='pCube1', target='pSphere1', uv='map1' )

You’d call this twice if you wanted to bake, say, normal and color.

If you’re trying to bake AO… that goes through convertLightmap instead of surfaceSampler. The basic procedure is to set up a bake set, set options for the bake set, and go from there. Depending on what you need to do you may also have to work through lots of MentalRay settings, which are incompletely exposed to Python – looking back at the last time I did this I see the code is full of mel calls and profanity laden code comments complaining about the fact that ConvertLightMap + mental ray did not work through Python as of Maya 2011; no idea if that’s fixed lately but be warned.

Hi Theodox!

Sorry to return to you so late- I’ve been Implementing Successfully!

I haven’t touched the AO implementation yet (I’'m trying to squash my bug list before it piles up) but I will definitely give it a fair try. Thank you so much for replying so quickly and completely!

//Robin