Skip to content

Instantly share code, notes, and snippets.

@amorgun
Created July 7, 2025 21:14
Show Gist options
  • Save amorgun/ca618ed2ed3531c8e21a3eebdd4f49ef to your computer and use it in GitHub Desktop.
Save amorgun/ca618ed2ed3531c8e21a3eebdd4f49ef to your computer and use it in GitHub Desktop.
Gladius fix parents
import bpy
orig_arm = bpy.data.objects['Armature']
bpy.context.view_layer.objects.active = orig_arm
bone_collection = orig_arm.data.collections.new('Orig')
bpy.ops.object.mode_set(mode='EDIT', toggle=True)
orig_names = []
for b in list(orig_arm.data.bones):
orig_name = b.name
orig_bone = orig_arm.data.edit_bones[orig_name]
bone_collection.assign(orig_bone)
orig_names.append(orig_name)
nb = orig_arm.data.edit_bones.new(orig_name + '_fix')
nb.length = b.length
nb.matrix = orig_bone.matrix
bpy.ops.object.mode_set(mode='EDIT', toggle=True)
bone_collection.is_visible = False
for name in orig_names:
bone = orig_arm.pose.bones[name + '_fix']
constraint = bone.constraints.new("COPY_TRANSFORMS")
constraint.target = orig_arm
constraint.subtarget = name
for obj in bpy.data.objects:
if obj.type != 'MESH':
continue
for g in obj.vertex_groups:
g.name = g.name + '_fix'
import bpy
armature = bpy.context.object
actions = list(bpy.data.actions)
latest = len(actions) - 1
for idx, a in enumerate(actions):
orig_name = a.name
armature.animation_data.action = a
bpy.ops.nla.bake(frame_start=1, frame_end=int(a.frame_end), only_selected=False, visual_keying=True, clear_constraints=idx == latest, bake_types={'POSE'}, channel_types={'LOCATION', 'ROTATION', 'SCALE', 'BBONE'})
action = bpy.data.actions['Action']
a.name = f'{a.name}_orig'
action.name = orig_name
action.use_fake_user = True
bpy.data.actions.remove(a, do_unlink=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment