The last weeks, i have been skinning some characters inside Blender 3D. In order to do it correctly, i’ve created some ‘vertex group’, that i use along with the ‘mask’ modifier to hide some parts of the mesh. it makes the job easier.
After skinning, i exported characters to display in a game engine, and therein lies the problem. The normalizing of the influences is not correct. In Blender, ‘vertex group’ that we use with ‘armature’, they mix with all ‘vertex group’ we create to do something else, so, when we normalize the influence, Blender takes this ‘vertex group’ in account, and the calculation is incorrect. The consecuence of this is simply a bad deformation inside the external game engine.
To solve the problem, i’ve written this little script, that tries to find a bone inside the armature, and if not, remove all the influences of that ‘vertex group’, and remove it. We could do this process manually. To do so, we should select all the vertex of the mesh, remove the influence of the ‘vertex groups’ that we don’t need, and erase them.
bb ^^
import bpy # select 1:armature, 2:mesh mesh_obj = bpy.context.selected_objects[1] skel_obj = bpy.context.selected_objects[0] for vg in mesh_obj.vertex_groups: '''Remove Vertex Groups that not correspond with any Bone in Armature''' if bpy.context.mode != 'EDIT': bpy.ops.object.mode_set(mode = 'EDIT') try: bone = bpy.context.selected_objects[0].data.bones[vg.name] except KeyError: #Borrar la influencia print ('Vertex Group '' + vg.name + '' - REMOVED') bpy.ops.object.vertex_group_set_active(group = vg.name) bpy.ops.object.vertex_group_remove_from(all = False) bpy.context.selected_objects[1].vertex_groups.remove(vg)
Durante las últimas dos semanas he estado pesando varios personajes dentro de Blender 3D. Para realizar el trabajo correctamente, voy creando varios ‘vertex group’ que utilizo junto con el modificador ‘mask’ para ocultar zonas de la malla que me quitan visibilidad, o que simplemente me molestan.
Después de realizar el pesado, exportamos los personajes para visualizarlos en un motor 3D, y es aquí donde aparece el problema. La normalización de las influencias no se ha llevado a cabo correctamente. En Blender, los ‘vertex group’ que usamos para el ‘armature’, se mezclan con cualquier otro ‘vertex group’ que nosotros creemos para otras cosas. A la hora de normalizar la influencia, también se tienen en cuenta estos ‘vertex group’, y los cálculos se realizan incorrectamente. La consecuencia de esto es simplemente que la malla no se va a deformar como nosotros esperamos.
Para solventar este pequeño problema, antes de exportar he realizado este pequeño script de 5 líneas, que intenta encontrar un hueso en el ‘armature’, y en caso de no encontrarlo, borra la influencia de ese ‘vertex group’ en toda la malla, y después lo borra. Podríamos realizar el proceso manualmente. Para ello, deberíamos seleccionar todos los vertices, borrar la influencia de los grupos que no necesitemos, y luego borrarlos.
Un saludo ^^