gpt4 book ai didi

python - 玛雅Python : rename duplicated joint children

转载 作者:行者123 更新时间:2023-12-03 01:58:24 25 4
gpt4 key购买 nike

因此,当我继续构建 Autowiring 脚本时,我遇到了我预计难以解决的三个问题中的第二个。这可能是一个非常简单的答案:但脚本本身非常容易使用,首先点击“生成代理定位器”,然后点击“构建脊柱关节”:但问题出在“构建 IK 控制”按钮上,它足够好地复制了绑定(bind)关节,并且重命名第一个:但我无法像绑定(bind)关节那样将其设置为正确的数字增量:如果展开它,它只会为名为“spine__IK”的 child 提供任何帮助,我们始终不胜感激:

'''
import DS_hybrid_spineOmatic_V1
reload (DS_hybrid_spineOmatic_V1)
DS_hybrid_spineOmatic_V1.gui()
'''

import re
import maya.cmds as cmds
import maya.mel as mel

if cmds.window("spineWin", exists =True):
cmds.deleteUI("spineWin", window = True)

myWindow = cmds.window("spineWin",t='DS_hybrid_spineOmatic_V1',w=200, h=500, toolbox=True)
column = cmds.columnLayout(adj=True)

'''
To DO:
-You're going to have a series of scrips splitting into an IKFK spine and a ribon spine: this script will build the IKFK spine
-make build spine joints orient joint chain
'''

def gui():

cmds.button( label="Generate Spine Proxy Locators", c = buildProxies)
cmds.separator( w=200, h=3)
cmds.button( label="Build Spine Joints", c = buildJointChain)
cmds.separator( w=200, h=3)
cmds.button( label="Build IK Controls", c = createIKcontrols)
cmds.separator( w=200, h=9)

cmds.setParent('..')
cmds.showWindow(myWindow)

def buildProxies(*args):
locAmount = 2
for i in range(locAmount):
countLoc = i+1
spaceLoc = cmds.spaceLocator(n = 'spineLoc_{}_PRX'.format(countLoc), p = [0,i*2.5,0])
cmds.makeIdentity(spaceLoc, a=1, t=1)
mel.eval('CenterPivot;')

cmds.parent('spineLoc_2_PRX','spineLoc_1_PRX')

def buildJointChain(*args):

cmds.select(cl=True) #this line clears your selection

#this For in range loop creates equidistant joints between the 2 proxy locators
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
countJnt = 7

startLoc = "spineLoc_1_PRX" #this is where the joint chain starts
endLoc = "spineLoc_2_PRX" #this is where the joint chain ends

jntPosSteps = 1.0/(countJnt-1) # Will use count to calculate how much it should increase percentage by each iteration. Need to do -1 so the joints reach both start and end points.
jntPerc = 0 # This will always go between a range of 0.0 - 1.0, and we'll use this in the constraint's weights.

for jNum in range(countJnt):
jntInc = jNum
jnt = cmds.joint(n = 'spineJnt_{}_Bound'.format(jntInc))
cmds.setAttr(jnt + ".displayLocalAxis", True) #display the local rotation axis of the joint

jntConstraint = cmds.pointConstraint(startLoc, jnt, weight=1.0 - jntPerc)[0] # Apply 1st constraint, with inverse of current percentage.
cmds.pointConstraint(endLoc, jnt, weight=jntPerc)
cmds.delete(jntConstraint) #constraint is now no longer neccisary

jntPerc += jntPosSteps #Increase percentage for next iteration
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#this will orient the joint chain(build later)
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
cmds.select(cl=True)
cmds.group(n='skeletonGrp',empty=True,world=True)
cmds.parent('spineJnt_0_Bound','skeletonGrp')
cmds.delete('spineLoc_1_PRX')

def createIKcontrols(*args):

#create spine control curves
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#create duplicate joint chain
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ikName = 'spineJnt_*_IK'
ikChain = cmds.duplicate('spineJnt_0_Bound', n='spineJnt_0_IK')[0]
cmds.parent(ikChain,world=True)
ikList = cmds.listRelatives(ikChain,ad=True,pa=True)
for name in ikList:
cmds.rename(name, ikName)
print(ikList)
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#create IK spline handle for joint chain

我只需要脚本来正确且按顺序重命名重复的关节链

最佳答案

您不能使用通配符重命名 cmds.rename(name, ikName),其中 ikName 为“spineJnt_*_IK”将导致“spineJnt___IK”,因为在 Maya 中,* 是无效字符并且将替换为下划线。但你可以这样做:

for idx, name in enumerate(ikList):
cmds.rename(name, 'spineJnt_{0}_IK'.format(idx))
print(ikList)

什么导致或多或少正确的命名。这里的问题是 listRelatives 在父节点之前先给出叶节点。所以你的编号将是相反的。这可以通过反转 id 来修复:

cmds.rename(name, 'spineJnt_{0}_IK'.format(len(ikList) - idx))

这应该会给你一个更好的结果。

关于python - 玛雅Python : rename duplicated joint children,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60543702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com