46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
ACTIVE_OBJECT = "WebGapAnimMergeActiveObject"
|
|
SOURCE_OBJECT = "WebGapAnimMergeSourceObject"
|
|
ACTIVE_ACTION = "WebGapAnimMergeActiveAction"
|
|
SOURCE_ACTION = "WebGapAnimMergeSourceAction"
|
|
|
|
|
|
def make_object(name, prop_name, action_name, 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[prop_name] = values[1]
|
|
for frame, value in zip((1, 3, 5), values):
|
|
bpy.context.scene.frame_set(frame)
|
|
obj[prop_name] = value
|
|
obj.keyframe_insert(data_path=f'["{prop_name}"]', frame=frame)
|
|
obj.animation_data.action.name = action_name
|
|
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-00198.py -- OUTPUT")
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
active = make_object(ACTIVE_OBJECT, "active_merge_target", ACTIVE_ACTION, (1.0, 3.0, 5.0))
|
|
source = make_object(SOURCE_OBJECT, "source_merge_target", SOURCE_ACTION, (10.0, 30.0, 50.0))
|
|
bpy.context.view_layer.objects.active = active
|
|
active.select_set(True)
|
|
source.select_set(True)
|
|
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()
|