From fbf1b9e6592dac486730253cd9b82ea8ea61be86 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Tue, 7 Mar 2023 17:24:58 +0100 Subject: [PATCH] :art: simple bgeo publishing in houdini --- .../houdini/plugins/create/create_bgeo.py | 65 +++++++++++++++++++ .../houdini/plugins/publish/collect_frames.py | 7 +- .../houdini/plugins/publish/extract_bgeo.py | 50 ++++++++++++++ openpype/plugins/publish/integrate.py | 3 +- 4 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 openpype/hosts/houdini/plugins/create/create_bgeo.py create mode 100644 openpype/hosts/houdini/plugins/publish/extract_bgeo.py diff --git a/openpype/hosts/houdini/plugins/create/create_bgeo.py b/openpype/hosts/houdini/plugins/create/create_bgeo.py new file mode 100644 index 0000000000..38e63dbc9f --- /dev/null +++ b/openpype/hosts/houdini/plugins/create/create_bgeo.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +"""Creator plugin for creating pointcache bgeo files.""" +from openpype.hosts.houdini.api import plugin +from openpype.pipeline import CreatedInstance +from openpype.lib import EnumDef + + +class CreateBGEO(plugin.HoudiniCreator): + """BGEO pointcache creator.""" + identifier = "io.openpype.creators.houdini.bgeo" + label = "BGEO PointCache" + family = "bgeo" + icon = "gears" + + def create(self, subset_name, instance_data, pre_create_data): + import hou + + instance_data.pop("active", None) + + instance_data.update({"node_type": "geometry"}) + instance_data["bgeo_type"] = pre_create_data.get("bgeo_type") + + instance = super(CreateBGEO, self).create( + subset_name, + instance_data, + pre_create_data) # type: CreatedInstance + + instance_node = hou.node(instance.get("instance_node")) + + file_path = "{}{}".format( + hou.text.expandString("$HIP/pyblish/"), + "{}.$F4.{}".format( + subset_name, + pre_create_data.get("bgeo_type") or "bgeo.sc") + ) + parms = { + "sopoutput": file_path + } + + if self.selected_nodes: + parms["soppath"] = self.selected_nodes[0].path() + + # try to find output node + for child in self.selected_nodes[0].children(): + if child.type().name() == "output": + parms["soppath"] = child.path() + break + + instance_node.setParms(parms) + instance_node.parm("trange").set(1) + + def get_pre_create_attr_defs(self): + attrs = super().get_pre_create_attr_defs() + bgeo_enum = [ + {"option": "bgeo", "value": "bgeo", "label": "uncompressed bgeo (.bgeo)"}, + {"option": "bgeosc", "value": "bgeosc", "label": "BLOSC compressed bgeo (.bgeosc)"}, + {"option": "bgeo.sc", "value": "bgeo.sc", "label": "BLOSC compressed bgeo (.bgeo.sc)"}, + {"option": "bgeo.gz", "value": "bgeo.gz", "label": "GZ compressed bgeo (.bgeo.gz)"}, + {"option": "bgeo.lzma", "value": "bgeo.lzma", "label": "LZMA compressed bgeo (.bgeo.lzma)"}, + {"option": "bgeo.bz2", "value": "bgeo.bz2", "label": "BZip2 compressed bgeo (.bgeo.bz2)"} + ] + + return attrs + [ + EnumDef("bgeo_type", bgeo_enum, label="BGEO Options"), + ] diff --git a/openpype/hosts/houdini/plugins/publish/collect_frames.py b/openpype/hosts/houdini/plugins/publish/collect_frames.py index 531cdf1249..f0264b10a6 100644 --- a/openpype/hosts/houdini/plugins/publish/collect_frames.py +++ b/openpype/hosts/houdini/plugins/publish/collect_frames.py @@ -8,13 +8,12 @@ import pyblish.api from openpype.hosts.houdini.api import lib - class CollectFrames(pyblish.api.InstancePlugin): """Collect all frames which would be saved from the ROP nodes""" order = pyblish.api.CollectorOrder label = "Collect Frames" - families = ["vdbcache", "imagesequence", "ass", "redshiftproxy"] + families = ["vdbcache", "imagesequence", "ass", "redshiftproxy", "bgeo"] def process(self, instance): @@ -35,7 +34,9 @@ class CollectFrames(pyblish.api.InstancePlugin): output = output_parm.eval() _, ext = lib.splitext(output, - allowed_multidot_extensions=[".ass.gz"]) + allowed_multidot_extensions=[ + ".ass.gz", ".bgeo.sc", ".bgeo.gz", + ".bgeo.lzma", ".bgeo.bz2"]) file_name = os.path.basename(output) result = file_name diff --git a/openpype/hosts/houdini/plugins/publish/extract_bgeo.py b/openpype/hosts/houdini/plugins/publish/extract_bgeo.py new file mode 100644 index 0000000000..8b14ca7418 --- /dev/null +++ b/openpype/hosts/houdini/plugins/publish/extract_bgeo.py @@ -0,0 +1,50 @@ +import os + +import pyblish.api + +from openpype.pipeline import publish +from openpype.hosts.houdini.api.lib import render_rop + +import hou + + +class ExtractBGEO(publish.Extractor): + + order = pyblish.api.ExtractorOrder + label = "Extract BGEO" + hosts = ["houdini"] + families = ["bgeo"] + + def process(self, instance): + + ropnode = hou.node(instance.data["instance_node"]) + + # Get the filename from the filename parameter + output = ropnode.evalParm("sopoutput") + staging_dir = os.path.dirname(output) + instance.data["stagingDir"] = staging_dir + + file_name = os.path.basename(output) + + # We run the render + self.log.info("Writing bgeo files '%s' to '%s'" % (file_name, + staging_dir)) + + # write files + ropnode.parm("execute").pressButton() + + output = instance.data["frames"] + self.log.debug(f"output: {output}") + + if "representations" not in instance.data: + instance.data["representations"] = [] + + representation = { + 'name': 'bgeo', + 'ext': instance.data["bgeo_type"], + 'files': output, + "stagingDir": staging_dir, + "frameStart": instance.data["frameStart"], + "frameEnd": instance.data["frameEnd"] + } + instance.data["representations"].append(representation) diff --git a/openpype/plugins/publish/integrate.py b/openpype/plugins/publish/integrate.py index b117006871..0971459c0c 100644 --- a/openpype/plugins/publish/integrate.py +++ b/openpype/plugins/publish/integrate.py @@ -132,7 +132,8 @@ class IntegrateAsset(pyblish.api.InstancePlugin): "mvUsdOverride", "simpleUnrealTexture", "online", - "uasset" + "uasset", + "bgeo" ] default_template_name = "publish"