diff --git a/README.md b/README.md index 0b961fd..bc9ecc1 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,18 @@ Jumpstart your publishing pipeline with a basic configuration.

+### Prerequisities + +- Maya + +
+
+ +### Assumptions + +
+
+ ### Features - Asset definition template @@ -183,12 +195,15 @@ pyblish_starter.setup() ##### Modeling +Create a new model from scratch and publish it. + ```python from maya import cmds cmds.file(new=True, force=True) cmds.polyCube(name="Paul") +cmds.group(name="model") instance = cmds.sets(name="Paul_model") data = { @@ -208,29 +223,33 @@ util.publish() ##### Rigging +Build upon the model from the previous example to produce a rig. + ```python import os from maya import cmds -from pyblish_starter.maya import hierarchy_from_string +import pyblish_starter.maya +import pyblish_starter.maya.lib +reload(pyblish_starter.maya.lib) +reload(pyblish_starter.maya) +from pyblish_starter.maya import ( + hierarchy_from_string, + outmesh, + load +) cmds.file(new=True, force=True) -asset = os.path.join( - "public", - "Paul_model", - "v001", - "Paul_model.ma" -) - # Load external asset -cmds.file(asset, reference=True, namespace="model_") -reference = cmds.file(asset, query=True, referenceNode=True) -nodes = cmds.referenceQuery(reference, nodes=True) -geometry = cmds.ls(nodes, assemblies=True) +input_ = load("Paul_model", version=1, namespace="Paul_") +model_assembly = cmds.listRelatives(input_[0], children=True)[0] +model_geometry = outmesh(cmds.listRelatives( + model_assembly, shapes=True)[0], name="Model") -hierarchy_from_string("""\ +assembly = hierarchy_from_string("""\ rig implementation + input geometry skeleton interface @@ -238,22 +257,63 @@ rig preview """) -# Build +# Rig control = cmds.circle(name="Control")[0] skeleton = cmds.joint(name="Skeleton") -preview = cmds.createNode("mesh") -cmds.connectAttr(geometry[0] + ".outMesh", preview + ".inMesh") -preview = cmds.listRelatives(preview, parent=True)[0] -preview = cmds.rename(preview, "preview") +preview = outmesh(model, name="Preview") +cmds.skinCluster(model, skeleton) +cmds.parentConstraint(control, skeleton) + +# Sets +sets = list() +sets.append(cmds.sets(control, name="all_controls")) +sets.append(cmds.sets(model, name="all_cachable")) +sets.append(cmds.sets(reference, name="all_resources")) # Organise +cmds.parent(input_, "input") cmds.parent(control, "controls") cmds.parent(skeleton, "skeleton") -cmds.parent(geometry, "geometry") +cmds.parent(model, "geometry") cmds.parent(preview, "interface|preview") +cmds.setAttr(control + ".overrideEnabled", True) +cmds.setAttr(control + ".overrideColor", 18) +cmds.hide("implementation") +cmds.select(deselect=True) + +# Create instance +instance = cmds.sets([assembly] + sets, name="Paul_rig") + +data = { + "id": "pyblish.starter.instance", + "family": "starter.rig" +} + +for key, value in data.items(): + cmds.addAttr(instance, longName=key, dataType="string") + cmds.setAttr(instance + "." + key, value, type="string") + +from pyblish import util +#util.publish() +``` + +
+ +##### Animation + +Build upon the previous example by referencing and producing an animation from the rig. + +```python +from maya import cmds +from pyblish_starter.maya import ( + load +) + +cmds.file(new=True, force=True) + +# Load external asset +rig = load("Paul_rig", version=1, namespace="Paul01_")[0] -# Setup -... ```
diff --git a/pyblish_starter/__init__.py b/pyblish_starter/__init__.py index 3bd932c..29da4c8 100644 --- a/pyblish_starter/__init__.py +++ b/pyblish_starter/__init__.py @@ -5,7 +5,8 @@ time, format_private_dir, ) - + + def register_plugins(): # Register accompanying plugins from . import plugins @@ -14,7 +15,7 @@ def register_plugins(): def setup(): - register_plugins() + register_plugins() __all__ = [ diff --git a/pyblish_starter/maya/__init__.py b/pyblish_starter/maya/__init__.py index 965d563..9b38a0b 100644 --- a/pyblish_starter/maya/__init__.py +++ b/pyblish_starter/maya/__init__.py @@ -1,13 +1,17 @@ from .cache import ( - export_alembic, + export_alembic, ) from .lib import ( - hierarchy_from_string + hierarchy_from_string, + outmesh, + load, ) __all__ = [ "export_alembic", "hierarchy_from_string", + "outmesh", + "load", ] diff --git a/pyblish_starter/maya/cache.py b/pyblish_starter/maya/cache.py index 17e01c9..356a1de 100644 --- a/pyblish_starter/maya/cache.py +++ b/pyblish_starter/maya/cache.py @@ -2,6 +2,16 @@ def export_alembic(nodes, file, frame_range=(1, 100), uv_write=True): + """Wrap native MEL command with limited set of arguments + + Arguments: + nodes (list): Long names of nodes to cache + file (str): Absolute path to output destination + frame_range (tuple): Start- and end-frame of cache + uv_write (bool): Whether or not to include UVs + + """ + options = [ ("file", file), ("frameRange", "%s %s" % frame_range), diff --git a/pyblish_starter/maya/lib.py b/pyblish_starter/maya/lib.py index b28e1dc..6d47c2a 100644 --- a/pyblish_starter/maya/lib.py +++ b/pyblish_starter/maya/lib.py @@ -1,3 +1,4 @@ +import os from maya import cmds @@ -11,9 +12,60 @@ def hierarchy_from_string(hierarchy): name = line.strip() padding = len(line[:-len(name)]) parents[padding] = name - + name = cmds.createNode("transform", name=name) - + for parent in sorted(parents): if parent < padding: cmds.parent(name, parents[parent]) + + # Return assembly + return parents[0] + + +def outmesh(shape, name=None): + """Construct a new shape with a connection to source.inMesh + + Arguments: + shape (str): Long name of source shape + name (str, optional): Default "outMesh1" + + Returns: + transform of new shape + + """ + + outmesh = cmds.createNode("mesh") + cmds.connectAttr(shape + ".outMesh", outmesh + ".inMesh") + outmesh = cmds.listRelatives(outmesh, parent=True)[0] + outmesh = cmds.rename(outmesh, name or "outMesh1") + cmds.sets(outmesh, addElement="initialShadingGroup") + return outmesh + + +def load(asset, version, namespace=None): + """Load asset + + Arguments: + asset (str): Name of asset + version (int): Version number + namespace (str, optional): Name of namespace + + Returns: + Assembly/ies + + """ + + assert isinstance(version, int), "Version must be integer" + + asset = os.path.join( + "public", + asset, + "v%03d" % version, + asset + ".ma" + ) + + cmds.file(asset, reference=True, namespace=namespace) + reference = cmds.file(asset, query=True, referenceNode=True) + nodes = cmds.referenceQuery(reference, nodes=True) + return cmds.ls(nodes, assemblies=True)