Little help with maya commands & python

For atlassing, there are really two basic approaches.

quilting

One way is to create the atlas out of your existing textures. Essentially you’d have these steps:

  1. Normalize all the UVs on each object
  2. scale them down by some fraction based on the total number of objects to atlas – it’s probably easiest just to take the square root of the number of atlassed objects, so for example 9 objects would give you a factor of 3, so you’d scale down all the UV values on the atlassed objects by one third
  3. Offset the UVs so each scaled-down set has an appropriate “zero”. In the case of a nine-way atlas you’d offset your UVs by (0,0), (.33, 0), (.66, 0), (0,. 33), (.33, .33), (.66, .33), (0, .66), (.33, .66), (.66, .66)
  4. make a photoshop atlas to combine your textures in the same order

baking

In this version you’ll use Maya’s texture baking to create the atlass for you.

  1. you copy all your objects
  2. merge them into a single mesh
  3. Auto-layout the UVs as appropriate. In this version you will get some wierd layouts but the overall efficiency is usually higher than using squares
  4. Use the surfaceSampler command to bake the textures from the original objects onto the new combined object

This method does more elaborate packing but can get messed up by details of how your UVs are layed out. It is a good project to use for learning.

As for file paths, you should be able to provide absolute paths for all of the maya commands – the UI often messes with your paths, especially on Windows, but if you tell it exactly where you want things to go it should be OK.

In any case you can always figure out if a path exists with

import os
os.path.exists("you/path/here")

I’ve already done the layout of my UVs.
One where all my UVs are normalized
Another one where they keep their ratio

I am happy with the result.
I’ve also done the baking with the surfaceSampler.

import os
os.path.exists("you/path/here")

As for this code, It works for folder but doesn’t for files :confused:

Is there a way bake the diffuse and the alpha into the same TGA file with the surfaceSampler ?

I think surfaceSampler outputs them as separate textures, you’d need to use a separate tool to pack the output of one into the the alpha of the other.

Actually the surfaceSampler can add the alpha channel to a color texture. (see the end of the article )

I almost made it work. But depending on the number of materials of my source mesh, it won’t work.
I don’t know why though :confused:

EDIT :
For the one who wants to create a texture with diffuse + alpha using the surfaceSampler, you have to use a tuple for each (or most) keywords argument in the surfaceSampler.
Something like this:

cmds.surfaceSampler(target=“targetShape”, uvSet=“map1”, source=“sourceShape”, mapOutput=(“diffuseRGB”, “alpha”), mapWidth=(128, 128), mapHeight=(128,128), mapSpace=(“tangent”, “tangent”), filename=(“C:/Users/Yann/Documents/maya/projects/default/images/test”, “C:/Users/Yann/Documents/maya/projects/default/images/test”), fileFormat=(“tga”, “tga”))

It’s used in loops:

maxVal = 5000

gMainProgressBar = maya.mel.eval('$tmp = $gMainProgressBar');

cmds.progressBar( gMainProgressBar,
                                edit=True,
                                beginProgress=True,
                                isInterruptable=True,
                                status='This is a progress bar',
                                maxValue=maxVal)
for i in range(maxVal) :
        if cmds.progressBar(gMainProgressBar, query=True, isCancelled=True ) :
                break
        cmds.progressBar(gMainProgressBar, edit=True, step=1)
cmds.progressBar(gMainProgressBar, edit=True, endProgress=True)
1 Like