Skip to content

Commit

Permalink
Expand upon example
Browse files Browse the repository at this point in the history
  • Loading branch information
mottosso committed Sep 15, 2016
1 parent 4e81c70 commit d12b750
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 27 deletions.
102 changes: 81 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ Jumpstart your publishing pipeline with a basic configuration.
<br>
<br>

### Prerequisities

- Maya

<br>
<br>

### Assumptions

<br>
<br>

### Features

- Asset definition template
Expand Down Expand Up @@ -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 = {
Expand All @@ -208,52 +223,97 @@ 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
controls
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()
```

<br>

##### 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
...
```

<br>
Expand Down
5 changes: 3 additions & 2 deletions pyblish_starter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
time,
format_private_dir,
)



def register_plugins():
# Register accompanying plugins
from . import plugins
Expand All @@ -14,7 +15,7 @@ def register_plugins():


def setup():
register_plugins()
register_plugins()


__all__ = [
Expand Down
8 changes: 6 additions & 2 deletions pyblish_starter/maya/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
10 changes: 10 additions & 0 deletions pyblish_starter/maya/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
56 changes: 54 additions & 2 deletions pyblish_starter/maya/lib.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from maya import cmds


Expand All @@ -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)

0 comments on commit d12b750

Please sign in to comment.