From c2167056720a93764eb3f4409350820fba476330 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 20 Mar 2024 16:59:48 +0100 Subject: [PATCH 01/22] Blender: Implement USD extractor and loader --- client/ayon_core/hosts/blender/api/lib.py | 59 ++++++++++++++ client/ayon_core/hosts/blender/api/plugin.py | 3 +- .../blender/plugins/create/create_usd.py | 30 +++++++ .../hosts/blender/plugins/load/load_abc.py | 27 +++++-- .../plugins/publish/collect_instance.py | 2 +- .../blender/plugins/publish/extract_usd.py | 79 +++++++++++++++++++ 6 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 client/ayon_core/hosts/blender/plugins/create/create_usd.py create mode 100644 client/ayon_core/hosts/blender/plugins/publish/extract_usd.py diff --git a/client/ayon_core/hosts/blender/api/lib.py b/client/ayon_core/hosts/blender/api/lib.py index 458a275b51..031a25e791 100644 --- a/client/ayon_core/hosts/blender/api/lib.py +++ b/client/ayon_core/hosts/blender/api/lib.py @@ -365,3 +365,62 @@ def maintained_time(): yield finally: bpy.context.scene.frame_current = current_time + + +def get_all_parents(obj): + """Get all recursive parents of object. + + Arguments: + obj (bpy.types.Object): Object to get all parents for. + + Returns: + List[bpy.types.Object]: All parents of object + + """ + result = [] + while True: + obj = obj.parent + if not obj: + break + result.append(obj) + return result + + +def get_highest_root(objects): + """Get the highest object (the least parents) among the objects. + + If multiple objects have the same amount of parents (or no parents) the + first object found in the input iterable will be returned. + + Note that this will *not* return objects outside of the input list, as + such it will not return the root of node from a child node. It is purely + intended to find the highest object among a list of objects. To instead + get the root from one object use, e.g. `get_all_parents(obj)[-1]` + + Arguments: + objects (List[bpy.types.Object]): Objects to find the highest root in. + + Returns: + Optional[bpy.types.Object]: First highest root found or None if no + `bpy.types.Object` found in input list. + + """ + included_objects = {obj.name_full for obj in objects} + num_parents_to_obj = {} + for obj in objects: + if isinstance(obj, bpy.types.Object): + parents = get_all_parents(obj) + # included parents + parents = [parent for parent in parents if + parent.name_full in included_objects] + if not parents: + # A node without parents must be a highest root + return obj + + num_parents_to_obj.setdefault(len(parents), obj) + + if not num_parents_to_obj: + return + + minimum_parent = min(num_parents_to_obj) + return num_parents_to_obj[minimum_parent] diff --git a/client/ayon_core/hosts/blender/api/plugin.py b/client/ayon_core/hosts/blender/api/plugin.py index 6c9bfb6569..383dd1e5c6 100644 --- a/client/ayon_core/hosts/blender/api/plugin.py +++ b/client/ayon_core/hosts/blender/api/plugin.py @@ -26,7 +26,8 @@ from .ops import ( ) from .lib import imprint -VALID_EXTENSIONS = [".blend", ".json", ".abc", ".fbx"] +VALID_EXTENSIONS = [".blend", ".json", ".abc", ".fbx", + ".usd", ".usdc", ".usda"] def prepare_scene_name( diff --git a/client/ayon_core/hosts/blender/plugins/create/create_usd.py b/client/ayon_core/hosts/blender/plugins/create/create_usd.py new file mode 100644 index 0000000000..2c2d0c46c6 --- /dev/null +++ b/client/ayon_core/hosts/blender/plugins/create/create_usd.py @@ -0,0 +1,30 @@ +"""Create a USD Export.""" + +from ayon_core.hosts.blender.api import plugin, lib + + +class CreateUSD(plugin.BaseCreator): + """Create USD Export""" + + identifier = "io.openpype.creators.blender.usd" + name = "usdMain" + label = "USD" + product_type = "usd" + icon = "gears" + + def create( + self, product_name: str, instance_data: dict, pre_create_data: dict + ): + # Run parent create method + collection = super().create( + product_name, instance_data, pre_create_data + ) + + if pre_create_data.get("use_selection"): + objects = lib.get_selection() + for obj in objects: + collection.objects.link(obj) + if obj.type == 'EMPTY': + objects.extend(obj.children) + + return collection diff --git a/client/ayon_core/hosts/blender/plugins/load/load_abc.py b/client/ayon_core/hosts/blender/plugins/load/load_abc.py index 938ae6106b..877cf0ca49 100644 --- a/client/ayon_core/hosts/blender/plugins/load/load_abc.py +++ b/client/ayon_core/hosts/blender/plugins/load/load_abc.py @@ -26,10 +26,11 @@ class CacheModelLoader(plugin.AssetLoader): Note: At least for now it only supports Alembic files. """ - product_types = {"model", "pointcache", "animation"} - representations = ["abc"] + product_types = {"model", "pointcache", "animation", "usd"} + representations = ["abc", "usd"] - label = "Load Alembic" + # TODO: Should USD loader be a separate loader instead? + label = "Load Alembic/USD" icon = "code-fork" color = "orange" @@ -53,10 +54,21 @@ class CacheModelLoader(plugin.AssetLoader): plugin.deselect_all() relative = bpy.context.preferences.filepaths.use_relative_paths - bpy.ops.wm.alembic_import( - filepath=libpath, - relative_path=relative - ) + + if any(libpath.lower().endswith(ext) + for ext in [".usd", ".usda", ".usdc"]): + # USD + bpy.ops.wm.usd_import( + filepath=libpath, + relative_path=relative + ) + + else: + # Alembic + bpy.ops.wm.alembic_import( + filepath=libpath, + relative_path=relative + ) imported = lib.get_selection() @@ -161,7 +173,6 @@ class CacheModelLoader(plugin.AssetLoader): self._link_objects(objects, asset_group, containers, asset_group) - product_type = context["product"]["productType"] asset_group[AVALON_PROPERTY] = { "schema": "openpype:container-2.0", "id": AVALON_CONTAINER_ID, diff --git a/client/ayon_core/hosts/blender/plugins/publish/collect_instance.py b/client/ayon_core/hosts/blender/plugins/publish/collect_instance.py index d47c69a270..314ffd368a 100644 --- a/client/ayon_core/hosts/blender/plugins/publish/collect_instance.py +++ b/client/ayon_core/hosts/blender/plugins/publish/collect_instance.py @@ -12,7 +12,7 @@ class CollectBlenderInstanceData(pyblish.api.InstancePlugin): order = pyblish.api.CollectorOrder hosts = ["blender"] families = ["model", "pointcache", "animation", "rig", "camera", "layout", - "blendScene"] + "blendScene", "usd"] label = "Collect Instance" def process(self, instance): diff --git a/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py b/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py new file mode 100644 index 0000000000..74d0756133 --- /dev/null +++ b/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py @@ -0,0 +1,79 @@ +import os + +import bpy + +from ayon_core.pipeline import publish +from ayon_core.hosts.blender.api import plugin, lib + + +class ExtractUSD(publish.Extractor): + """Extract as USD.""" + + label = "Extract USD" + hosts = ["blender"] + families = ["usd"] + + def process(self, instance): + + # Ignore runtime instances (e.g. USD layers) + # TODO: This is better done via more specific `families` + if not instance.data.get("transientData", {}).get("instance_node"): + return + + # Define extract output file path + stagingdir = self.staging_dir(instance) + filename = f"{instance.name}.usd" + filepath = os.path.join(stagingdir, filename) + + # Perform extraction + self.log.debug("Performing extraction..") + + # Select all members to "export selected" + plugin.deselect_all() + + selected = [] + for obj in instance: + if isinstance(obj, bpy.types.Object): + obj.select_set(True) + selected.append(obj) + + root = lib.get_highest_root(objects=instance[:]) + if not root: + instance_node = instance.data["transientData"]["instance_node"] + raise publish.KnownPublishError( + f"No root object found in instance: {instance_node.name}" + ) + self.log.debug(f"Exporting using active root: {root.name}") + + context = plugin.create_blender_context( + active=root, selected=selected) + + # Export USD + bpy.ops.wm.usd_export( + context, + filepath=filepath, + selected_objects_only=True, + export_textures=False, + relative_paths=False, + export_animation=False, + export_hair=False, + export_uvmaps=True, + # TODO: add for new version of Blender (4+?) + # export_mesh_colors=True, + export_normals=True, + export_materials=True, + use_instancing=True + ) + + plugin.deselect_all() + + # Add representation + representation = { + 'name': 'usd', + 'ext': 'usd', + 'files': filename, + "stagingDir": stagingdir, + } + instance.data.setdefault("representations", []).append(representation) + self.log.debug("Extracted instance '%s' to: %s", + instance.name, representation) From f856f5237c2735eb04663e857ca81677a517f0cd Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 20 Mar 2024 17:07:14 +0100 Subject: [PATCH 02/22] Fix export for recent blender versions --- .../blender/plugins/publish/extract_usd.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py b/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py index 74d0756133..70092ded7b 100644 --- a/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py +++ b/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py @@ -49,21 +49,21 @@ class ExtractUSD(publish.Extractor): active=root, selected=selected) # Export USD - bpy.ops.wm.usd_export( - context, - filepath=filepath, - selected_objects_only=True, - export_textures=False, - relative_paths=False, - export_animation=False, - export_hair=False, - export_uvmaps=True, - # TODO: add for new version of Blender (4+?) - # export_mesh_colors=True, - export_normals=True, - export_materials=True, - use_instancing=True - ) + with bpy.context.temp_override(**context): + bpy.ops.wm.usd_export( + filepath=filepath, + selected_objects_only=True, + export_textures=False, + relative_paths=False, + export_animation=False, + export_hair=False, + export_uvmaps=True, + # TODO: add for new version of Blender (4+?) + # export_mesh_colors=True, + export_normals=True, + export_materials=True, + use_instancing=True + ) plugin.deselect_all() From 5660ed58d39ff4755b2db97511c65aaabfe147f7 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 20 Mar 2024 17:08:35 +0100 Subject: [PATCH 03/22] Fix refactor --- client/ayon_core/hosts/blender/plugins/load/load_abc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client/ayon_core/hosts/blender/plugins/load/load_abc.py b/client/ayon_core/hosts/blender/plugins/load/load_abc.py index 877cf0ca49..2fec4cc78b 100644 --- a/client/ayon_core/hosts/blender/plugins/load/load_abc.py +++ b/client/ayon_core/hosts/blender/plugins/load/load_abc.py @@ -173,6 +173,7 @@ class CacheModelLoader(plugin.AssetLoader): self._link_objects(objects, asset_group, containers, asset_group) + product_type = context["product"]["productType"] asset_group[AVALON_PROPERTY] = { "schema": "openpype:container-2.0", "id": AVALON_CONTAINER_ID, From 78da85398d2ffb86673acf0f88dba94c54ad140a Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 4 Apr 2024 15:39:04 +0200 Subject: [PATCH 04/22] Refactor filename since it's now not only Alembic but also USD --- .../hosts/blender/plugins/load/{load_abc.py => load_cache.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename client/ayon_core/hosts/blender/plugins/load/{load_abc.py => load_cache.py} (100%) diff --git a/client/ayon_core/hosts/blender/plugins/load/load_abc.py b/client/ayon_core/hosts/blender/plugins/load/load_cache.py similarity index 100% rename from client/ayon_core/hosts/blender/plugins/load/load_abc.py rename to client/ayon_core/hosts/blender/plugins/load/load_cache.py From 6bb585c6a92b62f70fbfb2355ed45e3ff70f0d9a Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 3 May 2024 20:31:40 +0200 Subject: [PATCH 05/22] Change label to `Load Cache` --- client/ayon_core/hosts/blender/plugins/load/load_cache.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/ayon_core/hosts/blender/plugins/load/load_cache.py b/client/ayon_core/hosts/blender/plugins/load/load_cache.py index 65d45e6fc4..30c847f89d 100644 --- a/client/ayon_core/hosts/blender/plugins/load/load_cache.py +++ b/client/ayon_core/hosts/blender/plugins/load/load_cache.py @@ -29,8 +29,7 @@ class CacheModelLoader(plugin.AssetLoader): product_types = {"model", "pointcache", "animation", "usd"} representations = {"abc", "usd"} - # TODO: Should USD loader be a separate loader instead? - label = "Load Alembic/USD" + label = "Load Cache" icon = "code-fork" color = "orange" From bd0509a2c64d9488e5c79dbf9ea27e1b885b064d Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 3 May 2024 20:42:16 +0200 Subject: [PATCH 06/22] Allow publishing USD from `model` family and expose it in settings --- .../hosts/blender/plugins/publish/extract_usd.py | 11 +++++++++++ .../blender/server/settings/publish_plugins.py | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py b/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py index 70092ded7b..1d4fa3d7ac 100644 --- a/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py +++ b/client/ayon_core/hosts/blender/plugins/publish/extract_usd.py @@ -77,3 +77,14 @@ class ExtractUSD(publish.Extractor): instance.data.setdefault("representations", []).append(representation) self.log.debug("Extracted instance '%s' to: %s", instance.name, representation) + + +class ExtractModelUSD(ExtractUSD): + """Extract model as USD.""" + + label = "Extract USD (Model)" + hosts = ["blender"] + families = ["model"] + + # Driven by settings + optional = True diff --git a/server_addon/blender/server/settings/publish_plugins.py b/server_addon/blender/server/settings/publish_plugins.py index e998d7b057..8db8c5be46 100644 --- a/server_addon/blender/server/settings/publish_plugins.py +++ b/server_addon/blender/server/settings/publish_plugins.py @@ -151,6 +151,10 @@ class PublishPluginsModel(BaseSettingsModel): default_factory=ExtractPlayblastModel, title="Extract Playblast" ) + ExtractModelUSD: ValidatePluginModel = SettingsField( + default_factory=ValidatePluginModel, + title="Extract Model USD" + ) DEFAULT_BLENDER_PUBLISH_SETTINGS = { @@ -348,5 +352,10 @@ DEFAULT_BLENDER_PUBLISH_SETTINGS = { }, indent=4 ) + }, + "ExtractModelUSD": { + "enabled": True, + "optional": True, + "active": True } } From 8131b53983301b0d5f4e3a5a6a8fd42eff0eedbb Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 3 May 2024 20:42:41 +0200 Subject: [PATCH 07/22] Bump blender server addon version --- server_addon/blender/package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_addon/blender/package.py b/server_addon/blender/package.py index 667076e533..d2c02a4909 100644 --- a/server_addon/blender/package.py +++ b/server_addon/blender/package.py @@ -1,3 +1,3 @@ name = "blender" title = "Blender" -version = "0.1.8" +version = "0.1.9" From ade52e789702f7d7f57a6898d13e75e79537653c Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Fri, 3 May 2024 23:16:34 +0300 Subject: [PATCH 08/22] add model product type creator --- .../houdini/plugins/create/create_model.py | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 client/ayon_core/hosts/houdini/plugins/create/create_model.py diff --git a/client/ayon_core/hosts/houdini/plugins/create/create_model.py b/client/ayon_core/hosts/houdini/plugins/create/create_model.py new file mode 100644 index 0000000000..1f32ccde45 --- /dev/null +++ b/client/ayon_core/hosts/houdini/plugins/create/create_model.py @@ -0,0 +1,144 @@ +# -*- coding: utf-8 -*- +"""Creator plugin for creating Model product type. + +Note: + Currently, This creator plugin is the same as 'create_pointcache.py' + But renaming the product type to 'model'. + + It's purpose to support + Maya (load/publish model from maya to/from houdini). + + It's considered to support multiple representations in the future. +""" + +from ayon_core.hosts.houdini.api import plugin +from ayon_core.lib import BoolDef + +import hou + + + +class CreateModel(plugin.HoudiniCreator): + """Create Model""" + identifier = "io.openpype.creators.houdini.model" + label = "Model" + product_type = "model" + icon = "cube" + + def get_publish_families(self): + return ["model", "abc"] + + def create(self, product_name, instance_data, pre_create_data): + instance_data.pop("active", None) + instance_data.update({"node_type": "alembic"}) + creator_attributes = instance_data.setdefault( + "creator_attributes", dict()) + creator_attributes["farm"] = pre_create_data["farm"] + + instance = super(CreateModel, self).create( + product_name, + instance_data, + pre_create_data) + + instance_node = hou.node(instance.get("instance_node")) + parms = { + "use_sop_path": True, + "build_from_path": True, + "path_attrib": "path", + "prim_to_detail_pattern": "cbId", + "format": 2, + "facesets": 0, + "filename": hou.text.expandString( + "$HIP/pyblish/{}.abc".format(product_name)) + } + + if self.selected_nodes: + selected_node = self.selected_nodes[0] + + # Although Houdini allows ObjNode path on `sop_path` for the + # the ROP node we prefer it set to the SopNode path explicitly + + # Allow sop level paths (e.g. /obj/geo1/box1) + if isinstance(selected_node, hou.SopNode): + parms["sop_path"] = selected_node.path() + self.log.debug( + "Valid SopNode selection, 'SOP Path' in ROP will be set to '%s'." + % selected_node.path() + ) + + # Allow object level paths to Geometry nodes (e.g. /obj/geo1) + # but do not allow other object level nodes types like cameras, etc. + elif isinstance(selected_node, hou.ObjNode) and \ + selected_node.type().name() in ["geo"]: + + # get the output node with the minimum + # 'outputidx' or the node with display flag + sop_path = self.get_obj_output(selected_node) + + if sop_path: + parms["sop_path"] = sop_path.path() + self.log.debug( + "Valid ObjNode selection, 'SOP Path' in ROP will be set to " + "the child path '%s'." + % sop_path.path() + ) + + if not parms.get("sop_path", None): + self.log.debug( + "Selection isn't valid. 'SOP Path' in ROP will be empty." + ) + else: + self.log.debug( + "No Selection. 'SOP Path' in ROP will be empty." + ) + + instance_node.setParms(parms) + instance_node.parm("trange").set(1) + + # Explicitly set f1 and f2 to frame start. + # Which forces the rop node to export one frame. + instance_node.parmTuple('f').deleteAllKeyframes() + fstart = int(hou.hscriptExpression("$FSTART")) + instance_node.parmTuple('f').set((fstart, fstart, 1)) + + # Lock any parameters in this list + to_lock = ["prim_to_detail_pattern"] + self.lock_parameters(instance_node, to_lock) + + def get_network_categories(self): + return [ + hou.ropNodeTypeCategory(), + hou.sopNodeTypeCategory() + ] + + def get_obj_output(self, obj_node): + """Find output node with the smallest 'outputidx'.""" + + outputs = obj_node.subnetOutputs() + + # if obj_node is empty + if not outputs: + return + + # if obj_node has one output child whether its + # sop output node or a node with the render flag + elif len(outputs) == 1: + return outputs[0] + + # if there are more than one, then it have multiple output nodes + # return the one with the minimum 'outputidx' + else: + return min(outputs, + key=lambda node: node.evalParm('outputidx')) + + def get_instance_attr_defs(self): + return [ + BoolDef("farm", + label="Submitting to Farm", + default=False) + ] + + def get_pre_create_attr_defs(self): + attrs = super().get_pre_create_attr_defs() + # Use same attributes as for instance attributes + return attrs + self.get_instance_attr_defs() From ba57d6db6d37f3a8a5d24b02b4f5a3d66530eb7c Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Fri, 3 May 2024 23:18:33 +0300 Subject: [PATCH 09/22] add essential publish plugins for model product type --- .../plugins/publish/collect_cache_farm.py | 7 +-- .../plugins/publish/collect_chunk_size.py | 2 +- .../plugins/publish/collect_output_node.py | 3 +- .../validate_export_is_a_single_frame.py | 60 +++++++++++++++++++ .../publish/validate_mesh_is_static.py | 6 +- .../publish/validate_mkpaths_toggled.py | 2 +- .../publish/validate_sop_output_node.py | 2 +- 7 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 client/ayon_core/hosts/houdini/plugins/publish/validate_export_is_a_single_frame.py diff --git a/client/ayon_core/hosts/houdini/plugins/publish/collect_cache_farm.py b/client/ayon_core/hosts/houdini/plugins/publish/collect_cache_farm.py index 040ad68a1a..dc433f0f58 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/collect_cache_farm.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/collect_cache_farm.py @@ -10,7 +10,7 @@ class CollectDataforCache(pyblish.api.InstancePlugin): order = pyblish.api.CollectorOrder + 0.04 families = ["ass", "pointcache", "mantraifd", "redshiftproxy", - "vdbcache"] + "vdbcache", "model"] hosts = ["houdini"] targets = ["local", "remote"] label = "Collect Data for Cache" @@ -42,10 +42,7 @@ class CollectDataforCache(pyblish.api.InstancePlugin): cache_files = {"_": instance.data["files"]} # Convert instance family to pointcache if it is bgeo or abc # because ??? - for family in instance.data["families"]: - if family == "bgeo" or "abc": - instance.data["productType"] = "pointcache" - break + self.log.debug(instance.data["families"]) instance.data.update({ "plugin": "Houdini", "publish": True diff --git a/client/ayon_core/hosts/houdini/plugins/publish/collect_chunk_size.py b/client/ayon_core/hosts/houdini/plugins/publish/collect_chunk_size.py index 3e2561dd6f..f0913f2f0a 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/collect_chunk_size.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/collect_chunk_size.py @@ -10,7 +10,7 @@ class CollectChunkSize(pyblish.api.InstancePlugin, order = pyblish.api.CollectorOrder + 0.05 families = ["ass", "pointcache", "vdbcache", "mantraifd", - "redshiftproxy"] + "redshiftproxy", "model"] hosts = ["houdini"] targets = ["local", "remote"] label = "Collect Chunk Size" diff --git a/client/ayon_core/hosts/houdini/plugins/publish/collect_output_node.py b/client/ayon_core/hosts/houdini/plugins/publish/collect_output_node.py index 26381e065e..289222f32b 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/collect_output_node.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/collect_output_node.py @@ -15,7 +15,8 @@ class CollectOutputSOPPath(pyblish.api.InstancePlugin): "usd", "usdrender", "redshiftproxy", - "staticMesh" + "staticMesh", + "model" ] hosts = ["houdini"] diff --git a/client/ayon_core/hosts/houdini/plugins/publish/validate_export_is_a_single_frame.py b/client/ayon_core/hosts/houdini/plugins/publish/validate_export_is_a_single_frame.py new file mode 100644 index 0000000000..6775699adf --- /dev/null +++ b/client/ayon_core/hosts/houdini/plugins/publish/validate_export_is_a_single_frame.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +"""Validator for checking that export is a single frame.""" +import pyblish.api +from ayon_core.pipeline import ( + PublishValidationError, + OptionalPyblishPluginMixin +) +from ayon_core.pipeline.publish import ValidateContentsOrder +from ayon_core.hosts.houdini.api.action import SelectInvalidAction + + +class ValidateSingleFrame(pyblish.api.InstancePlugin, + OptionalPyblishPluginMixin): + """Validate Export is a Single Frame. + + It checks if rop node is exporting one frame. + This is mainly for Model product type. + """ + + families = ["model"] + hosts = ["houdini"] + label = "Validate Single Frame" + order = ValidateContentsOrder + 0.1 + actions = [SelectInvalidAction] + + def process(self, instance): + + invalid = self.get_invalid(instance) + if invalid: + nodes = [n.path() for n in invalid] + raise PublishValidationError( + "See log for details. " + "Invalid nodes: {0}".format(nodes) + ) + + @classmethod + def get_invalid(cls, instance): + + invalid = [] + + frame_start = instance.data.get("frameStartHandle") + frame_end = instance.data.get("frameEndHandle") + + # This happens if instance node has no 'trange' parameter. + if (frame_start or frame_end) is None: + cls.log.debug( + "No frame data, skipping check.." + ) + return + + if frame_start != frame_end: + invalid.append(instance.data["instance_node"]) + cls.log.error( + "Invalid frame range on '%s'." + "You should use the same frame number for 'f1' " + "and 'f2' parameters.", + instance.data["instance_node"].path() + ) + + return invalid diff --git a/client/ayon_core/hosts/houdini/plugins/publish/validate_mesh_is_static.py b/client/ayon_core/hosts/houdini/plugins/publish/validate_mesh_is_static.py index 289e00339b..9652367bfe 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/validate_mesh_is_static.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/validate_mesh_is_static.py @@ -16,9 +16,13 @@ class ValidateMeshIsStatic(pyblish.api.InstancePlugin, """Validate mesh is static. It checks if output node is time dependent. + this avoids getting different output from ROP node when extracted + from a different frame than the first frame. + (Might be overly restrictive though) """ - families = ["staticMesh"] + families = ["staticMesh", + "model"] hosts = ["houdini"] label = "Validate Mesh is Static" order = ValidateContentsOrder + 0.1 diff --git a/client/ayon_core/hosts/houdini/plugins/publish/validate_mkpaths_toggled.py b/client/ayon_core/hosts/houdini/plugins/publish/validate_mkpaths_toggled.py index 38f1c4e176..5e59eb505f 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/validate_mkpaths_toggled.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/validate_mkpaths_toggled.py @@ -7,7 +7,7 @@ class ValidateIntermediateDirectoriesChecked(pyblish.api.InstancePlugin): """Validate Create Intermediate Directories is enabled on ROP node.""" order = pyblish.api.ValidatorOrder - families = ["pointcache", "camera", "vdbcache"] + families = ["pointcache", "camera", "vdbcache", "model"] hosts = ["houdini"] label = "Create Intermediate Directories Checked" diff --git a/client/ayon_core/hosts/houdini/plugins/publish/validate_sop_output_node.py b/client/ayon_core/hosts/houdini/plugins/publish/validate_sop_output_node.py index 61cf7596ac..d67192d28e 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/validate_sop_output_node.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/validate_sop_output_node.py @@ -22,7 +22,7 @@ class ValidateSopOutputNode(pyblish.api.InstancePlugin): """ order = pyblish.api.ValidatorOrder - families = ["pointcache", "vdbcache"] + families = ["pointcache", "vdbcache", "model"] hosts = ["houdini"] label = "Validate Output Node (SOP)" actions = [SelectROPAction, SelectInvalidAction] From 475d1db69bc518522b57f270f174799842f6d031 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Thu, 9 May 2024 15:05:54 +0300 Subject: [PATCH 10/22] add 'model' product type to 'collect_instnaces_type' --- .../hosts/houdini/plugins/create/create_model.py | 3 --- ...intcache_type.py => collect_instances_type.py} | 15 +++++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) rename client/ayon_core/hosts/houdini/plugins/publish/{collect_pointcache_type.py => collect_instances_type.py} (51%) diff --git a/client/ayon_core/hosts/houdini/plugins/create/create_model.py b/client/ayon_core/hosts/houdini/plugins/create/create_model.py index 1f32ccde45..74d067b133 100644 --- a/client/ayon_core/hosts/houdini/plugins/create/create_model.py +++ b/client/ayon_core/hosts/houdini/plugins/create/create_model.py @@ -25,9 +25,6 @@ class CreateModel(plugin.HoudiniCreator): product_type = "model" icon = "cube" - def get_publish_families(self): - return ["model", "abc"] - def create(self, product_name, instance_data, pre_create_data): instance_data.pop("active", None) instance_data.update({"node_type": "alembic"}) diff --git a/client/ayon_core/hosts/houdini/plugins/publish/collect_pointcache_type.py b/client/ayon_core/hosts/houdini/plugins/publish/collect_instances_type.py similarity index 51% rename from client/ayon_core/hosts/houdini/plugins/publish/collect_pointcache_type.py rename to client/ayon_core/hosts/houdini/plugins/publish/collect_instances_type.py index 3323e97c20..07851387fe 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/collect_pointcache_type.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/collect_instances_type.py @@ -1,21 +1,24 @@ -"""Collector for pointcache types. +"""Collector for different types. -This will add additional family to pointcache instance based on +This will add additional families to different instance based on the creator_identifier parameter. """ import pyblish.api class CollectPointcacheType(pyblish.api.InstancePlugin): - """Collect data type for pointcache instance.""" + """Collect data type for different instances.""" order = pyblish.api.CollectorOrder hosts = ["houdini"] - families = ["pointcache"] - label = "Collect type of pointcache" + families = ["pointcache", "model"] + label = "Collect instances types" def process(self, instance): if instance.data["creator_identifier"] == "io.openpype.creators.houdini.bgeo": # noqa: E501 instance.data["families"] += ["bgeo"] - elif instance.data["creator_identifier"] == "io.openpype.creators.houdini.pointcache": # noqa: E501 + elif instance.data["creator_identifier"] in { + "io.openpype.creators.houdini.pointcache", + "io.openpype.creators.houdini.model" + }: instance.data["families"] += ["abc"] From b2b8cb132f78b4bc807e0dcaf0ef71d906f10f73 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Mon, 13 May 2024 17:59:23 +0300 Subject: [PATCH 11/22] add CreateModel --- server_addon/houdini/package.py | 2 +- server_addon/houdini/server/settings/create.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server_addon/houdini/package.py b/server_addon/houdini/package.py index 6c81eba439..06b034da38 100644 --- a/server_addon/houdini/package.py +++ b/server_addon/houdini/package.py @@ -1,3 +1,3 @@ name = "houdini" title = "Houdini" -version = "0.2.14" +version = "0.2.15" diff --git a/server_addon/houdini/server/settings/create.py b/server_addon/houdini/server/settings/create.py index 203ca4f9d6..cd1e110c23 100644 --- a/server_addon/houdini/server/settings/create.py +++ b/server_addon/houdini/server/settings/create.py @@ -57,6 +57,9 @@ class CreatePluginsModel(BaseSettingsModel): CreateMantraROP: CreatorModel = SettingsField( default_factory=CreatorModel, title="Create Mantra ROP") + CreateModel: CreatorModel = SettingsField( + default_factory=CreatorModel, + title="Create Model") CreatePointCache: CreatorModel = SettingsField( default_factory=CreatorModel, title="Create PointCache (Abc)") @@ -124,6 +127,10 @@ DEFAULT_HOUDINI_CREATE_SETTINGS = { "enabled": True, "default_variants": ["Main"] }, + "CreateModel": { + "enabled": True, + "default_variants": ["Main"] + }, "CreatePointCache": { "enabled": True, "default_variants": ["Main"] From caf3682e87bc3f4356f5ed8a9d54d0c040282588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A0=20Serra=20Arrizabalaga?= Date: Tue, 21 May 2024 22:22:33 +0200 Subject: [PATCH 12/22] Make sure actions in Launcher are sorted so they don't keep changing order randomly --- client/ayon_core/tools/launcher/models/actions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/tools/launcher/models/actions.py b/client/ayon_core/tools/launcher/models/actions.py index 32df600c87..c27f0cd757 100644 --- a/client/ayon_core/tools/launcher/models/actions.py +++ b/client/ayon_core/tools/launcher/models/actions.py @@ -332,7 +332,7 @@ class ActionsModel: selection = self._prepare_selection(project_name, folder_id, task_id) output = [] action_items = self._get_action_items(project_name) - for identifier, action in self._get_action_objects().items(): + for identifier, action in sorted(self._get_action_objects().items()): if not action.is_compatible(selection): continue From 6c461eb21c981ebb70c19d40013f63fcefbd1a5f Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 22 May 2024 09:54:27 +0200 Subject: [PATCH 13/22] add addon name to version.py --- server_addon/create_ayon_addons.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server_addon/create_ayon_addons.py b/server_addon/create_ayon_addons.py index f0a36d4740..749077d2a8 100644 --- a/server_addon/create_ayon_addons.py +++ b/server_addon/create_ayon_addons.py @@ -47,7 +47,7 @@ plugin_for = ["ayon_server"] """ CLIENT_VERSION_CONTENT = '''# -*- coding: utf-8 -*- -"""Package declaring AYON core addon version.""" +"""Package declaring AYON addon '{}' version.""" __version__ = "{}" ''' @@ -183,6 +183,7 @@ def create_addon_zip( def prepare_client_code( + addon_name: str, addon_dir: Path, addon_output_dir: Path, addon_version: str @@ -211,7 +212,9 @@ def prepare_client_code( version_path = subpath / "version.py" if version_path.exists(): with open(version_path, "w") as stream: - stream.write(CLIENT_VERSION_CONTENT.format(addon_version)) + stream.write( + CLIENT_VERSION_CONTENT.format(addon_name, addon_version) + ) zip_filepath = private_dir / "client.zip" with ZipFileLongPaths(zip_filepath, "w", zipfile.ZIP_DEFLATED) as zipf: @@ -262,7 +265,9 @@ def create_addon_package( server_dir, addon_output_dir / "server", dirs_exist_ok=True ) - prepare_client_code(addon_dir, addon_output_dir, addon_version) + prepare_client_code( + package.name, addon_dir, addon_output_dir, addon_version + ) if create_zip: create_addon_zip( From dd29bd8fa8f88853fb8cf4ea4ec496ec8e2a41cf Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Wed, 22 May 2024 15:46:03 +0300 Subject: [PATCH 14/22] remove original render instance --- .../ayon_core/hosts/houdini/plugins/publish/extract_render.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py b/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py index 7b4762a25f..651df15c10 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py @@ -72,3 +72,6 @@ class ExtractRender(publish.Extractor): raise RuntimeError("Failed to complete render extraction. " "Missing output files: {}".format( missing_frames)) + + # Remove original render instance + instance.context.remove(instance) From 60a76239bf254406eb19eef3096e3b94a40d0060 Mon Sep 17 00:00:00 2001 From: Mustafa Taher Date: Wed, 22 May 2024 18:32:28 +0300 Subject: [PATCH 15/22] disable integration for the original render instance Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- .../ayon_core/hosts/houdini/plugins/publish/extract_render.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py b/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py index 651df15c10..20e9341ebd 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py @@ -74,4 +74,4 @@ class ExtractRender(publish.Extractor): missing_frames)) # Remove original render instance - instance.context.remove(instance) + instance.data["integrate"] = False From ab8d5186b9f9c9a9fc885272dc398b579aa8225e Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Wed, 22 May 2024 18:42:19 +0300 Subject: [PATCH 16/22] update comment about skipping integration --- .../ayon_core/hosts/houdini/plugins/publish/extract_render.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py b/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py index 20e9341ebd..267280ad9f 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py @@ -73,5 +73,5 @@ class ExtractRender(publish.Extractor): "Missing output files: {}".format( missing_frames)) - # Remove original render instance + # Skip integrating original render instance instance.data["integrate"] = False From 48167e23c79baf4510d514426139f07f9ec86a9b Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 22 May 2024 17:43:31 +0200 Subject: [PATCH 17/22] Implement sorting proxy model --- .../tools/launcher/ui/actions_widget.py | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/tools/launcher/ui/actions_widget.py b/client/ayon_core/tools/launcher/ui/actions_widget.py index a225827418..3e4dfaf6e4 100644 --- a/client/ayon_core/tools/launcher/ui/actions_widget.py +++ b/client/ayon_core/tools/launcher/ui/actions_widget.py @@ -290,6 +290,34 @@ class ActionDelegate(QtWidgets.QStyledItemDelegate): painter.drawPixmap(extender_x, extender_y, pix) +class ActionsProxyModel(QtCore.QSortFilterProxyModel): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.setSortCaseSensitivity(QtCore.Qt.CaseInsensitive) + + def lessThan(self, left, right): + # Sort by action order and then by label + left_value = left.data(ACTION_SORT_ROLE) + right_value = right.data(ACTION_SORT_ROLE) + + # Values are same -> use super sorting + if left_value == right_value: + # Default behavior is using DisplayRole + return super().lessThan(left, right) + + # Validate 'None' values + if right_value is None: + return True + if left_value is None: + return False + # Sort values and handle incompatible types + try: + return left_value < right_value + except TypeError: + return True + + class ActionsWidget(QtWidgets.QWidget): def __init__(self, controller, parent): super(ActionsWidget, self).__init__(parent) @@ -316,10 +344,7 @@ class ActionsWidget(QtWidgets.QWidget): model = ActionsQtModel(controller) - proxy_model = QtCore.QSortFilterProxyModel() - proxy_model.setSortCaseSensitivity(QtCore.Qt.CaseInsensitive) - proxy_model.setSortRole(ACTION_SORT_ROLE) - + proxy_model = ActionsProxyModel() proxy_model.setSourceModel(model) view.setModel(proxy_model) From 88cae86ee67a0cedd2e0635dd1fe1f6a2a45f4d9 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 22 May 2024 17:43:42 +0200 Subject: [PATCH 18/22] reverse sorting in actions model --- client/ayon_core/tools/launcher/models/actions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/tools/launcher/models/actions.py b/client/ayon_core/tools/launcher/models/actions.py index c27f0cd757..32df600c87 100644 --- a/client/ayon_core/tools/launcher/models/actions.py +++ b/client/ayon_core/tools/launcher/models/actions.py @@ -332,7 +332,7 @@ class ActionsModel: selection = self._prepare_selection(project_name, folder_id, task_id) output = [] action_items = self._get_action_items(project_name) - for identifier, action in sorted(self._get_action_objects().items()): + for identifier, action in self._get_action_objects().items(): if not action.is_compatible(selection): continue From 7f586576415493f0c49bdb497fb70c9921b038ed Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Wed, 22 May 2024 18:46:39 +0300 Subject: [PATCH 19/22] move code to a dedicated place --- .../plugins/publish/collect_local_render_instances.py | 6 +++--- .../hosts/houdini/plugins/publish/extract_render.py | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/hosts/houdini/plugins/publish/collect_local_render_instances.py b/client/ayon_core/hosts/houdini/plugins/publish/collect_local_render_instances.py index 5a446fa0d3..474002e1ee 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/collect_local_render_instances.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/collect_local_render_instances.py @@ -132,6 +132,6 @@ class CollectLocalRenderInstances(pyblish.api.InstancePlugin): ] }) - # Remove original render instance - # I can't remove it here as I still need it to trigger the render. - # context.remove(instance) + # Skip integrating original render instance. + # We are not removing it because it's used to trigger the render. + instance.data["integrate"] = False diff --git a/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py b/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py index 267280ad9f..7b4762a25f 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/extract_render.py @@ -72,6 +72,3 @@ class ExtractRender(publish.Extractor): raise RuntimeError("Failed to complete render extraction. " "Missing output files: {}".format( missing_frames)) - - # Skip integrating original render instance - instance.data["integrate"] = False From 4bef6c9911ff47edf88dfa1b45fbb36c945e90e6 Mon Sep 17 00:00:00 2001 From: Mustafa Taher Date: Thu, 23 May 2024 12:34:54 +0300 Subject: [PATCH 20/22] refactor an if condition Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- .../plugins/publish/validate_export_is_a_single_frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/houdini/plugins/publish/validate_export_is_a_single_frame.py b/client/ayon_core/hosts/houdini/plugins/publish/validate_export_is_a_single_frame.py index 6775699adf..b188055bc7 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/validate_export_is_a_single_frame.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/validate_export_is_a_single_frame.py @@ -42,7 +42,7 @@ class ValidateSingleFrame(pyblish.api.InstancePlugin, frame_end = instance.data.get("frameEndHandle") # This happens if instance node has no 'trange' parameter. - if (frame_start or frame_end) is None: + if frame_start is None or frame_end is None: cls.log.debug( "No frame data, skipping check.." ) From c86c3770b54f03b898188ed74c780db18a75d517 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 23 May 2024 14:39:47 +0200 Subject: [PATCH 21/22] bump version to '0.3.2' --- client/ayon_core/version.py | 2 +- package.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/version.py b/client/ayon_core/version.py index 275e1b1dd6..655595d9f4 100644 --- a/client/ayon_core/version.py +++ b/client/ayon_core/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- """Package declaring AYON core addon version.""" -__version__ = "0.3.2-dev.1" +__version__ = "0.3.2" diff --git a/package.py b/package.py index b7b8d2dae6..cf9d7b2035 100644 --- a/package.py +++ b/package.py @@ -1,6 +1,6 @@ name = "core" title = "Core" -version = "0.3.2-dev.1" +version = "0.3.2" client_dir = "ayon_core" From 5be9f4e253f9765e635a3c98444712bfdf5365e9 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 23 May 2024 14:40:20 +0200 Subject: [PATCH 22/22] bump version to '0.3.3-dev.1' --- client/ayon_core/version.py | 2 +- package.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/version.py b/client/ayon_core/version.py index 655595d9f4..e4297e2000 100644 --- a/client/ayon_core/version.py +++ b/client/ayon_core/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- """Package declaring AYON core addon version.""" -__version__ = "0.3.2" +__version__ = "0.3.3-dev.1" diff --git a/package.py b/package.py index cf9d7b2035..73f7174b6f 100644 --- a/package.py +++ b/package.py @@ -1,6 +1,6 @@ name = "core" title = "Core" -version = "0.3.2" +version = "0.3.3-dev.1" client_dir = "ayon_core"