Author Topic: Python Texture Export Settings  (Read 308 times)

Hey! First let me also express thanks for releasing the Python API! It's very exciting and will be hugely helpful. And you're already on Python 3, so thanks for pushing that forward. :)

I'm wondering a couple things about the substance_painter.export.export_project_textures method, specifically.

First, is there any way to access the settings saved by the new "Save Settings" button in the export dialog? I'd like to be able to call the export from Python, but by default have it use whatever the user saved there last. I suppose this could also be some way to get the equivalent of the exportList and exportParameters objects in the JSON -- is that possible?

Secondly, does the defaultExportPreset need to be defined in the exportPresets JSON object, or can it be the name of a preset loaded from an .spexp file?


Thanks for asking this question, I'm curious about this as well, at the moment it seems like the dev would need to reimplement all the export configurations as Json from scratch.

Definitely slowing things down and throwing teams for a curve as all the change to the UI itself will have no reliance on custom export tools...

Can we get some feed back on this?

This is really frustrating that you can't just pass it a resource or something from the already created exports. Not only is the documentation lacking quite a bit, recreating these by typing them into json manually is time consuming and error prone.

Could we at least be able to get a .json output of our currently setup presets some how?

For instance, currently I do not understand how you are supposed to export multiple textures in a single exportPreset defined in json.

Both examples in the documentation only show a single map being exported.

defining the json how I imagine it would go shows up with duplicate key names in a json validator, but other ways of doing it just don't make any sense (like many things in Substance Painter).

Does anyone else have any guides on this?

TIA.

Hi John,

you can export multiple maps by adding entries to the list of "maps" in "exportPresets".
For example:

Code: [Select]
         "maps": [{
                "fileName": "$mesh_$textureSet_basecolor",
                "channels": [{
                        "destChannel": "R",
                        "srcChannel": "R",
                        "srcMapType": "DocumentMap",
                        "srcMapName": "BaseColor"
                    },
                    {
                        "destChannel": "G",
                        "srcChannel": "G",
                        "srcMapType": "DocumentMap",
                        "srcMapName": "BaseColor"
                    },
                    {
                        "destChannel": "B",
                        "srcChannel": "B",
                        "srcMapType": "DocumentMap",
                        "srcMapName": "BaseColor"
                    },
                    {
                        "destChannel": "A",
                        "srcChannel": "A",
                        "srcMapType": "DocumentMap",
                        "srcMapName": "BaseColor"
                    }
                ]
            },
            {
                "fileName": "$mesh_$textureSet_orm",
                "channels": [{
                        "destChannel": "R",
                        "srcChannel": "R",
                        "srcMapType": "MeshMap",
                        "srcMapName": "ambient_occlusion"
                    },
                    {
                        "destChannel": "G",
                        "srcChannel": "G",
                        "srcMapType": "DocumentMap",
                        "srcMapName": "metallic"
                    },
                    {
                        "destChannel": "B",
                        "srcChannel": "B",
                        "srcMapType": "DocumentMap",
                        "srcMapName": "roughness"
                    }
                ]
            }
        ]

This would export an albedo map with all RGBA channels and another map containing AO, Roughness and Metalness saved to its R/G/B channels.

Attached you can find a "baked" .json to see how it could look like.
Last Edit: June 04, 2020, 03:30:33 pm

I have tried the above and only the last filename and channel pair export, the other 3 are ignored. When running it thru a JSON validator it mentions duplicate key names which would kind of make sense. Its very possible that I have a JSON formatting error as its pretty annoying to break these up. I'll try using your preset shown here and report back.

**update it looks to me like their documentation has some glaring errors in regards to the map names. One of the comments lists them in all lower case, part of the code (and what you have shown here) has it camel case. Its possile that I just have the wrong names, or perhaps you were pseudo coding?

***update 2 - Your config is working to export multiple maps. Thank you so much. Where are you getting the exact naming of the channels and map types etc? I have a feeling its possible my naming on my channels was incorrect, I cant figure out any other reason as I had listed several maps with channels in the maps dict but only the last entry would export.
Last Edit: June 04, 2020, 07:17:02 pm

Glad to hear you got it working.

I was mixing camel case and lowercase indeed in the map names and it's better to streamline it. But apparently the map names are case insensitive.

You can find the available map names in the offline documentation at "Substance Painter Package" -> "substance_painter.export" in the comments of the example code "Full json_config dict possibilities".
(Offline URL ending with python-doc/substance_painter/export.html?highlight= srcMapName)

For convenience I'll copy that part right here:

Code: [Select]
// The type of map to read from:
//    documentMap: Maps present in the document (e.g. "baseColor").
//    meshMap: Baked mesh maps (e.g. "normal").
//    virtualMap: Generated map (e.g. "f0").
//    defaultMap: Constant color (e.g. "black").
"srcMapType" : "documentMap",

// Name of the map of type scrMapType.
//
// For type documentMap:
//    basecolor, height, specular, opacity, emissive, displacement,
//    glossiness, roughness, anisotropylevel, anisotropyangle,
//    transmissive, scattering, reflection, ior, metallic, normal,
//    ambientOcclusion, diffuse, specularlevel, blendingmask, user0,
//    user1, user2, user3, user4, user5, user6, user7.
//
// For type meshMap:
//    ambient_occlusion, id, curvature, normal_base,
//    world_space_normals, position, thickness.
//
// For type virtualMap:
//    Normal_OpenGL, Normal_DirectX, AO_Mixed, Diffuse, Specular,
//    Glossiness, Unity4Diff, Unity4Gloss, reflection, 1/ior,
//    Glossiness2, f0, View_2D.
//
// For type defaultMap:
//    black, white.
"srcMapName" : "baseColor"

Note: When using a classic document map like basecolor, roughness etc., the corresponding setting "srcMapType" should be set to "documentMap".
When using a mesh map like "ambient_occlusion" or "normal", the corresponding setting "srcMapType" should be set to "meshMap".

Thanks again, with your json I was able to catch where my initial mistake was. I had a missing comma between the maps dict entries.

The mesh/document/virtual maps all make sense to me. I am also pretty certain L is the equivalent of Gray source channel in the built in preset configuration file.

I have some pretty significant exporter stuff setup and working, will deploy it to the artists soon.

Would I drop other modules like P4's python API stuff in the modules folder within the plugin folder? Or is there another way to install new modules, or PIP stuff for Painters python install?

Really, thanks a lot!

Cool, I'm looking forward seeing your plugin published

Quote
Would I drop other modules like P4's python API stuff in the modules folder within the plugin folder? Or is there another way to install new modules, or PIP stuff for Painters python install?

I believe the easiest solution is to put external libraries in a local modules folder of your plugin and ship them with your package.