def reverseShape(self, objs=None, axis='x', *args): try: selectedItem = pm.radioCollection(self.AxisRC, q=True, select=True) axis = (pm.radioButton(selectedItem, q=True, label=True)).lower() except: pass scaleValue = (-1, 1, 1) if axis == 'y': scaleValue = (1, -1, 1) elif axis == 'z': scaleValue = (1, 1, -1) elif axis != 'x': pm.warning('Axis was not correct, used "x" axis instead.') if objs == None: objs = pm.ls(sl=True) else: objs = pm.ls(objs) for obj in objs: try: shape = obj.getShape() if shape.type() == 'mesh': pm.select(shape.vtx[:]) pm.scale(scaleValue) pm.select(objs) elif shape.type() == 'nurbsCurve': pm.select(shape.cv[:]) pm.scale(scaleValue) pm.select(objs) except: pm.warning("Object doesn't have a shape. Skipped!") '''
def _build_step(self, objName): pm.select(objName + '.f[4]') pm.move(self.strWidth, x=True) pm.select(objName + '.f[1]') pm.scale(self.strHeight, y=True) pm.select(objName + '.f[2]') pm.scale(self.strDepth, z=True)
def add_text_shape(ctrl, text): text_curve = pm.PyNode( pm.textCurves(ch=False, font="Arial Black", text=text, name='text_curve')[0] ) text_curve_length = text_curve.boundingBox()[1][0] #max X text_curve_height = text_curve.boundingBox()[1][1] #max Y shapes = pm.listRelatives(text_curve, ad=True, type="shape") pm.xform(text_curve, piv=[0,text_curve_height,0], ws=True) pm.move(text_curve, 0, -text_curve_height , 0) scale = 1 / text_curve_length pm.scale(text_curve, scale, scale, scale) pm.makeIdentity(text_curve, apply=True, t=True, r=True, s=True) display_attr = ("%s_text_display"%text) if not ctrl.hasAttr(display_attr): ctrl.addAttr(display_attr, at='bool', k=True, dv=1) for s in shapes: pm.parent(s, ctrl, s=True, r=True) s.rename('%sText'%text) pm.connectAttr("%s.%s" %(ctrl.name(), display_attr), s.visibility) pm.delete(text_curve)
def createFKControl(self, jnt): """ Create controls for the spine replacing the shape in the joints for a nurbs curve (control) :param jnt: string - first joint for the spine chain """ ctrlCrv = pm.circle(name=jnt.replace('_jnt', '_ctrl'), nr=(0, 1, 0), r=2.0)[0] rigUtils.setControlColor(ctrlCrv) pm.scale(0.12, 0.12, 0.12) pm.makeIdentity(a=True, s=True) pm.parent(ctrlCrv, jnt) # resets the transforms for the controller for trans in ['.tx', '.ty', '.tz', '.rx', '.ry', '.rz']: pm.setAttr(ctrlCrv + trans, 0) # unparent the control and parent the shape from the control to the joint, so we are adding a shape node to # the joint interact with the animator pm.parent(world=True) ctrlCrvShape = pm.listRelatives(ctrlCrv) pm.select(ctrlCrvShape) pm.select(jnt, add=True) pm.parent(r=True, s=True) pm.delete(ctrlCrv) pm.delete(ch=True) return ctrlCrv
def createCtrlGimbal(ctrlClass, overrideScale=None): side = getattr(ctrlClass, 'side') base = getattr(ctrlClass, 'base') ctrl = getattr(ctrlClass, 'ctrl') con = getattr(ctrlClass, 'con') scale = getattr(ctrlClass, 'scale') if overrideScale is not None: scale = overrideScale gimbal = rig_control(side=side, name=base + "Gimbal", parentOffset=ctrl, targetOffset=ctrl, con=0, pivot=0, child=con) pm.scale(gimbal.ctrl.cv, 0.75, 0.75, 0.75) pm.scale(gimbal.ctrl.cv, scale[0], scale[1], scale[2]) connectAttrToVisObj(ctrl, 'gimbalVis', gimbal.ctrl.getShape()) ''' pm.addAttr(ctrl, longName='gimbalVis', at='long', k=False, min=0, max=1) ctrl.gimbalVis.set(cb=True) pm.connectAttr(ctrl.gimbalVis, gimbal.ctrl.getShape().visibility) ''' return gimbal
def createCtrlPivot(ctrlClass, overrideScale=None): side = getattr(ctrlClass, 'side') base = getattr(ctrlClass, 'base') ctrl = getattr(ctrlClass, 'ctrl') scale = getattr(ctrlClass, 'scale') if overrideScale is not None: scale = overrideScale pivot = rig_control(side=side, name=base + 'Pivot', shape='sphere', parentOffset=ctrl, targetOffset=ctrl, con=0, pivot=0, lockHideAttrs=['rx', 'ry', 'rz']) pm.scale(pivot.ctrl.cv, 0.1, 0.1, 0.1) pm.scale(pivot.ctrl.cv, scale[0], scale[1], scale[2]) pm.connectAttr(pivot.ctrl.translate, ctrl.rotatePivot, f=True) pm.connectAttr(pivot.ctrl.scale, ctrl.scalePivot, f=True) connectAttrToVisObj(ctrl, 'pivotVis', pivot.ctrl.getShape()) return pivot
def scaleChara(self, mayaFalse): #this part does the importing and admin stuff try: pm.createReference( '//p.sv/Prism/project/Parallel/element/character_Roll/scenes/' + pm.optionMenu(self.charalist, q=True, value=True)[-4:-1] + '001_SP01.mb', namespace=':') except: pm.confirmDialog(title=u'Parallel scaling', message=u'Parallel フォルダーの許可がないです。') #this part does the scaling pm.optionMenu('listofchara', q=True, value=True) inverseScale = 1 / self.nameScale[pm.optionMenu( self.charalist, q=True, value=True)] pm.scale('Reference|Root', inverseScale, inverseScale, inverseScale) for i in pm.listRelatives('Reference', ad=True, type='joint'): try: pm.copyKey(i) pm.pasteKey(i.replace('Reference', 'Reference1')) except: print 'no keys to copypasta' pm.scaleKey('Reference1|Root|Hips', valueScale=inverseScale, valuePivot=0, attribute='translate') #this part cleans up the file pm.delete('Reference') pm.listReferences()[0].importContents(removeNamespace=False) pm.rename('Reference1', 'Reference')
def makeLantern(): #clear workspace cmds.select(all=True) cmds.delete() #get values from sliders ridges = cmds.intSliderGrp(ridgesSlider, q=True, value=True) deform = cmds.intSliderGrp(deformSlider, q=True, value=True) bend = cmds.intSliderGrp(bendSlider, q=True, value=True) bendNum = bend/100.0+1.0 flatten = float(cmds.intSliderGrp(flattenSlider, q=True, value=True)) lantern = pm.polySphere(n='lantern', sx=10, r=1, sy=ridges) rings = pm.polySelect( lantern, er=1) pm.select(lantern, cl=True) toggle = True for i in rings: if toggle: pm.polySelect( lantern, el=i) pm.scale(pm.selected(), [bendNum,bendNum,bendNum], xz=True) toggle = not toggle pm.select(lantern) pm.displaySmoothness(divisionsU=3, divisionsV=3, pointsWire=16, pointsShaded=4, polygonObject=3) wave = pm.nonLinear(type='wave', amplitude=0.03) pm.setAttr(wave[0]+'.wavelength', deform/100+0.1) pm.rotate(wave, 0, 0, '45deg') pm.select(all=True) pm.scale(lantern, [1,1-(flatten/100),1], xyz=True) pm.delete(ch=True)
def ReverseShape( objs=None, axis='x' ): scaleValue = ( -1, 1, 1 ) if axis == 'y': scaleValue = ( 1, -1, 1 ) elif axis == 'z': scaleValue = ( 1, 1, -1 ) elif axis != 'x': pm.warning('Axis was not correct, used "x" axis instead.') if objs == None: objs = pm.ls( sl=True ) else: objs = pm.ls( objs ) for obj in objs: try: shape = obj.getShape() if shape.type() == 'mesh': pm.select( shape.vtx[:] ) pm.scale( scaleValue ) pm.select( objs ) elif shape.type() == 'nurbsCurve': pm.select( shape.cv[:] ) pm.scale( scaleValue ) pm.select( objs ) except: pm.warning("Object doesn't have a shape. Skipped!") '''
def _set_step_pivot(self, objName): pm.select(objName + '.f[5]') pm.move(0, x=True) pm.select(objName + '.f[3]') pm.scale(0, y=True) pm.select(objName + '.f[0]') pm.scale(0, z=True)
def maketext(t=u"temptext",name = u"temptext", p=[0,0,0], r=[0,0,0], s=0.1) : t = str(t) obj = pm.textCurves(n = name, t=t, f ='Courier') pm.move(obj[0], p[0],p[1],p[2]) pm.rotate(obj[0],r[0],r[1],r[2]) pm.scale(obj[0],s,s,s) return obj[0]
def FUCBoxCreator(): pos = [0, 0, 0] thisW = 1 thisH = 1 thisD = 1 try: pm.select('FUC_Box') pos = cmds.objectCenter('FUC_Box', gl=True) thisW = pm.getAttr('FUC_Box' + '.sx') thisH = pm.getAttr('FUC_Box' + '.sy') thisD = pm.getAttr('FUC_Box' + '.sz') pm.delete() except: pass try: pm.select('FUC_Sphere') posX = pm.getAttr('FUC_Sphere' + '.tx') posY = pm.getAttr('FUC_Sphere' + '.ty') posZ = pm.getAttr('FUC_Sphere' + '.tz') pos = [posX, posY, posZ] r = pm.getAttr('FUC_Sphere' + '.sx') thisW = r thisH = thisW thisD = thisW pm.delete() except: pass pm.polyCube(name='FUC_Box', w=1, h=1, d=1) pm.move(pos) pm.scale(thisW, thisH, thisD) mel.eval('setAttr "FUC_Box.overrideEnabled" 1;') mel.eval('setAttr "FUC_Box.overrideShading" 0;')
def set_step_height(self, height): self._strHeight = height + self._strHeight for index in range(self.numStairs): name = self._index_to_name(index) pm.select(name + '.f[1]') pm.scale(self.strHeight, y=True) self._set_step_altitude(name, index)
def makeBulgeCtrl(handle, ctrCtrl, n, names, rotOrder): """Make inner control for softmod. Diamond for the softMod handle itself""" ctrlGrpRotMat = mu.rotMat(ctrCtrl.controlGroup.get().matrix) hCtrl = jc.makeCtrlShape(n.format(type=names["control"]), rotOrder, shape="diamond") for sh in hCtrl.getShapes(): ctrCtrl.create.inputs()[0].radius >> sh.create.inputs()[0].radius pmc.scale(sh.cv, .8, .8, .8) hCtrl.setParent(ctrCtrl) pmc.makeIdentity(hCtrl) # handle xforms must be ctrl in ctrCtrlGrp AND ctrCtrl space but without # any of their actual xforms parGrp = ctrCtrl.getParent() handleXform = mu.xformFromSpaces([ ctrlGrpRotMat.inverse(), ctrCtrl.inverseMatrix, parGrp.inverseMatrix, hCtrl.m, parGrp.matrix, ctrCtrl.matrix, ctrlGrpRotMat ], n.format(type="xforms"), rotOrder) handleXform.outputTranslate >> handle.t handleXform.outputRotate >> handle.r handleXform.outputScale >> handle.s return hCtrl
def createHandControl(self): """ Create hand control and sets the color based on the name :return - string - name of the created control """ crv = mel.eval('curve -d 3 -p 0 0 0 -p 0.4 0 0.111111 -p 1.2 0 0.333333 -p 1.2 0 -1.333333 -p 0.4 0 -1.111111 ' '-p 0 0 -1 -k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 3 -k 3 ;') pm.setAttr(crv + '.tz', 0.5) pm.makeIdentity(a=True, t=True) pm.xform(crv, piv=(0.0, 0.0, 0.0)) pm.scale(0.4, 0.4, 0.4) pm.makeIdentity(a=True, s=True) crv = pm.rename(crv, self.side + '_hand_ctrl') rigUtils.setControlColor(crv) #self.setControlColor(crv) # mirror the controller for the Right side if self.side == 'R': pm.scale(crv, (-1, 1, 1)) pm.makeIdentity(a=True, s=True) return crv
def chestCtrlShape(name, normalDirection=[1, 1, 0], scale=1): ctrl = pm.circle(n=name, s=10, nr=[0, 0, 1])[0] pm.move(0, 0, 1, ctrl.cv[3:4], ctrl.cv[8:9], r=True, os=True) pm.scale([ctrl.cv[3:4], ctrl.cv[8:9]], [1, 3, 1], r=True, p=[0, 0, 1]) pm.scale([ctrl.cv[0], ctrl.cv[2], ctrl.cv[5], ctrl.cv[7]], [1.75, 1.35, 1], r=True, p=[0, 0, 0]) pm.move(0, 0, -0.75, ctrl.cv[0], ctrl.cv[2], ctrl.cv[5], ctrl.cv[7], r=True, os=True) pm.move(0, 0, -1, ctrl.cv[1], ctrl.cv[6], r=True, os=True) pm.move(0, -0.75, 0, ctrl.cv[1], r=True, os=True) pm.move(0, 0.25, 0, ctrl.cv[0], ctrl.cv[2], r=True, os=True) # pm.xform(ctrl, ws=True, pivots=[0, 0, -0.35]) if normalDirection[0] == 1: pm.rotate(ctrl.cv[:], [90, 0, 0]) elif normalDirection[0] == -1: pm.rotate(ctrl.cv[:], [-90, 0, 0]) if normalDirection[1] == 1: pm.rotate(ctrl.cv[:], [0, 90, 0]) elif normalDirection[1] == -1: pm.rotate(ctrl.cv[:], [0, -90, 0]) if normalDirection[2] == 1: pm.rotate(ctrl.cv[:], [0, 0, 90]) elif normalDirection[2] == -1: pm.rotate(ctrl.cv[:], [0, 0, -90]) ctrl.scale.set(scale, scale, scale) common.deleteHistory(ctrl) common.freezeTranform(ctrl) return ctrl
def createJointOffset(Offset): if Offset == "": Offset = "Offset" selectJoints = pm.selected() for joint in selectJoints: offsetObjName = "" if prefix.getSelect() == 1: #置き換え offsetObjName = re.sub(r"^[a-zA-Z]*?_",Offset+"_",str(joint)) elif prefix.getSelect() == 2: #追加 offsetObjName = str(Offset) + "_" + str(joint) offsetObj = pm.group(em = True,name = offsetObjName) jointName = re.sub(r"^[a-zA-Z]*?_","Rig_",offsetObjName) pm.circle( name=jointName ) pm.select(jointName,r=30) # 回転の軸がなんでこれで(Z)いいのかわからないので確認する。 pm.rotate(0,0,90,r = True) pm.scale(2,2,2) pm.makeIdentity(apply=True,t=1,r=1,s=1,n=0,pn=1) pm.parent(jointName,offsetObj) #AにBをコンストレイント! pm.parentConstraint(joint,offsetObj, weight=1) #必要のないコンストレイントノードの削除 delNode = offsetObj.listRelatives(c=True,ad=True,type='constraint') pm.delete(delNode)
def splitHairCtrl(d='up'): '''add Hair Controls''' sel = pm.selected() if not sel: return directionDict = {'up': 1, 'down': -1} if not directionDict.has_key(d): return hairInfoAll = selHair(returnInfo=True) if not hairInfoAll: return #print hairInfo[0][0] #print hairInfo for selOb in sel: pm.select(selOb, r=1) hairInfo = hairInfoAll[sel.index(selOb)] ctrls = hairInfo[1].listRelatives(type=pm.nt.Transform) hair = hairInfo[0][0] for ctrl in ctrls: pm.rename(ctrl, '_'.join([ctrl.name(), "old"])) ctrlID = ctrls.index(selOb) if ctrlID == 0: directionDict[d] = 1 elif ctrlID == (len(ctrls) - 1): directionDict[d] = -1 newCtrl = pm.duplicate(ctrls[ctrlID])[0] pm.move( newCtrl, (ctrls[ctrlID].getTranslation(space='world') + ctrls[ctrlID + directionDict[d]].getTranslation(space='world')) / 2, a=1, ws=1) pm.scale(newCtrl, (ctrls[ctrlID].attr('scale').get() + ctrls[ctrlID + directionDict[d]].attr('scale').get()) / 2, a=1) ctrls.insert(ctrlID + (directionDict[d] + 1) / 2, newCtrl) for ctrl in ctrls: pm.rename( ctrl, '_'.join( [ctrl.name().split('_')[0], str(ctrls.index(ctrl) + 1)])) pm.parent(ctrl, w=1) pm.parent(ctrl, hairInfo[1]) oldname = hair.name() oldParent = hair.getParent() curMaterial = hair.getShape().listConnections( type=pm.nodetypes.ShadingEngine)[0].name() pm.rename(hair, '_'.join([oldname, 'old'])) newHair = createHairMesh(ctrls, name=oldname, mat=curMaterial, lengthDivs=hair.attr('lengthDivisions').get(), widthDivs=hair.attr('widthDivisions').get()) pm.parent(newHair[0], oldParent) pm.delete(hair) pm.select(newCtrl) pm.setToolTo('moveSuperContext')
def scaleCVs(nodes, scale): if type(nodes) == pm.nodetypes.Transform: nodes = pm.listRelatives(nodes, c=1, s=1) if type(nodes) != type([]): nodes = [nodes] for node in nodes: pm.select('%s.cv[:]' % node.name()) pm.scale(scale, scale, scale, objectSpace=1)
def locatorMake_L(mayaFalse): pivotLocL = mel.eval( 'curve -d 1 -p 0 0 1 -p 0 0 -1 -p -1 0 0 -p 0 0 -1 -p 1 0 0 -k 0 -k 1 -k 2 -k 3 -k 4 -n "Locator_Pivot_L" ;' ) pm.setAttr( pivotLocL + '.rotateAxisX', 90 ) #rotating the controller without affecting its axes to accurate depict its orientation pm.setAttr(pivotLocL + '.rotateAxisY', 90) pm.scale(pivotLocL, [2, 2, 3])
def makeFakeBone(): ''' Used by polySkeleton ''' bone = polyCylinder()[0] bone.ty.set(1) makeIdentity(bone, t=True, apply=True) xform(bone, ws=True, piv=(0, 0, 0)) #scale -r -p -1.19209e-07cm 2cm -1.78814e-07cm 0.0229933 0.0229933 0.0229933 ; scale( bone.vtx[20:39], (0, 0, 0), r=True, p=(0, 2, 0) ) return bone
def controlShapeAdaptive(controlList, geoList, ctrlSmooth=6, scaleConstant=1.5, rebuildCV=32): adaptiveShapeBuildGrp = pm.group(n='daptiveShapeBuild_GRP', em=True) geoList = pm.ls(geoList) dupliGeo = pm.duplicate(geoList) geoCombined = pm.polyUnite(dupliGeo, ch=False, name='tmpAdaptiveRef_GEO')[0] pm.parent(geoCombined, adaptiveShapeBuildGrp) ctrlList = pm.ls(controlList) for ctrl in ctrlList: ctrlShapeBuildGrp = pm.group(n=ctrl.name() + '_GRP', em=True, p=adaptiveShapeBuildGrp) dupliCtrl = pm.duplicate(ctrl, n='tmpCtrl')[0] pm.delete(pm.ls(dupliCtrl, dagObjects=True, exactType='transform')[1:]) pm.rebuildCurve(dupliCtrl, ch=False, s=rebuildCV) pm.parent(dupliCtrl, ctrlShapeBuildGrp) # extrusion extrudeCircle = pm.circle(r=0.1, ch=0)[0] pm.parent(extrudeCircle, ctrlShapeBuildGrp) motionPathNode = \ pm.ls(pm.pathAnimation(extrudeCircle, curve=dupliCtrl, fractionMode=True, follow=True, followAxis='z', upAxis='y', worldUpType='vector', worldUpVector=[0, 1, 0], inverseUp=False, inverseFront=False, bank=False))[0] pm.disconnectAttr(extrudeCircle.tx) pm.disconnectAttr(extrudeCircle.ty) pm.disconnectAttr(extrudeCircle.tz) pm.disconnectAttr(extrudeCircle.rx) pm.disconnectAttr(extrudeCircle.ry) pm.disconnectAttr(extrudeCircle.rz) pm.disconnectAttr(motionPathNode.u) pm.delete(motionPathNode) extrudedSurface = \ pm.extrude(extrudeCircle, dupliCtrl, ch=False, rn=False, po=0, et=2, ucp=0, fpt=1, upn=0, rotation=0, scale=1, rsp=1)[0] pm.parent(extrudedSurface, ctrlShapeBuildGrp) nurbsToPoly = pm.nurbsToPoly(extrudedSurface, ch=False, polygonType=1, chr=0.9) pm.parent(nurbsToPoly, ctrlShapeBuildGrp) # add deformer wrapNode = deform.wrapDeformer(dupliCtrl, nurbsToPoly) shrinkWrapNode = deform.shrinkWrapDeformer(nurbsToPoly, geoCombined) shrinkWrapNode.projection.set(4) shrinkWrapNode.targetSmoothLevel.set(ctrlSmooth) # delete history common.deleteHistory(nurbsToPoly) common.deleteHistory(dupliCtrl) pm.scale(dupliCtrl.cv[:], [scaleConstant, scaleConstant, scaleConstant]) copyShape(dupliCtrl, ctrl) pm.delete(adaptiveShapeBuildGrp)
def trapeziumCtrlShape(name, normalDirection=[0, 0, 0], scale=1): pm.mel.eval('softSelect -sse off;') bottomSquare = pm.nurbsSquare(c=[0, 0, 0], nr=[0, 1, 0], d=1, ch=False) topSquare = pm.nurbsSquare(c=[0, 1, 0], nr=[0, 1, 0], d=1, ch=False) leftSquare = pm.nurbsSquare(c=[-0.5, 0.5, 0], nr=[1, 0, 0], d=1, ch=False) rightSquare = pm.nurbsSquare(c=[0.5, 0.5, 0], nr=[1, 0, 0], d=1, ch=False) squareList = [bottomSquare, topSquare, leftSquare, rightSquare] for square in squareList: segmentList = pm.listRelatives(square, ad=1, type='transform') pm.attachCurve(segmentList[0], segmentList[1], ch=False, rpo=True, kmk=False, m=0, bb=0, bki=False, p=0.1) pm.attachCurve(segmentList[2], segmentList[3], ch=False, rpo=True, kmk=False, m=0, bb=0, bki=False, p=0.1) pm.attachCurve(segmentList[0], segmentList[2], ch=False, rpo=True, kmk=False, m=0, bb=0, bki=False, p=0.1) pm.delete(segmentList[1:]) cubePartsShape = [pm.listRelatives(square, ad=1, type='transform')[0].getShape() for square in squareList] for shape in cubePartsShape: pm.parent(shape, cubePartsShape[0].getParent(), r=1, s=1) # scale upper Box ctrl = pm.listRelatives(bottomSquare, ad=1, type='transform')[0] pm.parent(ctrl, w=True) pm.delete(squareList) ctrlShapesList = ctrl.getShapes() for shape in ctrlShapesList: pm.rebuildCurve(shape, ch=False, rpo=True, rt=1, end=1, kr=0, kcp=False, kep=True, kt=False, s=0, d=1, tol=0.01) vertSelection = pm.select(ctrlShapesList[3].cv[0:1], ctrlShapesList[1].cv[0:3], ctrlShapesList[2].cv[0:1]) pm.scale(vertSelection, [0.5, 0.5, 0.5], r=True) allVertSelection = pm.select([shape.cv[:] for shape in ctrlShapesList]) pm.scale(allVertSelection, [4, 1, 1], r=True) pm.select(cl=True) if normalDirection[0] == 1: pm.rotate(ctrl, [90, 0, 0]) elif normalDirection[0] == -1: pm.rotate(ctrl, [-90, 0, 0]) if normalDirection[1] == 1: pm.rotate(ctrl, [0, 90, 0]) elif normalDirection[1] == -1: pm.rotate(ctrl, [0, -90, 0]) if normalDirection[2] == 1: pm.rotate(ctrl, [0, 0, 90]) elif normalDirection[2] == -1: pm.rotate(ctrl, [0, 0, -90]) pm.rename(ctrl, name) ctrl.scale.set(scale, scale, scale) common.freezeTranform(ctrl) return ctrl
def buildHand(self, settingsNode, fingerDict, colour, cleanup): ctrlSize=None for finger in fingerDict.keys(): for i in range(len(fingerDict[finger])): if not ctrlSize: ctrlSize = coreUtils.getDistance(fingerDict[finger][0], fingerDict[finger][1]) * .25 if i > 0: j2 = coreUtils.createAlignedNode(fingerDict[finger][i], 'joint', '%s_%s_%s_translate_JNT' % (self.name, finger, str(i+1).zfill(2))) j2.setParent(self.joints[-1]) j2.jointOrient.set(fingerDict[finger][i].jointOrient.get()) j2.r.set((0, 0, 0)) coreUtils.addParent(j2, 'group', '%s_%s_%s_translateJnt_ZERO' % (self.name, finger, str(i+1).zfill(2))) self.joints.append(j2) j = coreUtils.createAlignedNode(fingerDict[finger][i], 'joint', '%s_%s_%s_JNT' % (self.name, finger, str(i+1).zfill(2))) c = controls.squareCtrl(axis='x', name='%s_%s_%s_CTRL' % (self.name, finger, str(i+1).zfill(2)), size=ctrlSize) coreUtils.align(c, j) pmc.select('%s.cv[*]' % c.name()) pmc.scale(5.0, scaleY=1) if i == 0: j.setParent(self.rig_grp) jGrp = coreUtils.addParent(j, 'group', '%s_%s_joints_GRP' % (self.name, finger)) j.jointOrient.set((0, 0, 0)) j.r.set((0, 0, 0)) c.setParent(self.ctrls_grp) cGrp = coreUtils.addParent(c, 'group', '%s_%s_ctrls_GRP' % (self.name, finger)) c.t.connect(j.t) c.r.connect(j.r) pmc.parentConstraint(cGrp, jGrp) else: j.setParent(self.joints[-1]) j.jointOrient.set((0, 0, 0)) j.r.set((0, 0, 0)) c.setParent(self.ctrls[-1]) coreUtils.addParent(c, 'group', '%s_%s_%s_ZERO' % (self.name, finger, str(i+1).zfill(2))) c.t.connect(j2.t) c.r.connect(j.r) self.joints.append(j) self.ctrls.append(c) coreUtils.colorize(colour, self.ctrls) if settingsNode: pmc.addAttr(settingsNode, longName='finger_ctrls_vis', at='bool', k=0, h=0) pmc.setAttr(settingsNode.finger_ctrls_vis, channelBox=1) settingsNode.finger_ctrls_vis.connect(self.ctrls_grp.visibility) if cleanup: self.cleanup()
def scale_curve(x, y, z, obj): X = 1.0 Y = 1.0 Z = 1.0 if x: X = x if y: Y = y if z: Z = z pmc.scale(obj, X, Y, Z)
def mirrorCurveShapes(self, node): _axis = utils.getAxis(self.opts['axis']) shapes = node.getChildren(s=True) for shape in shapes: if hasattr(shape, "cv"): if self.opts['mirrorMode'] == 'simple': pm.scale(shape.cv, [-1, -1, -1]) else: s = [1, 1, 1] s[_axis.index] = -1 pm.scale(shape.cv, s)
def createNeckCtrl(self): headCtrl = rigUtils.createRigControl('circle') headCtrl = pm.rename(headCtrl[0], 'M_head_ctrl') rigUtils.setControlColor(headCtrl) pm.move( headCtrl, (self.headRootPos[0], self.headRootPos[1], self.headRootPos[2])) pm.rotate(headCtrl, (0, 0, 90)) pm.scale(headCtrl, (1.5, 1.5, 1.5)) pm.makeIdentity(a=True, r=True, t=True, s=True)
def scaleAllCVs(obj, scaleFactor=1.0, space='object'): ''' Handles the annoying-ness of scaling the cvs of a multishape obj ''' if isinstance(scaleFactor, numbers.Number): scaleFactor = [scaleFactor] * 3 # Must provide all axes. kwargs = {'os': True} if space == 'object' else {'ws': True} for shape in core.shape.getShapes(obj): scale(shape.cv, scaleFactor, r=True, **kwargs)
def centerScale( val ): ''' 컴포넌트나.. 선택된 오브젝트그룹의 중심을 기준으로 스케일링 @param val: @return: ''' val = pm.dt.Vector( val ) bbox = pm.xform( q=True, ws=True, boundingBox=True) min = pm.dt.Vector( bbox[:3] ) max = pm.dt.Vector( bbox[3:] ) cent = min + (max - min) * 0.5 pm.scale( val, p=cent, relative=True )
def fourWayShapeControl(driver, shapes, parent, mult=0.5, ctrlSize=1, facialLoc='facialShapeDriver_LOC', **kwds): negPos = defaultReturn(-1, 'negPos', param=kwds) ctrlSizeHalf = [ctrlSize / 2.0, ctrlSize / 2.0, ctrlSize / 2.0] ctrlSizeQuarter = [ctrlSize / 4.0, ctrlSize / 4.0, ctrlSize / 4.0] ctrlSize = [ctrlSize, ctrlSize, ctrlSize] side = rig_nameGetSide(driver) base = rig_nameGetBase(driver) driverCtrl = rig_control(side=side, name=base, shape='pyramid', modify=1, lockHideAttrs=['rx', 'ry', 'rz', 'tx'], scale=ctrlSizeQuarter) pm.scale(driverCtrl.ctrl.cv, 1, 0, 1) pm.delete(pm.parentConstraint(driver, driverCtrl.offset)) #pm.parentConstraint(parent, driverCtrl.offset, mo=True) pm.parent(driverCtrl.offset, parent) rig_animDrivenKey(driverCtrl.ctrl.translateY, (0, 1), facialLoc + '.' + shapes[0], (0, 1)) rig_animDrivenKey(driverCtrl.ctrl.translateY, (0, -1), facialLoc + '.' + shapes[1], (0, 1)) rig_animDrivenKey(driverCtrl.ctrl.translateZ, (0, 1), facialLoc + '.' + shapes[2], (0, 1)) rig_animDrivenKey(driverCtrl.ctrl.translateZ, (0, -1), facialLoc + '.' + shapes[3], (0, 1)) multiplyDivideNode( side + base, 'multiply', input1=[driverCtrl.ctrl.translateY, driverCtrl.ctrl.translateZ, 0], input2=[negPos * mult, negPos * mult, negPos * mult], output=[ driverCtrl.modify + '.translateY', driverCtrl.modify + '.translateZ' ]) pm.transformLimits(driverCtrl.ctrl, ty=(-1, 1), ety=(1, 1)) pm.transformLimits(driverCtrl.ctrl, tz=(-1, 1), etz=(1, 1)) return driverCtrl
def __finalizeCnt(self): ''' Adjusting the control orientation, scales, and zeroing ''' self.__aimCnt() if self.size != 1: for s in self.control.getShapes(): pm.scale(s.cv, self.size,self.size,self.size, r=1) #delete history on the scaled control pm.delete(self.control, ch =1) self.setColor(self.control, self.objColor) self.controlGrp = xformUtils.zero(self.control)
def _finalize_ctrl(self): """ Orientates, scales and zeroes out the control. """ self._aim_ctrl() self._set_ctrl_color() if self.size != 1: for shape in self.ctrl.getShapes(): pm.scale(shape.cv, self.size, self.size, self.size, r=1) pm.delete(self.ctrl, ch=1) self.ctrl_grp = xform_utils.zero(self.ctrl)
def _finalize_ctrl(self): """ Orientates, scales and zeroes out the control. """ self._aim_ctrl() self._color_ctrl() if self.size != 1: for s in self.ctrl.getShapes(): pm.scale(s.cv, self.size, self.size, self.size, r=1) pm.delete(self.ctrl, ch=1) self.ctrl_grp = xform_utils.zero(self.ctrl)
def cyroFinish(): print 'Finishing cyro' rig_quadFinalize() pm.setAttr("neckFocus_CTRL.focusNeck", 0.75) pm.setAttr("spineUpperPivot_CTRL.translateY", -17.164) pm.setAttr("spineUpperPivot_CTRL.translateZ", 1.81) pm.setAttr("spineUpper_CTRL.stretch", 0.2) pm.move('tailUpperAim_LOCUp', 0, 1000, 0, r=True, os=True) pm.move('tailLowerAim_LOCUp', 0, 1000, 0, r=True, os=True) pm.move(pm.PyNode('neckTipIK_CTRL.cv[:]'), 0, 0, -5, r=True, os=True) pm.move(pm.PyNode('neckMidBIK_CTRL.cv[:]'), 0, -8.5, -13, r=True, os=True) pm.move(pm.PyNode('neckMidAIK_CTRL.cv[:]'), 0, -1, -23, r=True, os=True) controlSet = pm.PyNode('cyroRigPuppetControlSet') for s in ('l', 'r'): pm.setAttr("displayModulesToggleControl." + s + "_fingers", 0) pm.setAttr("displayModulesToggleControl." + s + "_toes", 0) pm.setAttr(s + "_armPV_CTRL.space", 1) #pm.setAttr(s+"_shoulder_CTRL.followArm", 1) pm.rotate(pm.PyNode(s + '_handBall_CTRL').cv, 0, 90, 0, r=True, os=True) pm.scale(pm.PyNode(s + '_handBall_CTRL').cv, 2, 2, 2) pm.parentConstraint(s + '_anklePos_JNT', s + '_toeThumbModify1_GRP', mo=True) controlSet.removeMembers([s + '_shoulder_CTRL']) hiDeltaMush = mm.eval('rig_returnDeformers("skin_C_body_GV", "deltaMush")') if len(hiDeltaMush) > 0: cNode = conditionNode('hiDeltaMush', 'equal', ('', 0), ('', 2), ('', 1), ('', 0)) pm.connectAttr("global_CTRL.lodDisplay", cNode + '.secondTerm') pm.connectAttr(cNode + '.outColorR', hiDeltaMush[0] + '.envelope') pm.setAttr("displayModulesToggleControl.flex", 0) # mid LOD cmds.setAttr("global_CTRL.lodDisplay", 1)
def scaleControl(x=True,y=True,z=True): ''' Usage: scaleControl() ''' if len(pm.ls(sl=True))==0: pm.error('select something numbnuts!') pm.promptDialog(m='Enter new scale value') val = float(pm.promptDialog(q=True)) for transform in pm.ls(sl=True,type='transform'): shapes = transform.getShapes() cvs = [] for shape in shapes: cvs = cvs + pm.ls(shape.cv[0:], fl=True) pm.scale(cvs, val*x, val*y, val*z, pivot=transform.getRotatePivot(ws=True), r=True)
def NormalizeMesh(mesh): """normalize the input mesh (scale its size to 1, 1, 1 and freeze it)""" pm.makeIdentity(mesh, apply = True, translate=True, rotate=True) meshBBox = mesh.getBoundingBox() edgeList = [] edgeList.append(meshBBox.height()) edgeList.append(meshBBox.depth()) edgeList.append(meshBBox.width()) maxLength = 0.0 for i in range(3): if edgeList[i] >= maxLength: maxLength = edgeList[i] # use 'if maxLength > 1:' if only want to decrease the sample pm.scale(mesh, mesh.getScale()[0]/(maxLength), mesh.getScale()[1]/(maxLength), mesh.getScale()[2]/(maxLength)) pm.makeIdentity(mesh, apply = True, translate=True, rotate=True, scale=True)
def __scaleCv(self,*args): scaleValue = pm.floatSliderGrp(self.sizeFloatSlider,q=1,v=1) if(scaleValue > 0): scaleValue = scaleValue+1 if(scaleValue<0): scaleValue = 1-abs(scaleValue)/2 sel = pm.ls(sl = 1) pm.select(cl = 1) for cv in sel: pm.select(cv + '.cv[*]',add = 1) pm.scale(scaleValue,scaleValue,scaleValue,r=1) pm.select(cl = 1) for obj in sel: pm.select(obj,add = 1)
def scaleShape(shape, objStart, objEnd, proportion=1, axis=[1,0,0]): # get distance distObj = pmc.createNode('distanceDimShape') if (isinstance(objStart, list)): distObj.startPoint.set(objStart) else: distObj.startPoint.set(objStart.getTranslation(space='world')) if (isinstance(objEnd, list)): distObj.startPoint.set(objEnd) else: distObj.endPoint.set(objEnd.getTranslation(space='world')) dist = distObj.distance.get() # delete distance object pmc.delete(distObj.getParent()) # create a vector distVect = dt.Vector( dist*axis[0], dist*axis[1], dist*axis[2] ) inveVect = dt.Vector( (1-axis[0])*proportion, (1-axis[1])*proportion, (1-axis[2])*proportion ) distVect = distVect+inveVect # scale shape pmc.scale(various.getAtoms(shape, flat=True), distVect, relative=True)
def scaleShape(sel, scalX = False, scalY = False, scalZ = False, scale = 2): pm.select(clear = True) shapList = (pm.listRelatives(sel, shapes = True)) for s in shapList: cvs = s.cv pm.select(cvs, add = True) pm.scale(scale, scale, scale, scaleX = scalX, scaleY = scalY, scaleZ = scalZ, relative = True,objectSpace = True) pm.select(sel) # sel = pm.ls(sl = True) # for s in sel: # moveShape(s, movX = True) # cvs = s.cv # print cvs # pm.select(cvs) # change shape # change color
def create_master_controls(type = "", assetName=""): if not type: return global_round_square_with_arrow = "curve -d 3 -p 0 0 0.75 -p 0.25 0 0.5 -p 0.25 0 0.5 -p 0.25 0 0.5 -p 0.375 0 0.5 -p 0.5 0 0.5 -p 0.5 0 0.375 -p 0.5 0 -0.375 -p 0.5 0 -0.5 -p 0.375 0 -0.5 -p -0.375 0 -0.5 -p -0.5 0 -0.5 -p -0.5 0 -0.375 -p -0.5 0 0.375 -p -0.5 0 0.5 -p -0.375 0 0.5 -p -0.25 0 0.5 -p -0.25 0 0.5 -p -0.25 0 0.5 -p 0 0 0.75 -k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 -k 17 -k 17" local_round_square_with_arrow = "curve -d 3 -p 0 0 0.5 -p 0.125 0 0.375 -p 0.125 0 0.375 -p 0.125 0 0.375 -p 0.25 0 0.375 -p 0.375 0 0.375 -p 0.375 0 0.25 -p 0.375 0 -0.25 -p 0.375 0 -0.375 -p 0.25 0 -0.375 -p -0.25 0 -0.375 -p -0.375 0 -0.375 -p -0.375 0 -0.25 -p -0.375 0 0.25 -p -0.375 0 0.375 -p -0.25 0 0.375 -p -0.125 0 0.375 -p -0.125 0 0.375 -p -0.125 0 0.375 -p 0 0 0.5 -k 0 -k 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 -k 17 -k 17" root_crosshair = "curve -d 1 -p 0 0 0.325 -p -0.0634045 0 0.318755 -p -0.124372 0 0.300261 -p -0.180561 0 0.270228 -p -0.22981 0 0.22981 -p -0.270228 0 0.180561 -p -0.300261 0 0.124372 -p -0.318755 0 0.0634045 -p -0.325 0 0 -p -0.318755 0 -0.0634045 -p -0.300261 0 -0.124372 -p -0.270228 0 -0.180561 -p -0.22981 0 -0.22981 -p -0.180561 0 -0.270228 -p -0.124372 0 -0.300261 -p -0.0634045 0 -0.318755 -p 0 0 -0.325 -p 0.0634045 0 -0.318755 -p 0.124372 0 -0.300261 -p 0.180561 0 -0.270228 -p 0.22981 0 -0.22981 -p 0.270228 0 -0.180561 -p 0.300261 0 -0.124372 -p 0.318755 0 -0.0634045 -p 0.325 0 0 -p 0.318755 0 0.0634045 -p 0.300261 0 0.124372 -p 0.270228 0 0.180561 -p 0.22981 0 0.22981 -p 0.180561 0 0.270228 -p 0.124372 0 0.300261 -p 0.0634045 0 0.318755 -p 0 0 0.325 -p 0 0 -0.325 -p 0 0 -0.25 -p -0.0487726 0 -0.245197 -p -0.095671 0 -0.23097 -p -0.138893 0 -0.207868 -p -0.176777 0 -0.176777 -p -0.207868 0 -0.138893 -p -0.23097 0 -0.095671 -p -0.245197 0 -0.0487726 -p -0.25 0 0 -p -0.325 0 0 -p 0.325 0 0 -p -0.25 0 0 -p -0.245197 0 0.0487726 -p -0.23097 0 0.095671 -p -0.207868 0 0.138893 -p -0.176777 0 0.176777 -p -0.138893 0 0.207868 -p -0.095671 0 0.23097 -p -0.0487726 0 0.245197 -p 0 0 0.25 -p 0.0487726 0 0.245197 -p 0.095671 0 0.23097 -p 0.138893 0 0.207868 -p 0.176777 0 0.176777 -p 0.207868 0 0.138893 -p 0.23097 0 0.095671 -p 0.245197 0 0.0487726 -p 0.25 0 0 -p 0.245197 0 -0.0487726 -p 0.23097 0 -0.095671 -p 0.207868 0 -0.138893 -p 0.176777 0 -0.176777 -p 0.138893 0 -0.207868 -p 0.095671 0 -0.23097 -p 0.0487726 0 -0.245197 -p 0 0 -0.25 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 -k 18 -k 19 -k 20 -k 21 -k 22 -k 23 -k 24 -k 25 -k 26 -k 27 -k 28 -k 29 -k 30 -k 31 -k 32 -k 33 -k 34 -k 35 -k 36 -k 37 -k 38 -k 39 -k 40 -k 41 -k 42 -k 43 -k 44 -k 45 -k 46 -k 47 -k 48 -k 49 -k 50 -k 51 -k 52 -k 53 -k 54 -k 55 -k 56 -k 57 -k 58 -k 59 -k 60 -k 61 -k 62 -k 63 -k 64 -k 65 -k 66 -k 67 -k 68 -k 69" if type == "global": c = pm.mel.eval(global_round_square_with_arrow) if type == "local": c = pm.mel.eval(local_round_square_with_arrow) if type == "root": c = pm.mel.eval(root_crosshair) if assetName and type == 'global': text_curve = pm.PyNode( pm.textCurves(ch=False, font="Arial Black", text=assetName, name='text_curve')[0] ) text_curve_length = text_curve.boundingBox()[1][0] #max X text_curve_height = text_curve.boundingBox()[1][1] #max Y shapes = pm.listRelatives(text_curve, ad=True, type="shape") pm.xform(text_curve, piv=[0,text_curve_height,0], ws=True) pm.move(text_curve, 0, -text_curve_height ,0.755) pm.rotate(text_curve, -90, 45,0) scales = 0.3535 / text_curve_length pm.scale(text_curve, scales, scales, scales) pm.makeIdentity(text_curve, apply=True, t=True, r=True, s=True) for s in shapes: pm.parent(s, c, s=True, r=True) pm.delete(text_curve) try: curve = pm.PyNode(c) except: pass return curve
def threePointlight( type): """ description: inputs: outputs """ l = ["keyLight", "rimLight", "fillLight"] if type == "directional": pm.rendering.directionalLight(n = l[0], i = 1.0, rgb = [1.0, 0.9, 0.8]) pm.rendering.directionalLight(n = l[1], i = 2.0, rgb = [1.0, 0.9, 0.8]) pm.rendering.directionalLight(n = l[2], i = 0.5, rgb = [0.6, 0.7, 0.8]) elif type == "point": pm.rendering.pointLight(n = l[0]) pm.rendering.pointLight(n = l[1]) pm.rendering.pointLight(n = l[2]) pm.rotate(l[0], [-44.5, 120, 0]) pm.rotate(l[1], [-13, -55, 0]) pm.scale(l[0], [4,4,4]) pm.scale(l[1], [4,4,4]) pm.scale(l[2], [4,4,4]) return l
def add_global_text(global_control, assetName, size): if assetName: text_curve = pm.PyNode( pm.textCurves(ch=False, font="Arial Black", text=assetName, name='text_curve')[0] ) text_curve_length = text_curve.boundingBox()[1][0] #max X text_curve_height = text_curve.boundingBox()[1][1] #max Y shapes = pm.listRelatives(text_curve, ad=True, type="shape") pm.xform(text_curve, piv=[0,text_curve_height,0], ws=True) pm.move(text_curve, 0, -text_curve_height ,0.755 * size) pm.rotate(text_curve, -90, 45,0) scales = 0.3535 / text_curve_length * size pm.scale(text_curve, scales, scales, scales) pm.makeIdentity(text_curve, apply=True, t=True, r=True, s=True) for s in shapes: pm.parent(s, global_control, s=True, r=True) s.rename('%sText'%global_control.name()) pm.delete(text_curve)
def reverseShape( self, objs=None, axis='x', *args ): try: selectedItem = pm.radioCollection( self.AxisRC, q=True, select=True ) axis = (pm.radioButton( selectedItem, q=True, label=True )).lower() except: pass scaleValue = ( -1, 1, 1 ) if axis == 'y': scaleValue = ( 1, -1, 1 ) elif axis == 'z': scaleValue = ( 1, 1, -1 ) elif axis != 'x': pm.warning('Axis was not correct, used "x" axis instead.') if objs == None: objs = pm.ls( sl=True ) else: objs = pm.ls( objs ) for obj in objs: try: shape = obj.getShape() if shape.type() == 'mesh': pm.select( shape.vtx[:] ) pm.scale( scaleValue ) pm.select( objs ) elif shape.type() == 'nurbsCurve': pm.select( shape.cv[:] ) pm.scale( scaleValue ) pm.select( objs ) except: pm.warning("Object doesn't have a shape. Skipped!") '''
def make_leaf(self): i = pm.polyCube(w=.5,d=1.5,h=4,sw=3,sh=3) pm.select(i[0].vtx[12:19]) pm.scale(0.1,0.1,1,r=True) pm.select(i[0].vtx[0:3],i[0].vtx[28:31]) pm.scale(0.1,0.1,1,r=True) pm.select(i[0].vtx[4],i[0].vtx[7:8],i[0].vtx[11],i[0].vtx[20],i[0].vtx[23:24],i[0].vtx[27]) pm.scale(0.8,0.8,0.8) pm.select(i[0]) pm.hyperShade(assign=Lsystem.leafShader) return i
def populate( self , obj = [] ): customRange = len(obj) self.obj = obj pm.select( '%sFollicle*' % self.geo ) pm.select( '%sFollicleShape*' % self.geo , d=1 ) self.folls = pm.ls( selection = True) self.window() # finding the name of the hair system to name the group() that all the duplicated objects will be parented to pm.select('%sFollicle*' % self.geo) pm.select('%sFollicleShape*' % self.geo, d = 1 ) folls = pm.ls( selection = True ) myHair = folls[0].getParent() system = myHair.split( 'F' ) mySystem = system[0] # the group() for the duplicated geo self.geoPad = pm.group(name = '%s_geo' % mySystem, em= True) # creating a pop up window to show the progress print self.obj , customRange for foll in self.folls: # picking a random number between 0 and 4 # this number will be plugged into a list[rand] to pick a random object self.rand = random.randrange(int(customRange)) # this section will randomize the transformations sx = random.uniform( xScaleFieldMin.getValue() , xScaleFieldMax.getValue() ) sy = random.uniform( yScaleFieldMin.getValue() , yScaleFieldMax.getValue() ) sz = random.uniform( zScaleFieldMin.getValue() , zScaleFieldMax.getValue() ) tx = random.uniform( xTranslateFieldMin.getValue() , xTranslateFieldMax.getValue() ) ty = random.uniform( yTranslateFieldMin.getValue() , yTranslateFieldMax.getValue() ) tz = random.uniform( zTranslateFieldMin.getValue() , zTranslateFieldMax.getValue() ) rx = random.uniform( xRotateFieldMin.getValue() , xRotateFieldMax.getValue() ) ry = random.uniform( yRotateFieldMin.getValue() , yRotateFieldMax.getValue() ) rz = random.uniform( zRotateFieldMin.getValue() , zRotateFieldMax.getValue() ) #print self.bar # duplicating the object newobj = pm.duplicate( self.obj[ self.rand ] , rr = True ) point = pm.pointConstraint( foll , newobj ) pm.delete( point ) pm.makeIdentity( newobj , apply = True , t = 1 , r = 1 , s = 1 , n = 0 ) # apllying the random Transforms pm.scale( newobj , [ sx , sy , sz ] ) pm.move( newobj , [ tx , ty , tz ] ) pm.rotate( newobj , [ rx , ry , rz ] ) # parentConstraint() to the follicle print rx, ry, rz, tx, tz, ty, sx, sy, sz pm.parentConstraint( foll , newobj, mo = True ) # parenting the objects to the group pm.parent(newobj , self.geoPad) self.edit() self.delete()
def MEL_b199(self):#Scale selected object #so far havent worked out a component pivot solution stringXYZ = str(self.ui.t003.text()) floatXYZ = float(stringXYZ) pm.scale (floatXYZ, floatXYZ, floatXYZ, objectSpace=True)
def rescaleShape(s): pm.scale('%s.cv[0:7]' % s, [0.5, 0.5, 1],relative = True, objectSpace = True)
pm.setDrivenKeyframe('R_Ball_Ctrl_Jnt.rotateZ',cd='R_Foot_Ctrl.ball_pivot') pm.setAttr('R_Foot_Ctrl.ball_pivot',0) #Freeze Transformations on Foot pm.select('L_Foot_Ctrl','R_Foot_Ctrl') pm.makeIdentity(apply=True,t=1,r=1,s=1,n=0,pn=1) ''' Mid Body Contruction ''' #Pelvis Controller pm.circle( n='Center_Controller',nr=(0, 1, 0), c=(0, 0, 0) , sw=360,r=1,d=3,ut=False,tol=0.01,s=24,cch=True) pm.scale(4.0,4.0,4.0,r=True) pm.select('Center_Controller.cv[1]','Center_Controller.cv[3]','Center_Controller.cv[5]','Center_Controller.cv[7]','Center_Controller.cv[9]','Center_Controller.cv[11]','Center_Controller.cv[13]','Center_Controller.cv[15]','Center_Controller.cv[17]','Center_Controller.cv[19]','Center_Controller.cv[21]','Center_Controller.cv[23]') pm.scale(.3,.3,.3,pivot=(0,0,0),r=True) pm.select('Center_Controller') pm.scale(2.5,2.5,2.5,r=True) pm.makeIdentity(apply=True,t=1,r=1,s=1,n=0,pn=1) #Back Controllers Create pm.curve(n='Bottom_Center_Controller',d=3,p=[(0, 0, 0),(0 ,0 ,-6),(0, -0.499797, -7.37584),(0, -1.30294 ,-6.319076),(0, -0.837963 ,-5.727286 ),(0 ,-0.457527 ,-5.980911),(0 ,-0.542068 ,-6.445888 ),(0, -0.795692 ,-6.488159),(0 ,-0.880233 ,-6.319076)],k=[0,0,0,1,2,3,4,5,6,6,6]) pm.scale(1, 1, 1.235647,r=True) pm.group('Bottom_Center_Controller','Bottom_Center_Controller',n='Bottom_Center_Ctrl_Grp',r=True) pm.select('Bottom_Center_Controller.cv[0:8]') pm.rotate(0,-90,0,r=True) pm.rotate(0,0,-90,r=True)
def drawCubes( letter ): cubeSize = scaleAmount * cubeScale sortedListOfPoints = sortByFork( codeStuff.InfoStore( "PointList", letter.lower() + "GenGroup" ).read(), codeStuff.InfoStore( "StartingForks", letter.lower() + "GenGroup" ).read() ) reduceInSize = py.getAttr( letter.lower() + "GenGroup.ReduceSize" ) #Abort if invalid if len( sortedListOfPoints ) == 0: print "Cannot generate cubes" return else: #Remove existing list of cubes try: py.delete( letter.lower() + "Cubes" ) except: pass #Recreate group cubeGroup = py.group( n = letter.lower() + 'Cubes', empty = True ) codeStuff.InfoStore( "CubeList", letter.lower() + "Cubes" ).set([]) py.parent( cubeGroup, letter.lower() + "GenGroup" ) #Delete cubes if the group hasn't deleted existingList = codeStuff.InfoStore( "CubeList", letter.lower() + "Cubes" ).read() if len( existingList ) > 0: print "Removing existing cubes..." for i in range( len( existingList ) ): try: py.delete( existingList[i] ) except: pass print "Generating cubes..." highestSequence = py.getAttr( letter.lower() + "GenGroup.HighestSequence" ) maxCubes = float( len( codeStuff.InfoStore( "PointList", letter.lower() + "GenGroup" ).read() ) ) startCubeTime = time() totalCubes = 0 nextTime = startCubeTime + timeIncrement listOfCubes = [] for forkNumber in sortedListOfPoints: #Draw cube curbeList = [] for i in range( len( sortedListOfPoints[forkNumber] ) ): #Get info coordinates = sortedListOfPoints[forkNumber][i][0] sequenceNumber = sortedListOfPoints[forkNumber][i][1] colourNumber = sortedListOfPoints[forkNumber][i][2] if highestSequence > 0: percentComplete = sequenceNumber/highestSequence else: percentComplete = 0 #Create cube newCube = py.polyCube( n = letter.lower() + "Cube", width = cubeSize, depth = cubeSize, height = cubeSize )[0] py.move( newCube, coordinates ) py.parent( newCube, letter.lower() + "Cubes" ) listOfCubes.append( str( newCube ) ) #Store colour value inside cube py.addAttr( newCube, longName = "ColourValue" ) py.setAttr( newCube + ".ColourValue", colourNumber ) #Scale cube based on colour value if reduceInSize == True: py.scale( newCube, colourNumber, colourNumber, colourNumber ) if totalCubes % iterationsCubes == 0: if time() > nextTime: nextTime = time() + timeIncrement percentage = totalCubes / maxCubes if percentage > 100: print totalCubes print maxCubes print indent + str( totalCubes ) + " cubes generated (" + str( round( 100*percentage, 2 ) ) + "%)" codeStuff.UpdateViewport() totalCubes += 1 print objectsPerSecond( startCubeTime, "cubes", totalCubes ) startStoreTime = time() print "Storing cube information..." codeStuff.UpdateViewport() codeStuff.InfoStore( "CubeList", letter.lower() + "Cubes" ).set( listOfCubes ) if time() - startStoreTime > minimumTimeToOutput: print "Stored in " + str( codeStuff.TimeOutput( startStoreTime, time() ) )
def ui_createLocators(self): ''' Create main control and locators for user to place ''' yShift = 3 # Used to space chain locators below root parentJnt = str(self.parentLineEdit.text()) if not parentJnt: raise Exception('Please select a parent joint.') pos = pm.xform(parentJnt, q=1, ws=1, rp=1) if pm.general.objExists('HairRig_MainCnt'): choice = pm.confirmBox(title='Hair Rig: Locators already exist', message='Delete Existing Locators?') if choice == 'No': return if choice == None: return pm.delete('HairRig_MainCnt') # Create root control mainCnt = pm.circle(radius=3, name='HairRig_MainCnt', c=pos, nr=(0,1,0), ch=0)[0] pm.mel.eval('CenterPivot;') # Get chain names and number of joints names = [] numJnts = [] for nameFld,numJntsFld in zip(self.nameFields,self.chainNumLcdFields): names.append(str(nameFld.text())) numJnts.append(str(numJntsFld.value())) poci = pm.shadingNode('pointOnCurveInfo', asUtility=True) pm.connectAttr('%s.ws'%mainCnt.getShape(),'%s.inputCurve'%poci,f=1) increment = 1/len(names) for name, numJnt in zip(names,numJnts): locatorChains = {} loc = pm.spaceLocator(n='%s_rootLoc'%name) locatorChains[loc] = [] pm.mel.eval('CenterPivot;') pm.scale(loc,.5,.5,.5) # Aim in negative x to parent joint to set Up vector pm.select(parentJnt, loc, replace=1) pm.mel.eval('doCreateAimConstraintArgList 1 { "0","0","0","0","-1","0","0","0","1","0","0","1","0","1","vector","","0","0","0","","1" };') # Get the initial position pm.connectAttr('%s.position'%poci,'%s.translate'%loc,f=1) pm.setAttr('%s.parameter'%poci,increment) pos = pm.xform(loc,q=1,ws=1,t=1) pm.disconnectAttr('%s.position'%poci,'%s.translate'%loc) increment = increment + 1 pm.setAttr('%s.translateX'%loc, pos[0]) pm.setAttr('%s.translateY'%loc, pos[1]) pm.setAttr('%s.translateZ'%loc, pos[2]) pm.parent(loc,mainCnt) # Create the rest of the locators for n in range(int(numJnt)): if n == 0: continue l = pm.spaceLocator(n='%s_loc%s'%(name,n)) pm.delete(pm.parentConstraint(loc,l,mo=False)) pm.scale(l,.5,.5,.5) pm.move(l,0,-(n*yShift),0,r=True) locatorChains[loc].append(l) pm.parent(l,loc)
def draw_axiom(self,axiom,ang,dist): stack = [] zdegr = 0 ydegr = 0 xdegr = 0 width = 0.5 dist = 0 world = False previous = None pdist = 0 #previous distance first_itr = True for c in axiom: command = c[0] argument = c[1] # draw flower if command is 'L': if argument is 'def': argument = self.dist current = self.make_flower(self.flower_index) self.flower_index += 1 if previous is not None: current.setMatrix(previous.getMatrix(worldSpace=True)) pm.parent(current,previous) pm.scale(15,15,15) if xdegr != 0 or zdegr != 0 or ydegr != 0: # print(pdist) current.translateY.set(pdist) # pm.move(0,pdist,0,current,os=True) # pm.rotate(current,xdegr,ydegr,zdegr,os=True,relative=True) print(width) # pm.move(0,width,0,current,os=True,relative=True) else: pm.move(0,dist+argument/2,0,current,os=True,relative=True) zdegr = 0 ydegr = 0 xdegr = 0 dist = 0 world = False previous = current if command is 'F': print ("{} {} {} {}".format("F command triggered", world, xdegr+ydegr+zdegr,width)) if argument is 'def': argument = self.dist if command is 'F': current = self.make_branch(argument,width)[0] elif command is 'L': current = self.make_flower(self.flower_index) # pm.scale(3,3,3) self.flower_index += 1 if previous is not None: current.setMatrix(previous.getMatrix(worldSpace=True)) pm.parent(current,previous) if command is 'L': pm.scale(8,8,8) #apply rotates and transforms if xdegr != 0 or zdegr != 0 or self.ternaryflag: pm.move(0,pdist,0,current,os=True) # print(tn.process(current)) if previous is not None and command is 'F' and self.ternaryflag: tn.apply_tropism(current,self.e,self.tropism) pm.rotate(current,xdegr,ydegr,zdegr,os=True,relative=True) if command is 'F': pm.move(0,dist+argument/2,0,current,os=True,relative=True) if command is 'L': pm.move(0,width,0,current,os=True,relative=True) else: if command is 'F': pm.move(0,pdist+dist+argument/2,0,current,os=True,relative=True) if command is 'L': pm.move(0,dist+argument/2,0,current,os=True,relative=True) zdegr = 0 ydegr = 0 xdegr = 0 dist = 0 world = False if command is 'F': pdist = argument/2 # print(xdegr) previous = current elif command is 'f': if argument is 'def': dist = 5 else: dist = argument elif command is '-': if argument is 'def': argument = ang zdegr += -argument print ("{} {}".format("- command triggered", zdegr)) elif command is '+': if argument is 'def': argument = ang zdegr += argument print ("{} {}".format("+ command triggered", zdegr)) elif command is '&': if argument is 'def': argument = ang print("& command triggered") xdegr += -argument print ("{} {}".format("+ command triggered", xdegr)) elif command is '^': if argument is 'def': argument = ang xdegr += argument elif command == "\\": print("\\ command triggered") ydegr += -argument elif command is '/': if argument is 'def': argument = ang ydegr += argument elif command is '[': print("[ triggered") stack.append([previous,xdegr,ydegr,zdegr,width,dist,world]) # print(stack) elif command is ']': print("] triggered") # print(stack) prev_state = stack.pop() previous = prev_state[0] xdegr = prev_state[1] ydegr = prev_state[2] zdegr = prev_state[3] width = prev_state[4] dist = prev_state[5] world = prev_state[6] # print(stack) #decrement width elif command is '!': print("! triggered") if argument is 'def': width*=0.9 else: width = argument #rotate Y and until Z-axis is horizontal (WIP) elif command is '$': pass
def mip_move_image_plane(imagePlane = '', *args, **kwargs): if imagePlane: connections = pm.connectionInfo(imagePlane+'.message', destinationFromSource=True) cam = 'none' for item in connections: if item.split('Shape.')[0] == 'front': cam = 'front' if item.split('Shape.')[0] == 'side': cam = 'side' if item.split('Shape.')[0] == 'top': cam = 'top' if cam != 'none': curve = pm.curve(per=True, d=1, p=[(0.5,0,0.5), (0.5,0,-0.5), (-0.5,0,-0.5), (-0.5,0,0.5), (0.5,0,0.5)], k=[0,1,2,3,4]) if cam == 'front': curve.setRotation((90,0,0)) if cam == 'top': curve.setRotation((0,0,0)) if cam == 'side': curve.setRotation((90,90,0)) pm.setAttr(curve+'.rx', lock=True, keyable=False, channelBox=False) pm.setAttr(curve+'.ry', lock=True, keyable=False, channelBox=False) pm.setAttr(curve+'.rz', lock=True, keyable=False, channelBox=False) pm.setAttr(curve+'.sy', lock=True, keyable=False, channelBox=False) filename = pm.getAttr(imagePlane+'.imageName').split('/')[-1].split('.')[0] pm.rename(curve, 'Mover_'+filename) pm.expression(name=imagePlane+'_expression', s='{0}.displayMode = {1}.visibility * 3'.format(imagePlane, curve)) ratio = 1.0 coverageX = float(pm.getAttr(imagePlane+'.coverageX')) coverageY = float(pm.getAttr(imagePlane+'.coverageY')) size = 1.0 sizeW = float(pm.getAttr(imagePlane+'.width')) sizeH = float(pm.getAttr(imagePlane+'.height')) if sizeW>sizeH: size = sizeW else: size = sizeH if coverageX > coverageY: ratio = coverageX/coverageY x = size z = size/ratio curve.setScale((x,1,z)) pm.select(curve.cv[0:3]) pm.scale(1.2,1+(.2/ratio),1) else: ratio = coverageY/coverageX x = size/ratio z = size curve.setScale((x,1,z)) pm.select(curve.cv[0:3]) pm.scale(1+(.2/ratio),1.2,1) if pm.mel.getApplicationVersionAsFloat() > 2012: pm.connectAttr(curve.translate, imagePlane+'.imageCenter') else: pm.connectAttr(curve.translate, imagePlane+'.center') pm.connectAttr(curve.scaleX, imagePlane+'.width') pm.connectAttr(curve.scaleZ, imagePlane+'.height') pm.select(curve, replace=True) else: pm.warning('not using the front, side or top camera !!!')
def createControl(*args, **kwargs): targets = makeList(args) if not len(targets): ## if there are no target objects passed in, put in a blank to ## force creation of one control targets = [ None ] ## default values data = { 'name':'CONTROL_#s_#d_CON', 'type':'box', 'color': colors.green, 'scale':1.0, 'aim':'x', 'up':'y', 'rotateOrder':'zxy', 'translation':[0,0,0], 'rotation':[0,0] } data.update(**kwargs) controls = [] zeros = [] for target in targets: if not 'side' in data and target is not None: data['side'] = determineSide(target) else: data['side'] = 'cn' curve = pm.curve( d=1, p=controllerCurves[data['type']] ) curve.rename( makeName(data['name'], side=data['side'], upper=True) ) setColor(curve, data['color']) scale = data['scale'] pm.scale(curve.cv, scale, scale, scale, r=True) setAttrSpecial(curve, 'origScale', data['scale'], channelBox=False) ##!FIXME: Apply aim and up setAttrSpecial(curve, 'aim', data['aim'], channelBox=False) setAttrSpecial(curve, 'up', data['up'], channelBox=False) ##!FIXME: apply controller translation and rotation ## rotate order rotateOrder = data['rotateOrder'] if isinstance(rotateOrder, str) or isinstance(rotateOrder, unicode): if not rotateOrder in rotateOrders.keys(): raise ValueError("rotateOrder must be an integer between 0 and 5 or one of " + ' '.join(rotateOrders.keys()) + '.' ) rotateOrder = rotateOrders[rotateOrder] curve.rotateOrder.set( rotateOrder ) if target is not None: snap(curve, target) ## lockdown ##!FIXME: only here until the channelBox flag is fixed in setAttrSpecial for attr in curve.origScale, curve.aim, curve.up: attr.set(k=False, cb=False) attr.lock() zeros.append( addZero(curve) ) controls.append( curve ) return(zip(zeros, controls))