我对一个列表中的育儿关节有一点问题。
spineJn = ['spine_IK_Jnt_A', 'spine_IK_Jnt_B', 'spine_IK_Jnt_C', 'spine_IK_Jnt_D', 'spine_IK_Jnt_E', 'spine_IK_Jnt_F', 'spine_IK_Jnt_G']所以,我需要在这个列表中用这些关节做一个关节链。关键点是我想让它反向,这意味着顶端的父关节是'spine_IK_Jnt_A‘,链的末端是'spine_IK_Jnt_G’
很抱歉问了这么简单的问题,但我在网上找不到任何东西。提前感谢您的帮助。
发布于 2020-04-08 21:57:31
因为您希望一次引用列表中的多个项,所以我认为使用索引来操作列表中的位置是最直接的。
for index in range(len(spineJn) - 1): # Iterate from 0 to 5 so we don't get an IndexError by going over 6 by doing + 1
pm.parent(spineJn[index + 1], spineJn[index])或者,使用一些zip魔术:
for cur, nxt in zip(spineJn, spineJn[1:]): # spineJn[1:] offsets the list by one, and then we combine the two lists with zip
pm.parent(nxt, cur)希望这能有所帮助!
https://stackoverflow.com/questions/61097149
复制相似问题