62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
OLD_ACTION = "WebGapAnimMoveSlotAction"
|
|
|
|
|
|
def make_object(name, action, slot, values):
|
|
mesh = bpy.data.meshes.new(f"{name}Mesh")
|
|
mesh.from_pydata(
|
|
[(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 1.0, 0.0), (-1.0, 1.0, 0.0)],
|
|
[],
|
|
[(0, 1, 2, 3)],
|
|
)
|
|
obj = bpy.data.objects.new(name, mesh)
|
|
bpy.context.scene.collection.objects.link(obj)
|
|
obj.animation_data_create()
|
|
obj.animation_data.action = action
|
|
obj.animation_data.action_slot = slot
|
|
for frame, value in zip((1, 3, 5), values):
|
|
obj["move_target"] = value
|
|
obj.keyframe_insert(data_path='["move_target"]', frame=frame)
|
|
return obj
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 1:
|
|
raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00206.py -- OUTPUT")
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
action = bpy.data.actions.new(OLD_ACTION)
|
|
slot_a = action.slots.new("OBJECT", "WebGapMoveSlotA")
|
|
slot_b = action.slots.new("OBJECT", "WebGapMoveSlotB")
|
|
object_a = make_object("WebGapAnimMoveSlotA", action, slot_a, (1.0, 3.0, 5.0))
|
|
object_b = make_object("WebGapAnimMoveSlotB", action, slot_b, (2.0, 4.0, 6.0))
|
|
slot_a.select = True
|
|
slot_b.select = False
|
|
action.use_fake_user = True
|
|
bpy.context.view_layer.objects.active = object_a
|
|
object_a.select_set(True)
|
|
object_b.select_set(False)
|
|
window = bpy.context.window
|
|
screen = window.screen
|
|
area = next((candidate for candidate in screen.areas if candidate.type == "DOPESHEET_EDITOR" and candidate.height >= 200), None)
|
|
if area is None:
|
|
area = next(candidate for candidate in screen.areas if candidate.type == "VIEW_3D" and candidate.height >= 200)
|
|
area.type = "DOPESHEET_EDITOR"
|
|
area.spaces.active.ui_mode = "ACTION"
|
|
bpy.context.scene.frame_start = 1
|
|
bpy.context.scene.frame_end = 5
|
|
bpy.context.scene.frame_set(3)
|
|
bpy.ops.wm.save_as_mainfile(
|
|
filepath=str(pathlib.Path(arguments[0]).resolve()), check_existing=False, compress=True
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|