本文整理汇总了Python中pymel.core.duplicate函数的典型用法代码示例。如果您正苦于以下问题:Python duplicate函数的具体用法?Python duplicate怎么用?Python duplicate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duplicate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __mirrorBlendShape
def __mirrorBlendShape(self,*args):
pm.select(self.baseShape)
baseShape = pm.ls(sl = 1)[0]
pm.select(self.sculptedShape)
sculptedShape = pm.ls(sl = 1)[0]
baseWarp = pm.duplicate(baseShape,n = nameUtils.setUniqueName(baseShape + 'Warp','geo'))
baseScaleNeg = pm.duplicate(baseShape,n = nameUtils.setUniqueName(baseShape + 'ScaleNeg','geo'))
#flip scale
pm.setAttr(baseScaleNeg[0] + '.scaleX', -1)
tempBlend = pm.blendShape(sculptedShape,baseScaleNeg[0],n = nameUtils.setUniqueName(sculptedShape + 'TempBlend','geo'))
#create warp between warp and neg
pm.select(cl=True)
pm.select(baseWarp)
pm.select(baseScaleNeg,add = 1)
pm.runtime.CreateWrap()
pm.setAttr(tempBlend[0] + '.' + sculptedShape, 1)
#Duplicate Wrapped shape for final result
pm.duplicate(baseWarp)
#Clean up setup
pm.delete(baseWarp,baseScaleNeg)
示例2: buildChains
def buildChains(self, *args):
"""
Build joint chains based on locator positions.
"""
self.jointChain = []
self.ikChain = []
self.fkChain = []
loc1Pos = pm.xform(self.loc1, q=True, ws=True, t=True)
loc2Pos = pm.xform(self.loc2, q=True, ws=True, t=True)
loc3Pos = pm.xform(self.loc3, q=True, ws=True, t=True)
jnt1='%s_shldrJnt'%self.prefix
jnt2='%s_elbow1Jnt'%self.prefix
jnt3='%s_wristJnt'%self.prefix
self.jointChain.append(pm.PyNode(pm.joint(p=loc1Pos, n=jnt1)))
self.jointChain.append(pm.PyNode(pm.joint(p=loc2Pos, n=jnt2)))
self.jointChain.append(pm.PyNode(pm.joint(p=loc3Pos, n=jnt3)))
#--- Orient the chain
self.orientChain()
#--- Creating duplicate ik/fk joint chains
for each in pm.duplicate(self.jointChain, rc=True):
# Slice off number maya adds during duplication
each.rename('%s_ik' % each[:-1])
self.ikChain.append(pm.PyNode(each))
for each in pm.duplicate(self.jointChain, rc=True):
each.rename('%s_fk' % each[:-1])
self.fkChain.append(pm.PyNode(each))
示例3: create_deltaMush
def create_deltaMush(bindGeo, iterations = [5, 10, 20, 30, 40]):
smoothGeo = pm.duplicate( bindGeo, rr=True, ic=True, name=bindGeo.name() + "_smooth") [0]
smoothGeo.addAttr("envelope", at='long', min=0, max=1, dv=1, k=True)
smoothGeo.addAttr("partitions", at='message')
deltaGeo = pm.duplicate( bindGeo, rr=True, ic=False, name="BS_" + bindGeo.name() + "_delta") [0]
pm.select(deltaGeo, smoothGeo)
pm.mel.eval("CreateWrap")
smoothNodes = []
smoothNodeSets = []
for i in range(0, len(iterations)):
smoothNode = pm.deformer([smoothGeo], type='smooth')[0]
smoothNode.iterations.set(iterations[i])
smoothGeo.envelope >> smoothNode.envelope
smoothNodes.append(smoothNode)
smoothNodeSet = smoothNode.message.listConnections()[0]
smoothNodeSet.clear()
smoothNodeSets.append(smoothNodeSet)
for smoothNodeSet in smoothNodeSets:
smoothNodeSet.clear()
partition = pm.partition(smoothNodeSets)
partition.message >> smoothGeo.partitions
skinCls = bindGeo.getShape().listConnections(type='skinCluster')[0]
joints = skinCls.getInfluence()
assign_iteration_set(joints, bindGeo, skinCls, deltaGeo)
示例4: instance
def instance(self, source_transform_node):
"""instances the given nodes hierarchy
"""
# duplicate the given node
# then replace the instanceable nodes with instances
# find instanceable nodes in the node and dupNode
source_hierarchy = self.walk_hierarchy(source_transform_node)
# if there is no node in the sourceHierarchy just return
# the instance of the given node
if len(source_hierarchy) < 1:
dup_node = pm.duplicate(source_transform_node, ilf=1, rc=True)[0]
pm.select(dup_node)
return
dup_node = pm.duplicate(source_transform_node, rc=True)[0]
dup_hierarchy = self.walk_hierarchy(dup_node)
for i, node in enumerate(dup_hierarchy):
shape = node.getShape()
if shape is not None and isinstance(shape,
tuple(self._instanceables)):
# instance the corresponding sourceNode
source_node = source_hierarchy[i]
new_instance_node = pm.duplicate(source_node, ilf=True)[0]
pm.parent(new_instance_node, node.getParent(), r=False)
pm.delete(node)
pm.select(dup_node)
return dup_node
示例5: duplicateArray
def duplicateArray(objA=None, noCopies=9, direction="+x", adj=0):
""" Duplicate Array of Objects """
if objA == None:
objA = getSelection()
else:
objA = pm.PyNode(objA)
if isinstance(objA, pm.nodetypes.Transform):
result = [objA]
width = getWidth(objA)
dup = pm.duplicate(objA)[0]
result.append(dup)
if "+x" in direction or "+X" in direction:
pos = dup.t.get()
pm.move(pos.x + width[0] + adj, pos.y, pos.z)
elif "-x" in direction or "-X" in direction:
pos = dup.t.get()
pm.move(pos.x - width[0] + adj, pos.y, pos.z)
if "+y" in direction or "+Y" in direction:
pos = dup.t.get()
pm.move(pos.x, pos.y + width[1] + adj, pos.z)
elif "-y" in direction or "-Y" in direction:
pos = dup.t.get()
pm.move(pos.x, pos.y - width[1] + adj, pos.z)
if "+z" in direction or "+Z" in direction:
pos = dup.t.get()
pm.move(pos.x, pos.y, pos.z + width[2] + adj)
elif "-z" in direction or "-Z" in direction:
pos = dup.t.get()
pm.move(pos.x, pos.y, pos.z - width[2] + adj)
for i in xrange(noCopies - 1):
dup = pm.duplicate(st=True)[0]
result.append(dup)
return result
示例6: gimbal
def gimbal(**kwargs):
final = pm.nt.Transform(name = 'Gimbal')
circle1 = pm.modeling.circle(
constructionHistory = False,
normal = kwargs['normal'] if 'normal' in kwargs else [0, 1, 0],
radius = kwargs['radius'] if 'radius' in kwargs else 1
)[0]
circle2 = pm.duplicate(circle1, returnRootsOnly = True)[0]
circle2.rotateBy((90, 0, 0))
circle3 = pm.duplicate(circle1, returnRootsOnly = True)[0]
circle3.rotateBy((0, 0, 90))
for circle in [circle1, circle2, circle3]:
pm.makeIdentity(circle, apply = True)
shape = circle.getShape()
pm.parent(shape, final, shape = True, relative = True)
shape.rename('{0}Circle1Shape'.format(final.nodeName()))
pm.delete(circle)
return final
示例7: bdSwitchFKIK
def bdSwitchFKIK(self):
if 'arm' in self.limb:
print self.side + ' arm FK->IK switch '
for loc in self.ikArmCons:
shadowLoc = pm.ls(self.namespace + self.side + loc + 'LOC')[0]
tempLoc = pm.duplicate(shadowLoc)
pm.parent(tempLoc,w=True)
ikCon = pm.ls(self.namespace + self.side + loc + 'CON',type='transform')[0]
if ikCon.name().find('armIK') > 0:
tempCnstr = pm.parentConstraint(tempLoc,ikCon)
else:
tempCnstr = pm.pointConstraint(tempLoc,ikCon)
pm.delete([tempCnstr,tempLoc])
self.armSwitchCon.attr('ikFkBlend').set(0)
elif 'leg' in self.limb:
print self.side + ' leg FK->IK switch '
for loc in self.ikLegCons:
shadowLoc = pm.ls(self.namespace + self.side + loc + 'LOC')[0]
tempLoc = pm.duplicate(shadowLoc)
pm.parent(tempLoc,w=True)
ikCon = pm.ls(self.namespace + self.side + loc + 'CON',type='transform')[0]
if ikCon.name().find('legIK') > 0:
tempCnstr = pm.parentConstraint(tempLoc,ikCon)
else:
tempCnstr = pm.pointConstraint(tempLoc,ikCon)
pm.delete([tempCnstr,tempLoc])
self.legSwitchCon.attr('ikFkBlend').set(0)
示例8: rig_ctrlDuplicate
def rig_ctrlDuplicate(ctrl, name):
"""Creates a hub set
Args:
ctrl (pm.PyNode): maya objects to rename
name (str): new name
Returns:
list: [offset_grp, ctrl, con_grp]
"""
orig_name = ctrl.split('_')[0]
grp_offset,grp_con = None,None
if str(ctrl.getParent()) == orig_name+'Offset_GRP':
grp_offset = pm.PyNode(orig_name + 'Offset_GRP')
if orig_name+'Con_GRP' in ctrl.getChildren():
grp_con = pm.PyNode(orig_name+'Con_GRP')
if grp_offset:
grp_offsetDup = pm.duplicate(grp_offset,n=name+'Offset_GRP',po=True)
ctrl_dup = pm.duplicate(ctrl,n=ctrl.replace(orig_name, name))
ctrl_dup[0].setParent(grp_offsetDup)
for child in ctrl_dup[0].getChildren():
if child.type() != 'nurbsCurve':
pm.delete(child)
if grp_con:
grp_conDup = pm.duplicate(grp_con,n=name+'Con_GRP',po=True)
grp_conDup[0].setParent(ctrl_dup)
if grp_offset:
return [grp_offsetDup[0],ctrl_dup[0],grp_conDup[0]]
else:
return [None,ctrl_dup[0],grp_conDup[0]]
示例9: bdSwitchIKFK
def bdSwitchIKFK(self):
if 'arm' in self.limb:
print self.side + ' arm IK -> FK switch'
for loc in self.fkArmCons:
shadowLoc = pm.ls(self.namespace + self.side + loc + 'LOC')[0]
tempLoc = pm.duplicate(shadowLoc)
pm.parent(tempLoc,w=True)
fkCon = pm.ls(self.namespace + self.side + loc + 'CON',type='transform')[0]
tempCnstr = pm.orientConstraint(tempLoc,fkCon)
pm.delete([tempCnstr,tempLoc])
self.armSwitchCon.attr('ikFkBlend').set(1)
elif 'leg' in self.limb:
print self.side + ' leg IK->FK switch '
for loc in self.fkLegCons:
shadowLoc = pm.ls(self.namespace + self.side + loc + 'LOC')[0]
tempLoc = pm.duplicate(shadowLoc)
pm.parent(tempLoc,w=True)
fkCon = pm.ls(self.namespace + self.side + loc + 'CON',type='transform')[0]
tempCnstr = pm.orientConstraint(tempLoc,fkCon)
pm.delete([tempCnstr,tempLoc])
self.legSwitchCon.attr('ikFkBlend').set(1)
示例10: createIKSpline
def createIKSpline( jntList ):
pymelLogger.debug('Starting: createIKSpline()...')
# Make IK Spline
ikHandleTorso = pm.ikHandle( startJoint=jntList[0], endEffector=jntList[-1], solver = 'ikSplineSolver', numSpans = 4, name = jntList[-1]+'_'+Names.suffixes['ikhandle'])
# we should probably rename the object created to know names ......
# CAREFULL // inherits Transform OFF, to avoid double transformation when grouped later on
pm.setAttr(ikHandleTorso[2] + '.inheritsTransform', 0)
# Duplicate last and first joint to use as Drivers of the spine Ik curve
print jntList
drvStart = pm.duplicate(jntList[0], parentOnly=True, name = Names.prefixes['driver']+'_'+ jntList[0] +'_'+Names.suffixes['start'])
drvEnd = pm.duplicate(jntList[-1], parentOnly=True, name = Names.prefixes['driver']+'_'+ jntList[-1] +'_'+Names.suffixes['end'])
pm.parent(drvEnd, w=1)
# Make radius bigger
pm.joint(drvStart, edit = True, radius = 1)
pm.joint(drvEnd, edit = True, radius = 1)
# Skin hip/shldr jnt's to back curve
pm.skinCluster(drvStart,drvEnd,ikHandleTorso[2],dr=4)
# return nedded elements
rList = [ikHandleTorso, drvStart, drvEnd ]
pymelLogger.debug('End: createIKSpline()...')
return rList
示例11: copy_correctiveToBlend
def copy_correctiveToBlend(base, corrective):
'''Bakes a static mesh that can be used as a corrective to what you've posed
Args:
base (pm.PyNode): base object with bad shape from skinCluster or blendShapes
corrective (pm.PyNode): sculpted fixed shape
Returns:
[pm.PyNode]: new corrected shape
Usage:
copy_correctiveToBlend(pm.ls(sl=True)[0], pm.ls(sl=True)[1])
'''
#Duplicate your deformed mesh twice, calling one positive and one negative. Move them a little away from your model
positive = corrective
negative = pm.duplicate(base, n=corrective.name()+"_negative")[0]
inputs = pm.listConnections(base.getShape(), type=['skinCluster','blendShape'])
for input in inputs:
input.attr('envelope').set(0)
corrected = pm.duplicate(base, n=corrective.name()+"_corrective")[0]
#Make a new blend-shape node on your character containing the two duplicate meshes. This blend shape must use the parallel blending mode.
blend = pm.blendShape(corrected, n='corrector_BS')[0]
pm.blendShape(blend, e=True, t=(corrected, 0, positive, 1.0))
pm.blendShape(blend, e=True, t=(corrected, 1, negative, 1.0))
set=1
for alias in blend.listAliases():
alias[1].set(set)
set=-1
#Move your character back to bind-pose and in the parallel blend-node, set the positive mesh to 1 and the negative to -1. This should blend your mesh so that you only have the deformations you made to the positive mesh, but now in a neutral pose.
#bindPose
#Duplicate this new mesh and call it something with the letters BS is the name because this is infinitely funny. This mesh can now be used as a corrective blend-shape
#Delete the parallel blend-node and repeat these steps for all your shapes. Yes, really.
#pm.delete(p_bs)
#pm.delete(base)
for input in inputs:
input.attr('envelope').set(1)
return corrected
示例12: makeFkIk
def makeFkIk(*args):
bindRoot = pm.ls(selection = True)[0]
bindChain = pm.ls(bindRoot, dag = True)
fkChain = pm.duplicate(bindRoot)
replaceSuffix(fkChain, 'fk')
makeFk(False, fkChain)
ikChain = pm.duplicate(bindRoot)
replaceSuffix(ikChain, 'ik')
makeIk(False, ikChain)
fkChainList = pm.ls(fkChain, dag = True)
ikChainList = pm.ls(ikChain, dag = True)
createPad(bindRoot)
suffixIndex = bindChain[0].rfind('_')
hanldeName = bindChain[0][:suffixIndex] + '_switch'
handle = createHandle(hanldeName)
pm.rename(handle, hanldeName)
pm.parentConstraint(bindChain[-1], handle)
constraintList = []
for i, item in enumerate(bindChain):
newConstraint = pm.orientConstraint(fkChainList[i], ikChainList[i], bindChain[i], mo = False)
fkCon = pm.orientConstraint(newConstraint, q = True, wal = True)[1]
ikCon = pm.orientConstraint(newConstraint, q = True, wal = True)[0]
pm.setDrivenKeyframe(fkCon, cd = handle + '.switch', v = 1, dv = 10)
pm.setDrivenKeyframe(fkCon, cd = handle + '.switch', v = 0, dv = 0)
pm.setDrivenKeyframe(ikCon, cd = handle + '.switch', v = 0, dv = 10)
pm.setDrivenKeyframe(ikCon, cd = handle + '.switch', v = 1, dv = 0)
示例13: createJnts
def createJnts( LegJnts, side ):
pymelLogger.debug('Starting: createJnts()...')
# duplicate joints
listJnts = []
print LegJnts
for jnt in LegJnts:
pm.select(clear=1)
newJnt = pm.duplicate(jnt,rr=True,po=True, name=jnt+'_'+Names.suffixes['ik'])[0]
try:
newJnt.setParent(world=1)
except: pass
listJnts.append(newJnt)
print listJnts
# parent joints
listJnts.reverse()
index = 0
for jnt in listJnts:
if index+1 == len(listJnts): break
jnt.setParent(listJnts[index+1])
index = index + 1
listJnts.reverse()
# joints for inverse foot
ankleFloorJnt = '%s%s' %(side,'AnkleFloor_if')
# duplicate only joints ww for inverse foot
pm.select(clear=1)
toeBaseWW = listJnts[-3]
invfootname = str(toeBaseWW).replace('_'+Names.suffixes['ik'], '_inversefoot')
invfootjnt = pm.duplicate( toeBaseWW, name=invfootname )[0]
invfootjnt.setParent(w=1)
index = 1
invjntlist = invfootjnt.listRelatives(ad=1)
invjntlist.reverse()
for jnt in invjntlist:
jnt.rename(invfootname+str(index))
jnt.setParent(w=1)
index += 1
invjntlist.reverse()
invjntlist.append(invfootjnt)
invjntlist.reverse()
index = 0
for jnt in invjntlist:
if index+1 == len(invjntlist): break
jnt.setParent(invjntlist[index+1])
index = index + 1
# make them child of the Ankle floor jnt
invjntlist[-1].setParent(ankleFloorJnt)
pm.select(clear=1)
pymelLogger.debug('End: createJnts()...')
print listJnts
return listJnts
示例14: duplicateJointChain
def duplicateJointChain( *joints ):
'''
update : 2015-04-04
'''
if joints:
pm.select(joints)
joints = pm.selected(type='joint')
# 입력된게 없으면 에러
if not joints:
raise
# 선택된게 하나이면?
if len(joints)==1 :
dupJnt = pm.duplicate( joints[0], po=True )[0]
dupJnt.setParent( w=True )
pm.select(dupJnt)
return [dupJnt]
else:
startJoint = joints[0]
endJoint = joints[-1]
# endJoint가 startJoint의 parent가 아니면 에러
if endJoint not in startJoint.getChildren( allDescendents=True ):
raise
# 복사할 조인트 리스트 만듦
jointList = [ endJoint ]
p = endJoint.getParent()
while p!=startJoint:
jointList.append( p )
p = p.getParent()
jointList.append( startJoint )
# 새로운 조인트 복사
newJoint = []
for jnt in jointList:
jnt = pm.duplicate(jnt, returnRootsOnly=True, renameChildren=True, parentOnly=True)[0]
newJoint.append(jnt)
# parent
for i in range( len(newJoint[:-1]) ):
newJoint[i].setParent( newJoint[i+1])
# 루트로 옮김
newJoint[-1].setParent(w=True)
#
newJoint.reverse()
return newJoint
示例15: bdBuildSplineSolverScale
def bdBuildSplineSolverScale():
selection = pm.ls(sl=1,type='transform')
startJoint = ''
if selection:
startJoint = selection[0]
else:
return
print startJoint
ikSpline = pm.listConnections(startJoint,type='ikHandle')[0]
print ikSpline
solver = ikSpline.ikSolver.inputs()[0]
if 'ikSplineSolver' in solver.name():
sclChain = pm.duplicate(startJoint,name = startJoint.name() + '_SCL')[0]
sclChainAll = sclChain.listRelatives(f=True, ad=True,type='joint')
print sclChainAll
for sclJnt in sclChainAll:
pm.rename(sclJnt,sclJnt+'_SCL')
splineCurve = pm.listConnections(ikSpline, type = 'nurbsCurve')[0]
effector = pm.listConnections(ikSpline ,source=True, type='ikEffector')[0]
endJoint = pm.listConnections(effector,source=True, type='joint')[0]
jointChain = startJoint.listRelatives(f=True, ad=True,type='joint')
jointChain = jointChain + [startJoint]
jointChain.reverse()
print jointChain
splineCurveScl = pm.duplicate(splineCurve,name = splineCurve.name().replace('crv','crv_scl'))
strArclenSCL = pm.arclen(splineCurveScl,ch=True)
strArclenCRV = pm.arclen(splineCurve,ch=True)
arclenSCL = pm.ls( strArclenSCL ) [0]
arclenCRV = pm.ls( strArclenCRV ) [0]
arclenSCL.rename(splineCurveScl[0].name() + '_length')
arclenCRV.rename(splineCurve.name() + '_length')
mdScaleFactor = pm.createNode('multiplyDivide', name = splineCurve.name().replace('crv','crv_scaleFactor_md'))
arclenCRV.arcLength.connect(mdScaleFactor.input1X)
arclenSCL.arcLength.connect(mdScaleFactor.input2X)
mdScaleFactor.operation.set(2)
for jnt in jointChain[1:]:
mdJntTr = pm.createNode('multiplyDivide', name = jnt + '_trX_MD')
#mdJntTr.operation.set(2)
sclJnt = pm.ls(jnt + '_SCL')[0]
mdScaleFactor.outputX.connect(mdJntTr.input2X)
sclJnt.translateX.connect(mdJntTr.input1X)
mdJntTr.outputX.connect(jnt.translateX)