Created
October 7, 2024 23:49
-
-
Save Ooseykins/f17d052417f580b70c39a20859d5c1a8 to your computer and use it in GitHub Desktop.
Point all bones up (z-axis) to "Normalize" them. This will mean when imported into Unity their rotations should all be euler (0, 0, 0). This is for apps like Warudo or VMC so you can preserve your workflow without having to use an in-Unity script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bl_info = { | |
"name": "Normalize bones", | |
"blender": (3, 4, 1), | |
"category": "Object", | |
} | |
import bpy | |
import mathutils | |
class NormalizeBonesOperator(bpy.types.Operator): | |
bl_idname = "object.normalizebones" | |
bl_label = "Normalize bones" | |
bl_description ="Point all bones along the same axis" | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
for target in bpy.context.selected_objects: | |
bpy.ops.object.mode_set(mode = 'EDIT') | |
if target.type == 'ARMATURE': | |
print(target.name) | |
for b in target.data.edit_bones: | |
b.use_connect = False | |
for b in target.data.edit_bones: | |
b.use_inherit_rotation = False | |
b.use_local_location = False | |
b.use_relative_parent = False | |
b.tail = b.head + mathutils.Vector((0.0,0.0,b.length)) | |
b.roll = 0.0 | |
bpy.ops.object.mode_set(mode = 'OBJECT') | |
return {'FINISHED'} | |
def invoke(self, context, event): | |
return self.execute(context) | |
def menu_func(self, context): | |
self.layout.operator(NormalizeBonesOperator.bl_idname) | |
def register(): | |
bpy.utils.register_class(NormalizeBonesOperator) | |
bpy.types.VIEW3D_MT_object.append(menu_func) | |
def unregister(): | |
bpy.utils.unregister_class(NormalizeBonesOperator) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment