Python maya.cmds.blendShape() Examples
The following are 13
code examples of maya.cmds.blendShape().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.cmds
, or try the search function
.
Example #1
Source File: dpFacialControl.py From dpAutoRigSystem with GNU General Public License v2.0 | 7 votes |
def dpLoadBSNode(self, *args): """ Load selected object as blendShapeNode """ selectedList = cmds.ls(selection=True) if selectedList: if cmds.objectType(selectedList[0]) == "blendShape": cmds.textField(self.bsNodeTextField, edit=True, text=selectedList[0]) self.dpLoadBSTgtList(selectedList[0]) self.bsNode = selectedList[0] elif cmds.objectType(selectedList[0]) == "transform": meshList = cmds.listRelatives(selectedList[0], children=True, shapes=True, noIntermediate=True, type="mesh") if meshList: bsNodeList = cmds.listConnections(meshList[0], type="blendShape") if bsNodeList: self.dpLoadBSTgtList(bsNodeList[0]) self.bsNode = bsNodeList[0] else: mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";") else: mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";") else: mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";") else: mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";")
Example #2
Source File: dpFacialControl.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def dpLoadBSTgtList(self, bsNodeName, *args): """ Add target list found in the blendShape node to target textScroll list """ if cmds.objExists(bsNodeName): if cmds.objectType(bsNodeName) == "blendShape": tgtList = cmds.blendShape(bsNodeName, query=True, target=True) if tgtList: cmds.textScrollList(self.bsTargetScrollList, edit=True, removeAll=True) cmds.textScrollList(self.bsTargetScrollList, edit=True, append=tgtList) cmds.textField(self.bsNodeTextField, edit=True, text=bsNodeName) self.bsNode = bsNodeName
Example #3
Source File: test_cmt_blendshape.py From cmt with MIT License | 6 votes |
def test_get_blendshape_on_new_shape(self): shape = cmds.polyCube()[0] blendshape = bs.get_or_create_blendshape_node(shape) self.assertTrue(cmds.objExists(blendshape)) blendshapes = cmds.ls(type="blendShape") self.assertEqual(len(blendshapes), 1) self.assertEqual(blendshapes[0], blendshape) blendshape = bs.get_or_create_blendshape_node(shape) blendshapes = cmds.ls(type="blendShape") self.assertEqual(len(blendshapes), 1) self.assertEqual(blendshapes[0], blendshape)
Example #4
Source File: blendshape.py From cmt with MIT License | 6 votes |
def get_blendshape_node(geometry): """Get the first blendshape node upstream from the given geometry. :param geometry: Name of the geometry :return: The blendShape node name """ geometry = shortcuts.get_shape(geometry) history = cmds.listHistory(geometry, il=2, pdo=False) or [] blendshapes = [ x for x in history if cmds.nodeType(x) == "blendShape" and cmds.blendShape(x, q=True, g=True)[0] == geometry ] if blendshapes: return blendshapes[0] else: return None
Example #5
Source File: blendshape.py From cmt with MIT License | 6 votes |
def export_blendshape_targets(blendshape, directory): """Export all targets of a blendshape as objs. :param blendshape: Blendshape name :param directory: Directory path """ connections = zero_weights(blendshape) targets = get_target_list(blendshape) base = cmds.blendShape(blendshape, q=True, g=True)[0] for t in targets: plug = "{}.{}".format(blendshape, t) cmds.setAttr(plug, 1) file_path = os.path.join(directory, "{}.obj".format(t)) export_obj(base, file_path) cmds.setAttr(plug, 0) restore_weights(blendshape, connections)
Example #6
Source File: freeze.py From SIWeightEditor with MIT License | 6 votes |
def store_blend_shape(mesh): shapes = cmds.listRelatives(mesh, s=True, f=True) skin = cmds.ls(cmds.listHistory(shapes), type='skinCluster') if skin: connections = cmds.listConnections(skin, s=True, d=False) else: connections = cmds.listConnections(shapes, s=True, d=False) blend_shapes = cmds.ls(connections, l=True, type='blendShape') bs_dict = {} if blend_shapes: for bs in blend_shapes: shape_target = cmds.ls(cmds.listConnections(bs, s=True, d=False), l=True, type='transform') bs_dict[bs]=shape_target return bs_dict return
Example #7
Source File: freeze.py From SISideBar with MIT License | 5 votes |
def store_blend_shape(mesh): shapes = cmds.listRelatives(mesh, s=True, f=True) skin = cmds.ls(cmds.listHistory(shapes), type='skinCluster') if skin: connections = cmds.listConnections(skin, s=True, d=False) else: connections = cmds.listConnections(shapes, s=True, d=False) blend_shapes = cmds.ls(connections, l=True, type='blendShape') bs_dict = {} if blend_shapes: for bs in blend_shapes: shape_target = cmds.ls(cmds.listConnections(bs, s=True, d=False), l=True, type='transform') bs_dict[bs]=shape_target return bs_dict return
Example #8
Source File: freeze.py From SISideBar with MIT License | 5 votes |
def set_blend_shape(mesh, bs_dict): if not bs_dict: return for bs, shape_target in bs_dict.items(): cmds.blendShape(shape_target+[mesh], name=bs, frontOfChain=True)
Example #9
Source File: test_cmt_blendshape.py From cmt with MIT License | 5 votes |
def test_get_blendshape_on_existing_blendshape(self): shape = cmds.polyCube()[0] blendshape = cmds.blendShape(shape)[0] existing_blendshape = bs.get_or_create_blendshape_node(shape) self.assertEqual(blendshape, existing_blendshape)
Example #10
Source File: blendshape.py From cmt with MIT License | 5 votes |
def get_or_create_blendshape_node(geometry): """Get the first blendshape node upstream from the given geometry or create one if one does not exist. :param geometry: Name of the geometry :return: The blendShape node name """ geometry = shortcuts.get_shape(geometry) blendshape = get_blendshape_node(geometry) if blendshape: return blendshape else: return cmds.blendShape(geometry, foc=True)[0]
Example #11
Source File: blendshape.py From cmt with MIT License | 5 votes |
def get_target_index(blendshape, target): indices = cmds.getAttr("{}.w".format(blendshape), mi=True) or [] for i in indices: alias = cmds.aliasAttr("{}.w[{}]".format(blendshape, i), q=True) if alias == target: return i raise RuntimeError( "Target {} does not exist on blendShape {}".format(target, blendshape) )
Example #12
Source File: blendshape.py From cmt with MIT License | 5 votes |
def transfer_shapes(source, destination, blendshape=None): """Transfers the shapes on the given blendshape to the destination mesh. It is assumed the blendshape indirectly deforms the destination mesh. :param source: Mesh to transfer shapes from. :param destination: Mesh to transfer shapes to. :param blendshape: Optional blendshape node name. If no blendshape is given, the blendshape on the source mesh will be used. :return: The new blendshape node name. """ if blendshape is None: blendshape = get_blendshape_node(source) if blendshape is None: return connections = zero_weights(blendshape) targets = get_target_list(blendshape) new_targets = [] for t in targets: cmds.setAttr("{}.{}".format(blendshape, t), 1) new_targets.append(cmds.duplicate(destination, name=t)[0]) cmds.setAttr("{}.{}".format(blendshape, t), 0) cmds.delete(destination, ch=True) new_blendshape = cmds.blendShape(new_targets, destination, foc=True)[0] cmds.delete(new_targets) for t in targets: cmds.connectAttr( "{}.{}".format(blendshape, t), "{}.{}".format(new_blendshape, t) ) restore_weights(blendshape, connections) return new_blendshape
Example #13
Source File: freeze.py From SIWeightEditor with MIT License | 5 votes |
def set_blend_shape(mesh, bs_dict): if not bs_dict: return for bs, shape_target in bs_dict.items(): cmds.blendShape(shape_target+[mesh], name=bs, frontOfChain=True)