def createConnector(self, pt1, pt2, radius=0.5): # create cylinder and align between pt1/pt2 base_name = pt1 _logger.debug('Connector base name is %s' % base_name) viz_shape = pm.cylinder(n=base_name + 'Connector') pm.pointConstraint([pt1, pt2], viz_shape[0], mo=0) pm.aimConstraint(pt2, viz_shape[0], weight=1, upVector=(0, 1, 0), worldUpType="vector", offset=(0, 0, 0), aimVector=(1, 0, 0), worldUpVector=(0, 1, 0)) viz_direction = pm.cone(n=base_name + 'Direction', r=3 * radius) viz_shape[0].t >> viz_direction[0].t viz_shape[0].r >> viz_direction[0].r # measure distance between dist_node = pm.createNode('distanceBetween', n=base_name + '_distanceBetween') pm.connectAttr(pt1 + '.worldMatrix[0]', dist_node + '.inMatrix1', f=True) pm.connectAttr(pt2 + '.worldMatrix[0]', dist_node + '.inMatrix2', f=True) _logger.debug('Distance between base name is %s' % base_name) # length divide_half = pm.createNode('multiplyDivide', n=base_name + '_distceBetween_multiplyDivide') divide_half.input2X.set(0.5) dist_node.distance >> divide_half.input1X divide_half.outputX >> viz_shape[0].scaleX # radius viz_shape[0].scaleZ.set(radius) viz_shape[0].scaleY.set(radius) return [viz_shape[0], viz_direction[0]]
def advSpaceSwitch(): # COMPLEX SPACE SWITCHING r = pmc.sphere(n="rightHand")[0] l = pmc.cylinder(n="leftHand")[0] w = pmc.cone(n="weapon")[0] ws = pmc.spaceLocator(n="worldLoc") locs = [ws] grps = [] names = ["World"] names.extend([s.name() for s in (r, l, w)]) for s in (r, l, w): grps.append(pmc.group(s, n=s.name() + "_space")) l = pmc.spaceLocator(n=s.name() + "_ws") l.setParent(s) locs.append(l) spaces = ":".join([n for n in names if n != s.name()]) s.addAttr("space", at="enum", k=True, enumName=spaces) for g in grps: spaceMat = pmc.nt.WtAddMatrix() spaceXform = pmc.nt.DecomposeMatrix() spaceMat.o >> spaceXform.inputMatrix spaceXform.ot >> g.t targets = [l for l in locs if not l.hasParent(g)] for i, t in enumerate(targets): driver = g.getChildren()[0] # uc = pmc.nt.UnitConversion() # t.wp >> uc.input # direct connection from l >> g, # modulated by enum value test = pmc.nt.FloatLogic() driver.space >> test.floatA test.floatB.set(i) cond = pmc.nt.FloatCondition() test.outBool >> cond.condition cond.floatA.set(0) cond.floatB.set(10) # cond.outFloat >> uc.nodeState hold = pmc.nt.HoldMatrix() t.wm >> hold.i cond.outFloat >> hold.nodeState # for second-round lookup # ensure no ping-ponging cond.message >> driver.childConditions cond.message >> t.getParent().parentConditions hold.o >> spaceMat.i[i].m test.outBool >> spaceMat.i[i].w
def vecViz(vector, tfm, name = "vectorPointer"): """visual aid for vectors""" vec = pm.dt.Vector(vector) grp = pm.group(em = True) loc = pm.spaceLocator() pointer = pm.cone(name = name, esw = 360, ch = 1, d = 1, hr = 20, ut = 0, ssw = 0, s = 3, r = 0.25, tol = 0.01, nsp = 1, ax = (1, 0, 0))[0] loc.setParent(grp) pointer.setParent(grp) loc.setTranslation(vec) pm.delete(pm.aimConstraint(loc, pointer, aimVector = (1, 0, 0))) vectNorm = vec.normal() pointer.translate.set(vectNorm *(2.5, 2.5, 2.5)) pm.delete(pm.pointConstraint(tfm, grp, mo = False)) pointer.setParent(world = True) pm.delete(grp) import Maya.colorMesh as colorMesh reload(colorMesh)
def yellow_component(name="", shape_type="", translate=(0, 0, 0), parent_node=None, have_loc=False, have_jnt=False): u"""黄色的基础控制器组件 黄色的控制器一般用来作为模块的细节控制器或次级控制器 :param name: 名字 :param shape_type: 控制器的节点类型,例如nurbsPlane,locator, joint, sphere, cone :param translate: 位移 :param parent_node: 父节点 :param have_loc: 在父节点下是否创建loc :return: grp """ if shape_type == "nurbsPlane": pm.nurbsPlane(name=name, p=[0, 0, 0], ax=[0, 0, 1], w=1, lr=1, d=3, u=1, v=1, ch=1) if shape_type == "locator": pm.spaceLocator(name=name) if shape_type == "joint": pm.select(cl=True) pm.joint(name=name) if shape_type == "sphere": pm.sphere(name=name, p=[0, 0, 0], ax=[0, 1, 0], ssw=0, esw=360, r=0.3, d=3, ut=0, tol=0.01, s=4, nsp=2, ch=1) if shape_type == "cone": pm.cone(name=name, p=[0, 0, 0], ax=[-1, 0, 0], ssw=0, esw=360, r=0.45, hr=2, d=1, ut=0, tol=0.01, s=4, nsp=1, ch=0) pm.parent(pm.createNode("transform", name="{}_02_Grp".format(name)), pm.createNode("transform", name="{}_Grp".format(name))) pm.parent(name, "{}_02_Grp".format(name)) if have_loc: pm.parent(pm.spaceLocator(name="{}_Roll_Loc".format(name)), "{}_Grp".format(name)) if have_jnt: pm.select(cl=True) jnt = pm.joint(name="{}_Jnt".format(name)) pm.parent(jnt, name) pm.PyNode("{}_Grp".format(name)).translate.set(translate) if parent_node is not None: if pm.objExists(parent_node): pm.parent("{}_Grp".format(name), parent_node) return "{}_Grp".format(name)
def createAxis(self): pm.select(cl=1) xyzTopGrp = pm.group(name=self.axName) rgbShaders = self.createRGBShaders() xCylinder = pm.cylinder(hr=12, r=0.1, p=[0, 0, 0], ax=[1, 0, 0], name=self.axName + 'X')[0] xCylinder.translateX.set(0.6) xCylinder.setPivots([0, 0, 0], worldSpace=1) pm.makeIdentity(t=1, a=1) pm.delete(ch=1) pm.hyperShade(a=rgbShaders[0]) yCylinder = pm.cylinder(hr=12, r=0.1, p=[0, 0, 0], ax=[0, 1, 0], name=self.axName + 'Y')[0] yCylinder.translateY.set(0.6) yCylinder.setPivots([0, 0, 0], worldSpace=1) pm.makeIdentity(t=1, a=1) pm.delete(ch=1) pm.hyperShade(a=rgbShaders[1]) zCylinder = pm.cylinder(hr=12, r=0.1, p=[0, 0, 0], ax=[0, 0, 1], name=self.axName + 'Z')[0] zCylinder.translateZ.set(0.6) zCylinder.setPivots([0, 0, 0], worldSpace=1) pm.makeIdentity(t=1, a=1) pm.delete(ch=1) pm.hyperShade(a=rgbShaders[2]) xArrow = pm.cone(hr=2, r=0.2, p=[0, 0, 0], ax=[1, 0, 0], name=self.axName + 'arrX')[0] xArrow.translateX.set(1.4) xArrow.setPivots([0, 0, 0], worldSpace=1) pm.makeIdentity(t=1, a=1) pm.delete(ch=1) pm.hyperShade(a=rgbShaders[0]) yArrow = pm.cone(hr=2, r=0.2, p=[0, 0, 0], ax=[0, 1, 0], name=self.axName + 'arrY')[0] yArrow.translateY.set(1.4) yArrow.setPivots([0, 0, 0], worldSpace=1) pm.makeIdentity(t=1, a=1) pm.delete(ch=1) pm.hyperShade(a=rgbShaders[1]) zArrow = pm.cone(hr=2, r=0.2, p=[0, 0, 0], ax=[0, 0, 1], name=self.axName + 'arrZ')[0] zArrow.translateZ.set(1.4) zArrow.setPivots([0, 0, 0], worldSpace=1) pm.makeIdentity(t=1, a=1) pm.delete(ch=1) pm.hyperShade(a=rgbShaders[2]) pm.parent([ xCylinder.getShape(), yCylinder.getShape(), zCylinder.getShape(), xArrow.getShape(), yArrow.getShape(), zArrow.getShape() ], xyzTopGrp, r=1, s=1) guidePos = self.axGuide.getTranslation(worldSpace=1) jntRadius = self.axGuide.radius.get() scaleFactor = [jntRadius * 1.2, jntRadius * 1.2, jntRadius * 1.2] xyzTopGrp.translate.set(guidePos) xyzTopGrp.scale.set(scaleFactor) pm.makeIdentity(xyzTopGrp, t=1, s=1, r=1, a=1) pm.delete([xCylinder, yCylinder, zCylinder, xArrow, yArrow, zArrow]) plug = pm.listConnections(xyzTopGrp.getShapes()[0].name() + '.instObjGroups[0]', plugs=1) if plug: xyzTopGrp.getShapes()[0].instObjGroups[0] // plug[0] xyzTopGrp.getShapes()[0].instObjGroups[0] >> plug[0] plug = pm.listConnections(xyzTopGrp.getShapes()[3].name() + '.instObjGroups[0]', plugs=1) if plug: xyzTopGrp.getShapes()[3].instObjGroups[0] // plug[0] xyzTopGrp.getShapes()[3].instObjGroups[0] >> plug[0] plug = pm.listConnections(xyzTopGrp.getShapes()[1].name() + '.instObjGroups[0]', plugs=1) if plug: xyzTopGrp.getShapes()[1].instObjGroups[0] // plug[0] xyzTopGrp.getShapes()[1].instObjGroups[0] >> plug[0] plug = pm.listConnections(xyzTopGrp.getShapes()[4].name() + '.instObjGroups[0]', plugs=1) if plug: xyzTopGrp.getShapes()[4].instObjGroups[0] // plug[0] xyzTopGrp.getShapes()[4].instObjGroups[0] >> plug[0] plug = pm.listConnections(xyzTopGrp.getShapes()[2].name() + '.instObjGroups[0]', plugs=1) if plug: xyzTopGrp.getShapes()[2].instObjGroups[0] // plug[0] xyzTopGrp.getShapes()[2].instObjGroups[0] >> plug[0] plug = pm.listConnections(xyzTopGrp.getShapes()[5].name() + '.instObjGroups[0]', plugs=1) if plug: xyzTopGrp.getShapes()[5].instObjGroups[0] // plug[0] xyzTopGrp.getShapes()[5].instObjGroups[0] >> plug[0]