Using ptexBake command with Xgen.

Using ptexBake command with Xgen.

Anonymous
Not applicable
1,629 Views
1 Reply
Message 1 of 2

Using ptexBake command with Xgen.

Anonymous
Not applicable

Hi

 

I have been looking into the Xgen python code, in order to write a script that makes sure that after importing an xgen collection, file textures get connected correctly to the  xgen maps (mainly connected to custom attributes), and that the ptex gets automatically baked out.

 

As part of this process, I want to emulate what the "start 3dpaint" and "Bake ptex textures to disk" buttons do in the xgen editor. After trawling through the xgen python code, I have found that the crucial line of code (in C:\Program Files\Autodesk\Maya2017\plug-ins\xgen\scripts\xgenm\ui\widgets\xgExpressionUI.py inside the ptexBaker class, stop() function):

cmds.ptexBake( inMesh=curMesh, outPtex=ptexBaker.g_OutputDir, bakeTexture=curFile[0], tpu=ptexBaker.g_Tpu )

There doesn't seem to be any documentation for the ptexBake command, which makes it a lot harder to figure out why I get this error when I try to run it with, what I am confident are, the correct arguments that the ptexBaker class would pass it:

 

# Error: RuntimeError: file <string> line 2: XGen:  Failed to create //<network_path_to_user_here>/maya/xgen/collections/anteater_col/anteater_descr_01/paintmaps/custom_color_color_map/not_just_any_plane.ptx
PtexWriter::edit error: header doesn't match existing file, conversions not currently supported # 

I should perhaps add that the path and .ptx file already exist when running this, I am trying to overwrite it. It also, interestingly enough, breaks the scene so that even if I do click on the "bake ptex" button, it no longer allows me to save (it did before I ran the above command), and I get this error:

 

// Error: XGen:  Trouble closing ptx file.
Can't write to ptex file: //<network_path_to_user_here>/maya/xgen/collections/anteater_col/anteater_descr_01/paintmaps/custom_color_color_map/not_just_any_plane.ptx
Permission denied  // 

So my question is - is there some flag in the ptexBake command that needs to be set in order to be able to write to the file? Or is there some other command that I can run beforehand that will either close the file or give me the permissions necessary? There doesn't seem to be anything of the sort in the above mentioned xgen function. I tried looking at the Ptex C++ source code, but I don't know C++ well enough to find anything useful.

 

 

Thanks!

0 Likes
1,630 Views
1 Reply
Reply (1)
Message 2 of 2

Zhihao.Li
Alumni
Alumni

If Maya is holding the file handle of .ptex file, you could try "xgmCache -clearPtexCache"  to free the handles manually.

 

More details:

An example is:

  ptexBake -inMesh pSphere1 -outPtex "${DESC}/paintmaps/custom_float_mycustom" -bakeTexture file1 -tpu 5

 

-inMesh: This is the node name of the mesh. XGen uses the name of the transform node. This flag also affects the ptex file name. pSphere1.ptx in the above example.

 

-outPtex: This is the directory to write ptex file to. ptexBake understands ${DESC} and expands it to the current description dir. The final .ptex file name is the combine of the above file name and this directory name.

 

-bakeTexture: This is the Maya file texture node name. When there is a paintable custom attribute, there must be a file texture node, which is connected to the mesh shape.  Maya artisan paint tool paints onto this file texture node when the user clicks paint button.

 

-tpu: Map resolution. Texel per unit.

 

When there is no such file, ptexBake will create one. Otherwise, ptexBake will try to edit the exiting file. In edit mode, ptexBake requires that the mesh topology matches. i.e. the mesh topo in the .ptex file must match the mesh topo from inMesh flag.

 

The error “PtexWriter::edit error: header doesn't match existing file, conversions not currently supported #” means that the mesh topo in the existing .ptex file doesn’t match the inMesh flag.  You mentioned that you tried to import a collection. Please make sure you're not overwriting the .ptex file in the source collection. you expect to create a new .ptex file in the target collection, right?

0 Likes