diff --git a/pype/plugins/maya/load/load_alembic.py b/pype/plugins/maya/load/load_alembic.py deleted file mode 100644 index 51caaf6adc..0000000000 --- a/pype/plugins/maya/load/load_alembic.py +++ /dev/null @@ -1,63 +0,0 @@ -import pype.maya.plugin -import os -from pypeapp import config - - -class AbcLoader(pype.maya.plugin.ReferenceLoader): - """Specific loader of Alembic for the pype.animation family""" - - families = ["animation", - "pointcache"] - label = "Reference animation" - representations = ["abc"] - order = -10 - icon = "code-fork" - color = "orange" - - def process_reference(self, context, name, namespace, data): - - import maya.cmds as cmds - - try: - family = context["representation"]["context"]["family"] - except ValueError: - family = "animation" - - groupName = "{}:{}".format(namespace, name) - cmds.loadPlugin("AbcImport.mll", quiet=True) - nodes = cmds.file(self.fname, - namespace=namespace, - sharedReferenceFile=False, - groupReference=True, - groupName=groupName, - reference=True, - returnNewNodes=True) - - nodes.pop(0) - roots = set() - for node in nodes: - try: - roots.add(cmds.ls(node, long=True)[0].split('|')[2]) - except: - pass - cmds.parent(roots, world=True) - cmds.makeIdentity(groupName, apply=False, rotate=True, - translate=True, scale=True) - cmds.parent(roots, groupName) - - nodes.append(groupName) - - presets = config.get_presets(project=os.environ['AVALON_PROJECT']) - colors = presets['plugins']['maya']['load']['colors'] - c = colors.get(family) - if c is not None: - cmds.setAttr(groupName + ".useOutlinerColor", 1) - cmds.setAttr(groupName + ".outlinerColor", - c[0], c[1], c[2]) - - self[:] = nodes - - return nodes - - def switch(self, container, representation): - self.update(container, representation) diff --git a/pype/plugins/maya/load/load_gpucache.py b/pype/plugins/maya/load/load_gpucache.py new file mode 100644 index 0000000000..b98ca8b7f4 --- /dev/null +++ b/pype/plugins/maya/load/load_gpucache.py @@ -0,0 +1,105 @@ +from avalon import api +import pype.maya.plugin +import os +from pypeapp import config +import pymel.core as pm +reload(config) + + +class GpuCacheLoader(api.Loader): + """Load model Alembic as gpuCache""" + + families = ["model"] + representations = ["abc"] + + label = "Import Gpu Cache" + order = -5 + icon = "code-fork" + color = "orange" + + def load(self, context, name, namespace, data): + + import maya.cmds as cmds + import avalon.maya.lib as lib + from avalon.maya.pipeline import containerise + + asset = context['asset']['name'] + namespace = namespace or lib.unique_namespace( + asset + "_", + prefix="_" if asset[0].isdigit() else "", + suffix="_", + ) + + cmds.loadPlugin("gpuCache", quiet=True) + + # Root group + label = "{}:{}".format(namespace, name) + root = cmds.group(name=label, empty=True) + + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] + c = colors.get('model') + if c is not None: + cmds.setAttr(root + ".useOutlinerColor", 1) + cmds.setAttr(root + ".outlinerColor", + c[0], c[1], c[2]) + + # Create transform with shape + transform_name = label + "_GPU" + transform = cmds.createNode("transform", name=transform_name, + parent=root) + cache = cmds.createNode("gpuCache", + parent=transform, + name="{0}Shape".format(transform_name)) + + # Set the cache filepath + cmds.setAttr(cache + '.cacheFileName', self.fname, type="string") + cmds.setAttr(cache + '.cacheGeomPath', "|", type="string") # root + + # Lock parenting of the transform and cache + cmds.lockNode([transform, cache], lock=True) + + nodes = [root, transform, cache] + self[:] = nodes + + return containerise( + name=name, + namespace=namespace, + nodes=nodes, + context=context, + loader=self.__class__.__name__) + + def update(self, container, representation): + + import maya.cmds as cmds + + path = api.get_representation_path(representation) + + # Update the cache + members = cmds.sets(container['objectName'], query=True) + caches = cmds.ls(members, type="gpuCache", long=True) + + assert len(caches) == 1, "This is a bug" + + for cache in caches: + cmds.setAttr(cache + ".cacheFileName", path, type="string") + + cmds.setAttr(container["objectName"] + ".representation", + str(representation["_id"]), + type="string") + + def switch(self, container, representation): + self.update(container, representation) + + def remove(self, container): + import maya.cmds as cmds + members = cmds.sets(container['objectName'], query=True) + cmds.lockNode(members, lock=False) + cmds.delete([container['objectName']] + members) + + # Clean up the namespace + try: + cmds.namespace(removeNamespace=container['namespace'], + deleteNamespaceContent=True) + except RuntimeError: + pass diff --git a/pype/plugins/maya/load/load_model.py b/pype/plugins/maya/load/load_model.py deleted file mode 100644 index a886c6f644..0000000000 --- a/pype/plugins/maya/load/load_model.py +++ /dev/null @@ -1,223 +0,0 @@ -from avalon import api -import pype.maya.plugin -import os -from pypeapp import config -reload(config) - - -class ModelLoader(pype.maya.plugin.ReferenceLoader): - """Load the model""" - - families = ["model"] - representations = ["ma", "abc"] - tool_names = ["loader"] - - label = "Reference Model" - order = -10 - icon = "code-fork" - color = "orange" - - def process_reference(self, context, name, namespace, data): - - import maya.cmds as cmds - from avalon import maya - - with maya.maintained_selection(): - - groupName = "{}:{}".format(namespace, name) - cmds.loadPlugin("AbcImport.mll", quiet=True) - nodes = cmds.file(self.fname, - namespace=namespace, - sharedReferenceFile=False, - groupReference=True, - groupName="{}:{}".format(namespace, name), - reference=True, - returnNewNodes=True) - - namespace = cmds.referenceQuery(nodes[0], namespace=True) - - nodes.pop(1) - roots = set() - for node in nodes: - try: - roots.add(cmds.ls(node, long=True)[0].split('|')[2]) - except: - pass - cmds.parent(roots, world=True) - cmds.makeIdentity(groupName, apply=False, rotate=True, - translate=True, scale=True) - cmds.parent(roots, groupName) - - nodes.append(groupName) - - presets = config.get_presets(project=os.environ['AVALON_PROJECT']) - colors = presets['plugins']['maya']['load']['colors'] - c = colors.get('model') - if c is not None: - cmds.setAttr(groupName + ".useOutlinerColor", 1) - cmds.setAttr(groupName + ".outlinerColor", - c[0], c[1], c[2]) - - self[:] = nodes - - return nodes - - def switch(self, container, representation): - self.update(container, representation) - - -class GpuCacheLoader(api.Loader): - """Load model Alembic as gpuCache""" - - families = ["model"] - representations = ["abc"] - - label = "Import Gpu Cache" - order = -5 - icon = "code-fork" - color = "orange" - - def load(self, context, name, namespace, data): - - import maya.cmds as cmds - import avalon.maya.lib as lib - from avalon.maya.pipeline import containerise - - asset = context['asset']['name'] - namespace = namespace or lib.unique_namespace( - asset + "_", - prefix="_" if asset[0].isdigit() else "", - suffix="_", - ) - - cmds.loadPlugin("gpuCache", quiet=True) - - # Root group - label = "{}:{}".format(namespace, name) - root = cmds.group(name=label, empty=True) - - presets = config.get_presets(project=os.environ['AVALON_PROJECT']) - colors = presets['plugins']['maya']['load']['colors'] - c = colors.get('model') - if c is not None: - cmds.setAttr(root + ".useOutlinerColor", 1) - cmds.setAttr(root + ".outlinerColor", - c[0], c[1], c[2]) - - # Create transform with shape - transform_name = label + "_GPU" - transform = cmds.createNode("transform", name=transform_name, - parent=root) - cache = cmds.createNode("gpuCache", - parent=transform, - name="{0}Shape".format(transform_name)) - - # Set the cache filepath - cmds.setAttr(cache + '.cacheFileName', self.fname, type="string") - cmds.setAttr(cache + '.cacheGeomPath', "|", type="string") # root - - # Lock parenting of the transform and cache - cmds.lockNode([transform, cache], lock=True) - - nodes = [root, transform, cache] - self[:] = nodes - - return containerise( - name=name, - namespace=namespace, - nodes=nodes, - context=context, - loader=self.__class__.__name__) - - def update(self, container, representation): - - import maya.cmds as cmds - - path = api.get_representation_path(representation) - - # Update the cache - members = cmds.sets(container['objectName'], query=True) - caches = cmds.ls(members, type="gpuCache", long=True) - - assert len(caches) == 1, "This is a bug" - - for cache in caches: - cmds.setAttr(cache + ".cacheFileName", path, type="string") - - cmds.setAttr(container["objectName"] + ".representation", - str(representation["_id"]), - type="string") - - def switch(self, container, representation): - self.update(container, representation) - - def remove(self, container): - import maya.cmds as cmds - members = cmds.sets(container['objectName'], query=True) - cmds.lockNode(members, lock=False) - cmds.delete([container['objectName']] + members) - - # Clean up the namespace - try: - cmds.namespace(removeNamespace=container['namespace'], - deleteNamespaceContent=True) - except RuntimeError: - pass - - -# class AbcModelLoader(pype.maya.plugin.ReferenceLoader): -# """Specific loader of Alembic for the studio.animation family""" -# -# families = ["model"] -# representations = ["abc"] -# tool_names = ["loader"] -# -# label = "Reference Model" -# order = -10 -# icon = "code-fork" -# color = "orange" -# -# def process_reference(self, context, name, namespace, data): -# -# import maya.cmds as cmds -# -# groupName = "{}:{}".format(namespace, name) -# cmds.loadPlugin("AbcImport.mll", quiet=True) -# nodes = cmds.file(self.fname, -# namespace=namespace, -# sharedReferenceFile=False, -# groupReference=True, -# groupName="{}:{}".format(namespace, name), -# reference=True, -# returnNewNodes=True) -# -# namespace = cmds.referenceQuery(nodes[0], namespace=True) -# -# nodes.pop(0) -# roots = set() -# for node in nodes: -# try: -# roots.add(cmds.ls(node, long=True)[0].split('|')[2]) -# except: -# pass -# cmds.parent(roots, world=True) -# cmds.makeIdentity(groupName, apply=False, rotate=True, -# translate=True, scale=True) -# cmds.parent(roots, groupName) -# -# nodes.append(groupName) -# -# presets = config.get_presets(project=os.environ['AVALON_PROJECT']) -# colors = presets['plugins']['maya']['load']['colors'] -# c = colors.get('model') -# if c is not None: -# cmds.setAttr(groupName + ".useOutlinerColor", 1) -# cmds.setAttr(groupName + ".outlinerColor", -# c[0], c[1], c[2]) -# -# self[:] = nodes -# -# return nodes -# -# def switch(self, container, representation): -# self.update(container, representation) diff --git a/pype/plugins/maya/load/load_reference.py b/pype/plugins/maya/load/load_reference.py new file mode 100644 index 0000000000..199d79c941 --- /dev/null +++ b/pype/plugins/maya/load/load_reference.py @@ -0,0 +1,85 @@ +from avalon import api +import pype.maya.plugin +import os +from pypeapp import config +import pymel.core as pm +reload(config) + + +class ReferenceLoader(pype.maya.plugin.ReferenceLoader): + """Load the model""" + + families = ["model", "pointcache", "animation"] + representations = ["ma", "abc"] + tool_names = ["loader"] + + label = "Reference" + order = -10 + icon = "code-fork" + color = "orange" + + def process_reference(self, context, name, namespace, data): + + import maya.cmds as cmds + from avalon import maya + + try: + family = context["representation"]["context"]["family"] + except ValueError: + family = "model" + + with maya.maintained_selection(): + + groupName = "{}:{}".format(namespace, name) + cmds.loadPlugin("AbcImport.mll", quiet=True) + nodes = cmds.file(self.fname, + namespace=namespace, + sharedReferenceFile=False, + groupReference=True, + groupName="{}:{}".format(namespace, name), + reference=True, + returnNewNodes=True) + + namespace = cmds.referenceQuery(nodes[0], namespace=True) + + groupNode = pm.PyNode(groupName) + roots = set() + print(nodes) + + for node in nodes: + try: + roots.add(pm.PyNode(node).getAllParents()[-2]) + except: + pass + for root in roots: + root.setParent(world=True) + + groupNode.root().zeroTransformPivots() + for root in roots: + root.setParent(groupNode) + + presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + colors = presets['plugins']['maya']['load']['colors'] + c = colors.get(family) + if c is not None: + groupNode.useOutlinerColor.set(1) + groupNode.outlinerColor.set(c[0], c[1], c[2]) + + self[:] = nodes + + return nodes + + def switch(self, container, representation): + self.update(container, representation) + +# for backwards compatibility +class AbcLoader(ReferenceLoader): + families = ["pointcache", "animation"] + representations = ["abc"] + tool_names = [] + +# for backwards compatibility +class ModelLoader(ReferenceLoader): + families = ["model", "pointcache"] + representations = ["abc"] + tool_names = [] diff --git a/pype/plugins/maya/publish/extract_animation.py b/pype/plugins/maya/publish/extract_animation.py index 30d5dae92b..794a80e7a6 100644 --- a/pype/plugins/maya/publish/extract_animation.py +++ b/pype/plugins/maya/publish/extract_animation.py @@ -82,7 +82,7 @@ class ExtractAnimation(pype.api.Extractor): representation = { 'name': 'abc', - 'ext': '.abc', + 'ext': 'abc', 'files': filename, "stagingDir": dirname, } diff --git a/pype/plugins/maya/publish/extract_ass.py b/pype/plugins/maya/publish/extract_ass.py index 0c7ef02b4b..1fed6c8dd7 100644 --- a/pype/plugins/maya/publish/extract_ass.py +++ b/pype/plugins/maya/publish/extract_ass.py @@ -42,7 +42,7 @@ class ExtractAssStandin(pype.api.Extractor): representation = { 'name': 'ass', - 'ext': '.ass', + 'ext': 'ass', 'files': filename, "stagingDir": staging_dir } diff --git a/pype/plugins/maya/publish/extract_assproxy.py b/pype/plugins/maya/publish/extract_assproxy.py index bc807be9b0..34c3113e11 100644 --- a/pype/plugins/maya/publish/extract_assproxy.py +++ b/pype/plugins/maya/publish/extract_assproxy.py @@ -68,7 +68,7 @@ class ExtractAssProxy(pype.api.Extractor): representation = { 'name': 'ma', - 'ext': '.ma', + 'ext': 'ma', 'files': filename, "stagingDir": stagingdir } diff --git a/pype/plugins/maya/publish/extract_camera_alembic.py b/pype/plugins/maya/publish/extract_camera_alembic.py index 01239fd1e8..77e055daa6 100644 --- a/pype/plugins/maya/publish/extract_camera_alembic.py +++ b/pype/plugins/maya/publish/extract_camera_alembic.py @@ -75,7 +75,7 @@ class ExtractCameraAlembic(pype.api.Extractor): representation = { 'name': 'abc', - 'ext': '.abc', + 'ext': 'abc', 'files': filename, "stagingDir": dir_path, } diff --git a/pype/plugins/maya/publish/extract_camera_mayaAscii.py b/pype/plugins/maya/publish/extract_camera_mayaAscii.py index 152acb98fe..cafee6593d 100644 --- a/pype/plugins/maya/publish/extract_camera_mayaAscii.py +++ b/pype/plugins/maya/publish/extract_camera_mayaAscii.py @@ -173,7 +173,7 @@ class ExtractCameraMayaAscii(pype.api.Extractor): representation = { 'name': 'ma', - 'ext': '.ma', + 'ext': 'ma', 'files': filename, "stagingDir": dir_path, } diff --git a/pype/plugins/maya/publish/extract_fbx.py b/pype/plugins/maya/publish/extract_fbx.py index 93a99eea72..73d56f9a2c 100644 --- a/pype/plugins/maya/publish/extract_fbx.py +++ b/pype/plugins/maya/publish/extract_fbx.py @@ -213,7 +213,7 @@ class ExtractFBX(pype.api.Extractor): representation = { 'name': 'mov', - 'ext': '.mov', + 'ext': 'mov', 'files': filename, "stagingDir": stagingDir, } diff --git a/pype/plugins/maya/publish/extract_maya_ascii_raw.py b/pype/plugins/maya/publish/extract_maya_ascii_raw.py index c8f10d5b9b..895b6acbfe 100644 --- a/pype/plugins/maya/publish/extract_maya_ascii_raw.py +++ b/pype/plugins/maya/publish/extract_maya_ascii_raw.py @@ -56,7 +56,7 @@ class ExtractMayaAsciiRaw(pype.api.Extractor): representation = { 'name': 'ma', - 'ext': '.ma', + 'ext': 'ma', 'files': filename, "stagingDir": dir_path } diff --git a/pype/plugins/maya/publish/extract_model.py b/pype/plugins/maya/publish/extract_model.py index f6d9681222..d6e5e66c23 100644 --- a/pype/plugins/maya/publish/extract_model.py +++ b/pype/plugins/maya/publish/extract_model.py @@ -74,7 +74,7 @@ class ExtractModel(pype.api.Extractor): representation = { 'name': 'ma', - 'ext': '.ma', + 'ext': 'ma', 'files': filename, "stagingDir": stagingdir, } diff --git a/pype/plugins/maya/publish/extract_pointcache.py b/pype/plugins/maya/publish/extract_pointcache.py index 907dfe0e18..0879a4bfe3 100644 --- a/pype/plugins/maya/publish/extract_pointcache.py +++ b/pype/plugins/maya/publish/extract_pointcache.py @@ -84,7 +84,7 @@ class ExtractAlembic(pype.api.Extractor): representation = { 'name': 'abc', - 'ext': '.abc', + 'ext': 'abc', 'files': filename, "stagingDir": dirname } diff --git a/pype/plugins/maya/publish/extract_rendersetup.py b/pype/plugins/maya/publish/extract_rendersetup.py index b8dbfc178e..c8d8db0bbb 100644 --- a/pype/plugins/maya/publish/extract_rendersetup.py +++ b/pype/plugins/maya/publish/extract_rendersetup.py @@ -30,7 +30,7 @@ class ExtractRenderSetup(pype.api.Extractor): representation = { 'name': 'json', - 'ext': '.json', + 'ext': 'json', 'files': json_filename, "stagingDir": parent_dir, } diff --git a/pype/plugins/maya/publish/extract_rig.py b/pype/plugins/maya/publish/extract_rig.py index 713d5e2b59..c98e562313 100644 --- a/pype/plugins/maya/publish/extract_rig.py +++ b/pype/plugins/maya/publish/extract_rig.py @@ -39,7 +39,7 @@ class ExtractRig(pype.api.Extractor): representation = { 'name': 'ma', - 'ext': '.ma', + 'ext': 'ma', 'files': filename, "stagingDir": dir_path } diff --git a/pype/plugins/maya/publish/extract_thumbnail.py b/pype/plugins/maya/publish/extract_thumbnail.py index 4bc1d91174..e47915c4cf 100644 --- a/pype/plugins/maya/publish/extract_thumbnail.py +++ b/pype/plugins/maya/publish/extract_thumbnail.py @@ -137,7 +137,7 @@ class ExtractThumbnail(pype.api.Extractor): representation = { 'name': 'thumbnail', - 'ext': '.jpg', + 'ext': 'jpg', 'files': thumbnail, "stagingDir": stagingDir, "thumbnail": True diff --git a/pype/plugins/maya/publish/extract_vrayproxy.py b/pype/plugins/maya/publish/extract_vrayproxy.py index b2c84db22b..dcaa910730 100644 --- a/pype/plugins/maya/publish/extract_vrayproxy.py +++ b/pype/plugins/maya/publish/extract_vrayproxy.py @@ -59,7 +59,7 @@ class ExtractVRayProxy(pype.api.Extractor): representation = { 'name': 'vrmesh', - 'ext': '.vrmesh', + 'ext': 'vrmesh', 'files': file_name, "stagingDir": staging_dir, }