68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
def mesh(name):
|
|
data = bpy.data.meshes.new(f"{name}Mesh")
|
|
data.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)],
|
|
)
|
|
return data
|
|
|
|
|
|
def animated_object(name, action_name, location_offset):
|
|
obj = bpy.data.objects.new(name, mesh(name))
|
|
bpy.context.scene.collection.objects.link(obj)
|
|
for frame, location in (
|
|
(1, location_offset),
|
|
(3, tuple(value + 1.0 for value in location_offset)),
|
|
(5, tuple(value + 2.0 for value in location_offset)),
|
|
):
|
|
obj.location = location
|
|
obj.keyframe_insert(data_path="location", frame=frame, index=-1)
|
|
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-00172.py -- OUTPUT")
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
|
|
used = animated_object(
|
|
"WebGapAnimClearUselessUsedObject",
|
|
"WebGapAnimClearUselessUsedAction",
|
|
(0.0, 0.0, 0.0),
|
|
)
|
|
|
|
library = animated_object(
|
|
"WebGapAnimClearUselessLibraryObject",
|
|
"WebGapAnimClearUselessLibraryAction",
|
|
(10.0, 0.0, 0.0),
|
|
)
|
|
library_action = library.animation_data.action
|
|
library.animation_data.action = None
|
|
library_action.use_fake_user = True
|
|
|
|
empty_action = bpy.data.actions.new("WebGapAnimClearUselessEmptyAction")
|
|
empty_action.use_fake_user = True
|
|
|
|
bpy.context.scene.frame_start = 1
|
|
bpy.context.scene.frame_end = 5
|
|
bpy.context.scene.frame_preview_start = 1
|
|
bpy.context.scene.frame_preview_end = 5
|
|
bpy.ops.anim.clear_useless_actions()
|
|
bpy.ops.wm.save_as_mainfile(
|
|
filepath=str(pathlib.Path(arguments[0]).resolve()), check_existing=False, compress=True
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|