Skip to content

Instantly share code, notes, and snippets.

@Ooseykins
Last active December 28, 2022 20:10
Show Gist options
  • Save Ooseykins/ee55ca931ef91ef4e101a09fcb159977 to your computer and use it in GitHub Desktop.
Save Ooseykins/ee55ca931ef91ef4e101a09fcb159977 to your computer and use it in GitHub Desktop.
Imported vrm/vroid models have bone names that aren't compatible with Blender's mirrored bone editing. This will toggle the vertex group names and bone names between the two versions. This script adds a menu option for object mode "VRM Swap Bone Names".
bl_info = {
"name": "VRM Swap Bone Names",
"blender": (3, 4, 1),
"category": "Object",
}
import bpy
class VRMSwapBoneNamesOperator(bpy.types.Operator):
bl_idname = "object.vrmswapbonenames"
bl_label = "VRM Swap Bone Names"
bl_description ="Swap VRM style bone names to append _Left and _Right to all selected objects' vertex group names and bone names. Run this operator again to swap back to VRM style names with _L_ and _R_"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
def replaceName(namedObject, mode):
if "_L_" in namedObject.name and mode >= 0:
namedObject.name = namedObject.name.replace("_L_","_d_")+"_Left"
return 1
elif "_R_" in namedObject.name and mode >= 0:
namedObject.name = namedObject.name.replace("_R_","_d_")+"_Right"
return 1
elif "_d_" in namedObject.name and "_Left" in namedObject.name and mode <= 0:
namedObject.name = namedObject.name.replace("_d_","_L_").removesuffix("_Left")
return -1
elif "_d_" in namedObject.name and "_Right" in namedObject.name and mode <= 0:
namedObject.name = namedObject.name.replace("_d_","_R_").removesuffix("_Right")
return -1
return mode
mode = 0
for target in bpy.context.selected_objects:
v_groups = target.vertex_groups
for vg in v_groups:
mode = replaceName(vg, mode)
if target.type == 'ARMATURE':
for b in target.data.bones:
mode = replaceName(b, mode)
return {'FINISHED'}
def invoke(self, context, event):
return self.execute(context)
def menu_func(self, context):
self.layout.operator(VRMSwapBoneNamesOperator.bl_idname)
def register():
bpy.utils.register_class(VRMSwapBoneNamesOperator)
bpy.types.VIEW3D_MT_object.append(menu_func)
def unregister():
bpy.utils.unregister_class(VRMSwapBoneNamesOperator)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment