我有两套骷髅(A和B),并试图将一组关节设为父约束。
我所做的是将A选择放入A数组,B选择放入B数组。 但是如何按距离进行父约束A到B,距离基本为0,所以脚趾关节不会用手指连接。 比如波纹管。
如果有人能告诉我,我会很感激。
firstSel = []
secondSel = []
def firstSelection(*args):
sel = mc.select(hi = True)
joints = mc.ls(sl=True, type = "joint")
firstSel.append(joints)
print "this is first selection"
def secondSelection(*args):
tsmgRoot = mc.select(hi = True)
tsmgJoints = mc.ls(sl=True, type = "joint")
secondSel.append(tsmgJoints)
答案 0 :(得分:0)
以下是一个示例,说明如何通过世界位置将对象从一个列表约束到另一个列表。可能有更聪明的方法,比如将值添加到Sub Choose_Country()
If (c2 = "Germany") Then
Sheet8.Visible = True
Sheet9.Visible = False
Sheet10.Visible = False
ElseIf (C2 = Australia) Then
Sheet8.Visible = False
Sheet9.Visible = True
Sheet10.Visible = False
ElseIf (C2 = Austria) Then
Sheet8.Visible = False
Sheet9.Visible = False
Sheet10.Visible = True
End if
End sub
然后对其进行排序,但这样会感觉更具可读性。
dict
另外作为附注,当您获得选择时,不需要import math
# Add code here to get your two selection lists
# Loop through skeleton A
for obj in first_sel:
closest_jnt = None # Name of the closest joint
closest_dist = 0 # Distance of the closest joint
obj_pos = cmds.xform(obj, q=True, ws=True, t=True)
# Loop through skeleton B to find the nearest joint
for target in second_sel:
target_pos = cmds.xform(target, q=True, ws=True, t=True)
# Calculate the distance between the 2 objects
dist = math.sqrt((target_pos[0]-obj_pos[0])**2 +
(target_pos[1]-obj_pos[1])**2 +
(target_pos[2]-obj_pos[2])**2)
# If this is the first object we loop through, automatically say it's the closest
# Otherwise, check to see if this distance beats the closest distance
if closest_jnt is None or dist < closest_dist:
closest_jnt = target
closest_dist = dist
cmds.parentConstraint(closest_jnt, obj, mo=True)
(您实际上是在列表中添加列表!)。你可以像firstSel.append(joints)
一样直接分配它,或者如果列表中已存在某些项目并且你想添加它,你可以使用firstSel = mc.ls(sl=True, type = "joint")