def ckFidgetBump( fdgAttr, bumpDir): """ ckFidgetBump( fdgAttr, bumpDir ) description: evaluates fidget for given attribute, adds or subtracts by percent or increment inputs: fdgAttr: the object.attribute that we will be looking for data in bumpDir: determines if the operation is add or subtract outputs: None """ print "bumping " + str(bumpDir)+ " " + str(fdgAttr) bumpBy = pm.getAttr("ckFidget_GRP.bumpBy") fdgVal = pm.getAttr( fdgAttr ) bumpAmt = pm.melGlobals.get('gckFidgetBump') # bumping by percentage, figure out percentage and adjust fdgVal attribute if(bumpBy == True): print " by percent" bumpAmt = bumpAmt / 100 bumpAmt = fdgVal * bumpAmt if bumpDir == "Up": fdgVal = fdgVal + bumpAmt else: fdgVal = fdgVal - bumpAmt # store adjustment pm.setAttr( fdgAttr, fdgVal)
def displayConnect(self, obj): # Create curve for display, between selected objects # Return [curve, locator1, locator2] if len(obj) == 0: obj = pm.ls(transforms=1, sl=1) if len(obj) < 2: pm.error(u"KH_curve_Connect : 선택된 오브젝트가 없습니다.") pointA = obj[0] pointB = obj[1] curve = pm.curve(p=[(0, 0, 0), (0, 0, 0)], k=[0, 1], d=1) pointCurveConstraint1 = pm.pointCurveConstraint(curve + ".ep[0]", ch=True) pointCurveConstraint2 = pm.pointCurveConstraint(curve + ".ep[1]", ch=True) pointCostraint1 = pm.pointConstraint(pointA, pointCurveConstraint1[0]) pointCostraint2 = pm.pointConstraint(pointB, pointCurveConstraint2[0]) locShape1 = pm.listRelatives(pointCurveConstraint1[0], s=1) locShape2 = pm.listRelatives(pointCurveConstraint2[0], s=1) pm.setAttr(locShape1[0] + ".visibility", 0) pm.setAttr(locShape2[0] + ".visibility", 0) return [ curve, pm.PyNode(pointCurveConstraint1[0]), pm.PyNode(pointCurveConstraint2[0]), pointCostraint1, pointCostraint2 ]
def sd_random_y_offset(selection, y_value, both_directions=True): """ Randomly offsets objects in the range of -n to n where n is the y_value if both_directions is True :param selection: The current selection. :param y_value: -n to n where n is y_value :param both_directions: clamps the range to 0 to n where n is y_value :return: None """ # for obj in _is_group(selection): for obj in selection: pm.select(obj) if y_value == 0: y_random = 0 else: y_random = random.uniform(-y_value, y_value) if not both_directions: y_random = abs(y_random) if type(obj) == pm.MeshVertex: pm.setAttr('{}.pnty'.format(obj), y_random) else: obj.setAttr('translateY', y_random) pm.select(selection) return None
def changePresetPreComp(self): if not self.bashMode: value = pm.optionMenu(self.UI.preCompNuke_CB, query=True, value=True) pm.setAttr('vraySettings.deeXVrayFastLastPresetPreComp', value, type='string') self.actualPresetPrecomp = value else: pm.setAttr('vraySettings.deeXVrayFastLastPresetPreComp', self.actualPresetPrecomp, type='string') self.preCompInit() self.refresh()
def edit_blinn(self, *args): if not self.normal_shader: if not self.blinn_tex_warning: pm.displayWarning('you havent made a blinn yet you potato!') self.blinn_tex_warning = True else: newColour = pm.colorSliderGrp(self.blinnCol, q=True, rgbValue=True) pm.setAttr('%s.color' % self.normal_shader, newColour, type='double3')
def removeMultimatteMask(self, layer = None, number = None): if layer is None: OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass') return actualList = pm.getAttr(layer + '_arsenalPass.multimatteMaskName') if actualList in ('default', '', ' '): actualList = '{}' actualList = eval(actualList) if number in actualList: actualList.pop(number) pm.setAttr(layer + '_arsenalPass.multimatteMaskName', str(actualList))
def setValue(self, attribute = None, value = None, node = None): if node is None or not pm.objExists(node): OpenMaya.MGlobal.displayError('[Arsenal] Node ' + str(node) + 'does not exist') return if attribute is None: OpenMaya.MGlobal.displayError('[Arsenal] Attribute not found on the pass') return if value is None: OpenMaya.MGlobal.displayError('[Arsenal] No value gave to the pass') return if not pm.objExists(node + '.' + attribute): OpenMaya.MGlobal.displayError('[Arsenal] Attribute not found on the node ' + node) return pm.setAttr(node + '.' + attribute, value)
def at_selection(self, **kwargs): # get inputs setup_name = kwargs.get("name", None) path_name = kwargs.get("path", None) sample_obj = kwargs.get("sample", None) obj_lst = kwargs.get("selection_list", None) full_length = pm.arclen(path_name) paramVal = [] uVal = [] for obj in obj_lst: pos = pm.xform(obj, query=True, translation=True, worldSpace=True) param = self.getuParamVal(pnt=pos, crv=path_name) paramVal.append(param) crv_shp = pm.listRelatives(path_name, shapes=True)[0] arcLen = pm.arcLengthDimension(crv_shp + ".u[0]") for val in paramVal: pm.setAttr(str(arcLen) + ".uParamValue", val) len_at_pos = pm.getAttr(str(arcLen) + ".arcLength") uVal.append(len_at_pos / full_length) pm.delete(arcLen) path_anim_list = [] if not self.get_use_selection(): obj_lst = [] if sample_obj: for i in uVal: obj_lst.append( pm.duplicate(sample_obj, name=setup_name + str(i + 1) + "_OBJECT")) else: for i in uVal: pm.select(clear=True) obj_lst.append( pm.joint(name=setup_name + str(i + 1) + "_JNT")) index = 0 for u in uVal: pm.select(clear=True) pathanim = pm.pathAnimation(obj_lst[index], curve=path_name, fractionMode=True, follow=True, followAxis="x", worldUpType="vector", worldUpVector=(0, 1, 0)) index += 1 path_anim_list.append(pathanim) pm.setAttr(str(pathanim) + ".uValue", u) pm.disconnectAttr(str(pathanim) + ".u") return (obj_lst, path_anim_list)
def initializePythonScript(self): if not pm.objExists('vraySettings.postTranslatePython'): return False pm.setAttr('vraySettings.postTranslatePython', lock=False) actualValue = pm.getAttr('vraySettings.postTranslatePython') toAdd = '' if 'import arsenalFunction;' not in actualValue: toAdd += 'import arsenalFunction;' if 'reload(arsenalFunction);' not in actualValue: toAdd += 'reload(arsenalFunction);' if 'arsenalFunction.arsenalFunction();' not in actualValue: toAdd += 'arsenalFunction.arsenalFunction();' pm.setAttr('vraySettings.postTranslatePython', toAdd + actualValue) if pm.control('vrayPostTranslatePythonCallbackControl', query=True, ex=True): pm.scrollField('vrayPostTranslatePythonCallbackControl', edit=True, text=toAdd) return True
def setValue(self, renderPass = None, attribute = None, value = None): if renderPass is None: OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass') return if attribute is None: OpenMaya.MGlobal.displayError('[Arsenal] Attribute not found on the pass') return if value is None: OpenMaya.MGlobal.displayError('[Arsenal] No value gave to the pass') return pm.setAttr(renderPass + '_arsenalPass.' + attribute, value) if pm.objExists('vraySettings.' + attribute): pm.setAttr('vraySettings.' + attribute, value) self.initAttributes(attribut=attribute, renderPass=renderPass, fromRenderGlobal=True) else: self.initAttributes(attribut=attribute, renderPass=renderPass)
def ckAddToList(fdgAttr, fdgVal): """ ckAddToList(fdgAttr, fdgVal): description: adds value in fdgVal to the list located at fdgAttr assumes the list always ends with ; inputs: fdgAttr: the object.attribute that we will be looking for data in fdgVal: the data we will be adding to the list outputs: None """ ckAttr = pm.getAttr(fdgAttr) ckAttr = ckAttr + str(fdgVal) + ";" pm.setAttr(fdgAttr, ckAttr )
def writeMultimatteMask(self, name = None, layer = None, number = None): if layer is None: OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass') return actualList = pm.getAttr(layer + '_arsenalPass.multimatteMaskName') if actualList in ('default', '', ' '): actualList = '{}' actualList = eval(actualList) if len(actualList) != 0: if name in actualList.values() and number not in actualList: OpenMaya.MGlobal.displayError('[Arsenal] You must to choose an another name') return False if not self.checkStringName(text=name): OpenMaya.MGlobal.displayError('[Arsenal] You must to choose a valid name') return False actualList[number] = name pm.setAttr(layer + '_arsenalPass.multimatteMaskName', str(actualList)) self.passName[pm.PyNode(layer)].multimatteMaskName = actualList return True
def ckAddFidget(): """ ckAddFidget( ) description: this function collects the selected attribute and adds it to the list of data that fidget will work with inputs: None outputs: None CK - this would be a great place to add data to a persistent node in the maya file(working) """ # fist we are collecting the selected attribute atribSel = pm.mel.eval('selectedChannelBoxAttributes();') # then we get the object said attribute belongs to slectItm = pm.ls( selection = True ) # the two are added together so we can work with the information # inside the maya context newAttr = slectItm.pop() + '.' + atribSel.pop() # this is a test to ensure that we are in fact getting some kind of data from # the attribute newVal = pm.getAttr( newAttr ) print newVal pm.select( clear = True ) # given that has worked we will add the data to the lists ckAddToList( "ckFidget_GRP.ckFidgetList", newAttr) ckAddToList( "ckFidget_GRP.ckFidgetSav", newVal) pm.group(name = str(newAttr+"_SAV0" )) pm.addAttr( longName="fdgSave", dataType="string", keyable=False) newAttr = newAttr.split(".") pm.setAttr( str(newAttr[0]+"_"+newAttr[1]+"_SAV0.fdgSave"), str(newVal)) pm.select( "ckFidget_GRP") pm.parent( str(newAttr[0]+"_"+newAttr[1]+"_SAV0") ) pm.select( clear = True ) pm.select(newAttr[0]) # now issue the call to rebuild the interface ckFidgetWin()
def ckSavRstZerAll( fdgOps ): """ ckSavRstZerAll( fdgAttr, fdgOps ) description: saves, restores, or zeros all attributes listed in fidget set. inputs: fdgOps: the operation to complete, save or restore outputs: None """ print fdgOps + "ing all fidgets in dataset" ckList = ckGetList("ckFidget_GRP.ckFidgetList") for fdg in ckList: if fdgOps == "save": ckSavRst(fdg, fdgOps) elif fdgOps == "restore": ckSavRst(fdg, fdgOps) else: pm.setAttr(fdg, 0)
def setSimpleValue(self, selection = list(), attribute = None, value = None, message = None): if len(selection) == 0: OpenMaya.MGlobal.displayError('[Arsenal] You must to have a selection') return if attribute is None: OpenMaya.MGlobal.displayError('[Arsenal] Attribute not found') return if value is None: OpenMaya.MGlobal.displayError('[Arsenal] No value gave') return for sel in selection: if pm.objExists(sel + '.' + attribute): con = pm.listConnections(sel + '.' + attribute, d=False, s=True) if con: if len(con) != 0: return print '[Arsenal] ' + str(sel) + ' :' pm.setAttr(sel + '.' + attribute, value) if message is not None: print ' ' + message
def uniform_distribution(self, **kwargs): setup_name = kwargs.get("name", None) path_name = kwargs.get("path", None) sample_obj = kwargs.get("sample", None) divisions = kwargs.get("divisions", None) count = 0 part = float(1) / float(divisions) init = 0 obj_lst = [] path_anim_list = [] if not sample_obj: for i in range(divisions): pm.select(clear=True) obj_lst.append(pm.joint(name=setup_name + str(i + 1) + "_JNT")) else: for i in range(divisions): obj_lst.append( pm.duplicate(sample_obj, name=setup_name + str(i + 1) + "_Object")) index = 0 while count < divisions: pathanim = pm.pathAnimation(obj_lst[index], curve=path_name, fractionMode=True, follow=True, followAxis="x", worldUpType="vector", worldUpVector=(0, 1, 0)) index += 1 path_anim_list.append(pathanim) pm.setAttr(str(pathanim) + ".uValue", init) pm.disconnectAttr(str(pathanim) + ".u") init += part count += 1 return (obj_lst, path_anim_list)
def rsPhysicalLight(): mel.eval('redshiftCreateLight("RedshiftPhysicalLight")') light = ls(selection=True)[0] setAttr(light + '.colorMode', 1) setAttr(light + '.intensity', 10) setAttr(light + '.areaVisibleInRender', 0) locator = spaceLocator() move(locator, (0, 0, -1)) setAttr(locator + '.inheritsTransform', 0) locator.setParent(light) aim = aimConstraint(locator, light) setAttr(aim + '.aimVector', (0, 0, -1)) position = autoPlace() move(light, position, relative=True) move(locator, position, relative=True) rename(locator, '{}_aim'.format(light)) modelEditor('modelPanel4', e=True, lights=True, locators=True)
def ckFidgetInit(): """ ckFidgetInit() description: this function should initialize ckFidget it should check for existing persistent data and create a new node if none exists then it creates the interface inputs: None outputs: initializes ckFidget """ try: print "checking for persistent fidget data" pm.select("ckFidget_GRP") isFidget = pm.getAttr("ckFidget_GRP.ckIsFidget") if isFidget == True: print "Data Found!" pm.setAttr("ckFidget_GRP.bumpBy", False) except: print "data not found initializing new ckFidget instance" pm.group(empty=True, name="ckFidget_GRP") pm.addAttr( longName="ckIsFidget", attributeType='bool', keyable=False ) pm.setAttr("ckFidget_GRP.ckIsFidget", True) pm.addAttr( longName="bumpBy", attributeType='bool', keyable=False ) pm.setAttr("ckFidget_GRP.bumpBy", False) pm.addAttr( longName="ckFidgetBump", attributeType='float', keyable=False, defaultValue=0.1 ) pm.addAttr( longName="numSaves", attributeType="short", keyable=False, defaultValue=0 ) print "here is where I should ask about starting a new fidget" # should pop up a dialog and ask the name of the new fidget pm.addAttr( longName="ckFidgetList", dataType='string', keyable=False ) pm.addAttr( longName="ckFidgetSav", dataType='string', keyable=False ) pm.setAttr( "ckFidget_GRP.ckFidgetList","" ) pm.setAttr( "ckFidget_GRP.ckFidgetSav","" ) pm.select( clear = True ) ckFidgetWin()
def ckSavRst(fdgAttr, fdgOps ): """ ckSavRst() description: saves or restores values from fidget data inputs: fdgAttr: the object.attribute pair we will be working with fdgOps: the operation to complete, save or restore outputs: None """ print str(fdgOps) + "ing entry for, ", fdgAttr fdgGrp = fdgAttr.split(".") if fdgOps == "save": fdgSav = pm.getAttr(fdgAttr) pm.setAttr(str("ckFidget_GRP|"+fdgGrp[0]+"_"+fdgGrp[1]+"_SAV0.fdgSave"), str(fdgSav) ) else: fdgSav = pm.getAttr(str("ckFidget_GRP|"+fdgGrp[0]+"_"+fdgGrp[1]+"_SAV0.fdgSave")) pm.setAttr(fdgAttr, float(fdgSav))
def loadeRenderGlobal(): if not pm.objExists('renderInfoNode'): print u'lightInfoNode 가 존재 하지 않습니다.' return if( pm.getAttr( 'defaultRenderGlobals.currentRenderer' ) != 'arnold' ): pm.setAttr('defaultRenderGlobals.currentRenderer', 'arnold') renderInfoNode = pm.PyNode('renderInfoNode') renderInfo = json.loads(renderInfoNode.renderInfo.get()) for attr, value in renderInfo.items(): try: attrNode = pm.PyNode(attr) attrNode.set(value) except: pass #print '{} failed set value {}.'.format(attr, value) renderInfoNode.unlock() pm.delete(renderInfoNode) print u'렌더 셋팅을 성공 적으로 로드 하였습니다.'
def optimizeMat(self, layerMode = False, minSub = 8, maxSubd = 92): maxGlo = 1 minGlo = 0 allMaterials = pm.ls(type=['VRayCarPaintMtl', 'VRayFastSSS2', 'VRayMtl']) for myMat in allMaterials: reflectanceAttributes = {'["reflectionGlossiness"]': 'reflectionSubdivs', '["refractionGlossiness"]': 'refractionSubdivs', '["glossiness"]': 'reflectionSubdivs', '["coat_glossiness", "base_glossiness"]': 'subdivs'} for gloAttList in reflectanceAttributes: if pm.objExists(myMat + '.' + reflectanceAttributes[gloAttList]): if not pm.getAttr(myMat + '.' + reflectanceAttributes[gloAttList], lock=True) and len(pm.listConnections(myMat + '.' + reflectanceAttributes[gloAttList], d=False, s=True)) == 0: lastMoyeneValue = 1 first = True go = False for gloAtt in eval(gloAttList): if pm.objExists(myMat + '.' + gloAtt) and len(pm.listConnections(myMat + '.' + gloAtt, d=False, s=True)) == 0: gloValue = pm.getAttr(myMat + '.' + gloAtt) if first: lastMoyeneValue = gloValue first = False else: lastMoyeneValue = (lastMoyeneValue + gloValue) / 2 go = True if go: value = (lastMoyeneValue - maxGlo) * (maxSubd - minSub) / (minGlo - maxGlo) + minSub if layerMode: if pm.editRenderLayerGlobals(query=True, currentRenderLayer=True) == 'defaultRenderLayer': OpenMaya.MGlobal.displayError('[Arsenal Quality] You can not use layerMode if you are on masterLayer') return pm.editRenderLayerAdjustment(myMat + '.' + reflectanceAttributes[str(gloAttList)]) pm.setAttr(myMat.name() + '.' + reflectanceAttributes[str(gloAttList)], value) print '[Arsenal Quality] ' + str(value) + ' setted on attribute ' + reflectanceAttributes[str(gloAttList)] + ' for material ' + myMat.name() print '[Arsenal Quality] All materials optimized.'
def replaceInstances(self, parentNode, instanceNodes): for instanceNode in instanceNodes: trans = pm.getAttr(str(instanceNode) + '.translate') rot = pm.getAttr(str(instanceNode) + '.rotate') scl = pm.getAttr(str(instanceNode) + '.scale') pm.delete(instanceNode) pm.duplicate(parentNode, name=str(instanceNode)) pm.setAttr(str(instanceNode) + '.translate', trans) pm.setAttr(str(instanceNode) + '.rotate', rot) pm.setAttr(str(instanceNode) + '.scale', scl) return
def backSetting(self, *args): if pm.attributeQuery('deeXVrayFastActualSettings', n='vraySettings', ex=True): if pm.objExists('deeXVrayFastExpression'): pm.delete('deeXVrayFastExpression') print '[Arsenal Quality] OdeeXVrayFastExpression deleted.' lines = pm.getAttr('vraySettings.deeXVrayFastActualSettings') dico = eval(lines) for myAttr in dico: value = dico[myAttr] if type(dico[myAttr]) == list: value = dico[myAttr][0] if value: try: locked = 0 if pm.getAttr('vraySettings.' + myAttr, lock=True) == 1: pm.setAttr('vraySettings.' + myAttr, lock=False) locked = 1 pm.setAttr('vraySettings.' + myAttr, value) if locked == 1: pm.setAttr('vraySettings.' + myAttr, lock=True) except: print '[Arsenal Quality] ' + myAttr + ' value can not be setted.' locked = False if pm.lockNode('vraySettings', query=True, lock=True)[0]: locked = True pm.lockNode('vraySettings', lock=False) attToDelete = ['deeXVrayFastLastQuality', 'deeXVrayFastOptimized', 'deeXVrayFastActualSettings', 'deeXVrayFastoptimizationChooserSettings', 'deeXVrayFastLastTypePreset', 'deeXVrayFastLastPresetPreComp'] for myAttr in attToDelete: if pm.attributeQuery(myAttr, n='vraySettings', ex=True): pm.deleteAttr('vraySettings.' + myAttr) if locked: pm.lockNode('vraySettings', lock=True) print '[Arsenal Quality] Original settings applied.' else: print '[Arsenal Quality] deeXVrayFastActualSettings attribute not found'
def vtx_normal_length(self, *args): oSel = pm.ls(sl=True, flatten=True) length = pm.floatSliderGrp(self.float3, q=True, value=True) for objs in oSel: name = objs.name() pm.setAttr('%s.normalSize' % name, length)
def btn_hide_vts_normals(self, *args): oSel = pm.ls(sl=True, flatten=True) for objs in oSel: name = objs.name() pm.setAttr('%s.normalType' % name, 2) pm.setAttr('%s.displayNormal' % name, 0)
def createCtrl(self, name): #cameraName = camera[0].name() cameraShape = self.camera.getShape() # 그룹 리깅 constraint = pm.group(n=name + "_constraint", em=True) offset = pm.group(n=name + "_offset") shakeTransform = pm.group(n=name + "_Shake") offsetTz = pm.group(n=name + "_offsetTz") offsetTy = pm.group(n=name + "_offsetTy") offsetTx = pm.group(n=name + "_offsetTx") tz = pm.group(n=name + "_tz") rz = pm.group(n=name + "_rz") rx = pm.group(n=name + "_rx") ry = pm.group(n=name + "_ry") ctrl = pm.group(n=name + "_Ctrl") pm.setAttr(ctrl + ".displayHandle", 1) pm.setAttr(ctrl + ".overrideEnabled", 1) pm.setAttr(ctrl + ".overrideColor", 7) #dark_green # Display dispGrp = pm.group(n=name + "_Template_Grp", em=1) pm.parent(dispGrp, ctrl) pm.setAttr(dispGrp + ".overrideEnabled", 1) pm.setAttr(dispGrp + ".overrideDisplayType", 1) pm.setAttr(dispGrp + ".overrideColor", 7) #dark_green dispNodeList = [] dispNodeList.extend(self.displayConnect([ctrl, tz])) dispNodeList.extend(self.displayConnect([tz, offsetTx])) dispNodeList.extend(self.displayConnect([offsetTx, offsetTy])) dispNodeList.extend(self.displayConnect([offsetTy, offsetTz])) # Outline for dispNode in dispNodeList: dispNode.rename(name + '_' + dispNode.name()) pm.parent(dispNodeList, dispGrp) # Add attribute # Camera attribute pm.addAttr(ctrl, ln="Camera", en="Option:", at="enum") pm.setAttr(ctrl + ".Camera", e=1, channelBox=True) pm.addAttr(ctrl, ln="focalLength", dv=35, at='double', nn="FocalLength (mm)", keyable=True) pm.addAttr(ctrl, ln="overscan", dv=1, at='double', nn="Overscan", keyable=True) pm.addAttr(ctrl, ln="frameRange", at='double2', nn="Frame Range (frame)") pm.addAttr(ctrl, ln="startFrame", p='frameRange', at='double', nn="Start Frame", keyable=True) pm.addAttr(ctrl, ln="endFrame", p='frameRange', at='double', nn="End Frame", keyable=True) # Tumble attribute pm.addAttr(ctrl, ln="Tumble", en="Option:", at="enum") pm.setAttr(ctrl + ".Tumble", e=1, channelBox=True) pm.addAttr(ctrl, ln="tumbleTranslateZ", at='double', nn="Tumble Translate Z", keyable=True) pm.addAttr(ctrl, ln="tumbleRotate", at='double3', nn="Tumble Rotate") pm.addAttr(ctrl, ln="tumbleRotateX", p='tumbleRotate', at='double', nn="Tumble Rotate X", keyable=True) pm.addAttr(ctrl, ln="tumbleRotateY", p='tumbleRotate', at='double', nn="Tumble Rotate Y", keyable=True) pm.addAttr(ctrl, ln="tumbleRotateZ", p='tumbleRotate', at='double', nn="Tumble Rotate Z", keyable=True) # Shake attribute pm.addAttr(ctrl, ln="Shake", en="Option:", at="enum") pm.setAttr(ctrl + ".Shake", e=1, channelBox=True) pm.addAttr(ctrl, ln="time", keyable=False, at='double', nn="Shake Time (second)") pm.addAttr(ctrl, ln="timeOffset", keyable=False, at='double', nn="Shake Time Offset (second)") pm.addAttr(ctrl, ln="shake1", at='double2', nn=u"Shake 1st (진폭, 주기)") pm.addAttr(ctrl, ln="shakeAmplitude1", p='shake1', at='double', nn=u"Shake 1st (진폭)", keyable=True) pm.addAttr(ctrl, ln="shakeFrequency1", p='shake1', at='double', nn=u"Frequency 1st (주기)", keyable=True) pm.addAttr(ctrl, ln="noise1", at='double3', nn="Shake Noise 1st") pm.addAttr(ctrl, ln="noise1X", p='noise1', at='double', nn="Shake Noise 1 X") pm.addAttr(ctrl, ln="noise1Y", p='noise1', at='double', nn="Shake Noise 1 Y") pm.addAttr(ctrl, ln="noise1Z", p='noise1', at='double', nn="Shake Noise 1 Z") pm.addAttr(ctrl, ln="shake2", at='double2', nn=u"Shake 2nd (진폭, 주기)") pm.addAttr(ctrl, ln="shakeAmplitude2", p='shake2', at='double', nn=u"Shake 2nd (진폭)", keyable=True) pm.addAttr(ctrl, ln="shakeFrequency2", p='shake2', at='double', nn=u"Frequency 2nd (주기)", keyable=True) pm.addAttr(ctrl, ln="noise2", at='double3', nn="Shake Noise 2nd") pm.addAttr(ctrl, ln="noise2X", p='noise2', at='double', nn="Shake Noise 2 X") pm.addAttr(ctrl, ln="noise2Y", p='noise2', at='double', nn="Shake Noise 2 Y") pm.addAttr(ctrl, ln="noise2Z", p='noise2', at='double', nn="Shake Noise 2 Z") pm.addAttr(ctrl, ln="shakeTranslate", at='double3', nn="Shake Translate") pm.addAttr(ctrl, ln="shakeTranslateX", p='shakeTranslate', at='double', nn="Shake Translate X", keyable=True) pm.addAttr(ctrl, ln="shakeTranslateY", p='shakeTranslate', at='double', nn="Shake Translate Y", keyable=True) pm.addAttr(ctrl, ln="shakeTranslateZ", p='shakeTranslate', at='double', nn="Shake Translate Z", keyable=True) pm.addAttr(ctrl, ln="shakeRotate", at='double3', nn="Shake Rotate") pm.addAttr(ctrl, ln="shakeRotateX", p='shakeRotate', at='double', nn="Shake Rotate X", keyable=True) pm.addAttr(ctrl, ln="shakeRotateY", p='shakeRotate', at='double', nn="Shake Rotate Y", keyable=True) pm.addAttr(ctrl, ln="shakeRotateZ", p='shakeRotate', at='double', nn="Shake Rotate Z", keyable=True) pm.addAttr(ctrl, ln="shakeScale", at='double', dv=1.0, keyable=True) pm.addAttr(ctrl, ln="timeScale", at='double', dv=1.0, keyable=True) # Offset attribute pm.addAttr(ctrl, ln="Offset", en="Option:", at="enum") pm.setAttr(ctrl + ".Offset", e=1, channelBox=True) pm.addAttr(ctrl, ln="offsetTranslate", at='double3', nn="Offset Translate") pm.addAttr(ctrl, ln="offsetTranslateX", p='offsetTranslate', at='double', nn="Offset Translate X", keyable=True) pm.addAttr(ctrl, ln="offsetTranslateY", p='offsetTranslate', at='double', nn="Offset Translate Y", keyable=True) pm.addAttr(ctrl, ln="offsetTranslateZ", p='offsetTranslate', at='double', nn="Offset Translate Z", keyable=True) pm.addAttr(ctrl, ln="offsetRotate", at='double3', nn="Offset Rotate") pm.addAttr(ctrl, ln="offsetRotateX", p='offsetRotate', at='double', nn="Offset Rotate X", keyable=True) pm.addAttr(ctrl, ln="offsetRotateY", p='offsetRotate', at='double', nn="Offset Rotate Y", keyable=True) pm.addAttr(ctrl, ln="offsetRotateZ", p='offsetRotate', at='double', nn="Offset Rotate Z", keyable=True) # Display attribute pm.addAttr(ctrl, ln="Display", en="Option:", at="enum") pm.setAttr(ctrl + ".Display", e=1, channelBox=True) pm.addAttr(ctrl, ln="cameraScale", dv=1, at='double', nn="Camera Scale", keyable=True) pm.addAttr(ctrl, en="off:on:", nn="Display Ctrler", ln="displayCtrler", keyable=1, at="enum", dv=1) # Connect Attr pm.connectAttr(ctrl + ".cameraScale", name + ".sx") pm.connectAttr(ctrl + ".cameraScale", name + ".sy") pm.connectAttr(ctrl + ".cameraScale", name + ".sz") pm.connectAttr(ctrl + ".focalLength", cameraShape + ".focalLength") pm.connectAttr(ctrl + ".overscan", cameraShape + ".overscan") pm.connectAttr(ctrl + ".tumbleRotateX", rx + ".rx") pm.connectAttr(ctrl + ".tumbleRotateY", ry + ".ry") pm.connectAttr(ctrl + ".tumbleRotateZ", rz + ".rz") pm.connectAttr(ctrl + ".tumbleTranslateZ", tz + ".tz") pm.connectAttr(ctrl + ".offsetTranslateX", offsetTx + ".tx") pm.connectAttr(ctrl + ".offsetTranslateY", offsetTy + ".ty") pm.connectAttr(ctrl + ".offsetTranslateZ", offsetTz + ".tz") pm.connectAttr(ctrl + ".offsetRotate", offset + ".r") pm.connectAttr(ctrl + ".displayCtrler", dispGrp + ".v") # Lock and Hide unused attr attrList = [ "_ry.tx", "_ry.ty", "_ry.tz", "_ry.rx", "_ry.rz", "_ry.sx", "_ry.sy", "_ry.sz", "_ry.v", "_rx.tx", "_rx.ty", "_rx.tz", "_rx.ry", "_rx.rz", "_rx.sx", "_rx.sy", "_rx.sz", "_rx.v", "_rz.tx", "_rz.ty", "_rz.tz", "_rz.rx", "_rz.ry", "_rz.sx", "_rz.sy", "_rz.sz", "_rz.v", "_tz.tx", "_tz.ty", "_tz.rx", "_tz.ry", "_tz.rz", "_tz.sx", "_tz.sy", "_tz.sz", "_tz.v", "_offsetTx.ty", "_offsetTx.tz", "_offsetTx.rx", "_offsetTx.ry", "_offsetTx.rz", "_offsetTx.sx", "_offsetTx.sy", "_offsetTx.sz", "_offsetTx.v", "_offsetTy.tx", "_offsetTy.tz", "_offsetTy.rx", "_offsetTy.ry", "_offsetTy.rz", "_offsetTy.sx", "_offsetTy.sy", "_offsetTy.sz", "_offsetTy.v", "_offsetTz.tx", "_offsetTz.ty", "_offsetTz.rx", "_offsetTz.ry", "_offsetTz.rz", "_offsetTz.sx", "_offsetTz.sy", "_offsetTz.sz", "_offsetTz.v", "_offset.sx", "_offset.sy", "_offset.sz", "_offset.v", "_Ctrl.sx", "_Ctrl.sy", "_Ctrl.sz" ] for attr in attrList: pm.setAttr(name + attr, lock=True, channelBox=False, keyable=False) pm.setAttr(cameraShape + ".orthographic", lock=False, channelBox=False, keyable=True) pm.setAttr(cameraShape + ".orthographicWidth", lock=False, channelBox=False, keyable=True) # Constraint camera const = pm.parentConstraint(constraint, self.camera, n=name + '_parentConstraint') pm.setAttr(const + ".nds", lock=True, channelBox=False, keyable=False) pm.setAttr(const + ".int", lock=True, channelBox=False, keyable=False) pm.setAttr(const + ".w0", lock=True, channelBox=False, keyable=False) pm.parent(const, ctrl) # Add and Connect message attr = "camera" nodes = [self.camera, ctrl] for node in nodes: if node.hasAttr(attr): node.deleteAttr(attr) pm.addAttr(node, ln=attr, multi=1, attributeType="message", indexMatters=False) for node in nodes: for i in range(0, 2): pm.connectAttr('{}.message'.format(nodes[i].name()), '{}.{}[{}]'.format(node.name(), attr, str(i)), f=1) # Return self.ctrl = ctrl uitConvertsion = self.ctrl.outputs(type="unitConversion") for uit in uitConvertsion: pm.rename(uit.name(), name + '_' + uit.name()) del self.extNode[:] self.extNode.extend([ constraint, offset, shakeTransform, offsetTz, offsetTy, offsetTx, tz, rz, rx, ry, ctrl ]) self.extNode.extend(dispNodeList) self.extNode.extend(uitConvertsion) pm.select(self.ctrl, r=1) return ctrl
def loadVray(self): pm.loadPlugin('vrayformaya.mll', quiet=True) pm.setAttr('defaultRenderGlobals.currentRenderer', 'vray', type='string') pm.mel.eval('vrayCreateVRaySettingsNode();')
def setCameraForBig(self, ctrl, cameraShape): pm.setAttr(ctrl + ".cameraScale", 10) pm.setAttr(cameraShape + ".nearClipPlane", 1) pm.setAttr(cameraShape + ".farClipPlane", 100000) pm.setAttr(cameraShape + ".displayResolution", 1)
def matchFilmBackToResolution(self, cameraShape): renderGlobal = pm.PyNode('defaultResolution') width = float(renderGlobal.width.get()) height = float(renderGlobal.height.get()) pm.setAttr(cameraShape + ".horizontalFilmAperture", (width / height)) pm.setAttr(cameraShape + ".verticalFilmAperture", 1)
def treadAtPoints(**kwargs): #get inputs tread_name = kwargs.get("tr_name", "Tread") crv = kwargs.get("path_crv", None) crv = str(pm.duplicate(crv, name=str(tread_name) + "PathCrv")[0]) pm.xform(crv, centerPivots=True) #obtain curve length full_length = pm.arclen(crv) paramVal = [] uVal = [] # get param value on the curve at each position selected (locators) sel_obj = pm.ls(selection=True) for obj in sel_obj: pos = pm.xform(obj, query=True, translation=True, worldSpace=True) param = getuParamVal(pos, crv) paramVal.append(param) crv_shp = pm.listRelatives(crv, shapes=True)[0] # create arc length dimension tool arcLen = pm.arcLengthDimension(crv_shp + ".u[0]") # for each param value obtained set the arc length tool attribute and # store the length of curve at that param value # normalize the curve to obtain the motion path U value at each position for val in paramVal: pm.setAttr(str(arcLen) + ".uParamValue", val) len_at_pos = pm.getAttr(str(arcLen) + ".arcLength") uVal.append(len_at_pos / full_length) pm.delete(arcLen) mthPthLst = [] jntLst = [] # create joints, assign motion path and set U value obtained for u in uVal: pm.select(clear=True) jnt = pm.joint() jntLst.append(jnt) pathanim = pm.pathAnimation(jnt, curve=crv, fractionMode=True, follow=True, followAxis="x", worldUpType="vector", worldUpVector=(0, 1, 0)) mthPthLst.append(pathanim) pm.setAttr(str(pathanim) + ".uValue", u) pm.disconnectAttr(str(pathanim) + ".u") # create up locator at mid point of all joints #loc_pos = midPos(selected_items = jntLst) #loc_pos = pm.xform(crv, query=True, translation=True, worldSpace=True) loc_pos = midPosVec(objects=jntLst) loc = pm.spaceLocator() pm.xform(loc, translation=loc_pos, worldSpace=True) for mtPth in mthPthLst: pm.pathAnimation(mtPth, edit=True, worldUpType="object", worldUpObject=loc) # create control curve, add run and speed attributes control_crv = pm.circle(name=tread_name + "CTRL", normalX=1, normalY=0, normalZ=0) pm.xform(control_crv, translation=loc_pos) pm.select(clear=True) pm.addAttr(control_crv, longName="run", attributeType="float", keyable=True) pm.addAttr(control_crv, longName="speed", attributeType="float", keyable=True, minValue=0.0, defaultValue=0.5) # group the tread setup pm.parent(crv, control_crv) pm.parent(loc, control_crv) pm.select(clear=True) gp = pm.group(name=tread_name + "GP") pm.select(clear=True) jnt_gp = pm.group(jntLst, name=tread_name + "JNTGP") pm.xform(gp, translation=loc_pos) pm.parent(control_crv, gp) pm.parent(jnt_gp, gp) createTreadExpression(mtnPth=mthPthLst, runAttr=str(control_crv[0]) + ".run", speedAttr=str(control_crv[0]) + ".speed", exp_nm=tread_name) return None #treadAtPoints(pathCrv = "nurbsCircle1", tr_name = "testTread")
def createTread(**kwargs): # get inputs divisions = kwargs.get("no_of_joints", 0) tread_name = kwargs.get("tr_name", "Tread") path_crv = kwargs.get("path_crv", None) # duplicate the existing curve to use for tread creation path_crv = str(pm.duplicate(path_crv, name=str(tread_name) + "PathCrv")[0]) pm.xform(path_crv, centerPivots=True) count = 0 part = float(1) / float(divisions) init = 0 path_anim_list = [] jnt_lst = [] # create joints and place them on curve using motion path at equal distance while count < divisions: pm.select(clear=True) jnt = pm.joint() jnt_lst.append(jnt) pathanim = pm.pathAnimation(jnt, curve=path_crv, fractionMode=True, follow=True, followAxis="x", worldUpType="vector", worldUpVector=(0, 1, 0)) path_anim_list.append(pathanim) pm.setAttr(str(pathanim) + ".uValue", init) pm.disconnectAttr(str(pathanim) + ".u") init += part count += 1 # obtain the midpoint of all joints to create an up locator and position it at midpoint #loc_pos = midPos(selected_items = jnt_lst) #loc_pos = pm.xform(path_crv, query=True, translation=True, worldSpace=True) loc_pos = midPosVec(objects=jnt_lst) loc = pm.spaceLocator(name=tread_name + "_up_loc") pm.xform(loc, translation=loc_pos) # create a nurb circle to act as parent controller control_crv = pm.circle(name=tread_name + "CTRL", normalX=1, normalY=0, normalZ=0) pm.xform(control_crv, translation=loc_pos) pm.select(clear=True) # add unr and speed attributes on parent nurb curve pm.addAttr(control_crv, longName="run", attributeType="float", keyable=True) pm.addAttr(control_crv, longName="speed", attributeType="float", keyable=True, minValue=0.0, defaultValue=0.5) #edit the existing motion path to assign up locator for mtPth in path_anim_list: pm.pathAnimation(mtPth, edit=True, worldUpType="object", worldUpObject=loc) #parent the setup under the parent nurb curve pm.parent(path_crv, control_crv) pm.parent(loc, control_crv) pm.select(clear=True) gp = pm.group(name=tread_name + "GP") pm.select(clear=True) jnt_gp = pm.group(jnt_lst, name=tread_name + "JNTGP") pm.xform(gp, translation=loc_pos) pm.parent(control_crv, gp) pm.parent(jnt_gp, gp) # call to create expression function createTreadExpression(mtnPth=path_anim_list, runAttr=str(control_crv[0]) + ".run", speedAttr=str(control_crv[0]) + ".speed", exp_nm=tread_name) return None