Automatically set weight of each bone to 1 for each vertex group?

Prefacing by saying I am on day 4 total of using blender at all. Very likely this is something simple which I lack the experience for but I have yet to find any documentation which has helped. Any help appreciated.

Essentially, I have this model which has a mesh for each cube(I know, it imported that way). My goal is to make each bone influence each corresponding (parented and similarly named) mesh with a weight of 1 (completely), and have no other bone influence that specific mesh (except the one which it is parented to). Once that is finished, I’ll ctrl+J the mesh and (hopefully) all the weights will be preserved and instead of ~200 meshes I will have one rigged mesh which moves as intended.

The issue is that in order to do this manually, I have to individually select each vertex group and then subsequent corresponding mesh, and assign the weight manually, and then switch to the next vertex group, repeat ~200 times. Obviously, this is immensely time consuming and incredibly tedious, and I am trying anything I can to figure out a way to automate this. I intend to do something similar to many models which are exactly like this one, as well.

If there is some sort of script, addon, or feature I can use to automate this process or in any way decrease the pain, I would be very grateful.

Thanks!

Welcome! :vulcan_salute: Eh… Do you have a separate bone for every single part? :thinking: And is the character supposed to be animated like a humanoid character? And where is the rig from? I’m not an expert, but that doesn’t seem like a rig that was made with Blender (might be from Maya perhaps?). And do you really need all those bones for this character? Would it be possible to combine some of them to be moved by a single bone, like upper arm, forearm, etc? If some part does not need to move on its own, it doesn’t need it’s own bone.

But anyway, for the original question: I don’t know a shortcut to this, but you would get it done fastest with weight painting instead of creating and renaming and selecting and assigning vertex groups. First, combine all the parts together that are symmetrical and to be moved by the same bone, and join them into one object. After this select all the parts, select the armature, ctrl+p with keep transform to parent them into the armature. Then deselect the armature, select all the parts so that one of them is the active object, add an armature modifier and use the eyedropper to select the armature as the armature for the modifier. Then from the modifier dropdown icon select copy to selected. Now, if you click the armature and then shif click one of the parts and go to weight paint mode, you can alt+left click on a bone to select that for weight painting its vertex group. Then you should select from the tools options mirror x axis, check auto normalize, make sure you don’t have front faces only checked, then from the brush settings you should change the falloff to constant and projected. Now if you alt+left click a bone and from front view paint the whole object with it, it should automatically add a vertex group and paint the whole object red with weight of 1 to that group, with mirrored group on the other side. Then do this to all part clusters you created. I did the exact same thing for a scifi armor today, but it only had about 30 parts :smile:

But if you are staying inside Blender you can also use bone parenting instead of armature modifier and vertex groups, so you won’t need any of the strugglings involved in it. But if you export it and then want to import it in a game engine then I think it is not that easy. :thinking: Because parenting relationships usually will not export, at least what I’ve learned…

So, this model comes from the game Vintage Story, open source game I quite like. The bones are already parented and do work and move correctly in blender just fine with only the parents. They also do actually export fine, I’m porting it to unity and the rigs work smoothly. The only actual issue I’m having is that the model consists of 200 separate meshes, and every one of those meshes incurs a draw call, turning a low poly and otherwise incredibly well optimized asset into an absolute nightmare GPU eating machine. I want to keep the artist intended bone structure, because I want to eventually make all the plates and whatnot move with the character. So I’m just trying to figure out how to efficiently weight each bone to it’s parented part and then combine all the meshes, for optimization.

As of now, as a temporary fix, I have taken your advice and created part clusters and made a new, much simpler armature, which is generally working okay so far, but lacks the depth I was hoping for. Thanks for your help!

Okay, that’s good news :clap: Yeah, usually rigs made with other softwares actually are fine if imported into Blender correctly. Even if they look weird. The main difference between softwares I think is that Blender bones have a length value, but softwares like Maya and UE don’t (don’t know about Unity but I guess it’s the same in it too), their bones are actually just joints parented to each other. Another difference is that the primary axis of bones is different, in Blender it’s y axis, but I think in Unreal Engine and Maya it’s x. That must be the reason why some rigs look so weird when imported into Blender, because the bones might follow their original orientations and in Blender they look like they are positioned crosswise. But they still fuction like they should. But animating them in Blender is not so simple. For example, if you try to mirror poses, Blender might mirror them in weird directions because the bone axises are designed differently.

Okay, I see. But if you want to make all the parts rigged in the original way you can still join all symmetrical parts and weight paint with x axis mirroring, so you only have to paint half of the parts. :smiley:

Try this silly little thing I hacked together…

In blender, switch an editor (any editor - 3d view - for example) to be a Text Editor. In the header for the text editor, click on the ‘New’ button to create a new empty text. Copy and paste this code into the new empty text -

import bpy

print ("\n Script Starting.")

objects = bpy.data.objects

for obj in objects:
    print ("Object - ", obj.name)
    print ("Object type = ", obj.type)
    
    if obj.type == 'MESH':
        
        if bpy.data.objects[obj.name].parent_type == 'BONE':
            print (obj.name, "has bone parent")
            
            bpy.context.view_layer.objects.active = obj
            
            vert_groups = bpy.data.objects[obj.name].vertex_groups   
            
            if len(vert_groups) > 0:
                bpy.ops.object.vertex_group_remove(all=True)
            
            bpy.ops.object.vertex_group_add()
            
            bpy.data.objects[obj.name].vertex_groups['Group'].name = bpy.data.objects[obj.name].parent_bone
            
            bpy.ops.object.mode_set(mode = 'EDIT')
            bpy.ops.mesh.select_all(action='SELECT')
            bpy.ops.object.vertex_group_assign()
            bpy.ops.object.mode_set(mode = 'OBJECT')
                

Then, with your fingers crossed, click on the ‘Play’ icon in the text editor’s header to run this python script.

The script will go thru every object in the file. For each mesh object it finds, it will check if the object has a bone parent. If the object has a bone parent, it will remove any vertex groups the object has, and create a new vertex group named after it’s parent bone.

This script doesn’t do any error checking and will likely throw an error because of that. If it errors out, take a look at blender’s console (Window → Toggle System Console) to see the error message. If it errors, would probably need to see the file your working on to figure out why it error.

Good luck,
Randy