Files
workinf_Blender_Wasm/tools/web/generated/M16-GAP-00013.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

51 lines
2.0 KiB
Python

#!/usr/bin/env python3
import pathlib
import sys
import bpy
def set_socket(node, name, value):
socket = node.inputs.get(name)
if socket is not None:
socket.default_value = value
def main(output: pathlib.Path) -> None:
bpy.ops.wm.read_factory_settings(use_empty=True)
material = bpy.data.materials.new("WebGapMaterial")
material.use_nodes = True
material.diffuse_color = (0.2, 0.4, 0.8, 0.9)
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 Principled/Output nodes are missing")
set_socket(principled, "Base Color", (0.2, 0.4, 0.8, 0.9))
set_socket(principled, "Metallic", 0.35)
set_socket(principled, "Roughness", 0.6)
set_socket(principled, "IOR", 1.6)
set_socket(principled, "Specular IOR Level", 0.35)
set_socket(principled, "Transmission Weight", 0.27)
set_socket(principled, "Coat Weight", 0.64)
set_socket(principled, "Coat Roughness", 0.12)
set_socket(principled, "Emission Color", (0.05, 0.1, 0.2, 1.0))
set_socket(principled, "Emission Strength", 3.5)
set_socket(principled, "Alpha", 0.9)
if not any(link.from_node == principled and link.to_node == output_node for link in links):
links.new(principled.outputs["BSDF"], output_node.inputs["Surface"])
mesh = bpy.data.meshes.new("WebGapMaterialMesh")
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("WebGapMaterialObject", 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-00013.py -- OUTPUT")
main(pathlib.Path(arguments[0]))