def joint_display_reset(): """ ----------------------------------------------------------------------------------------------------- This function resets the joint display size to default setting :return: ----------------------------------------------------------------------------------------------------- """ mc.intSlider("jointSize_sld", edit=True, value=10) mc.jointDisplayScale(1)
def joint_display(): """ ----------------------------------------------------------------------------------------------------- This function sets the joint display size :return: ----------------------------------------------------------------------------------------------------- """ # Query UI information and assign them to variables joint_size = mc.intSlider("jointSize_sld", query=True, value=True) / 10.00 # Set the joint display size mc.jointDisplayScale(joint_size)
def skeletonUI(): # Header ui = cmds.columnLayout(adj=True) # Body UI cmds.frameLayout(l='Display', mh=mar, mw=mar, bgs=True, cl=True) j1 = cmds.button(l='Toggle LRA', enable=False) j2 = cmds.button(l='Show', enable=False) j3 = cmds.button(l='Hide', enable=False) autoRow([j1, j2, j3]) divider('Joint Scale') jdUI = cmds.floatSliderGrp(field=True, pre=2, min=0.01, max=10.00, v=cmds.jointDisplayScale(q=True), cc=lambda *x: cmds.jointDisplayScale(cmds.floatSliderGrp(jdUI, q=True, v=True))) cmds.setParent('..') cmds.frameLayout(l='Create', mh=mar, mw=mar, bgs=True, cl=True) b1 = cmds.button(l='Create Joint', c=utils.createJoint) b2 = cmds.button(l='Orient Chain', c=utils.orientJointChain) b3 = cmds.button(l='Select Hierarchy', c=utils.getJointHierarchy) autoRow([b1, b2, b3]) cmds.setParent('..') cmds.frameLayout(l='Joint Labels', mh=mar, mw=mar, bgs=True, cl=True) a1 = cmds.button(l='Toggle Visibility', c=utils.toggleJointLabel) a2 = cmds.button(l='Show', c=lambda *x: mel.eval('displayJointLabels 4;')) a3 = cmds.button(l='Hide', c=lambda *x: mel.eval('displayJointLabels 3;')) autoRow([a1, a2, a3]) # Add Label UI divider('Add Label') cmds.rowLayout(nc=2, adj=1, cat=[1, 'right', -4], rat=[1, 'both', 0]) om1 = cmds.optionMenuGrp(adj=1, rat=[1, 'both', -2], cat=[1, 'right', 0], cc=lambda *x: utils.jointLabel().addTypeFromUI(cmds.optionMenuGrp(om1, q=True, sl=True))) for l in utils.jointLabel().masterList: cmds.menuItem(l=l, dtg=l) cmds.button(l='+', w=20, c=lambda *x: utils.jointLabel().addTypeFromUI(cmds.optionMenuGrp(om1, q=True, sl=True))) cmds.setParent('..') cmds.setParent('..') cmds.frameLayout(l='Skinning', mh=mar, mw=mar, bgs=True, cl=True) swb1 = cmds.button(l='Paint Weights', c=lambda *x: mel.eval('ArtPaintSkinWeightsToolOptions;')) #swb2 = cmds.button(l='Smooth Weights', c=tf_smoothSkinWeight.paint) swb3 = cmds.button(l='Mirror Weights', c=lambda *x: [utils.mirrorSkinWeights(mesh=x) for x in cmds.ls(sl=True)]) autoRow([swb1, swb3]) cmds.setParent('..') # End UI cmds.setParent('..') return ui
def create_orient_manipulator(joint, material): joint_scale = cmds.jointDisplayScale(query=True) joint_radius = cmds.getAttr('{0}.radius'.format(joint)) radius = joint_scale * joint_radius children = cmds.listRelatives(joint, children=True, path=True) if children: p1 = cmds.xform(joint, q=True, ws=True, t=True) p1 = OpenMaya.MPoint(*p1) p2 = cmds.xform(children[0], q=True, ws=True, t=True) p2 = OpenMaya.MPoint(*p2) radius = p1.distanceTo(p2) arrow_cvs = [[-1, 0, 0], [-1, 2, 0], [-2, 2, 0], [0, 4, 0], [2, 2, 0], [1, 2, 0], [1, 0, 0], [-1, 0, 0]] arrow_cvs = [[x[0] * radius, x[1] * radius, x[2] * radius] for x in arrow_cvs] shape = cmds.curve(name='{0}_zForward'.format(joint), degree=1, point=arrow_cvs) # shape = cmds.sphere(n='{0}_zForward'.format(joint), p=(0, 0, 0), ax=(0, 0, -1), ssw=0, esw=180, r=radius, d=3, ut=0, tol=0.01, s=8, nsp=4, ch=0)[0] # cmds.setAttr('{0}.sz'.format(shape), 0) # cmds.select(shape) # cmds.hyperShade(assign=material) group = cmds.createNode('transform', name='{0}_grp'.format(shape)) cmds.parent(shape, group) cmds.makeIdentity(shape, apply=True) cmds.addAttr(shape, longName=MESSAGE_ATTRIBUTE, attributeType='message') cmds.connectAttr('{0}.message'.format(joint), '{0}.{1}'.format(shape, MESSAGE_ATTRIBUTE)) for attr in ['tx', 'ty', 'tz', 'ry', 'rz', 'v']: cmds.setAttr('{0}.{1}'.format(shape, attr), lock=True, keyable=False) return group, shape
def __init__(self): self.jntScale = rig.jointDisplayScale(q=True) #获得骨骼缩放值 self.grps = [ u'Main_Control_GRP', u'Ear_Control_GRP', u'Eye_Control_GRP', u'Eyebrow_Control_GRP', u'Tongue_Control_GRP', u'Tooth_Control_GRP', u'Head_Control_GRP' ]
def convert_joint(curr_joint, group_name, root_jnt=True): scale_size = mc.jointDisplayScale(q=True) * 2.0 _children = mc.listRelatives(curr_joint, c=True) if _children is not None: for node in _children: if mc.nodeType(node) == 'joint': convert_joint(node, group_name, root_jnt=False) parent = mc.listRelatives(curr_joint, p=True) if parent is None or root_jnt: return _name_ball = curr_joint + group_name + "_ball" new_ball = mc.sphere(n=_name_ball) _name_cone = curr_joint + group_name + "_joint" new_cone = mc.cone(p=(0, 0, 0), ax=(1, 0, 0), ssw=0, esw=360, r=0.5, hr=4, d=1, ut=0, tol=0.01, s=8, nsp=4, ch=1, n=_name_cone) mc.move(-1, 0, 0, _name_cone + ".scalePivot", _name_cone + ".rotatePivot", r=True) mc.parent(new_cone, group_name) mc.parent(new_ball, group_name) xform1 = mc.xform(curr_joint, q=True, ws=True, t=True) xform2 = mc.xform(parent[0], q=True, ws=True, t=True) dist = 0.0 for i in range(len(xform1)): dist += (xform1[i] - xform2[i]) * (xform1[i] - xform2[i]) dist = (dist**0.5) / 2.0 mc.scale(scale_size, scale_size, scale_size, new_ball, r=True) bbox = mc.exactWorldBoundingBox(new_ball) bbox_size = ((((bbox[3] - bbox[0])**2 + (bbox[4] - bbox[1])**2 + (bbox[5] - bbox[2])**2)**0.5) / 4.0) * 2.0 mc.scale(dist, bbox_size, bbox_size, new_cone, r=True) mc.pointConstraint(parent[0], new_cone, weight=1) mc.pointConstraint(parent[0], new_ball, weight=1) mc.aimConstraint(curr_joint, new_cone, aim=(1, 0, 0), u=(0, 1, 0), wu=(0, 1, 0), weight=1) create_node(group_name, new_ball[0], 'ball') create_node(group_name, new_cone[0], 'edge')
def gtu_reset_joint_sizes(): ''' Resets the radius attribute back to one in all joints, then changes the global multiplier (jointDisplayScale) back to one ''' try: desired_size = 1 all_joints = cmds.ls(type='joint') for obj in all_joints: if cmds.objExists(obj): if cmds.getAttr(obj + ".radius", lock=True) is False: cmds.setAttr(obj + '.radius', 1) if cmds.getAttr(obj + ".v", lock=True) is False: cmds.setAttr(obj + '.v', 1) cmds.jointDisplayScale(1) except Exception as exception: raise exception
def createArrow(jointName): curve = cmds.curve(name='%s_ForwardDirection' % jointName, degree=1, point=[(-1, 0, 0), (-1, 2, 0), (-2, 2, 0), (0, 4, 0), (2, 2, 0), (1, 2, 0), (1, 0, 0), (-1, 0, 0)]) cvtools.lockAndHide(curve, lockAndHide=['ry', 'rz', 'tx', 'ty', 'tz', 'sz', 'visibility']) overrideColor.overrideColor(overrideColor.BLUE) group = cmds.group() cmds.xform(objectSpace=True, pivots=(0, 0, 0)) jointScale = cmds.jointDisplayScale(query=True) jointRadius = cmds.getAttr('%s.radius' % jointName) jointScale *= jointRadius cmds.xform(scale=(jointScale, jointScale, jointScale)) return group
def create_arrow(jointName): curve = cmds.curve(name='%s_ForwardDirection' % jointName, degree=1, point=[(-1, 0, 0), (-1, 2, 0), (-2, 2, 0), (0, 4, 0), (2, 2, 0), (1, 2, 0), (1, 0, 0), (-1, 0, 0)]) group = cmds.group() cmds.xform(objectSpace=True, pivots=(0, 0, 0)) jointScale = cmds.jointDisplayScale(query=True) jointRadius = cmds.getAttr('%s.radius' % jointName) jointScale *= jointRadius cmds.xform(scale=(jointScale, jointScale, jointScale)) return group
def createArrow(jointName): curve = cmds.curve(name='%s_ForwardDirection' % jointName, degree=1, point=[(-1, 0, 0), (-1, 2, 0), (-2, 2, 0), (0, 4, 0), (2, 2, 0), (1, 2, 0), (1, 0, 0), (-1, 0, 0)]) cvtools.lockAndHide( curve, lockAndHide=['ry', 'rz', 'tx', 'ty', 'tz', 'sz', 'visibility']) overrideColor.overrideColor(overrideColor.BLUE) group = cmds.group() cmds.xform(objectSpace=True, pivots=(0, 0, 0)) jointScale = cmds.jointDisplayScale(query=True) jointRadius = cmds.getAttr('%s.radius' % jointName) jointScale *= jointRadius cmds.xform(scale=(jointScale, jointScale, jointScale)) return group
def makePrimitiveJoint(currentJoint): SJsize = mc.jointDisplayScale(q=True) * SS_scale children = mc.listRelatives(currentJoint, c=True) if (children != None) : for node in children : if(mc.nodeType(node) == "joint") : makePrimitiveJoint(node) else : SJballEndName = currentJoint + SS_group + "_SJballEnd" solidEndBall = mc.sphere(n=SJballEndName) mc.parent(solidEndBall, SS_group) mc.scale(SJsize, SJsize, SJsize, solidEndBall, r=True) mc.pointConstraint(currentJoint, solidEndBall, weight=1) createMDN(solidEndBall, 'ball') elif (children == None) : SJballEndName = currentJoint + SS_group + "_SJballEnd" solidEndBall = mc.sphere(n=SJballEndName) mc.parent(solidEndBall, SS_group) mc.scale(SJsize, SJsize, SJsize, solidEndBall, r=True) mc.pointConstraint(currentJoint, solidEndBall, weight=1) createMDN(solidEndBall, 'ball') SJname = currentJoint + SS_group + "_SJ" SJballName = currentJoint + SS_group + "_SJball" parent = mc.listRelatives(currentJoint, p=True) if (parent != None) and (currentJoint != SS_root_jnt): parentJoint = parent[0] solidBall = mc.sphere(n=SJballName) solidJoint = mc.cone(p=(0,0,0), ax=(1,0,0), ssw=0, esw=360, r=0.5, hr=4, d=1, ut=0, tol=0.01, s=8, nsp=4, ch=1, n=SJname) mc.move(-1, 0, 0, SJname+".scalePivot", SJname+".rotatePivot", r=True) mc.parent(solidJoint, SS_group) mc.parent(solidBall, SS_group) xform1 = mc.xform(currentJoint, q=True, ws=True, t=True) xform2 = mc.xform(parentJoint, q=True, ws=True, t=True) dist = 0.0 for i in range(len(xform1)):dist += (xform1[i]-xform2[i])*(xform1[i]-xform2[i]) dist = (dist ** 0.5) / 2.0 mc.scale(SJsize, SJsize, SJsize, solidBall, r=True) bbox = mc.exactWorldBoundingBox(solidBall) bboxSize = ((((bbox[3]-bbox[0])**2+(bbox[4]-bbox[1])**2+(bbox[5]-bbox[2])**2)**0.5)/4.0)*SS_edgeScale mc.scale(dist, bboxSize, bboxSize, solidJoint, r=True) mc.pointConstraint(parentJoint, solidJoint, weight=1) mc.pointConstraint(parentJoint, solidBall, weight=1) mc.aimConstraint(currentJoint, solidJoint, aim=(1,0,0), u=(0,1,0), wu=(0,1,0), weight=1) createMDN(solidBall, 'ball') createMDN(solidJoint, 'edge')
def create_orient_manipulator(joint, material): joint_scale = cmds.jointDisplayScale(query=True) joint_radius = cmds.getAttr('{0}.radius'.format(joint)) radius = joint_scale * joint_radius children = cmds.listRelatives(joint, children=True, path=True) if children: p1 = cmds.xform(joint, q=True, ws=True, t=True) p1 = OpenMaya.MPoint(*p1) p2 = cmds.xform(children[0], q=True, ws=True, t=True) p2 = OpenMaya.MPoint(*p2) radius = p1.distanceTo(p2) sphere = cmds.sphere(n='{0}_forward'.format(joint), p=(0, 0, 0), ax=(0, 0, -1), ssw=0, esw=180, r=radius, d=3, ut=0, tol=0.01, s=8, nsp=4, ch=0)[0] group = cmds.createNode('transform', name='{0}_grp'.format(sphere)) cmds.parent(sphere, group) cmds.setAttr('{0}.sz'.format(sphere), 0) cmds.makeIdentity(sphere, apply=True) cmds.addAttr(sphere, longName=MESSAGE_ATTRIBUTE, attributeType='message') cmds.connectAttr('{0}.message'.format(joint), '{0}.{1}'.format(sphere, MESSAGE_ATTRIBUTE)) cmds.select(sphere) cmds.hyperShade(assign=material) for attr in ['tx', 'ty', 'tz', 'ry', 'rz', 'v']: cmds.setAttr('{0}.{1}'.format(sphere, attr), lock=True, keyable=False) return group, sphere
def jointSize(): j = cmds.floatSliderGrp(jnt, q=True, v=True) cmds.jointDisplayScale(j)
def JointSize(): j=cmds.floatSliderGrp(jnt, q=True, v=True) cmds.jointDisplayScale(j) print "Change Jnts Size: "+str(j)