我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用maya.cmds.polyCube()。
def setUp(self): self.group = cmds.createNode('transform', name='skeleton_grp') cmds.select(cl=True) j1 = cmds.joint(p=(0, 10, 0)) cmds.joint(p=(1, 9, 0)) cmds.joint(p=(2, 8, 0)) j = cmds.joint(p=(3, 9, 0)) cmds.joint(p=(4, 6, 0)) cmds.joint(p=(5, 5, 0)) cmds.joint(p=(6, 3, 0)) self.cube = cmds.polyCube()[0] cmds.parent(self.cube, j) cmds.parent(j1, self.group) self.translates = [cmds.getAttr('{0}.t'.format(x))[0] for x in cmds.ls(type='joint')] self.rotates = [cmds.getAttr('{0}.r'.format(x))[0] for x in cmds.ls(type='joint')] self.orients = [cmds.getAttr('{0}.jo'.format(x))[0] for x in cmds.ls(type='joint')]
def create_bounding_box(self, meshName="bounding_GEO"): """ Create the bounding box mesh. :param meshName(string): Name of created mesh. Raises: None Returns: (string) Cube Transform """ obbCube = cmds.polyCube(constructionHistory=False, name="obb_GEO")[0] for ind, pnt in enumerate(self.boundPoints): cmds.xform("%s.vtx[%s]" % (obbCube, ind), translation=[pnt.x, pnt.y, pnt.z]) return obbCube
def test_hasattr(self): print(u"test_hasattr") cmds.file(new=True, f=True) cube = cmds.polyCube()[0] m = mtn.M(u"pCube1") assert(m.hasAttr(u"t.tx") == True) assert(m.hasAttr(u"t") == True) assert(m.hasAttr(u"tx") == True) assert(m.hasAttr(u"aaa") == False) assert(m.hasAttr(u"wm") == True) assert(m.hasAttr(u"wm[0]") == True) assert(m.hasAttr(m.t) == True) assert(m.hasAttr(m.tx) == True) assert(m.hasAttr(m.wm) == True) assert(m.hasAttr(m.wm[0]) == True)
def test_cached_attribute(self): print(u"test_cached_attribute") cmds.file(new=True, f=True) cube = cmds.polyCube()[0] m1 = mtn.M(u"pCube1") # m1._cache = True # default:True m2 = mtn.M(u"pCube1") m2._cache = False assert(m1._cache_attribute == {}) assert(m2._cache_attribute == {}) m1.t m2.t assert(u"t" in m1._cache_attribute) assert(u"t" not in m2._cache_attribute) assert(m1._cache == True) assert(m2._cache == False) assert(m1.t._cache == True) assert(m2.t._cache == False) assert(m1.t.tx._cache == True) assert(m2.t.tx._cache == False)
def test_listconnections(self): print(u"test_listconnections") cmds.file(new=True, f=True) cube = cmds.polyCube()[0] m = mtn.M(u"pCube1") cmds.setKeyframe("pCube1.tx", "pCube1.ty", "pCube1.tz", "pCube1.rx", "pCube1.ry", "pCube1.rz", "pCube1.sx", "pCube1.sy", "pCube1.sz") assert(type(m.listConnections()) == list) assert(m.listConnections(asGenerator=True).__class__.__name__ == "generator") m.listConnections(asGenerator=True, c=True) m.listConnections(asGenerator=True, p=True) m.listConnections(asGenerator=True, c=True, p=True) m.listConnections(c=True) m.listConnections(p=True) m.listConnections(c=True, p=True) assert(m.listConnections(c=True,s=False) == []) assert(m.listConnections(p=True,s=False) == [])
def doit(cage_tgt=None): if not cage_tgt: cage_tgt = cmds.ls(sl=True, o=True) cage = cage_tgt[0] tgt = cage_tgt[1:] cmds.loadPlugin('greenCageDeformer.py', qt=True) deformer = cmds.deformer(tgt, type='greenCageDeformer')[0] freezer = cmds.createNode('transformGeometry') cmds.connectAttr(cage + '.o', freezer + '.ig') cmds.connectAttr(cage + '.wm', freezer + '.txf') cmds.connectAttr(freezer + '.og', deformer + '.bc') cmds.disconnectAttr(freezer + '.og', deformer + '.bc') cmds.delete(freezer) cmds.connectAttr(cage + '.w', deformer + '.ic') cmds.dgeval(cmds.listConnections(deformer + '.og', s=False, d=True, sh=True, p=True)) #doit([cmds.polyCube(w=2.5, d=2.5, h=2.5)[0], cmds.polySphere()[0]])
def setUp(self): self.joint1 = cmds.joint(p=(-0.5, -0.5, 0)) self.joint2 = cmds.joint(p=(0, 0.0, 0)) self.joint3 = cmds.joint(p=(0.5, 0.5, 0)) self.shape = cmds.polyCube()[0] cmds.delete(self.shape, ch=True) self.skin = cmds.skinCluster(self.joint1, self.joint2, self.joint3, self.shape)[0] self.expected = { 'bindMethod': 1, 'blendWeights': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 'dropoffRate': 4.0, 'heatmapFalloff': 0.0, 'maintainMaxInfluences': False, 'maxInfluences': 2, 'name': u'skinCluster1', 'normalizeWeights': 1, 'shape': u'pCube1', 'skinningMethod': 0, 'useComponents': False, 'weightDistribution': 0, 'weights': { u'joint1': [0.9, 0.5, 0.5, 0.0, 0.5, 0.0, 0.9, 0.5], u'joint2': [0.10000000000000002, 0.5, 0.5, 0.5, 0.5, 0.5, 0.10000000000000002, 0.5], u'joint3': [0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0]} }
def _create_cube(self): cmds.polyCube()
def test_listattr(self): cmds.file(new=True, f=True) cube = cmds.polyCube()[0] m = mtn.M(u"pCube1") m.listAttrStr("rotateQuaternion", "selectHandle") m.listAttrStr("pCube1.rotateQuaternion", "pCube1.selectHandle") m.listAttrStr(array=True) m.listAttrStr("rotateQuaternion", "selectHandle", array=True) m._listAttr("rotateQuaternion", "selectHandle") m._listAttr("pCube1.rotateQuaternion", "pCube1.selectHandle") m._listAttr(array=True) m._listAttr("rotateQuaternion", "selectHandle", array=True)
def test_modeling(): """Modeling workflow is functional""" transform, generator = cmds.polyCube(name="body_PLY") group = cmds.group(transform, name="ROOT") cmds.select(group, replace=True) maya.create( name="modelDefault", asset=ASSET_NAME, family="mindbender.model", options={"useSelection": True} ) # Comply with save validator cmds.file(save=True) publish() asset = io.find_one({ "type": "asset", "name": ASSET_NAME }) assert asset subset = io.find_one({ "parent": asset["_id"], "type": "subset", "name": "modelDefault" }) assert subset version = io.find_one({ "parent": subset["_id"], "type": "version", }) assert version assert io.find_one({ "parent": version["_id"], "type": "representation", "name": "ma" }) is not None
def test_update(): """Updating works""" transform, generator = cmds.polyCube(name="body_PLY") group = cmds.group(transform, name="ROOT") cmds.select(group, replace=True) maya.create( name="modelDefault", asset=ASSET_NAME, family="mindbender.model", options={"useSelection": True} ) # Comply with save validator cmds.file(save=True) publish() publish() publish() # Version 3 cmds.file(new=True, force=True) asset = io.find_one({ "type": "asset", "name": ASSET_NAME }) subset = io.find_one({ "parent": asset["_id"], "type": "subset", "name": "modelDefault" }) version = io.find_one({ "parent": subset["_id"], "type": "version", "name": 2 }) assert version representation = io.find_one({ "parent": version["_id"], "type": "representation", "name": "ma" }) maya.load(representation["_id"]) container = next(maya.ls()) maya.update(container, 3)
def test_types(self): print("start : node type test.") cmds.file(new=True, f=True) m = mtn.M(cmds.polyCube()[0]) _name = m.name() m2 = mtn.M(_name) assert(m.nodeType() == u'transform') assert(hash(m) == hash(m2)) assert(hash(m.t) == hash(m2.attr("t"))) assert(hash(m.translate) == hash(m2.attr("t"))) assert(hash(m.t) == hash(m2.attr("translate"))) assert(hash(m.t.tx) == hash(m2.attr("translate").tx)) assert(hash(m.tx) == hash(m2.attr("translate").attr("tx"))) assert(hash(m.translateX) == hash(m2.attr("translate").attr("tx"))) assert(hash(m.pim) == hash(m2.attr("pim"))) assert(hash(m.pim) == hash(m2.pim)) assert(hash(m.pim[0]) != hash(m2.pim)) assert(hash(m.pim[0]) == hash(m2.pim[0])) assert(hash(mtn.M(_name+".translateX")) == hash(mtn.M(_name).attr("t").attr("tx"))) assert(hash(mtn.M(_name+".translateX")) == hash(mtn.M(_name).attr("t.translateX"))) assert(m == m2) assert(m.t == m2.attr("t")) assert(m.translate == m2.attr("t")) assert(m.t == m2.attr("translate")) assert(m.t.tx == m2.attr("translate").tx) assert(m.tx == m2.attr("translate").attr("tx")) assert(m.translateX == m2.attr("translate").attr("tx")) assert(m.pim == m2.attr("pim")) assert(m.pim == m2.pim) assert(m.pim[0] != m2.pim) assert(m.pim[0] == m2.pim[0]) assert(mtn.M(_name+".translateX") == mtn.M(_name).attr("t").attr("tx")) assert(mtn.M(_name+".translateX") == mtn.M(_name).attr("t.translateX")) j = mtn.M(cmds.createNode(u"joint")) assert(j.nodeType() == u'joint') t = mtn.M(u"time1") assert(t.nodeType() == u'time') print("end : node type test.")
def imprint(node, data): """Write `data` to `node` as userDefined attributes Arguments: node (str): Long name of node data (dict): Dictionary of key/value pairs Example: >>> from maya import cmds >>> def compute(): ... return 6 ... >>> cube, generator = cmds.polyCube() >>> imprint(cube, { ... "regularString": "myFamily", ... "computedValue": lambda: compute() ... }) ... >>> cmds.getAttr(cube + ".computedValue") 6 """ for key, value in data.items(): if callable(value): # Support values evaluated at imprint value = value() if isinstance(value, bool): add_type = {"attributeType": "bool"} set_type = {"keyable": False, "channelBox": True} elif isinstance(value, basestring): add_type = {"dataType": "string"} set_type = {"type": "string"} elif isinstance(value, int): add_type = {"attributeType": "long"} set_type = {"keyable": False, "channelBox": True} elif isinstance(value, float): add_type = {"attributeType": "double"} set_type = {"keyable": False, "channelBox": True} else: raise TypeError("Unsupported type: %r" % type(value)) cmds.addAttr(node, longName=key, **add_type) cmds.setAttr(node + "." + key, value, **set_type)