Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Flavelius/c934a09f2ced2a8477e58ecc03ebcd08 to your computer and use it in GitHub Desktop.
Save Flavelius/c934a09f2ced2a8477e58ecc03ebcd08 to your computer and use it in GitHub Desktop.
Helpers to import fbx characters exported from Akeytsu, correct actions and export as glb
import bpy
bl_info = {
"name": "Akeytsu to Godot Helper",
"author": "Flavelius",
"description":"Provides gltf export corrections for characters",
"version": (0, 1),
"blender": (3, 1, 0),
"category":"Object",
"support":"COMMUNITY",
"location": "View3D -> Properties -> Misc"
}
def adjust_display_type():
for obj in bpy.context.scene.objects:
if obj.type == 'ARMATURE':
obj.show_in_front = True
for obj in bpy.data.armatures:
obj.display_type = 'STICK'
def correct_scale():
targets = []
#apply scale and rotation to meshes and armatures
for obj in bpy.context.scene.objects:
if obj.type == 'MESH' or obj.type == 'ARMATURE':
targets.append(obj)
if obj.type == 'ARMATURE':
obj.show_in_front = True
bpy.ops.object.transform_apply( {'selected_editable_objects' : targets}, location = False, scale = True, rotation = True)
#correct animation offsets afterwards
y_scale = 0.01
for ac in bpy.data.actions:
for fcu in ac.fcurves:
if fcu.data_path.endswith("location"):
for kp in fcu.keyframe_points:
kp.co.y *= y_scale
kp.handle_left.y *= y_scale
kp.handle_right.y *= y_scale
def correct_nla():
ob = bpy.context.object
def hasaction(action):
for track in ob.animation_data.nla_tracks:
if track.name == action.name:
return True
return False
if ob.animation_data is None:
ob.animation_data_create()
for action in bpy.data.actions:
if '|' in action.name:
action.name = action.name.split('|')[1]
if hasaction(action):
continue
track = ob.animation_data.nla_tracks.new()
track.name = action.name
track.strips.new(action.name, int(action.frame_range[0]), action)
class ConvertGodotAkeytsuOperator(bpy.types.Operator):
"""Corrections are applied to the whole scene, make sure it is directly after import only"""
bl_idname = "object.convert_akeytsu_to_godot"
bl_label = "Apply Akeytsu to Godot corrections"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
correct_scale()
correct_nla()
adjust_display_type()
return {'FINISHED'}
class GodeytsuPanel(bpy.types.Panel):
bl_idname = "OBJECT_PT_godeytsu"
bl_label = "Godot Akteytsu Helper"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
def draw(self, context):
layout = self.layout
row = layout.row()
op = row.operator("wm.read_homefile", text="Clear Scene")
op.use_empty = True
op.app_template=''
row = layout.row()
op = row.operator("import_scene.fbx", text="Import Akeytsu fbx")
op.use_custom_normals=False
op.anim_offset=0
op.automatic_bone_orientation=True
row = layout.row()
row.operator("object.convert_akeytsu_to_godot", text="Convert")
row = layout.row()
op = row.operator("export_scene.gltf", text="Export Godot gltf")
op.export_format = 'GLB'
op.export_apply = True
op.export_extras = True
registerable_classes = [
GodeytsuPanel,
ConvertGodotAkeytsuOperator
]
def register():
for item in registerable_classes:
bpy.utils.register_class(item)
def unregister():
for item in registerable_classes:
bpy.utils.unregister_class(item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment