Files
workinf_Blender_Wasm/tools/web/generated/M16-GAP-00214.py
mes123456 9f43244982
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Continue Blender Web parity task handoff
2026-08-23 05:47:21 -04:00

67 lines
2.6 KiB
Python

#!/usr/bin/env python3
import pathlib
import sys
import bpy
OBJECT_NAME = "WebGapAnimViewCurveGraphEditorObject"
ACTION_NAME = "WebGapAnimViewCurveGraphEditorAction"
PROPERTY_NAME = "curve_target"
def configure_graph_editor():
window = bpy.context.window
if window is None or window.screen is None:
raise RuntimeError("fixture requires a Blender window")
screen = window.screen
area = next((candidate for candidate in screen.areas if candidate.type in {"DOPESHEET_EDITOR", "VIEW_3D"}), None)
if area is None:
raise RuntimeError("default Layout VIEW_3D area is missing")
area.type = "GRAPH_EDITOR"
return area
def main():
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 1:
raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00214.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)
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
obj[PROPERTY_NAME] = -3.0
obj.keyframe_insert(data_path=f'["{PROPERTY_NAME}"]', frame=1)
obj[PROPERTY_NAME] = 7.0
obj.keyframe_insert(data_path=f'["{PROPERTY_NAME}"]', frame=10)
obj.animation_data.action.name = ACTION_NAME
obj.animation_data.action.use_fake_user = True
curve = next(curve for curve in obj.animation_data.action.layers[0].strips[0].channelbags[0].fcurves)
for keyframe in curve.keyframe_points:
keyframe.select_control_point = False
curve.keyframe_points[0].select_control_point = True
curve.keyframe_points[1].select_control_point = False
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 10
bpy.context.scene.frame_set(5)
bpy.context.preferences.view.smooth_view = 0
graph_area = configure_graph_editor()
graph_region = next(candidate for candidate in graph_area.regions if candidate.type == "WINDOW")
with bpy.context.temp_override(window=bpy.context.window, screen=bpy.context.screen, area=graph_area, region=graph_region):
if "FINISHED" not in bpy.ops.graph.view_selected():
raise RuntimeError("Graph Editor view_selected failed while preparing fixture")
bpy.ops.wm.save_as_mainfile(
filepath=str(pathlib.Path(arguments[0]).resolve()), check_existing=False, compress=True
)
if __name__ == "__main__":
main()