情景描述
使用Rigify模块自定义骨架的时候,生成的最终Rig一般会如下图所示:按钮有了,但是没有名称 以前的文章介绍过标准流程,就是在MetaRig上编辑层和UI的对应关系。不过如果绑定的时候忘了,已经生成最终Rig以后,也是完全可以补救的,而且更加简单。
将任意窗口切换成文本编辑器
,然后在下图红框所示的下拉菜单找到rig_ui.py
这个python脚本(由Rigify生成的脚本)。
找到
draw
这个函数的定义:
这个函数,本例中该函数如下所示
def draw(self, context):
layout = self.layout
col = layout.column()
row = col.row()
row.prop(context.active_object.data, 'layers', index=1, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=4, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=8, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=9, toggle=True, text=' ')
row = col.row()
row.prop(context.active_object.data, 'layers', index=13, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=14, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=15, toggle=True, text=' ')
row = col.row()
row.separator()
row = col.row()
row.separator()
row = col.row()
row.prop(context.active_object.data, 'layers', index=28, toggle=True, text='Root')
这个函数的原理很简单:
# 换行
row = col.row()
#设置按钮和层的对应关系,并为该按钮命名
row.prop(context.active_object.data, 'layers', index=15, toggle=True, text=' ')
def draw(self, context):
layout = self.layout
col = layout.column()
row = col.row()
row.prop(context.active_object.data, 'layers', index=1, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=4, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=8, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=9, toggle=True, text=' ')
row = col.row()
row.prop(context.active_object.data, 'layers', index=13, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=14, toggle=True, text=' ')
row.prop(context.active_object.data, 'layers', index=15, toggle=True, text=' ')
row = col.row()
row.separator()
row = col.row()
row.separator()
row = col.row()
row.prop(context.active_object.data, 'layers', index=28, toggle=True, text='Root')
修改后的draw
函数
def draw(self, context):
layout = self.layout
col = layout.column()
row = col.row()
row.prop(context.active_object.data, 'layers', index=1, toggle=True, text='Arms')
row.prop(context.active_object.data, 'layers', index=4, toggle=True, text=' Legs')
row.prop(context.active_object.data, 'layers', index=8, toggle=True, text=' Torso')
row.prop(context.active_object.data, 'layers', index=9, toggle=True, text=' Torso(Tweak)')
row = col.row()
row.prop(context.active_object.data, 'layers', index=13, toggle=True, text='Arms(Tweak) ')
row.prop(context.active_object.data, 'layers', index=14, toggle=True, text='Legs(Tweak) ')
row.prop(context.active_object.data, 'layers', index=15, toggle=True, text=' Tail')
row = col.row()
row.separator()
row = col.row()
row.separator()
row = col.row()
row.prop(context.active_object.data, 'layers', index=28, toggle=True, text='Root')
别忘了运行一下
于是乎,按钮就有名字了
你甚至还可以照猫画虎地给任意层添加按钮