Files
workinf_Blender_Wasm/tools/web/generated/M16-GAP-00011.py
mes123456 10640aeb3c
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
Govern task context and advance execution pointer
2026-08-20 06:02:43 -04:00

50 lines
1.5 KiB
Python

#!/usr/bin/env python3
import pathlib
import sys
import bpy
LIBRARY_NAME = "WebGapLibrary.blend"
OBJECT_NAME = "WebGapLibraryObject"
def reset() -> None:
bpy.ops.wm.read_factory_settings(use_empty=True)
def create_source(path: pathlib.Path) -> None:
reset()
mesh = bpy.data.meshes.new("WebGapLibraryMesh")
mesh.from_pydata([(-1.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0)], [], [(0, 1, 2)])
obj = bpy.data.objects.new(OBJECT_NAME, mesh)
bpy.context.scene.collection.objects.link(obj)
bpy.ops.wm.save_as_mainfile(filepath=str(path), check_existing=False, compress=True)
def create_fixture(output: pathlib.Path) -> None:
source = output.with_name(LIBRARY_NAME)
create_source(source)
reset()
with bpy.data.libraries.load(str(source), link=True) as (data_from, data_to):
if OBJECT_NAME not in data_from.objects:
raise RuntimeError("source object is missing")
data_to.objects = [OBJECT_NAME]
linked = data_to.objects[0]
if linked is None:
raise RuntimeError("linked object is missing")
bpy.context.scene.collection.objects.link(linked)
bpy.ops.wm.save_as_mainfile(filepath=str(output), check_existing=False, compress=True)
def main(output: pathlib.Path) -> None:
output.parent.mkdir(parents=True, exist_ok=True)
create_fixture(output.resolve())
if __name__ == "__main__":
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 1:
raise SystemExit("usage: blender -b --python M16-GAP-00011.py -- OUTPUT")
main(pathlib.Path(arguments[0]))