#!/usr/bin/env python3 import pathlib import sys import bpy def main(output: pathlib.Path) -> None: bpy.ops.wm.read_factory_settings(use_empty=True) material = bpy.data.materials.new("WebGapNodeTreeMaterial") material.use_nodes = True nodes = material.node_tree.nodes links = material.node_tree.links principled = nodes.get("Principled BSDF") output_node = nodes.get("Material Output") if principled is None or output_node is None: raise RuntimeError("default shader nodes are missing") rgb = nodes.new("ShaderNodeRGB") rgb.name = "WebGapRGB" rgb.outputs["Color"].default_value = (0.1, 0.3, 0.7, 1.0) links.new(rgb.outputs["Color"], principled.inputs["Base Color"]) links.new(principled.outputs["BSDF"], output_node.inputs["Surface"]) mesh = bpy.data.meshes.new("WebGapNodeTreeMesh") mesh.from_pydata([(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (0.0, 1.0, 0.0)], [], [(0, 1, 2)]) mesh.materials.append(material) obj = bpy.data.objects.new("WebGapNodeTreeObject", mesh) bpy.context.collection.objects.link(obj) bpy.ops.wm.save_as_mainfile(filepath=str(output.resolve()), check_existing=False, compress=True) if __name__ == "__main__": arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 1: raise SystemExit("usage: blender -b --python M16-GAP-00016.py -- OUTPUT") main(pathlib.Path(arguments[0]))