39 lines
1.8 KiB
Python
39 lines
1.8 KiB
Python
"""Run in Blender: edit a copy of the Mixamo fighter and save an animated .blend."""
|
|
from pathlib import Path
|
|
|
|
import bpy
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
bpy.ops.object.select_all(action="SELECT")
|
|
bpy.ops.object.delete(use_global=False)
|
|
bpy.ops.import_scene.fbx(filepath=str(root / "build/SkeletalFixture/fighter.fbx"))
|
|
meshes = [obj for obj in bpy.context.scene.objects if obj.type == "MESH"]
|
|
rig = next(obj for obj in bpy.context.scene.objects if obj.type == "ARMATURE")
|
|
original_objects = set(bpy.context.scene.objects)
|
|
bpy.ops.import_scene.fbx(filepath=str(root / "build/SkeletalFixture/walk.fbx"))
|
|
animation_rig = next(obj for obj in bpy.context.scene.objects
|
|
if obj not in original_objects and obj.type == "ARMATURE")
|
|
rig.animation_data_create()
|
|
rig.animation_data.action = animation_rig.animation_data.action
|
|
if hasattr(animation_rig.animation_data, "action_slot"):
|
|
rig.animation_data.action_slot = animation_rig.animation_data.action_slot
|
|
for obj in list(bpy.context.scene.objects):
|
|
if obj not in original_objects:
|
|
bpy.data.objects.remove(obj, do_unlink=True)
|
|
collection = bpy.data.collections.new("Character")
|
|
bpy.context.scene.collection.children.link(collection)
|
|
for obj in [*meshes, rig]:
|
|
if obj.name not in collection.objects:
|
|
collection.objects.link(obj)
|
|
# A small mesh edit while retaining the imported weights/armature modifier.
|
|
for vertex in meshes[0].data.vertices:
|
|
vertex.co.x *= 1.02
|
|
action = rig.animation_data.action
|
|
bpy.context.scene.frame_start = int(action.frame_range[0])
|
|
bpy.context.scene.frame_end = int(action.frame_range[1])
|
|
bpy.context.scene.frame_set(bpy.context.scene.frame_start)
|
|
output = root / "build/SkeletalFixture/edited_fighter.blend"
|
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
bpy.ops.wm.save_as_mainfile(filepath=str(output))
|
|
print("WORKSHOP_SKELETAL_FIXTURE=" + str(output))
|