Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
# Run with: blender -b -P tools/make_test_fbx.py
|
|
# Writes tests/data/rigged_box.fbx: a tall box with a two-bone armature and a shape key.
|
|
import os
|
|
import bpy
|
|
|
|
out = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "tests", "data", "rigged_box.fbx")
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
|
|
bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 1))
|
|
mesh = bpy.context.active_object
|
|
mesh.name = "Body"
|
|
mesh.scale = (0.5, 0.5, 2.0)
|
|
bpy.ops.object.transform_apply(scale=True)
|
|
bpy.ops.object.mode_set(mode="EDIT")
|
|
bpy.ops.mesh.subdivide(number_cuts=6)
|
|
bpy.ops.object.mode_set(mode="OBJECT")
|
|
|
|
bpy.ops.object.armature_add(location=(0, 0, 0))
|
|
arm = bpy.context.active_object
|
|
arm.name = "Armature"
|
|
bpy.ops.object.mode_set(mode="EDIT")
|
|
lower = arm.data.edit_bones[0]
|
|
lower.name = "Lower"
|
|
lower.head, lower.tail = (0, 0, 0), (0, 0, 1)
|
|
upper = arm.data.edit_bones.new("Upper")
|
|
upper.head, upper.tail = (0, 0, 1), (0, 0, 2)
|
|
upper.parent = lower
|
|
bpy.ops.object.mode_set(mode="OBJECT")
|
|
|
|
mesh.select_set(True)
|
|
arm.select_set(True)
|
|
bpy.context.view_layer.objects.active = arm
|
|
bpy.ops.object.parent_set(type="ARMATURE_AUTO")
|
|
|
|
mesh.shape_key_add(name="Basis")
|
|
key = mesh.shape_key_add(name="MouthOpen")
|
|
for i, v in enumerate(mesh.data.vertices):
|
|
if v.co.z > 1.6:
|
|
key.data[i].co.x += 0.3
|
|
|
|
bpy.ops.object.select_all(action="SELECT")
|
|
bpy.ops.export_scene.fbx(filepath=out, use_selection=True, add_leaf_bones=False, bake_anim=False)
|
|
print("wrote", out)
|