Skip to content

Commit

Permalink
Merge pull request #960 from BigRoy/enhancement/usd_contribution_attr…
Browse files Browse the repository at this point in the history
…ibutes_per_instance_toggle

USD Contribution Workflow: Show/hide attributes per instance based on status of other toggles
  • Loading branch information
BigRoy authored Oct 29, 2024
2 parents 86e4c42 + c5a31bb commit a0c57c5
Showing 1 changed file with 62 additions and 11 deletions.
73 changes: 62 additions & 11 deletions client/ayon_core/plugins/publish/extract_usd_layer_contributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,18 @@ def get_or_create_instance(self,
return new_instance

@classmethod
def get_attribute_defs(cls):
def get_attr_defs_for_instance(cls, create_context, instance):
# Filtering of instance, if needed, can be customized
if not cls.instance_matches_plugin_families(instance):
return []

# Attributes logic
publish_attributes = instance["publish_attributes"].get(
cls.__name__, {})

visible = publish_attributes.get("contribution_enabled", True)
variant_visible = visible and publish_attributes.get(
"contribution_apply_as_variant", True)

return [
UISeparatorDef("usd_container_settings1"),
Expand All @@ -484,7 +495,8 @@ def get_attribute_defs(cls):
"the contribution itself will be added to the "
"department layer."
),
default="usdAsset"),
default="usdAsset",
visible=visible),
EnumDef("contribution_target_product_init",
label="Initialize as",
tooltip=(
Expand All @@ -495,7 +507,8 @@ def get_attribute_defs(cls):
"setting will do nothing."
),
items=["asset", "shot"],
default="asset"),
default="asset",
visible=visible),

# Asset layer, e.g. model.usd, look.usd, rig.usd
EnumDef("contribution_layer",
Expand All @@ -507,7 +520,8 @@ def get_attribute_defs(cls):
"the list) will contribute as a stronger opinion."
),
items=list(cls.contribution_layers.keys()),
default="model"),
default="model",
visible=visible),
BoolDef("contribution_apply_as_variant",
label="Add as variant",
tooltip=(
Expand All @@ -518,13 +532,16 @@ def get_attribute_defs(cls):
"appended to as a sublayer to the department layer "
"instead."
),
default=True),
default=True,
visible=visible),
TextDef("contribution_variant_set_name",
label="Variant Set Name",
default="{layer}"),
default="{layer}",
visible=variant_visible),
TextDef("contribution_variant",
label="Variant Name",
default="{variant}"),
default="{variant}",
visible=variant_visible),
BoolDef("contribution_variant_is_default",
label="Set as default variant selection",
tooltip=(
Expand All @@ -535,10 +552,41 @@ def get_attribute_defs(cls):
"The behavior is unpredictable if multiple instances "
"for the same variant set have this enabled."
),
default=False),
default=False,
visible=variant_visible),
UISeparatorDef("usd_container_settings3"),
]

@classmethod
def register_create_context_callbacks(cls, create_context):
create_context.add_value_changed_callback(cls.on_values_changed)

@classmethod
def on_values_changed(cls, event):
"""Update instance attribute definitions on attribute changes."""

# Update attributes if any of the following plug-in attributes
# change:
keys = ["contribution_enabled", "contribution_apply_as_variant"]

for instance_change in event["changes"]:
instance = instance_change["instance"]
if not cls.instance_matches_plugin_families(instance):
continue
value_changes = instance_change["changes"]
plugin_attribute_changes = (
value_changes.get("publish_attributes", {})
.get(cls.__name__, {}))

if not any(key in plugin_attribute_changes for key in keys):
continue

# Update the attribute definitions
new_attrs = cls.get_attr_defs_for_instance(
event["create_context"], instance
)
instance.set_publish_plugin_attr_defs(cls.__name__, new_attrs)


class CollectUSDLayerContributionsHoudiniLook(CollectUSDLayerContributions):
"""
Expand All @@ -551,9 +599,12 @@ class CollectUSDLayerContributionsHoudiniLook(CollectUSDLayerContributions):
label = CollectUSDLayerContributions.label + " (Look)"

@classmethod
def get_attribute_defs(cls):
defs = super(CollectUSDLayerContributionsHoudiniLook,
cls).get_attribute_defs()
def get_attr_defs_for_instance(cls, create_context, instance):
# Filtering of instance, if needed, can be customized
if not cls.instance_matches_plugin_families(instance):
return []

defs = super().get_attr_defs_for_instance(create_context, instance)

# Update default for department layer to look
layer_def = next(d for d in defs if d.key == "contribution_layer")
Expand Down

0 comments on commit a0c57c5

Please sign in to comment.