#!BPY """ Name: 'Merge to parent' Blender: 248.1 Group: 'WeightPaint' Tooltip: 'Merge weights to Parent bone' """ __author__ = "Ivo Grigull" __url__ = ["www.ivogrigull.com"] __version__ = "0.1" __bpydoc__ = """\ Merge to parent ---------------------- Menu: Weightpaint->Merge to Parent This script is supposed to be used in conjunction with the bone heating appoach. Because the bone heating does sometimes not reach all areas i want, (for example in the head) i usually add additional child bones and apply bone heating again. This script can then be used to merge the weights to the parent bone, to get rid of the extra vertex groups and remove the clutter. This Script is to be used only in weight paint mode, and if the mesh has an armature modifier ( i.e. you have to make the armature modifier "real" before using the script ). # -------------------------------------------------------------------------- # ***** BEGIN GPL LICENSE BLOCK ***** # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # ***** END GPL LICENCE BLOCK ***** """ import Blender from Blender import Scene, Draw, Object, Modifier, Armature import BPyMesh def main(): ob = Object.GetSelected()[0] print ob.name arm = None Bone = None for m in ob.modifiers: if m.type== Modifier.Types.ARMATURE: arm = m[Modifier.Settings.OBJECT] if arm: print arm bones = arm.getData().bones.values() for bone in bones: options = bone.options if Armature.BONE_SELECTED in options: Bone = bone if not Bone == None: print 'Bone: %s' % Bone.name print 'Mesh: %s' % ob me= ob.getData(mesh=1) groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me) for n in range(0, len(vWeightDict)): if Bone.name in vWeightDict[n]: # print Bone.name # print 'parent: %s' % Bone.parent.name if Bone.parent.name in vWeightDict[n]: value = ( vWeightDict[n][Bone.parent.name] + vWeightDict[n][Bone.name] ) * 0.5 vWeightDict[n][Bone.parent.name] += vWeightDict[n][Bone.name] vWeightDict[n].pop(Bone.name) else: vWeightDict[n][Bone.parent.name] = vWeightDict[n][Bone.name] vWeightDict[n].pop(Bone.name) BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict) if __name__=='__main__': main()