def createDynamicChainLocators(self, prefix = ''): #set instance prefix var self.setPrefix(prefix) pm.select(cl = True) #Create Space locators and translate self.dynamic_chain_locator_base = pm.spaceLocator(n = self.prefix + '_dynamic_chain_locator_base') self.dynamic_chain_locator_base.translate.set(0, 0, 0) pm.select(cl = True) self.dynamic_chain_locator_tip = pm.spaceLocator(n = self.prefix + '_dynamic_chain_locator_tip') self.dynamic_chain_locator_tip.translate.set(0, 10, 0) pm.select(cl = True) #Create Annotations and rename self.annotation_dynamic_chain_locator_base = pm.annotate( self.dynamic_chain_locator_base, tx = self.prefix +'_dynamic_chain_base' ) pm.rename(self.annotation_dynamic_chain_locator_base.getParent().name(), self.prefix + '_dynamic_chain_base_annotation') self.annotation_dynamic_chain_locator_tip = pm.annotate( self.dynamic_chain_locator_tip, tx = self.prefix +'_dynamic_chain_tip' ) pm.rename(self.annotation_dynamic_chain_locator_tip.getParent().name(), self.prefix + '_dynamic_chain_tip_annotation') pm.select(cl = True) #Parent constrain annotation transforms pm.parentConstraint(self.dynamic_chain_locator_base, self.annotation_dynamic_chain_locator_base.getParent(), mo = False) pm.parentConstraint(self.dynamic_chain_locator_tip, self.annotation_dynamic_chain_locator_tip.getParent(), mo = False)
def build(self): # Create the annotation pm.select(clear=True) locPosition = libUtilities.get_world_space_pos(self.pynode) pm.select(self.mNode) fakeJoint = pm.annotate(self.mNode, point=locPosition).getParent() fakeJoint.setParent(self.pynode) fakeJoint.v.set(False) fakeJointMeta = core.MovableSystem(fakeJoint.name()) fakeJointMeta.template = True self.transferPropertiesToChild(fakeJointMeta, "FakeJoint") fakeJointMeta.part = self.part fakeJointMeta.resetName() self.fakeJoint = fakeJointMeta # Build the label annotation annotation = pm.annotate(self.mNode, point=locPosition, tx=self.trueName).getParent() annotation.displayArrow.set(False) annotationMeta = core.MovableSystem(annotation.name()) annotationMeta.template = True self.transferPropertiesToChild(annotationMeta, "Anno") annotationMeta.part = self.part annotationMeta.resetName() annotationMeta.setParent(self) self.annotation = annotationMeta
def setButtonPress(self, *args): """Sets the plane we'll be snapping to from the three selected vertices Called by "set plane" button """ sel = pm.ls(selection=1, flatten=1) if len(sel) ==3: self.cleanUp() pos1 = sel[0].getPosition() pos2 = sel[1].getPosition() pos3 = sel[2].getPosition() vct1 = pos2-pos1 vct2 = pos3-pos1 # ^ is owerwritten to perform a cross product self.normal = vct1 ^ vct2 self.normal.normalize() self.position = pos1 pm.select(sel) layerObj = pm.createDisplayLayer(name=self.layername, empty=1) for i, vtx in enumerate(sel): annotation = pm.annotate(vtx, tx="V%d" % (i+1), p=vtx.getPosition(space="world") ) annotation.setAttr("overrideEnabled", 1) annotation.setAttr("overrideColor", 17) annTrans = annotation.getParent() annTrans.rename("annotateVts%d" % (i+1)) layerObj.addMembers(annTrans) layerObj.addMembers(annotation) layerObj.setAttr("displayType", 1) else: pm.confirmDialog(message="Please select exactly 3 vertices", title="Error", button="OK", defaultButton="OK", dismissString="OK", cancelButton="OK")
def annotateSelectionHandle(obj, text, pos=None): ''' Make an annotation of the `obj`'s selection handle, optionally specifying the position of the handle as well. ''' obj.displayHandle.set( True ) if pos: obj.selectHandle.set( pos ) loc = spaceLocator() ann = annotate(loc, text=text).getParent() ann.setParent( obj ) ann.t.set(obj.selectHandle.get()) ann.r.lock() ann.s.lock() loc.setParent(ann) loc.t.set(0, 0, 0) hide(loc) add = createNode( 'plusMinusAverage' ) ann.t >> add.input3D[0] add.input3D[1].set( 0, 1, 0 ) add.output3D >> obj.selectHandle
def _add_annotation(self, control, name): """Implement annotation shape and merge with control shape.""" control.group.addAttr('label', at='short', min=0, max=1, dv=1, k=True) ano = pm.annotate(control.transform, text=name) ano.rename('%s_%s_ANOShape' % (self.side, name)) ano.ove.set(1) ano.ovdt.set(2) trn = ano.listRelatives(p=True)[0] trn.rename('%s_%s_ANO' % (self.side, name)) trn.tz.set(control.shape.attr('size').get() * 2) pm.parent(trn, control.transform) control.group.attr('label') >> ano.v
def __init__(self, nameObj, nameAnnotation, textObj, pointObj, startObj, positionObj=[]): self.nameObj = nameObj self.nameAnnotation = nameAnnotation self.textObj = textObj self.pointObj = pointObj self.startObj = startObj self.positionObj = positionObj if (self.startObj == ''): pm.annotate(self.pointObj, tx=self.textObj, p=self.positionObj) pm.rename('annotation1', self.nameAnnotation) pm.setAttr(self.nameAnnotation+'.overrideEnabled', 1) pm.setAttr(self.nameAnnotation + '.overrideColor', 17) pm.setAttr(self.nameAnnotation + '.overrideDisplayType', 2) else: #pos = pm.xform(self.startObj, q=True, ws=True, t=True) pos = pm.pointPosition(self.startObj, w=True) pm.annotate(self.pointObj, tx=self.textObj, p=pos) pm.rename('annotation1', self.nameAnnotation) pm.setAttr(self.nameAnnotation+'.overrideEnabled', 1) pm.setAttr(self.nameAnnotation + '.overrideColor', 17) pm.setAttr(self.nameAnnotation + '.overrideDisplayType', 2) pm.parent(self.nameAnnotation, self.startObj)
def _annotation(self, name): """Implement annotation shape and merge with control shape.""" self.transform.addAttr('label', at='short', min=0, max=1, dv=0, k=True) if self.gimbal: ano = pm.annotate(self.gimbal.transform, text=name) else: ano = pm.annotate(self.transform, text=name) # end if gimbal is given trn = ano.getParent() if '_' in name: splitname = '%s' % (name.split('_')[1]) ano.rename('%s_%s_ANOShape' % (self.side, splitname)) trn.rename(ano.replace('ANOShape', 'ANO')) # end if proper naming convention ano.ove.set(1) ano.ovdt.set(2) trn.tz.set(self.transform.sy.get() * 2) if self.gimbal: trn.setParent(self.gimbal.transform) else: trn.setParent(self.transform) # end if parent anno transform under control self.transform.label >> ano.v
def connectingLine(src, dest): ''' Draw an annotation arrow from the src to the dest. ''' loc = spaceLocator() line = annotate(loc, tx='').getParent() line.setParent(src) line.t.set(0, 0, 0) shape = line.getShape() shape.overrideEnabled.set(True) shape.overrideDisplayType.set(1) loc.setParent(dest) loc.t.set(0, 0, 0) loc.t.lock() hide(loc.listRelatives())
def build_annotation(pole, ik_joint, tags=None, name='placeholder', net=None): """ Draw a line from the pole vector ctrl to the ik joint for visual reference. :param pole: pole vector controller :param ik_joint: mid joint in the ik chain :param name: name :param net: network node. Expecting Region and Side attrs :return: anno, anno_parent, locator, point_constraint """ log.info('*build_annotation: {} {} {}*'.format(pole, ik_joint, net)) # Locator locator_name = naming_utils.concatenate([name, 'Loc']) locator = pymel.spaceLocator(name=locator_name, p=(0, 0, 0), a=True) naming_utils.add_tags(locator, tags=tags) # Point constrain Locator point_constraint_name = naming_utils.concatenate( [name, 'PointConstraint', 'A']) point_constraint_a = pymel.pointConstraint(ik_joint, locator, mo=False, name=point_constraint_name) naming_utils.add_tags(point_constraint_a, tags=tags) # Annotation anno_name = naming_utils.concatenate([name, 'Anno']) annotation = pymel.annotate(locator, tx='', p=(0, 0, 0)) anno_parent = annotation.listRelatives(parent=True)[0] pymel.rename(anno_parent, anno_name) naming_utils.add_tags(anno_parent, tags=tags) # Point constrain pole point_constraint_name = naming_utils.concatenate( [name, 'PointConstraint', 'B']) point_constraint_b = pymel.pointConstraint(pole, anno_parent, maintainOffset=False, name=point_constraint_name) naming_utils.add_tags(point_constraint_b, tags=tags) return annotation, anno_parent, locator, point_constraint_a, point_constraint_b
def createFootRigBLocators(self, prefix = ''): #set instance prefix var self.setPrefix(prefix) pm.select(cl = True) #Create Space locators and translate self.leg_locator_base = pm.spaceLocator(n = self.prefix + '_leg_locator_base') self.leg_locator_base.translate.set(0, 0, 0) pm.select(cl = True) self.leg_locator_knee = pm.spaceLocator(n = self.prefix + '_leg_locator_knee') self.leg_locator_knee.translate.set(4, 2, 0) pm.select(cl = True) self.leg_locator_tip = pm.spaceLocator(n = self.prefix + '_leg_locator_tip') self.leg_locator_tip.translate.set(8, -2, 0) pm.select(cl = True) self.leg_locator_poleVector = pm.spaceLocator(n = self.prefix + '_leg_locator_poleVector') self.leg_locator_poleVector.translate.set(4, 4, 0) pm.select(cl = True) self.foot_locator = pm.spaceLocator(n = self.prefix + '_foot_locator') self.foot_locator.translate.set(12, -2, 0) pm.select(cl = True) #Create Annotations and rename self.annotation_leg_locator_base = pm.annotate( self.leg_locator_base, tx = self.prefix +'_leg_locator_base' ) pm.rename(self.annotation_leg_locator_base.getParent().name(), self.prefix + '_leg_locator_base_annotation') self.annotation_leg_locator_knee = pm.annotate( self.leg_locator_knee, tx = self.prefix +'_leg_locator_knee' ) pm.rename(self.annotation_leg_locator_knee.getParent().name(), self.prefix + '_leg_locator_knee_annotation') self.annotation_leg_locator_tip = pm.annotate( self.leg_locator_tip, tx = self.prefix +'_leg_locator_tip' ) pm.rename(self.annotation_leg_locator_tip.getParent().name(), self.prefix + '_leg_locator_tip_annotation') self.annotation_leg_locator_poleVector = pm.annotate( self.leg_locator_poleVector, tx = self.prefix +'_leg_locator_poleVector' ) pm.rename(self.annotation_leg_locator_poleVector.getParent().name(), self.prefix + '_leg_locator_poleVector_annotation') self.annotation_foot_locator = pm.annotate( self.foot_locator, tx = self.prefix +'_foot_locator' ) pm.rename(self.annotation_foot_locator.getParent().name(), self.prefix + '_foot_locator_annotation') pm.select(cl = True) #Parent constrain annotation transforms pm.parentConstraint(self.leg_locator_base, self.annotation_leg_locator_base.getParent(), mo = False) pm.parentConstraint(self.leg_locator_knee, self.annotation_leg_locator_knee.getParent(), mo = False) pm.parentConstraint(self.leg_locator_tip, self.annotation_leg_locator_tip.getParent(), mo = False) pm.parentConstraint(self.leg_locator_poleVector, self.annotation_leg_locator_poleVector.getParent(), mo = False) pm.parentConstraint(self.foot_locator, self.annotation_foot_locator.getParent(), mo = False) pm.select(cl = True)
def lcTxGn_init_shaders(*args, **kwargs): ''' make the shader if it does not exist update connections if it does ''' renderMode = pm.text(prefix + '_text_vp2mode', query=True, l=True) shaderType = 'dx11Shader' shaderFileExtension = '.fx' if renderMode == 'OpenGL': shaderType = 'GLSLShader' shaderFileExtension = '.glsl' texGenShader = lcShader.ShaderNode(s_texgen_name, shaderType) texGenShader.create() texGenShader.setShaderFile( os.path.join(srcPath, 'shaders', 'lcTexGen{}'.format(shaderFileExtension))) texGenShader.setFileTexture( 'NormalTexture', os.path.join(srcPath, 'shaders', 'texture', 'default_normal.tga')) texGenShader.setFileTexture( 'LitSphereTexture', os.path.join(srcPath, 'shaders', 'texture', 'default_sphere.tga')) texGenShader.setFileTexture( 'TilingSphereTexture', os.path.join(srcPath, 'shaders', 'texture', 'default_tiling.tga')) texGenShader.setFileTexture( 'MaskCube', os.path.join(srcPath, 'shaders', 'texture', 'maskCube.dds')) pm.swatchDisplayPort(prefix + '_swatch_tex', edit=True, shadingNode=texGenShader.shaderName) aoGenShader = lcShader.ShaderNode(s_aogen_name, shaderType) aoGenShader.create() aoGenShader.setShaderFile( os.path.join(srcPath, 'shaders', 'lcAOGen{}'.format(shaderFileExtension))) aoGenShader.setFileTexture( 'NormalTexture', os.path.join(srcPath, 'shaders', 'texture', 'default_normal.tga')) pm.swatchDisplayPort(prefix + '_swatch_ao', edit=True, shadingNode=aoGenShader.shaderName) # make the gradient ramp proxy locators for ramp positions if not pm.objExists('LcTxGn'): lcTxGnGrp = pm.group(n='LcTxGn', empty=True) if not pm.objExists('GradientTop'): gradTop = pm.spaceLocator(n='GradientTop') gradTop.setPosition((0, 5, 0)) gradTop.tx.lock() gradTop.tz.lock() gradTop.rotate.lock() gradTop.scale.lock() gradTop.getShape().localScale.set(2, 2, 2) gradTopAno = lcGeometry.Geometry.getTransformsFromShapes( pm.annotate(gradTop, tx='Gradient Top', p=(1, 7, 0)))[0] gradTopAno.template.set(1) pm.parent(gradTopAno, gradTop) pm.parent('GradientTop', 'LcTxGn') pm.connectAttr(gradTop.ty, aoGenShader.shader.rampTop) if not pm.objExists('GradientBottom'): gradBot = pm.spaceLocator(n='GradientBottom') gradBot.setPosition((0, 0, 0)) gradBot.tx.lock() gradBot.tz.lock() gradBot.rotate.lock() gradBot.scale.lock() gradBot.getShape().localScale.set(2, 2, 2) gradBotAno = \ lcGeometry.Geometry.getTransformsFromShapes(pm.annotate(gradBot, tx='Gradient Bottom', p=(1, 1, 0)))[0] gradBotAno.template.set(1) pm.parent(gradBotAno, gradBot) pm.parent('GradientBottom', 'LcTxGn') pm.connectAttr(gradBot.ty, aoGenShader.shader.rampBottom)