53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
ACTION_NAME = "WebGapAnimNlaSlotAction"
|
|
OBJECT_NAME = "WebGapAnimNlaSlotObject"
|
|
STRIP_NAME = "WebGapNlaSlotStrip"
|
|
SLOT_NAME = "WebGapNlaSlot"
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 1:
|
|
raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00210.py -- OUTPUT")
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
mesh = bpy.data.meshes.new(f"{OBJECT_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(OBJECT_NAME, mesh)
|
|
bpy.context.scene.collection.objects.link(obj)
|
|
action = bpy.data.actions.new(ACTION_NAME)
|
|
slot = action.slots.new("OBJECT", SLOT_NAME)
|
|
obj.animation_data_create()
|
|
obj.animation_data.action = action
|
|
obj.animation_data.action_slot = slot
|
|
for frame, value in zip((1, 3, 5), (1.0, 3.0, 5.0)):
|
|
obj["nla_slot_target"] = value
|
|
obj.keyframe_insert(data_path='["nla_slot_target"]', frame=frame)
|
|
track = obj.animation_data.nla_tracks.new()
|
|
track.name = "WebGapNlaSlotTrack"
|
|
strip = track.strips.new(STRIP_NAME, 1, action)
|
|
strip.action_slot = slot
|
|
strip.frame_end = 5
|
|
action.use_fake_user = True
|
|
bpy.context.view_layer.objects.active = obj
|
|
obj.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()
|