def import_nodes(self, info_mats): dic_nodes = {} for info_node in info_mats['nodes']: name = info_node['name'] node_type = info_node['type'] # attrs = info_node['node_attr'] if node_type == 'shadingEngine': node = pm.sets(renderable=1, noSurfaceShader=1, empty=1, name=name) elif node_type == 'blinn' or node_type == 'lambert': node = pm.shadingNode(node_type, asShader=1, name=name) elif node_type == 'bulge': node = pm.shadingNode(node_type, at=1, name=name) elif node_type == 'place2dTexture': node = pm.shadingNode(node_type, au=1, name=name) elif node_type == 'file': node = pm.shadingNode('file', asTexture=1, isColorManaged=1, name=name) elif node_type == 'noise': node = pm.shadingNode(node_type, at=1, name=name) else: node = pm.createNode(node_type, n=name) dic_nodes[name] = node return dic_nodes
def attach_fk_ik_to_blend_to_result(i_fk_joints, i_ik_joints, i_result_joints, i_name_prefixes): blend_nodes = [] if len(i_fk_joints) == len(i_ik_joints) and len(i_ik_joints) == len( i_result_joints): for i in range(len(i_fk_joints)): translation_blend = pm.shadingNode('blendColors', au=True, n=i_name_prefixes[i] + "Trans_FKIK_Blend") rotation_blend = pm.shadingNode('blendColors', au=True, n=i_name_prefixes[i] + "Rot_FKIK_Blend") pm.connectAttr(i_ik_joints[i].translate, translation_blend.color1) pm.connectAttr(i_ik_joints[i].rotate, rotation_blend.color1) pm.connectAttr(i_fk_joints[i].translate, translation_blend.color2) pm.connectAttr(i_fk_joints[i].rotate, rotation_blend.color2) pm.connectAttr(translation_blend.output, i_result_joints[i].translate) pm.connectAttr(rotation_blend.output, i_result_joints[i].rotate) blend_nodes.append(translation_blend) blend_nodes.append(rotation_blend) else: print("Mismatching FK/IK/Result Chain Joint Size") return blend_nodes
def create_file_node(path, name): """ creates a file node connected to a place2dTexture node, and sets the file path to given path :param path: a string, image file path :param name: a string, the name for the nodes creation. gets a suffix according to node type :return: a PyNode, the file node created """ file_node = pm.shadingNode('file', n=name + "_file", asTexture=1, isColorManaged=1) p2d_node = pm.shadingNode('place2dTexture', name=name + "_place2dTexture", asUtility=1) attribute_list = [ "coverage", "translateFrame", "rotateFrame", "mirrorU", "mirrorV", "stagger", "wrapU", "wrapV", "repeatUV", "offset", "rotateUV", "noiseUV", "vertexUvOne", "vertexUvTwo", "vertexUvThree", "vertexCameraOne" ] for at in attribute_list: p2d_node.attr(at) >> file_node.attr(at) p2d_node.outUV >> file_node.uv p2d_node.outUvFilterSize >> file_node.uvFilterSize file_node.ftn.set(path) return file_node
def sumAttr(sumCtrl=None, ctrlAttrA=None, ctrlAttrB=None, ctrlAttrResult=None, scaleA=None, scaleB=None): pmaNode = pm.shadingNode('plusMinusAverage',n='%s_Sum'%sumCtrl, asUtility=1) if scaleA: scaleA_node = pm.shadingNode('multiplyDivide',n='%s_ScaleA'%sumCtrl, asUtility=1) pm.setAttr('%s.input1X'%scaleA_node,scaleA) pm.connectAttr(ctrlAttrA,'%s.input2X'%scaleA_node,f=1) pm.connectAttr('%s.outputX'%scaleA_node,'%s.input1D[0]'%pmaNode,f=1) else: pm.connectAttr(ctrlAttrA,'%s.input1D[0]'%pmaNode,f=1) if scaleB: scaleB_node = pm.shadingNode('multiplyDivide',n='%s_ScaleB'%sumCtrl, asUtility=1) pm.setAttr('%s.input1X'%scaleB_node,scaleB) pm.connectAttr(ctrlAttrB,'%s.input2X'%scaleB_node,f=1) pm.connectAttr('%s.outputX'%scaleB_node,'%s.input1D[1]'%pmaNode,f=1) else: pm.connectAttr(ctrlAttrB,'%s.input1D[1]'%pmaNode,f=1) try: pm.addAttr(sumCtrl, ln=ctrlAttrResult.split('.')[1], k=1) except Exception, e: raise( e )
def create_system(self): shader = pm.shadingNode('transmat', asShader= True) volume = pm.polyCube(name= 'fog_volume', width=40, height=40, depth=40)[0] pm.hyperShade(volume, assign= shader) parti_volume = pm.mel.eval('mrCreateCustomNode -asShader "" parti_volume;') pm.setAttr('%s.scatter' % (parti_volume), 1,1,1, type= 'double3' ) pm.setAttr('%s.min_step_len' % (parti_volume), .03) pm.setAttr('%s.max_step_len' % (parti_volume), .2) pm.connectAttr('%s.outValue' % (parti_volume), '%sSG.miVolumeShader' % (shader), force= True) light_node = pm.shadingNode('%s' % (self.light_types[value]), asLight= True) light_node.translate.set(0,15,0) light_node.rotate.set(-90,0,0) light = pm.rename(light_node, 'fog_light') pm.connectAttr('%s.message' % (light.getShape()), '%s.lights[0]' % (parti_volume), force= True) if self.checkBox.getValue() == 1: # mrCreateCustomNode -asUtility "" physical_light; # // Result: Connected physical_light1.message to fog_lightShape.mentalRayControls.miLightShader. // phys_light = pm.mel.eval('mrCreateCustomNode -asUtility "" physical_light;') pm.connectAttr('%s.message' % (phys_light), '%s.mentalRayControls.miLightShader' % (light.getShape()))
def matrixConstrain(driver, driven, parent=None, translate=True, rotate=True, scale=False): driver = pm.ls(driver)[0] driven = pm.ls(driven)[0] if not parent: parent = driven.getParent() mulMatrix = pm.shadingNode('multMatrix', asUtility=True) decomposeMatrix = pm.shadingNode('decomposeMatrix', asUtility=True) pm.connectAttr(mulMatrix.matrixSum, decomposeMatrix.inputMatrix) pm.connectAttr(driver.worldMatrix[0], mulMatrix.matrixIn[0]) pm.connectAttr(parent.worldInverseMatrix[0], mulMatrix.matrixIn[1]) if translate: pm.connectAttr(decomposeMatrix.outputTranslate, driven.translate) if rotate: pm.connectAttr(decomposeMatrix.outputRotate, driven.rotate) if scale: pm.connectAttr(decomposeMatrix.outputScale, driven.scale)
def create_file_node(name=None): """ Create a file node, and its 2dPlacement Node. Kwargs: name (str): file node name Returns: PyNode. Image file node """ file_node = pm.shadingNode('file', name=name, asTexture=True, isColorManaged=True) placement_name = '%s_place2dfile_nodeture' % name placement_node = pm.shadingNode('place2dTexture', name=placement_name, asUtility=True) file_node.filterType.set(0) pm.connectAttr(placement_node.outUV, file_node.uvCoord) pm.connectAttr(placement_node.outUvFilterSize, file_node.uvFilterSize) pm.connectAttr(placement_node.coverage, file_node.coverage) pm.connectAttr(placement_node.mirrorU, file_node.mirrorU) pm.connectAttr(placement_node.mirrorV, file_node.mirrorV) pm.connectAttr(placement_node.noiseUV, file_node.noiseUV) pm.connectAttr(placement_node.offset, file_node.offset) pm.connectAttr(placement_node.repeatUV, file_node.repeatUV) pm.connectAttr(placement_node.rotateFrame, file_node.rotateFrame) pm.connectAttr(placement_node.rotateUV, file_node.rotateUV) pm.connectAttr(placement_node.stagger, file_node.stagger) pm.connectAttr(placement_node.translateFrame, file_node.translateFrame) pm.connectAttr(placement_node.wrapU, file_node.wrapU) pm.connectAttr(placement_node.wrapV, file_node.wrapV) return file_node
def add_rig(jnt, axis, ctrlName, side, attrName): ctrl = pm.ls(ctrlName)[0] # mdl = pm.shadingNode('multDoubleLinear', asUtility=1, name=jnt.name() + '_mdl') num_jnt = int(jnt.name().split('_')[1]) pma = pm.shadingNode('plusMinusAverage', asUtility=1, name=jnt.name() + '_tz_pma') rv = pm.shadingNode('remapValue', asUtility=1, name=jnt.name() + '_tz_rv') rv.attr('inputMin').set(-10) rv.attr('inputMax').set(10) if side == 'left': rv.attr('outputMin').set(-1 * tongue_hor[num_jnt]) rv.attr('outputMax').set(tongue_hor[num_jnt]) elif side == 'right': rv.attr('outputMin').set(tongue_hor[num_jnt]) rv.attr('outputMax').set(-1 * tongue_hor[num_jnt]) else: rv.attr('outputMin').set(-1 * tongue_hor[num_jnt]) rv.attr('outputMax').set(tongue_hor[num_jnt]) # default_val = jnt.attr(axis).get() pma.attr('input1D[0]').set(default_val) rv.attr('outValue') >> pma.attr('input1D[1]') pma.attr('output1D') >> jnt.attr(axis) ctrl.attr(attrName) >> rv.attr('inputValue')
def Maya_createNode(self, nodeType, *args): if nodeType == 'aiStandard': # Ask for name name = self.User_inputDialog("Create aiStandard", "Enter a name for the node: ") # Create and assign shader aiStd = pc.shadingNode('aiStandard', asShader=True, name=name) aiStdSg = pc.sets(renderable=True, noSurfaceShader=True, empty=True, name=name + 'SG') aiStd.outColor >> aiStdSg.surfaceShader self.UI_refreshShaders() return(str(aiStd)) if nodeType == 'file': # Ask for name name = self.User_inputDialog("Create file", "Enter a name for the node: ") # Ask for location of the file location = pc.fileDialog2(fm=1, dialogStyle=2) myTex = pc.shadingNode('file', asTexture=True, name=name) myTex.fileTextureName.set(location) return(str(myTex)) if nodeType == 'ygColorCorrect': # Ask for name name = self.User_inputDialog("Create ygColorCorrect", "Enter a name for the node: ") ygC = pc.shadingNode('ygColorCorrect', asShader=True, name=name) return(str(ygC))
def Maya_createFullNetwork(self, withFile, nodeName, *args): if not withFile: nodeName = self.Maya_createNode('file') fileNode = pc.PyNode(nodeName) aiName = self.Maya_createNode('aiStandard') aiNode = pc.PyNode(aiName) # DiffCC diffCC = pc.shadingNode('ygColorCorrect', asTexture=True, name='diffCC_' + aiNode) # specCC specCC = pc.shadingNode('ygColorCorrect', asTexture=True, name='specCC_' + aiNode) # roughCC roughCC = pc.shadingNode('ygColorCorrect', asTexture=True, name='roughCC_' + aiNode) # bumpCC bumpCC = pc.shadingNode('ygColorCorrect', asTexture=True, name='bumpCC_' + aiNode) # Bump node bumpNode = pc.shadingNode('bump2d', asUtility=True, name='bump_' + aiNode) # Connect everything fileNode.outColor >> diffCC.image fileNode.outColor >> specCC.image fileNode.outColor >> roughCC.image fileNode.outColor >> bumpCC.image bumpCC.outAlpha >> bumpNode.bumpValue bumpNode.outNormal >> aiNode.normalCamera diffCC.outColor >> aiNode.color specCC.outColor >> aiNode.KsColor roughCC.outAlpha >> aiNode.specularRoughness
def create_mr_material(shader_type, shader_name): if not pm.objExists(shader_name): if shader_type == 'aiStandard': shader = pm.shadingNode('mia_material_x', asShader=1, name=shader_name) elif shader_type == 'aiSkinSss': mr_texture = pm.ls(type='mentalrayTexture') if mr_texture: shader = pm.shadingNode('misss_fast_skin_maya', asShader=1, name=shader_name) mr_texture[0].message >> shader.lightmap else: name = mel.eval( "mrCreateCustomNode -asShader \"\" misss_fast_skin_maya;") pm.PyNode(name).rename(shader_name) shader = pm.PyNode(shader_name) elif shader_type == 'aiOf_aiLayerMixer': shader = pm.shadingNode('layeredShader', asShader=1, name=shader_name) return shader else: return pm.PyNode(shader_name)
def setupNetwork(aovName, *args): # If already existing, do nothing listShd = pc.ls(aovName+'_SHD') if len(listShd) == 0: # aiUserDataColor dataColor = pc.shadingNode('aiUserDataColor', asShader=True, name=aovName+'DataColor') dataColor.setAttr('colorAttrName', aovName, type='string') # aiWriteColor writeColor = pc.shadingNode('aiWriteColor', asShader=True, name=aovName+'WriteColor') # Target aiStandard aiStd = pc.shadingNode('surfaceShader', asShader = True, name=aovName+'_SHD') # Make connections dataColor.outColor >> writeColor.beauty writeColor.outColor >> aiStd.outColor # Creates AOV aovs.AOVInterface().addAOV('id_'+aovName) idAov = pc.PyNode('aiAOV_id_'+aovName) # Connect the shader previously created to the default shader input of the AOV aiStd.outColor >> idAov.defaultValue else: print "Network already in place. Skipping setup."
def stretchy_twist_joints(self): locators, distance_node = self.distance_between_points_measure( self.twist_origin, self.twist_end) stretchy_reference_group = pm.group(empty=True) self.name_convention.rename_based_on_base_name( self.twist_origin, stretchy_reference_group, name="stretchyReferencePoints") stretchy_reference_group.setParent(self.rig_system.kinematics) pm.parent(locators, stretchy_reference_group) twist_joint_divide = pm.shadingNode("multiplyDivide", asUtility=True) scale_compensation = pm.shadingNode("multiplyDivide", asUtility=True, name="StretchScaleCompensation") self.name_convention.rename_name_in_format(twist_joint_divide, name="StretchyTwistJoint") pm.connectAttr("%s.distance" % distance_node, "{}.input1X".format(twist_joint_divide)) pm.setAttr("%s.input2X" % twist_joint_divide, (len(self.joints) - 1)) pm.connectAttr("{}.outputX".format(twist_joint_divide), "{}.input1X".format(scale_compensation)) pm.connectAttr("{}.scaleX".format(self.reset_joints[0]), "{}.input2X".format(scale_compensation)) # twist_origin pm.setAttr("{}.operation".format(twist_joint_divide), 2) pm.setAttr("{}.operation".format(scale_compensation), 2)
def create_file_node(name=None): """ Create a file node, with a place2dTexture node attached. This is similar to importImageFile, but that function spews a lot of junk to the console. """ texture = pm.shadingNode('file', asTexture=True, isColorManaged=True, ss=True) if name is not None: pm.rename(texture, name) place = pm.shadingNode('place2dTexture', asUtility=True, ss=True) place.coverage.connect(texture.coverage) place.translateFrame.connect(texture.translateFrame) place.rotateFrame.connect(texture.rotateFrame) place.mirrorU.connect(texture.mirrorU) place.mirrorV.connect(texture.mirrorV) place.stagger.connect(texture.stagger) place.wrapU.connect(texture.wrapU) place.wrapV.connect(texture.wrapV) place.repeatUV.connect(texture.repeatUV) place.offset.connect(texture.offset) place.rotateUV.connect(texture.rotateUV) place.noiseUV.connect(texture.noiseUV) place.vertexUvOne.connect(texture.vertexUvOne) place.vertexUvTwo.connect(texture.vertexUvTwo) place.vertexUvThree.connect(texture.vertexUvThree) place.vertexCameraOne.connect(texture.vertexCameraOne) place.outUV.connect(texture.uv) place.outUvFilterSize.connect(texture.uvFilterSize) return texture, place
def create(cls, path, place='2d'): '''creates a file node with its ''' file_node = pc.shadingNode(cls.nodeType, asTexture=True) file_node.attr('ftn').set(path) if place == '2d': place_node = pc.shadingNode('place2dTexture', asUtility=True) place_node.coverage >> file_node.coverage place_node.translateFrame >> file_node.translateFrame place_node.rotateFrame >> file_node.rotateFrame place_node.mirrorU >> file_node.mirrorU place_node.mirrorV >> file_node.mirrorV place_node.stagger >> file_node.stagger place_node.wrapU >> file_node.wrapU place_node.wrapV >> file_node.wrapV place_node.repeatUV >> file_node.repeatUV place_node.offset >> file_node.offset place_node.rotateUV >> file_node.rotateUV place_node.noiseUV >> file_node.noiseUV place_node.vertexUvOne >> file_node.vertexUvOne place_node.vertexUvTwo >> file_node.vertexUvTwo place_node.vertexUvThree >> file_node.vertexUvThree place_node.vertexCameraOne >> file_node.vertexCameraOne place_node.outUV >> file_node.uv place_node.outUvFilterSize >> file_node.uvFilterSize return cls(file_node)
def texNode(cgfx, texType, shdName): """ :return: """ import pymel.core as pm # create file nodes for all textures and set them up texFile = pm.shadingNode("file", asTexture = True, n = str(shdName+texType+"_File")) placeUV = pm.shadingNode("place2dTexture", asUtility = True, n = str(shdName+texType+"_uvPlace")) placeUV.coverage >> texFile.coverage placeUV.translateFrame >> texFile.translateFrame placeUV.rotateFrame >> texFile.rotateFrame placeUV.mirrorU >> texFile.mirrorU placeUV.mirrorV >> texFile.mirrorV placeUV.stagger >> texFile.stagger placeUV.wrapU >> texFile.wrapU placeUV.wrapV >> texFile.wrapV placeUV.repeatUV >> texFile.repeatUV placeUV.offset >> texFile.offset placeUV.rotateUV >> texFile.rotateUV placeUV.noiseUV >> texFile.noiseUV placeUV.vertexUvOne >> texFile.vertexUvOne placeUV.vertexUvTwo >> texFile.vertexUvTwo placeUV.vertexUvThree >> texFile.vertexUvThree placeUV.vertexCameraOne >> texFile.vertexCameraOne placeUV.outUV >> texFile.uv placeUV.outUvFilterSize >> texFile.uvFilterSize return texFile
def rigFlcs(self): for flc in self.flcTransformList: self.addRigJnt(flc) index = self.flcTransformList.index(flc) ikJoint = self.ikJntList[index] # get the world position of the ik joint using a vectorProduct node vp = pm.shadingNode('vectorProduct', asUtility=1, name=ikJoint + '_ws_pmm') # use a closestPointOnSurface to get the coordinates on the surface of the closesest point from the ik joint cps = pm.shadingNode('closestPointOnSurface', asUtility=1, name=ikJoint + '_cps') # the blendTwoAttr is used to blend the flc position between its default position and the ik joints the bta = pm.shadingNode('blendTwoAttr', asUtility=1, name=flc + '_drv_bta') rev = pm.shadingNode('reverse', asUtility=1, name=flc + '_stretch_rev') vp.operation.set(4) ikJoint.worldMatrix >> vp.matrix ikJoint.rotatePivot >> vp.input1 vp.output >> cps.inPosition self.rbnSrf.worldSpace[0] >> cps.inputSurface # get the default U parameter of the follicle to store it in the blendAttr input flcU = flc.getShape().parameterU.get() bta.input[0].set(flcU) cps.parameterU >> bta.input[1] self.mainCtrl.stretch >> rev.input.inputX rev.output.outputX >> bta.attributesBlender bta.output >> flc.getShape().parameterU
def offsets_hookUp(): loc = pm.ls(sl=True)[-1] iks = pm.ls(sl=True)[:-1] loc.addAttr('chomp', k=True, at='double', min=0, max=10) for attr in ['offset','offsetMax','offsetMin']: for ik in iks: attrName = '%s_%s'%(ik.name().replace('_IK',''), attr) loc.addAttr(attrName, at='double', k=False, dv=0) for ik in iks: attrName = '%s_offset'%ik.name().replace('_IK','') attrNameMax = '%s_offsetMax'%ik.name().replace('_IK','') attrNameMin = '%s_offsetMin'%ik.name().replace('_IK','') loc.attr(attrName).set(1, cb=True) loc.attr(attrNameMin).set(0, cb=True) loc.attr(attrNameMax).set(1, cb=True) linearMult = pm.shadingNode('multDoubleLinear', n=ik.name().replace('_IK','_LMD'), asUtility=True) remapValue = pm.shadingNode('remapValue', n=ik.name().replace('_IK','_RMV'), asUtility=True) loc.chomp.connect(linearMult.input1) loc.attr(attrName).connect(linearMult.input2) linearMult.output.connect(remapValue.inputValue) loc.attr(attrNameMin).connect(remapValue.outputMin) loc.attr(attrNameMax).connect(remapValue.outputMax) remapValue.outValue.connect(ik.offset)
def doIDShdNetwork(*args): ## check if the shading network is existing shdName = 'idSetup' if( len( pm.ls(shdName + "_SHD") ) ) != 0: pm.confirmDialog(t="Warning", message="The shader has been existed!", icon='warning') return 0 # aiUserDataColor dataColor = pm.shadingNode('aiUserDataColor', asUtility=True, name=shdName+'DataColor') dataColor.colorAttrName.set('idcolor') # aiUserDataString dataString = pm.shadingNode('aiUserDataString', asUtility=True, name=shdName+'DataString') dataString.stringAttrName.set('Id') # aiWriteColor writeColor = pm.shadingNode('aiWriteColor', asUtility=True, name=shdName+'WriteColor') # aiUtility aiIDShd = pm.shadingNode('aiUtility', asShader=True, name=shdName+'_SHD') aiIDShd.shadeMode.set(2) # connections dataColor.outColor >> writeColor.input dataString.outValue >> writeColor.aovName writeColor.outColor >> aiIDShd.color
def txShow( ): # GET TEXTURE FROM CUSTOM ATTR AND ASIGN MATERIAL TO OBJ WITH TEXTURE pm.pickWalk(d="down") sel = pm.ls(sl=1) # get shapes of selection for i in sel: if getTXShape(i): # Check, if attribute has value texturePath, textureName = getTXShape( i) # get texture name with path, texture name if textureName: # Check, if attribute has value if pm.objExists('PREV_' + textureName): pm.sets(('PREV_' + str(textureName) + 'SG'), forceElement=i) else: previewShader = pm.shadingNode('lambert', asShader=True, n='PREV_' + textureName) previewIF = pm.shadingNode('file', asTexture=True, n='PREV_IF_' + textureName) previewSG = pm.sets(renderable=True, noSurfaceShader=True, empty=True, n=previewShader + 'SG') previewIF.fileTextureName.set('sourceimages/' + str(texturePath)) previewIF.outColor >> previewShader.color previewShader.outColor >> previewSG.surfaceShader pm.sets(previewSG, forceElement=i)
def creatRedShiftNode(self, shader, texSet, pbrName, exist, udim, dot, ext): texture_path = self.texturePath_LE.text() if exist == 'yes': if pbrName != 'Normal' and pbrName != 'Height': tex_node = pm.shadingNode('file', n=texSet + '_' + pbrName + '_file', asTexture=True, isColorManaged=True) if udim == 'yes': file = texture_path + '/' + texSet + '_' + pbrName + dot + '1001.' + ext pm.setAttr(tex_node + '.fileTextureName', file, type="string") pm.setAttr(tex_node + '.uvTilingMode', 3) else: file = texture_path + '/' + texSet + '_' + pbrName + '.' + ext pm.setAttr(tex_node + '.fileTextureName', file, type="string") if pbrName == 'BaseColor': pm.setAttr(tex_node + '.colorSpace', 'sRGB', type='string') pm.connectAttr(tex_node + '.outColor', shader + '.diffuse_color') elif pbrName == 'Metallic': pm.setAttr(tex_node + '.colorSpace', 'Raw', type='string') pm.connectAttr(tex_node + '.outColorR', shader + '.refl_metalness') elif pbrName == 'Roughness': pm.setAttr(tex_node + '.colorSpace', 'Raw', type='string') pm.connectAttr(tex_node + '.outColorR', shader + '.refl_roughness') elif pbrName == 'Emissive': pm.setAttr(tex_node + '.colorSpace', 'sRGB', type='string') pm.connectAttr(tex_node + '.outColor', shader + '.emission_color') elif pbrName == 'Normal': tex_node = pm.shadingNode('RedshiftNormalMap', n=texSet + '_' + pbrName + '_RedshiftNormalMap', asUtility=True) if udim == 'yes': file = texture_path + '/' + texSet + '_' + pbrName + dot + '<UDIM>.' + ext pm.setAttr(tex_node + '.tex0', file, type="string") else: file = texture_path + '/' + texSet + '_' + pbrName + '.' + ext pm.setAttr(tex_node + '.tex0', file, type="string") pm.connectAttr(tex_node + '.outDisplacementVector', shader + '.bump_input')
def connect_pxrnormal(self, pxrtexture_node, slot_name, directx_normal=True, adjustNormal=True): self.pxrnormalmap_node = pm.shadingNode("PxrNormalMap", asTexture=True) #self.pxrnormalmap_node.invertBump.set(directx_normal) # OLD if directx_normal: self.pxrnormalmap_node.orientation.set(1) else: self.pxrnormalmap_node.orientation.set(0) pm.connectAttr(pxrtexture_node.resultRGB, self.pxrnormalmap_node.inputRGB) if not adjustNormal: pm.connectAttr(self.pxrnormalmap_node.resultN, '%s.%s' % (self.shader, slot_name)) else: self.pxradjustnormal_node = pm.shadingNode("PxrAdjustNormal", asTexture=True) pm.connectAttr(self.pxrnormalmap_node.resultN, self.pxradjustnormal_node.inputNormal) pm.connectAttr(self.pxradjustnormal_node.resultN, '%s.%s' % (self.shader, slot_name))
def createLight(self, position): value = self.distance_float.value() if self.lightType_menu.currentIndex() == 1: light = pm.shadingNode('areaLight', asLight=True) pm.setAttr(light + '.intensity', 500) pm.setAttr(light + '.decayRate', 2) pm.setAttr(light + '.areaLight', 1) elif self.lightType_menu.currentIndex() == 2: light = pm.shadingNode('spotLight', asLight=True) pm.setAttr(light + '.intensity', 500) pm.setAttr(light + '.decayRate', 2) elif self.lightType_menu.currentIndex() == 3: light = pm.shadingNode('directionalLight', asLight=True) elif self.lightType_menu.currentIndex() == 4: light = pm.shadingNode('pointLight', asLight=True) pm.setAttr(light + '.intensity', 500) pm.setAttr(light + '.decayRate', 2) pm.rename(light, light_name) pm.xform(light, a=True, t=position) pm.xform(light, r=True, t=(0, 0, value)) return light
def connectAttr(attribute_source, attribute_destination, name = 'additiveConnection' ): attribute_source = validate_pymel_nodes(attribute_source) attribute_destination = validate_pymel_nodes(attribute_destination) value = pm.listConnections(attribute_destination, destination = False, plugs=True, skipConversionNodes = True) if value: print value[0].node() if pm.objectType(value[0].node()) == 'plusMinusAverage': plusMinus = value[0].node() if attribute_source.get(type=True) in ['float','doubleLinear', 'doubleAngle']: attribute_source >> plusMinus.input1D[len(plusMinus.input1D.elements())] #elif attribute_source.get(type=True) in [vector]: # print 'connecting vector' elif attribute_source.get(type=True) in ['double3']: attribute_source >> plusMinus.input3D[len(plusMinus.input3D.elements()) % 3] else: print 'could not add data type: %s' % attribute_source.get(type=True) else: if attribute_source.get(type=True) in ['float', 'doubleLinear', 'doubleAngle']: plusMinus = pm.shadingNode("plusMinusAverage", asUtility=True, name="additiveConnection") value[0] // attribute_destination value[0] >> plusMinus.input1D[0] attribute_source >> plusMinus.input1D[1] plusMinus.output1D >> attribute_destination elif attribute_source.get(type=True) in ['double3']: plusMinus = pm.shadingNode("plusMinusAverage", asUtility=True, name="additiveConnection") value[0] // attribute_destination value[0] >> plusMinus.input3D[0] attribute_source >> plusMinus.input3D[1] plusMinus.output3D >> attribute_destination else: print 'could not add data type: %s' % attribute_source.get(type=True) else: pm.connectAttr(attribute_source, attribute_destination)
def bdScaleAlong(): travelLoc = pm.ls('Mag01TailFront_scaleFollicle')[0] rigJnt = pm.ls(sl=1, type='joint') if rigJnt: for jnt in rigJnt: distance = pm.shadingNode('distanceBetween', asUtility=1, n=jnt.name() + '_DB') print distance pm.connectAttr(travelLoc + '.worldMatrix[0]', distance + '.inMatrix1') pm.connectAttr(travelLoc + '.rotatePivotTranslate', distance + '.point1') flc = jnt.getParent() print flc pm.connectAttr(flc + '.worldMatrix[0]', distance + '.inMatrix2') pm.connectAttr(flc + '.rotatePivotTranslate', distance + '.point2') rv = pm.shadingNode('remapValue', asUtility=1, n=jnt.name() + '_RV') rv.inputMin.set(3) rv.inputMax.set(0) rv.outputMin.set(1) rv.outputMax.set(2) pm.connectAttr(distance + '.distance', rv.name() + '.inputValue') pm.connectAttr(rv.name() + '.outValue', jnt.name() + '.scaleX') pm.connectAttr(rv.name() + '.outValue', jnt.name() + '.scaleY') pm.connectAttr(rv.name() + '.outValue', jnt.name() + '.scaleZ')
def create_shader(shader_name, PDX_material, texture_dir): new_shader = pmc.shadingNode('phong', asShader=True, name=shader_name) new_shadinggroup = pmc.sets(renderable=True, noSurfaceShader=True, empty=True, name='{}_SG'.format(shader_name)) pmc.connectAttr(new_shader.outColor, new_shadinggroup.surfaceShader) # add the game shader attribute, PDX tool uses ENUM attr to store but writes as a string pmc.addAttr(longName=PDX_SHADER, dataType='string') getattr(new_shader, PDX_SHADER).set(PDX_material.shader[0]) if getattr(PDX_material, 'diff', None): texture_path = os.path.join(texture_dir, PDX_material.diff[0]) new_file, _ = create_filetexture(texture_path) pmc.connectAttr(new_file.outColor, new_shader.color) if getattr(PDX_material, 'n', None): texture_path = os.path.join(texture_dir, PDX_material.n[0]) new_file, _ = create_filetexture(texture_path) bump2d = pmc.shadingNode('bump2d', asUtility=True) bump2d.bumpDepth.set(0.1) new_file.alphaIsLuminance.set(True) pmc.connectAttr(new_file.outAlpha, bump2d.bumpValue) pmc.connectAttr(bump2d.outNormal, new_shader.normalCamera) if getattr(PDX_material, 'spec', None): texture_path = os.path.join(texture_dir, PDX_material.spec[0]) new_file, _ = create_filetexture(texture_path) pmc.connectAttr(new_file.outColor, new_shader.specularColor) return new_shader, new_shadinggroup
def processtex(self, item): #Connect place 2d Texture nodes to File Nodes) fileTruename = item.split(".") fileNode = pm.shadingNode('file', name='%s' % fileTruename[0], asTexture=True) fullfile = self.folder + '\\' + item fileNode.setAttr('fileTextureName', str(fullfile)) p2d = pm.shadingNode('place2dTexture', name='is2d%s' % fileTruename[0], asUtility=True) fileNode.filterType.set(0) pm.connectAttr(p2d.outUV, fileNode.uvCoord) pm.connectAttr(p2d.outUvFilterSize, fileNode.uvFilterSize) pm.connectAttr(p2d.vertexCameraOne, fileNode.vertexCameraOne) pm.connectAttr(p2d.vertexUvOne, fileNode.vertexUvOne) pm.connectAttr(p2d.vertexUvThree, fileNode.vertexUvThree) pm.connectAttr(p2d.vertexUvTwo, fileNode.vertexUvTwo) pm.connectAttr(p2d.coverage, fileNode.coverage) pm.connectAttr(p2d.mirrorU, fileNode.mirrorU) pm.connectAttr(p2d.mirrorV, fileNode.mirrorV) pm.connectAttr(p2d.noiseUV, fileNode.noiseUV) pm.connectAttr(p2d.offset, fileNode.offset) pm.connectAttr(p2d.repeatUV, fileNode.repeatUV) pm.connectAttr(p2d.rotateFrame, fileNode.rotateFrame) pm.connectAttr(p2d.rotateUV, fileNode.rotateUV) pm.connectAttr(p2d.stagger, fileNode.stagger) pm.connectAttr(p2d.translateFrame, fileNode.translateFrame) pm.connectAttr(p2d.wrapU, fileNode.wrapU) pm.connectAttr(p2d.wrapV, fileNode.wrapV) print fileNode, ' connected' return fileNode
def create_slideSystem(self): slideAttr = attribute.addAttr(self.autoJnt, 'slide', attributeType='double', min=0, max=10, defaultValue=0, keyable=True) slideMD = pm.shadingNode('multiplyDivide', asUtility=True, name=self.autoJnt + '_MD') slideREV = pm.shadingNode('reverse', asUtility=True, name=self.autoJnt + '_REV') slideAttr.connect(slideMD.input1X) slideMD.operation.set(2) slideMD.input2X.set(10) slideMD.outputX.connect(slideREV.inputX) for fol in self.ribbonSystem.folList: shapeRel = pm.listRelatives(fol, shapes=True)[0] mult = pm.shadingNode("multiplyDivide", asUtility=True, name=fol + "_MD") slideREV.outputX.connect(mult.input2X) mult.input1X.set(shapeRel.parameterU.get()) mult.outputX.connect(shapeRel.parameterU)
def createFileTexture(fileTextureName, p2dName): tex = pm.shadingNode('file', name=fileTextureName, asTexture=True, isColorManaged=True) if not pm.objExists(p2dName): pm.shadingNode('place2dTexture', name=p2dName, asUtility=True) p2d = pm.PyNode(p2dName) tex.filterType.set(0) pm.connectAttr(p2d.outUV, tex.uvCoord) pm.connectAttr(p2d.outUvFilterSize, tex.uvFilterSize) pm.connectAttr(p2d.vertexCameraOne, tex.vertexCameraOne) pm.connectAttr(p2d.vertexUvOne, tex.vertexUvOne) pm.connectAttr(p2d.vertexUvThree, tex.vertexUvThree) pm.connectAttr(p2d.vertexUvTwo, tex.vertexUvTwo) pm.connectAttr(p2d.coverage, tex.coverage) pm.connectAttr(p2d.mirrorU, tex.mirrorU) pm.connectAttr(p2d.mirrorV, tex.mirrorV) pm.connectAttr(p2d.noiseUV, tex.noiseUV) pm.connectAttr(p2d.offset, tex.offset) pm.connectAttr(p2d.repeatUV, tex.repeatUV) pm.connectAttr(p2d.rotateFrame, tex.rotateFrame) pm.connectAttr(p2d.rotateUV, tex.rotateUV) pm.connectAttr(p2d.stagger, tex.stagger) pm.connectAttr(p2d.translateFrame, tex.translateFrame) pm.connectAttr(p2d.wrapU, tex.wrapU) pm.connectAttr(p2d.wrapV, tex.wrapV) return tex
def createRGBShaders(): search = pm.ls('redAxisSG', type='shadingEngine') if search: xShadingGrp = search[0] else: xShader = pm.shadingNode("blinn", asShader=True, name='redAxis') xShadingGrp = pm.sets(renderable=True, noSurfaceShader=True, empty=True, name='redAxisSG') xShader.outColor >> xShadingGrp.surfaceShader xShader.color.set([1, 0, 0]) search = pm.ls('greenAxisSG', type='shadingEngine') if search: yShadingGrp = search[0] else: yShader = pm.shadingNode("blinn", asShader=True, name='greenAxis') yShader.color.set([0, 1, 0]) yShadingGrp = pm.sets(renderable=True, noSurfaceShader=True, empty=True, name='greenAxisSG') yShader.outColor >> yShadingGrp.surfaceShader search = pm.ls('blueAxisSG', type='shadingEngine') if search: zShadingGrp = search[0] else: zShader = pm.shadingNode("blinn", asShader=True, name='blueAxis') zShader.color.set([0, 0, 1]) zShadingGrp = pm.sets(renderable=True, noSurfaceShader=True, empty=True, name='blueAxisSG') zShader.outColor >> zShadingGrp.surfaceShader return [xShadingGrp, yShadingGrp, zShadingGrp]
def tongue_globals(): tongue_end_ctrl = pm.ls('tongue_end_ctrl', type='transform')[0] tongue_config_ctrl = pm.ls('tongue_config', type='transform')[0] wide_narrow_nodes = pm.listConnections(tongue_end_ctrl.name() + '.wide_narrow') pma = pm.shadingNode('plusMinusAverage', name='wide_narrow_config_pma', asUtility=True) tongue_end_ctrl.attr('wide_narrow') >> pma.attr('input1D[0]') tongue_config_ctrl.attr('wide_narrow') >> pma.attr('input1D[1]') for node in wide_narrow_nodes: tongue_end_ctrl.attr('wide_narrow') // node.attr('inputValue') pma.attr('output1D') >> node.attr('inputValue') thin_thick_nodes = pm.listConnections(tongue_end_ctrl.name() + '.thin_thick') pma = pm.shadingNode('plusMinusAverage', name='thin_thick_config_pma', asUtility=True) tongue_end_ctrl.attr('thin_thick') >> pma.attr('input1D[0]') tongue_config_ctrl.attr('thin_thick') >> pma.attr('input1D[1]') for node in thin_thick_nodes: tongue_end_ctrl.attr('thin_thick') // node.attr('inputValue') pma.attr('output1D') >> node.attr('inputValue')
def create_shadow_shader_arnold(): if not pm.objExists('shadow_shader_hs_arnold'): shadow_shader = pm.shadingNode('aiUtility', asShader=1, name='shadow_shader_hs_arnold') shadow_shader.shadeMode.set(1) else: shadow_shader = pm.PyNode('shadow_shader_hs_arnold') if not pm.objExists('shadow_catcher_hs_arnold'): shadow_catcher = pm.shadingNode('aiShadowCatcher', asShader=1, name='shadow_catcher_hs_arnold') shadow_catcher.enableTransparency.set(1) shadow_shader.outColor >> shadow_catcher.shadowTransparency else: shadow_catcher = pm.PyNode('shadow_catcher_hs_arnold') if not pm.objExists('shadow_SG_hs_arnold'): shadow_sg = pm.sets(renderable=1, noSurfaceShader=1, empty=1, name='shadow_SG_hs_arnold') shadow_catcher.outColor >> shadow_sg.surfaceShader else: shadow_sg = pm.PyNode('shadow_SG_hs_arnold') pm.select(clear=1) return shadow_catcher, shadow_sg
def createMatteAttrNode(self): for num in range(8): matteID_r = 'MatteID'+str(num)+'_red_pxrAttr' matteID_g = 'MatteID'+str(num)+'_green_pxrAttr' matteID_b = 'MatteID'+str(num)+'_blue_pxrAttr' if pm.objExists(matteID_r): print str(matteID_r)+' already exists' else: node_r = pm.shadingNode('PxrAttribute', at=True, n=matteID_r) node_r = pm.PyNode(matteID_r) node_r.setAttr('defaultFloat3', (1, 0, 0)) if pm.objExists(matteID_g): print str(matteID_g)+' already exists' else: node_g = pm.shadingNode('PxrAttribute', at=True, n=matteID_g) node_g = pm.PyNode(matteID_g) node_g.setAttr('defaultFloat3', (0, 1, 0)) if pm.objExists(matteID_b): print str(matteID_b)+' already exists' else: node_b = pm.shadingNode('PxrAttribute', at=True, n=matteID_b) node_b = pm.PyNode(matteID_b) node_b.setAttr('defaultFloat3', (0, 0, 1))
def create_filetexture(tex_filepath): """ Creates & connects up a new file node and place2dTexture node, uses the supplied filepath. """ newFile = pmc.shadingNode('file', asTexture=True) new2dTex = pmc.shadingNode('place2dTexture', asUtility=True) pmc.connectAttr(new2dTex.coverage, newFile.coverage) pmc.connectAttr(new2dTex.translateFrame, newFile.translateFrame) pmc.connectAttr(new2dTex.rotateFrame, newFile.rotateFrame) pmc.connectAttr(new2dTex.mirrorU, newFile.mirrorU) pmc.connectAttr(new2dTex.mirrorV, newFile.mirrorV) pmc.connectAttr(new2dTex.stagger, newFile.stagger) pmc.connectAttr(new2dTex.wrapU, newFile.wrapU) pmc.connectAttr(new2dTex.wrapV, newFile.wrapV) pmc.connectAttr(new2dTex.repeatUV, newFile.repeatUV) pmc.connectAttr(new2dTex.offset, newFile.offset) pmc.connectAttr(new2dTex.rotateUV, newFile.rotateUV) pmc.connectAttr(new2dTex.noiseUV, newFile.noiseUV) pmc.connectAttr(new2dTex.vertexUvOne, newFile.vertexUvOne) pmc.connectAttr(new2dTex.vertexUvTwo, newFile.vertexUvTwo) pmc.connectAttr(new2dTex.vertexUvThree, newFile.vertexUvThree) pmc.connectAttr(new2dTex.vertexCameraOne, newFile.vertexCameraOne) pmc.connectAttr(new2dTex.outUV, newFile.uv) pmc.connectAttr(new2dTex.outUvFilterSize, newFile.uvFilterSize) newFile.fileTextureName.set(tex_filepath) return newFile, new2dTex
def createOffsetSystem_Trans(self): #inner outer offset self.innerOuterPMA = pm.shadingNode('plusMinusAverage', asUtility=True) self.innerOuterPMA.renameNode(name=self.TipName, base="%sInnerOuterOffsetTrans") self.innerOuterPMA.addTag(self.rigGrp) self.innerOuterMD = pm.shadingNode('multiplyDivide', asUtility=True) self.innerOuterMD.renameNode(name=self.TipName, base="%sInnerOuterOffsetTrans") self.innerOuterMD.addTag(self.rigGrp) self.innerOuterPMA.input1D[0].set(2) self.upper.getParent().translateY.connect(self.innerOuterPMA.input1D[0]) self.innerOuterPMA.input1D[1].set(2) self.lower.getParent().translateY.connect(self.innerOuterPMA.input1D[1]) self.innerOuterPMA.output1D.connect(self.innerOuterMD.input1X) self.InnerOuter_follow.connect(self.innerOuterMD.input2X) self.innerOuterMD.outputX.connect(self.inner.getParent().translateY) self.innerOuterMD.outputX.connect(self.outer.getParent().translateY) #upper lower offset self.upperLowerPMA = pm.shadingNode('plusMinusAverage', asUtility=True) self.upperLowerPMA.renameNode(name=self.TipName, base="%sUpperLowerOffsetTrans") self.upperLowerPMA.addTag(self.rigGrp) self.upperLowerMD = pm.shadingNode('multiplyDivide', asUtility=True) self.upperLowerMD.renameNode(name=self.TipName, base="%sUpperLowerOffsetTrans") self.upperLowerMD.addTag(self.rigGrp) self.upperLowerPMA.input1D[0].set(2) self.inner.getParent().translateZ.connect(self.upperLowerPMA.input1D[0]) self.upperLowerPMA.input1D[1].set(2) self.outer.getParent().translateZ.connect(self.upperLowerPMA.input1D[1]) self.upperLowerPMA.output1D.connect(self.upperLowerMD.input1X) self.UpperLower_follow.connect(self.upperLowerMD.input2X) self.upperLowerMD.outputX.connect(self.upper.getParent().translateZ) self.upperLowerMD.outputX.connect(self.lower.getParent().translateZ)
def create_VarFkCtrls( IdName, guideSurface, numberOfCtrls ): # create controls ctrlGrp = pm.group( name = IdName + '_ctrls', empty = True, world = True) ctrlGrp.inheritsTransform.set(0) listOfCtrls = [] for currentCtrlIndex in range(numberOfCtrls): if numberOfCtrls > 1: FolliclePos = ( 1.0 / (numberOfCtrls-1) ) * currentCtrlIndex else: FolliclePos = ( 1.0 / (numberOfCtrls) ) * currentCtrlIndex # create controlshape currentCtrl = pm.circle( name = ( 'ctrl_vFK' + str( currentCtrlIndex+1 )+ '_' + IdName ), c=(0,0,0), nr=(1,0,0), sw=360, r=1.5, d=3, ut=0, tol=0.01, s=8, ch=False) currentCtrl[0].overrideEnabled.set(True) currentCtrl[0].overrideColor.set(4) # lock'n hide translates + scaleX currentCtrl[0].translateX.set( lock = True, keyable = False, channelBox = False ) currentCtrl[0].translateY.set( lock = True, keyable = False, channelBox = False ) currentCtrl[0].translateZ.set( lock = True, keyable = False, channelBox = False ) currentCtrl[0].scaleX.set( lock = True ) # add strength, position, radius attributes pm.addAttr( longName='rotateStrength', attributeType='float', keyable=True, defaultValue=1 ) pm.addAttr( longName='position', attributeType='float', keyable=True, min=0-FolliclePos, max=1-FolliclePos ) pm.addAttr( longName='radius', attributeType='float', keyable=True, min=0.0001, defaultValue=0.3 ) # position min/max relative to defaultposition so ctrl can be zeroed out. Is remapped later back to 0 to 1 when connected to Follicle currentFollicle = create_follicle( guideSurface[0], uPos=FolliclePos, vPos=0.5 ) currentFollicle.simulationMethod.set(0) currentFollicle.collide.set(0) currentFollicle.flipDirection.set( True ) currentFollicle = pm.listRelatives( currentFollicle, parent=True ) # connect to strength multiplier rotateStrengthMultiplier = pm.shadingNode( 'multiplyDivide', asUtility = True, n = str( currentCtrl[0] ) + '_strength_mult' ) currentCtrl[0].rotate >> rotateStrengthMultiplier.input1 pm.connectAttr( currentCtrl[0] + '.rotateStrength', rotateStrengthMultiplier + '.input2X', f=1 ) pm.connectAttr( currentCtrl[0] + '.rotateStrength', rotateStrengthMultiplier + '.input2Y', f=1 ) pm.connectAttr( currentCtrl[0] + '.rotateStrength', rotateStrengthMultiplier + '.input2Z', f=1 ) # compensate position zero value by current follicle position jntposZeroCompensate = pm.shadingNode( 'plusMinusAverage', asUtility = True, n=currentCtrl[0] + '_jntposZeroCompensate' ) pm.setAttr( jntposZeroCompensate + '.input1D[0]', pm.getAttr( currentFollicle[0].getShape() + '.parameterU' ) ) pm.connectAttr( currentCtrl[0] + '.position', jntposZeroCompensate + '.input1D[1]', f=1 ) pm.connectAttr( jntposZeroCompensate + '.output1D', currentFollicle[0].getShape() + '.parameterU', f=1 ) # grouping buf = createBufGrp( currentCtrl )[0] pm.parent( buf, ctrlGrp, relative = True ) pm.parent( currentFollicle, ctrlGrp ) # connect follicle position to control buffer currentFollicle[0].translate >> buf.translate listOfCtrls.append( currentCtrl[0] ) pm.select( clear = 1 ) print( 'Successfully created ' + currentCtrl[0] ) return listOfCtrls
def createSpec(): NowSpec = pm.shadingNode('reverse', asUtility=True, n='RevSpec') NowTexC = pm.shadingNode('file', asTexture=True, isColorManaged=True, n='Revfile') pm.connectAttr(NowTexC + '.outAlpha', NowSpec + '.inputX', f=True) pm.connectAttr(NowSpec + '.outputX', mat[0] + '.specularRoughness', f=True)
def update_file(create_file, file_name, p2d_name, texture_path, render_plugin): if create_file == 1 and render_plugin != "Renderman_PxrDisney": # create file and place2d tex = pm.shadingNode('file', name=file_name, asTexture=True, isColorManaged=True) if not pm.objExists(p2d_name): pm.shadingNode('place2dTexture', name=p2d_name, asUtility=True) p2d = pm.PyNode(p2d_name) tex.filterType.set(0) pm.connectAttr(p2d.outUV, tex.uvCoord) pm.connectAttr(p2d.outUvFilterSize, tex.uvFilterSize) pm.connectAttr(p2d.vertexCameraOne, tex.vertexCameraOne) pm.connectAttr(p2d.vertexUvOne, tex.vertexUvOne) pm.connectAttr(p2d.vertexUvThree, tex.vertexUvThree) pm.connectAttr(p2d.vertexUvTwo, tex.vertexUvTwo) pm.connectAttr(p2d.coverage, tex.coverage) pm.connectAttr(p2d.mirrorU, tex.mirrorU) pm.connectAttr(p2d.mirrorV, tex.mirrorV) pm.connectAttr(p2d.noiseUV, tex.noiseUV) pm.connectAttr(p2d.offset, tex.offset) pm.connectAttr(p2d.repeatUV, tex.repeatUV) pm.connectAttr(p2d.rotateFrame, tex.rotateFrame) pm.connectAttr(p2d.rotateUV, tex.rotateUV) pm.connectAttr(p2d.stagger, tex.stagger) pm.connectAttr(p2d.translateFrame, tex.translateFrame) pm.connectAttr(p2d.wrapU, tex.wrapU) pm.connectAttr(p2d.wrapV, tex.wrapV) elif create_file == 1 and render_plugin == "Renderman_PxrDisney": # create pxrTexture tex = pm.shadingNode('PxrTexture', name=file_name, asTexture=True) pm.setAttr(tex.atlasStyle, 1) else: # node exists tex = pm.PyNode(file_name) if render_plugin == "Renderman_PxrDisney": pm.setAttr(tex.filename, texture_path.replace("$textureSet", "_MAPID_")) pm.setAttr(tex.atlasStyle, 1) elif render_plugin == "RedShift" and "rsNormal" in tex: pm.setAttr(tex.tex0, texture_path.replace('$textureSet', '<UDIM>'), type="string") else: try: pm.setAttr(tex.fileTextureName, texture_path.replace('$textureSet', '<UDIM>')) pm.setAttr(tex.alphaIsLuminance, 1) pm.setAttr(tex.uvTilingMode, 3) except: pass print "finished updating " + file_name return tex
def complex_outdoor(* args): #create_ibl() my_sun = pm.shadingNode('directionalLight', asLight= True) pm.rename(my_sun, 'Sun') my_sky = pm.shadingNode('areaLight', asLight= True) new_light = pm.rename(my_sky, 'Sky') new_light.translate.set(0,16,0) new_light.rotate.set(-90,0,0) new_light.scale.set(16,16,16)
def make_file_nodes(textures, shaders, attribute='color'): """ Creates (or uses existing) file nodes and assigns them to shaders on the given attribute Args: textures [str]: list of file paths to textures shaders [pm.nodetypes.Blinn] list of blinn (or other) shaders attribute (str): attribute to connect texture to on shader """ file_nodes = [] print shaders for shader in shaders: udims = re.findall('1[01][0-9][0-9]', shader.name()) file_node = shader_udim = tex_match = None if udims: shader_udim=udims[0] # Get the corresponding exr for the proper udim of the shader if shader_udim: for texture in textures: print 'checking texture %s against udim search %s'%(tex_match, shader_udim) try: tex_match = re.search('.*%s.*'%shader_udim, texture).group() print 'texture %s matches for udim search %d'%(tex_match, shader_udim) break except: pass # Get connected file node or make a non-existing one connected_textures = shader.attr(attribute).listConnections() if connected_textures and shader_udim: print 'Using previously connected file nodes for attribute %s on shader %s'%(attribute, shader.name()) file_node = connected_textures[0] # Special bump map section if attribute == 'normalCamera': try: bump_node = shader.attr(attribute).listConnections()[0] file_node = bump_node.bumpValue.listConnections()[0] except: pass else: file_node = pm.shadingNode('file', asTexture=True, n=file_name%(shader_udim, attribute)) # Special bump map section if attribute == 'normalCamera': bump_node = pm.shadingNode('bump2d', asUtility=True) file_node.alphaIsLuminance.set(True) file_node.outAlpha.connect(bump_node.bumpValue) bump_node.outNormal.connect(shader.attr(attribute)) else: file_node.outColor.connect(shader.attr(attribute)) # Now if we have a file node and a matching exr we can finally set the file texture name if tex_match and file_node: file_node.fileTextureName.set(tex_match) file_nodes.append(file_node) return file_nodes
def complex_outdoor(*args): #create_ibl() my_sun = pm.shadingNode('directionalLight', asLight=True) pm.rename(my_sun, 'Sun') my_sky = pm.shadingNode('areaLight', asLight=True) new_light = pm.rename(my_sky, 'Sky') new_light.translate.set(0, 16, 0) new_light.rotate.set(-90, 0, 0) new_light.scale.set(16, 16, 16)
def createFlcs(self,direction,ends): folicles = [] pm.select(cl=1) for i in range(self.numJnt): jnt = self.ikJntList[i] print jnt pm.select(cl=1) flcShape = pm.createNode('follicle', name = self.srf.name() + '_flcShape_' + str(i).zfill(2) ) flcTransform = flcShape.getParent() flcTransform.rename(flcShape.name().replace('flcShape','flc') ) folicles.append(flcTransform) srfShape = pm.listRelatives(self.srf)[0] srfShape.local.connect(flcShape.inputSurface) srfShape.worldMatrix[0].connect(flcShape.inputWorldMatrix) flcShape.outRotate.connect(flcTransform.rotate) flcShape.outTranslate.connect(flcTransform.translate) #flcShape.flipDirection.set(1) cposNode = pm.shadingNode( 'closestPointOnSurface', asUtility = True ,n = jnt.name() + '_cpos') decMtx = pm.shadingNode('decomposeMatrix',asUtility = True, name = jnt.name() + '_dmtx') self.srf.getShape().worldSpace[0].connect(cposNode.inputSurface) decMtx.outputTranslate.connect(cposNode.inPosition) jnt.worldMatrix[0].connect(decMtx.inputMatrix) pm.addAttr(jnt, shortName='jointPosition', longName='jointPosition', defaultValue=0, minValue=0, maxValue=1) jntPos = cposNode.parameterU.get() jnt.jointPosition.set(jntPos) self.cposList.append(cposNode) #cposNode.parameterU >> flcShape.parameterU flcShape.parameterV.set(0.5) pm.orientConstraint(flcTransform,self.rigJntList[i],mo=1) #pm.pointConstraint(flcTransform,self.rigJntList[i],mo=1,weight=0) blendAttr = pm.shadingNode( 'blendTwoAttr', asUtility = True ,n = flcTransform.name() + '_b2a') self.stretchRev.outputX >> blendAttr.attributesBlender jnt.jointPosition >> blendAttr.input[0] cposNode.parameterU >> blendAttr.input[1] blendAttr.output >> flcShape.parameterU pm.select(cl=1) flcGrp = pm.group(folicles,n=self.srf.name() + '_flc_grp') pm.select(cl=1) pm.parent(flcGrp,self.mainGrp) self.flcTransformList = folicles
def add_squash_n_stretch(self, follicles): """ Args: None Returns (None) Usage: """ base_name = '%s_flexiPlane' % self.flexiPlaneNameField.getText() wire_name = '%s_wire_CRV' % base_name main_crv_name = '%s_main_CTRL' % base_name wire = pm.PyNode(wire_name) arc_len = pm.arclen(wire, ch = True) pm.rename( arc_len, wire_name + 'info' ) arc_len_val = pm.getAttr( wire_name + 'info.arcLength') multDiv_length = pm.shadingNode( 'multiplyDivide', asUtility = True ) pm.rename( multDiv_length, base_name + '_div_squashStretch_length' ) pm.setAttr( base_name + '_div_squashStretch_length.operation', 2 ) pm.connectAttr( wire_name + 'info.arcLength', base_name + '_div_squashStretch_length.input1X' ) pm.setAttr( base_name + '_div_squashStretch_length.input2X', arc_len_val ) multDiv_volume = pm.shadingNode( 'multiplyDivide', asUtility = True ) pm.rename( multDiv_volume, base_name + '_div_volume' ) pm.setAttr( base_name + '_div_volume.operation', 2 ) pm.setAttr( base_name + '_div_volume.input1X', 1 ) pm.connectAttr( base_name + '_div_squashStretch_length.outputX', base_name + '_div_volume.input2X', f = True ) conditional_volume = pm.shadingNode( 'condition', asUtility = True ) pm.rename( conditional_volume, base_name + '_cond_volume' ) pm.setAttr( base_name + '_cond_volume.secondTerm', 1 ) pm.connectAttr( main_crv_name + '.squashN_stretch', base_name + '_cond_volume.firstTerm' ) multDiv_globelScale = pm.shadingNode( 'multiplyDivide', asUtility = True ) pm.rename( multDiv_globelScale, base_name + '_mult_globalScale' ) pm.connectAttr( base_name + '_div_volume.outputX', base_name + '_mult_globalScale.input1X' ) pm.connectAttr( main_crv_name + '.scaleX', base_name + '_mult_globalScale.input2X' ) pm.connectAttr( base_name + '_mult_globalScale.outputX', base_name + '_cond_volume.colorIfTrueR' ) for index,follicle in enumerate(follicles): jnt_name = self.format_string.format(PREFIX = self.flexiPlaneNameField.getText(), INDEX = 'flexiPlane_jnt%03d' % (index+1), SUFFIX = 'JNT') jnt_offset_name = jnt_name.replace('_JNT','Offset_GRP') tweek_crv_name = self.format_string.format(PREFIX = self.flexiPlaneNameField.getText(), INDEX = 'flexiPlane_tweak%03d' % (index+1), SUFFIX = 'CTRL') pm.scaleConstraint( tweek_crv_name + 'Con_GRP', jnt_offset_name ) pm.connectAttr( base_name + '_cond_volume.outColorR', jnt_name + '.scaleX') pm.connectAttr( base_name + '_cond_volume.outColorR', jnt_name + '.scaleZ') pm.select( clear = True )
def addUV(*args): #Create UV pass with shader if not pm.objExists( 'aiAOV_UV' ): #check if UV AOV already exists shdrUV = pm.shadingNode('aiUtility', asShader = True, name = 'GEN_UV') shdrUV.shadeMode.set(2) shdrUV.color.set(0,0,0) siUV = pm.shadingNode('samplerInfo', asShader = True, name = 'INFO_UV') siUV.uvCoord.uCoord >> shdrUV.color.colorR siUV.uvCoord.vCoord >> shdrUV.color.colorG aovUV = aovs.AOVInterface().addAOV('UV') aovUV = pm.PyNode('aiAOV_UV') shdrUV.outColor >> aovUV.defaultValue print 'UV AOV DONE!'
def createRenderNode(self, nodeType=None): log.debug("createRenderNode callback for renderer {0} with node: {1}".format(self.rendererName.lower(), nodeType)) if nodeType == "TheaMaterial": mat = pm.shadingNode("TheaMaterial", asShader=True) bsdf = pm.shadingNode("BasicBSDF", asShader=True) bsdf.outColor >> mat.bsdf shadingGroup = pm.sets(renderable=True, noSurfaceShader=True, empty=True, name="{0}SG".format(mat)) mat.outColor >> shadingGroup.surfaceShader return mat = pm.shadingNode(nodeType, asShader=True) shadingGroup = pm.sets(renderable=True, noSurfaceShader=True, empty=True, name="{0}SG".format(mat)) mat.outColor >> shadingGroup.surfaceShader
def addJntPosAttr(self): for jnt in self.ikJntList: cposNode = pm.shadingNode( 'closestPointOnSurface', asUtility = True ) decMtx = pm.shadingNode('decomposeMatrix',asUtility = True ) self.srf.getShape().worldSpace[0].connect(cposNode.inputSurface) decMtx.outputTranslate.connect(cposNode.inPosition) jnt.worldMatrix[0].connect(decMtx.inputMatrix) pm.addAttr(jnt, shortName='jointPosition', longName='jointPosition', defaultValue=0, minValue=0, maxValue=1) jntPos = cposNode.parameterU.get() jnt.jointPosition.set(jntPos) pm.delete([cposNode,decMtx])
def addCtrlJntAffected(ctrl,jntTotal): pm.addAttr(ctrl,longName='jointsAffected', defaultValue=0, minValue=0.0, maxValue=jntTotal,keyable=False) numJntMd = pm.shadingNode('multiplyDivide', asUtility = True ) numJntSr = pm.shadingNode('setRange', asUtility = True ) ctrl.falloff.connect(numJntMd.input1.input1X) numJntMd.input2.input2X.set(2) numJntMd.output.outputX.connect(numJntSr.value.valueX) numJntSr.maxX.set(jntTotal) numJntSr.oldMaxX.set(1) numJntSr.outValueX.connect(ctrl.jointsAffected)
def make_proxy_wheel(obj, wheel_name, cutout=False): tolerance = .5 sel = pm.selected() bb = obj.getBoundingBox() radius = max(bb.depth(), bb.width(), bb.height())/2 height = min(bb.depth(), bb.width(), bb.height()) axis = [0,1,0] if bb.height() - bb.width() > tolerance: # allow for a tolerance of difference axis = [1,0,0] if bb.width() - bb.depth() > tolerance: axis = [0,0,1] #print axis, bb.depth(), bb.width(), bb.height() cylinder = pm.polyCylinder(n=wheel_name, axis=axis, height=height, radius=radius, sc=True) pm.xform(cylinder, t=bb.center()) cylinder_shape = cylinder[0].getShape() bevel_edges = cylinder_shape.e[0:39] pm.polyBevel(bevel_edges, com=0, fraction=0.4, offsetAsFraction=1, autoFit=1, segments=4, worldSpace=1, uvAssignment=0, smoothingAngle=30, fillNgons=1, mergeVertices=1, mergeVertexTolerance=0.0001, miteringAngle=180, angleTolerance=180, ch=1) pm.polyExtrudeFacet(cylinder_shape.f[180:219], ltz=-0.16, lsx=0.2, lsy=0.2) light_faces_indexes = [224, 225, 228, 229, 232, 233, 244, 245, 248, 249, 252, 253] dark_faces = [face for face in cylinder_shape.f[:] if face.index() not in light_faces_indexes] dark_lambert = pm.shadingNode("blinn", n="dark_shader", asShader=True) dark_lambert.color.set([.16, .16, .16]) dark_lambert.eccentricity.set(0.5) dark_lambert.specularColor.set([.16, .16, .16]) dark_set = pm.sets( renderable=True, noSurfaceShader=True, empty=True, name="dark_shaderSG" ) dark_lambert.outColor.connect(dark_set.surfaceShader) pm.sets(dark_set, forceElement=dark_faces) light_faces = [cylinder_shape.f[index] for index in light_faces_indexes] light_lambert = pm.shadingNode("lambert", n="light_shader", asShader=True) light_lambert.color.set([.7, .7, .7]) light_set = pm.sets( renderable=True, noSurfaceShader=True, empty=True, name="light_shaderSG" ) light_lambert.outColor.connect(light_set.surfaceShader) pm.sets(light_set, forceElement=light_faces) if cutout: if "r_" == wheel_name[:2]: pm.delete(cylinder_shape.f[200:219]) if "l_" == wheel_name[:2]: pm.delete(cylinder_shape.f[180:199]) pm.select(sel,r=True) return cylinder[0]
def create_node_by_type(node_type, **kwargs): """Create node by type. Args: node_type (str): Type of the node to be created **kwargs: Extra arguments to use in some nodes types creation. Returns: PyNode: New node of the goal and use specified. """ cmds.select(clear=True) if node_type == "spaceLocator": return pm.PyNode(cmds.spaceLocator(p=(0, 0, 0))[0]) elif node_type == "empty": return pm.PyNode(cmds.group(empty=True)) elif node_type == "joint": return pm.PyNode(cmds.joint()) elif node_type == "circle": radius = kwargs["radius"] if "radius" in kwargs else 5 degree = kwargs["degree"] if "degree" in kwargs else 3 sections = kwargs["sections"] if "sections" in kwargs else 8 sweep = kwargs["sweep"] if "sweep" in kwargs else 360 normal = kwargs["normal"] if "normal" in kwargs else (0, 1, 0) return pm.PyNode(cmds.circle(radius=radius, degree=degree, sections=sections, sweep=sweep, normal=normal)[0]) elif node_type == "renderBox": sizeX = kwargs["sizeX"] if "sizeX" in kwargs else 2 sizeY = kwargs["sizeY"] if "sizeY" in kwargs else 2 sizeZ = kwargs["sizeZ"] if "sizeZ" in kwargs else 2 new_node = pm.PyNode(cmds.createNode("renderBox")) new_node.attr("sizeX").set(sizeX) new_node.attr("sizeY").set(sizeY) new_node.attr("sizeZ").set(sizeZ) return pm.PyNode(new_node.listRelatives(parent=True, fullPath=True)[0]) elif node_type == "plusMinusAverage": return pm.PyNode(pm.shadingNode("plusMinusAverage", asUtility=True)) elif node_type == "multiplyDivide": return pm.PyNode(pm.shadingNode("multiplyDivide", asUtility=True))
def create(self): """creates the node """ node_type = self.specs.get('node_type') secondary_type = self.specs.get('secondary_type') if secondary_type == 'shader': shader, shading_engine = pm.createSurfaceShader(node_type) return shader if secondary_type == 'utility': shader = pm.shadingNode(node_type, asUtility=1) return shader elif secondary_type == 'light': light_transform = pm.shadingNode(node_type, asLight=1) return light_transform.getShape()
def stretchyBack( ikHandleTorso, jntList ): pymelLogger.debug('Starting: stretchyBack()...') #Stretchy process # ArcLen to create curveInfo curveInfoNodeBack = pm.arclen( ikHandleTorso[2], ch=True ) # add attr to curveinfo Node (normalizedScale) # this will have a value coming from a multiply divide node that will be # dividing the current length by the initial length of the curve # this will be used later to scale the joints pm.addAttr(curveInfoNodeBack, longName='normalizedScale', attributeType='double') # get initial length of the curve iniLen = pm.getAttr( curveInfoNodeBack + '.arcLength' ) # create a node multiplydivide, operation set to division MDCurveBack = pm.shadingNode( 'multiplyDivide', asUtility=True ) pm.setAttr( MDCurveBack+'.operation', 2 ) # divide # Connect curve arcLength to input1X pm.connectAttr( curveInfoNodeBack + '.arcLength', MDCurveBack + '.input1X', force=True ) # Set input2X to initial length of the curve pm.setAttr(MDCurveBack+'.input2X', iniLen) # connect outpux x from multiplydivide to normalized scale of the curve info pm.connectAttr(MDCurveBack + '.outputX', curveInfoNodeBack + '.normalizedScale', force=True) returnList = [curveInfoNodeBack,MDCurveBack] pymelLogger.debug('End: stretchyBack()...') return returnList
def binMeshCheckAndCreateShadingGroup(shadingGroup): try: shadingGroup = pm.PyNode(shadingGroup) except: shader = pm.shadingNode("appleseedSurfaceShader", asShader=True) shadingGroup = pm.sets(renderable=True, noSurfaceShader=True, empty=True, name=shadingGroup) shader.outColor >> shadingGroup.surfaceShader
def _visualizer_setup(self): """Add a shader to visualize the outValue and the coneAngle.""" visualize_sdr = pm.shadingNode('surfaceShader', asShader=True, n='visualize') sets = pm.sets(renderable=True, noSurfaceShader=True, empty=True, n='visualize') visualize_sdr.outColor >> sets.surfaceShader vis_ramp = pm.createNode('ramp', n='visualize') vis_ramp.setAttr('type', 1) vis_ramp.setAttr('colorEntryList[0].color', 0, 0, 0) vis_ramp.setAttr('colorEntryList[1].position', 1) vis_ramp.setAttr('colorEntryList[1].color', 0, 0, 0) vis_ramp.setAttr('colorEntryList[2].position', 0) cmds.setAttr('%s.colorEntryList[2].color' % vis_ramp, 0, 0, 0, type='double3') vis_ramp.setAttr('colorEntryList[3].color', 0, 0, 0) self.ramp.outColorR >> vis_ramp.colorEntryList[1].color.colorG rmv = pm.createNode('remapValue', n='visualize') rmv.setAttr('inputMin', -1) rmv.setAttr('inputMax', 0) rmv.setAttr('outputMin', 1) rmv.setAttr('outputMax', 0) self.ramp.outColorR >> rmv.inputValue rmv.outValue >> vis_ramp.colorEntryList[2].color.colorR (self.ramp.colorEntryList[0].position >> vis_ramp.colorEntryList[0].position) (self.ramp.colorEntryList[3].position >> vis_ramp.colorEntryList[3].position) vis_ramp.outColor >> visualize_sdr.outColor pm.defaultNavigation(source=visualize_sdr, destination=self.sphere.getShape().instObjGroups[0], connectToExisting=True)
def createCtrls(self): ctrlList = [] crv = pm.ls(self.crv)[0] pm.select(cl=1) self.allCtrlGrp = pm.group(n=self.name + '_ctrl_grp') # pociNode = pm.shadingNode('pointOnCurveInfo',asUtility = 1) pociNode.turnOnPercentage.set(1) crv.getShape().worldSpace[0] >> pociNode.inputCurve tempLoc = pm.spaceLocator() pociNode.position >> tempLoc.translate segmentLength = 1.0 /( self.numCtrl - 1) for i in range(self.numCtrl): pociNode.parameter.set(i*segmentLength) pos = tempLoc.getTranslation(space='world') ctrl = self.addCtrl(i) self.ctrlList.append(ctrl) ctrlMainGrp = self.getCtrlMainGrp(ctrl) ctrlMainGrp.setTranslation(pos) pm.parent(ctrlMainGrp,self.allCtrlGrp) pm.parent(self.allCtrlGrp,self.mainGrp) pm.delete([tempLoc,pociNode])
def gammaCorrect_node(self): # Create a GammaCorrect node to correct the gamma value of color of the Materials shader # Create a GammaCorrect node shader = pm.shadingNode('gammaCorrect', asShader = True) # Create a file texture node file_node = pm.shadingNode('file', asTexture = True) # a shading group shading_group = pm.sets(renderable = True, noSurfaceShader = True, empty = True) # Connect shader to sg surface shader pm.connectAttr('%s.value' % shader ,'%s.surfaceShader' % shading_group) # Connect file texture node to shader's color pm.connectAttr('%s.outColor' % file_node, '%s.value' % shader) # Set the gamma value to 0.454 pm.setAttr('%s.gamma' % shader, 0.454, 0.454, 0.454, type = 'double3')
def assignLambert(meshes=None, hueShift = 0.50, hsValue=0.3,rgb=None): """ Assigns a random lambert to a piece of geometry hueShift will allow divergence from the hsValue hsValue 0.0 is dark 0.5 is pastel and higher is ghostlike """ # GET all of teh MESHES or just selected meshes objs = meshes or [x.getParent() for x in pm.ls(type="mesh",dag=True,sl=True)] # DON't DO ANYTHING IF THERE IS NOTHING SELECTED if not objs: return # GENERATE A RANGE OF COLORS THAT IS PLEASING startHueR = random.random() * hsValue + 0.5 startHueG = random.random() * hsValue + 0.5 startHueB = random.random() * hsValue + 0.5 for mesh in objs: lamb = pm.shadingNode("lambert", asShader=True,name="tempLambert") sg = pm.sets(lamb,renderable=True, noSurfaceShader=True, empty=True, name='%sSG'%lamb) if rgb: r=rgb[0] g=rgb[1] b=rgb[2] else: r = returnNearHue(startHueR,hueShift) g = returnNearHue(startHueG,hueShift) b = returnNearHue(startHueB,hueShift) lamb.color.set(r,g,b) pm.select(mesh,r=True) pm.hyperShade(assign=lamb)
def create_wireframe_rl(name="wireframe"): """ Creates wireframe material Creates wireframe layer Adds all geometry and rendercam to the renderlayer @param name: str layername """ mat_name = "%s_mat" % name if not pm.objExists(mat_name): material_node = pm.shadingNode("lambert", n=mat_name, asShader=True) material_node.setColor([1, 1, 1]) material_sg_node = pm.sets(renderable=True, noSurfaceShader=True, empty=True, name="%sSG" % mat_name) material_sg_node.miContourEnable.set(1) material_sg_node.miContourColor.set([0,0,0]) material_sg_node.miContourWidth.set(1.5) material_node.outColor >> material_sg_node.surfaceShader if not pm.objExists(name): render_layer = pm.createRenderLayer(n=name) render_layer.setCurrent() render_layer.addMembers(pm.ls(geometry=True, cameras=True)) material_sg_node.message >> render_layer.shadingGroupOverride
def _createNode(self): assert self.node is None assert self.name is not None # create a new dl_textureMap node with our name and path # need to call shadingNode, as the File constructor calls createNode instead of shadingNode # this results in a node that can't be seen in the hypershade return pm.shadingNode("dl_textureMap", name=self.name, asTexture=True)
def rig_getClosestPointAndPositionOnCurve(obj, crv): ''' Gets the closest point for an object to a curve and returns a pointOnCurveInfo Args: obj (pm.PyNode): Object to constrain to crv (pm.nt.NurbsCurve): Curve to get info from Returns (pm.shadingNode.pointOnCurveInfo): pointOnCurveInfo node that results Usage: rig_getClosestPointAndPositionOnCurve(pm.ls(sl=True)[0], pm.ls(sl=True)[1]) ''' cpoc = pm.shadingNode('nearestPointOnCurve', asUtility=True) crv.getShape().attr('worldSpace').connect(cpoc.inputCurve) cpoc=pm.PyNode(cpoc, n=obj+'_POCI') #1. Create a pointConstraint node. (Use createNode pointConstraint rather than using the UI.) #2. Connect transform.parentMatrix[0] to pointConstraint.target[0].targetParentMatrix #3. Connect transform.rotatePivot to pointConstraint.target[0].targetRotatePivot #4. Connect transform.rotatePivotTranslate to pointConstraint.target[0].targetRotateTranslate #5. Connect transform.translate to pointConstraint.target[0].targetTranslate pointConstraint = pm.createNode('pointConstraint') obj.parentMatrix[0].connect(pointConstraint.target[0].targetParentMatrix) obj.rotatePivot.connect(pointConstraint.target[0].targetRotatePivot) obj.rotatePivotTranslate.connect(pointConstraint.target[0].targetRotateTranslate) obj.translate.connect(pointConstraint.target[0].targetTranslate) #Now pointConstraint.constraintTranslate will hold the worldSpace position of your object. pointConstraint.constraintTranslate.connect(cpoc.inPosition) #obj.t.connect(cpoc.inPosition) poci = pm.nodetypes.PointOnCurveInfo(n=obj+"_POCI") crv.getShape().attr("worldSpace[0]").connect(poci.inputCurve) cpoc.parameter.connect(poci.parameter) return [poci, cpoc, pointConstraint]