50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
import pathlib
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
|
|
OBJECT_NAME = "WebGapAnimatedTransformConstraintObject"
|
|
ACTION_NAME = "WebGapAnimatedTransformConstraintAction"
|
|
CONSTRAINT_NAME = "WebGapAnimatedTransformConstraint"
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 1:
|
|
raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00212.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)
|
|
constraint = obj.constraints.new("TRANSFORM")
|
|
constraint.name = CONSTRAINT_NAME
|
|
constraint.map_from = "ROTATION"
|
|
constraint.from_min_x = -30.0
|
|
obj.animation_data_create()
|
|
action = bpy.data.actions.new(ACTION_NAME)
|
|
obj.animation_data.action = action
|
|
constraint.keyframe_insert(data_path="from_min_x", frame=1)
|
|
constraint.from_min_x = 60.0
|
|
constraint.keyframe_insert(data_path="from_min_x", frame=10)
|
|
action.use_fake_user = True
|
|
bpy.context.view_layer.objects.active = obj
|
|
obj.select_set(True)
|
|
scene = bpy.context.scene
|
|
scene.frame_start = 1
|
|
scene.frame_end = 10
|
|
scene.frame_set(5)
|
|
bpy.ops.wm.save_as_mainfile(
|
|
filepath=str(pathlib.Path(arguments[0]).resolve()), check_existing=False, compress=True
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|