Implement OCIO support for Substance Painter + publish color space with textures

This commit is contained in:
Roy Nieterau 2023-01-15 01:30:43 +01:00
parent 9e8b6f8246
commit 33aafc3ff6
5 changed files with 89 additions and 3 deletions

View file

@ -0,0 +1,37 @@
from openpype.lib import PreLaunchHook
from openpype.pipeline.colorspace import get_imageio_config
from openpype.pipeline.template_data import get_template_data_with_names
class PreLaunchHostSetOCIO(PreLaunchHook):
"""Set OCIO environment for the host"""
order = 0
app_groups = ["substancepainter"]
def execute(self):
"""Hook entry method."""
anatomy_data = get_template_data_with_names(
project_name=self.data["project_doc"]["name"],
asset_name=self.data["asset_doc"]["name"],
task_name=self.data["task_name"],
host_name=self.host_name,
system_settings=self.data["system_settings"]
)
ocio_config = get_imageio_config(
project_name=self.data["project_doc"]["name"],
host_name=self.host_name,
project_settings=self.data["project_settings"],
anatomy_data=anatomy_data,
anatomy=self.data["anatomy"]
)
if ocio_config:
ocio_path = ocio_config["path"]
self.log.info(f"Setting OCIO config path: {ocio_path}")
self.launch_context.env["OCIO"] = ocio_path
else:
self.log.debug("OCIO not set or enabled")

View file

@ -67,8 +67,6 @@ class CollectTextureSet(pyblish.api.InstancePlugin):
if bool(outputs[0].get("udim")):
representation["udim"] = True
# TODO: Store color space with the representation
# Clone the instance
image_instance = context.create_instance(instance.name)
image_instance[:] = instance[:]
@ -83,6 +81,13 @@ class CollectTextureSet(pyblish.api.InstancePlugin):
# Group the textures together in the loader
image_instance.data["subsetGroup"] = instance.data["subset"]
# Store color space with the instance
# Note: The extractor will assign it to the representation
colorspace = outputs[0].get("colorSpace")
if colorspace:
self.log.debug(f"{image_subset} colorspace: {colorspace}")
image_instance.data["colorspace"] = colorspace
# Set up the representation for thumbnail generation
# TODO: Simplify this once thumbnail extraction is refactored
staging_dir = os.path.dirname(first_filepath)

View file

@ -2,7 +2,7 @@ from openpype.pipeline import KnownPublishError, publish
import substance_painter.export
class ExtractTextures(publish.Extractor):
class ExtractTextures(publish.ExtractorColormanaged):
"""Extract Textures using an output template config.
Note:
@ -40,6 +40,23 @@ class ExtractTextures(publish.Extractor):
# TODO: Confirm the files indeed exist
# TODO: make sure representations are registered
# We'll insert the color space data for each image instance that we
# added into this texture set. The collector couldn't do so because
# some anatomy and other instance data needs to be collected prior
context = instance.context
for image_instance in instance:
colorspace = image_instance.data.get("colorspace")
if not colorspace:
self.log.debug("No color space data present for instance: "
f"{image_instance}")
continue
for representation in image_instance.data["representations"]:
self.set_representation_colorspace(representation,
context=context,
colorspace=colorspace)
# Add a fake representation which won't be integrated so the
# Integrator leaves us alone - otherwise it would error
# TODO: Add `instance.data["integrate"] = False` support in Integrator?

View file

@ -1,3 +1,13 @@
{
"imageio": {
"ocio_config": {
"enabled": true,
"filepath": []
},
"file_rules": {
"enabled": true,
"rules": {}
}
},
"shelves": {}
}

View file

@ -5,6 +5,23 @@
"label": "Substance Painter",
"is_file": true,
"children": [
{
"key": "imageio",
"type": "dict",
"label": "Color Management (ImageIO)",
"is_group": true,
"children": [
{
"type": "schema",
"name": "schema_imageio_config"
},
{
"type": "schema",
"name": "schema_imageio_file_rules"
}
]
},
{
"type": "dict-modifiable",
"key": "shelves",