Copy link to clipboard
Copied
Hey guys, I have a custom script working for exporting tiff files. All the logic works and Im using a custom preset for converting my custom maps. The issue Im hitting right now is that it always exports every texture in the preset, regardless if it has information in it or not. So now Im trying to find a way to only export textures that have "Is Computed" set to on. I know I can update the script everytime I have a different set of textures that need to be exported but that seems silly.
I've looked through the API documention for sampler and nothing stands out that appears to answer this goal. Also I have also tried to make calls to the export api that is standard in sampler export process. The idea here is maybe I can set the active channels in that list and use that as a way of exporting what I need. I was blocked in this attempt too.
Curious what you guys think and if there is a way to only export "Is Computed" channel that are on.
# Import the necessary modules
import os
import substance_sampler as ssa
import logging
# Set up logging
logging.basicConfig(filename=os.path.expanduser('~/Desktop/export.log'), level=logging.DEBUG)
# Define your presets and their corresponding formats
presets = {
"Poliigon_Samlper_Exporter_RM_16Bit_Global": ["tif"],
}
# Define the channels to export for each format
channels = {
"tif": ["BaseColor", "BaseColorOpacity", "Opacity", "ScatteringColor", "SheenColor", "Emission", "TranslucencyColor", "VolumeColor", "AmbientOcclusion", "Transmission", "Roughness", "Metallic", "ORM", "Normal", "Height"],
}
# Define the directory names for each format
directories = {
"tif": "tiff",
}
# Verify if the project is already saved to get its path
if ssa.save_project():
ssa.save_project()
# Get the folder path of the project
project_path = ssa.get_project_path()
# Define your base directory
base_dir = os.path.dirname(project_path)
# Define your base export directory
base_export_dir = os.path.join(base_dir, "..", "Textures")
# Get all assets of your project in a list
all_project_assets = ssa.get_project_assets()
# Define the resolution
w_res = h_res = 8192
# Iterate over each asset in the project
for asset in all_project_assets:
# Get the material name
material_name = asset.name
# Iterate over each preset and its corresponding formats
for preset_name, formats in presets.items():
# Get the preset
preset = ssa.get_export_presets(preset_name)[0]
# Iterate over each format
for format in formats:
# Create a unique export directory for each format
format_export_dir = os.path.join(base_export_dir, directories[format], "8K")
os.makedirs(format_export_dir, exist_ok=True)
# Export the asset
for _ in range(3): # Retry up to 3 times
try:
asset.export_material(path=format_export_dir,
name=material_name,
format=getattr(ssa.MaterialExportFormat, format.lower()),
preset=preset,
channels=channels[format],
w_resolution=w_res,
h_resolution=h_res)
logging.info(f"Export successful for asset {material_name} with format {format}")
break # If export is successful, break the loop
except Exception as e:
logging.error(f"Export failed for asset {material_name} with format {format}. Error: {str(e)}")
pass # If export fails, continue to the next attempt
else:
print("Save first your project", file=sys.stderr)
Have something to add?