Files
workinf_Blender_Wasm/web/protocol/shader-graph-commands.ts
mes123456 7549b9a15c
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
feat(web): switch to implementation-first capability wave
2026-08-29 01:22:03 +08:00

29 lines
1.5 KiB
TypeScript

import type { ShaderGraphIR, ShaderSocketIR } from "./shader-graph";
const input = (id: string, name: string, dataType: ShaderSocketIR["dataType"], defaultValue?: ShaderSocketIR["defaultValue"]): ShaderSocketIR => ({ id, name, direction: "INPUT", dataType, ...(defaultValue === undefined ? {} : { defaultValue }) });
const output = (id: string, name: string, dataType: ShaderSocketIR["dataType"]): ShaderSocketIR => ({ id, name, direction: "OUTPUT", dataType });
/** Build a valid bounded graph for the source-backed Principled writer. */
export const shaderGraphCommands = Object.freeze({
setPrincipledGraph(materialId: string, baseColor: readonly number[], roughness: number, metallic: number): ShaderGraphIR {
const principled = "shader:principled";
const materialOutput = "shader:material-output";
return {
schemaVersion: 1,
id: `shader-graph:${materialId}`,
materialId,
nodes: [
{ id: principled, type: "PRINCIPLED", name: "Principled BSDF", sockets: [
input("Base Color", "Base Color", "COLOR", [...baseColor].slice(0, 4)),
input("Metallic", "Metallic", "VALUE", metallic),
input("Roughness", "Roughness", "VALUE", roughness),
output("BSDF", "BSDF", "SHADER"),
] },
{ id: materialOutput, type: "MATERIAL_OUTPUT", name: "Material Output", sockets: [input("Surface", "Surface", "SHADER")] },
],
links: [{ fromNodeId: principled, fromSocketId: "BSDF", toNodeId: materialOutput, toSocketId: "Surface" }],
outputNodeId: materialOutput,
};
},
} as const);