├── .gitignore ├── README.md ├── LICENSE └── __init__.py /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .idea 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blender-unity-rotation-fix 2 | 3 | Fix Armature Rotation (Blender to Unity) 4 | 5 | [Download](https://github.com/gizmo-ds/blender-unity-rotation-fix/archive/main.zip) 6 | 7 | ![before.png](https://files.catbox.moe/zgx6tw.png) 8 | 9 | ↑ before after ↓ 10 | 11 | ![after.png](https://files.catbox.moe/9np8u7.png) 12 | 13 | ![panel.png](https://files.catbox.moe/djetys.png) 14 | 15 | Panel 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Gizmo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2023 Gizmo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import bpy 24 | import math 25 | 26 | bl_info = { 27 | "name": "unity-rotation-fix", 28 | "author": "gizmo-ds", 29 | "description": "Fix Armature Rotation (Blender to Unity)", 30 | "blender": (2, 80, 0), 31 | "version": (0, 0, 1), 32 | "location": "", 33 | "warning": "", 34 | "category": "Generic" 35 | } 36 | 37 | class URF_Panel(bpy.types.Panel): 38 | bl_label = "Unity Rotation Fix" 39 | bl_idname = "urf.panel" 40 | bl_space_type = "VIEW_3D" 41 | bl_region_type = "UI" 42 | bl_category = "URF" 43 | 44 | def draw(self, context): 45 | layer = self.layout 46 | layer.row().operator('urf.operator', text='Unity Rotation Fix', icon='MODIFIER') 47 | 48 | class URF_Operator(bpy.types.Operator): 49 | bl_idname = 'urf.operator' 50 | bl_label = 'Operator' 51 | 52 | def execute(self, context): 53 | '''Unity Rotation Fix''' 54 | armature = None 55 | all_objects = bpy.context.collection.all_objects 56 | for obj in all_objects: 57 | if obj.type == 'ARMATURE': 58 | # 检测是否存在多个 Armature 59 | if armature != None: 60 | self.report({'ERROR'}, 'Multiple armatures found.') 61 | return {'CANCELLED'} 62 | armature = obj 63 | else: 64 | # 检测是否已经旋转 65 | x = math.floor(math.degrees(obj.rotation_euler.x)) 66 | if x != 0: 67 | self.report({'ERROR'}, 'Object ' + obj.name + ' already rotated.') 68 | return {'CANCELLED'} 69 | bpy.ops.object.select_all(action='SELECT') 70 | bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM') 71 | bpy.ops.transform.rotate(value=math.radians(-90), orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False, snap=False, snap_elements={'INCREMENT'}, use_snap_project=False, snap_target='CLOSEST', use_snap_self=True, use_snap_edit=True, use_snap_nonedit=True, use_snap_selectable=False) 72 | bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) 73 | bpy.ops.transform.rotate(value=math.radians(90), orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False, snap=False, snap_elements={'INCREMENT'}, use_snap_project=False, snap_target='CLOSEST', use_snap_self=True, use_snap_edit=True, use_snap_nonedit=True, use_snap_selectable=False) 74 | armature.select_set(False) 75 | bpy.context.view_layer.objects.active = armature 76 | bpy.ops.object.parent_set(type='ARMATURE') 77 | self.report({'INFO'}, 'Rotation fixed.') 78 | return {'FINISHED'} 79 | 80 | def register(): 81 | bpy.utils.register_class(URF_Operator) 82 | bpy.utils.register_class(URF_Panel) 83 | 84 | def unregister(): 85 | pass 86 | 87 | if __name__ == "__main__": 88 | register() 89 | --------------------------------------------------------------------------------