Skip to content
Shapemetry

Model - Materials

API reference for src/lanes/materials/materials on @huukhanhnguyen/model, reachable from ..

See the Guide for the ModelJSON / evaluate pipeline.

API reference

Signatures are generated from the live package .d.ts - not hand-written.

clearMaterialArg

function

Clear an optional arg when the author leaves it empty.

clearMaterialArg(node: Operation, key: string): void

collectMaterialNodes

function

Evaluate every materials[] node on the scope into resolved Material records (the ONE entry consumers should use — Model.evaluateMaterials wraps this in a SnapshotLaneNode). Never throws (fail-soft per node).

collectMaterialNodes(scope: ModelScope): Material[]

evaluateMaterialNode

function

Evaluate one material node into a resolved Material. Null when the name cannot be resolved (skip — fail-soft).

evaluateMaterialNode(node: Operation, context: EvalContext, namespaces?: Record<string, unknown>): Material | null

isMaterialNode

function

True when node is a non-container operation with method "material".

isMaterialNode(node: (Operation | Container)): node is Operation

MATERIAL_METHOD

const

Materials lane — evaluation of material nodes into resolved Material records.

Authored shape (ModelJSON.materials / ModelScope.materials): (Operation | Container)[] where each operation has method "material" and expression args for every Material field (name/baseColor/texture/…/density). Consumers (applyMaterial, render dispatch, exporters) still read resolved Material records via Model.evaluateMaterials().value / collectMaterialNodes(scope) — by evaluated name, never re-implementing evaluation.

Expression fields resolve against the live parameter scope (same laneParameterContext as layers/references) so a color/texture formula tracking a param dirty-cascades through the SnapshotLaneNode pull.

Fail-soft per node: a broken arg falls back (omit optional fields; skip a node with no resolvable name) — a broken material never breaks the render.

const MATERIAL_METHOD: "material"

materialArgInput

function

Arg input of a material (or any) operation node.

materialArgInput(node: Operation, key: string): string | undefined

materialLiteralName

function

Static literal name of a material node (quoted string only). Undefined when the name is an expression or missing — validation can only check literals.

materialLiteralName(node: (Operation | Container)): string | undefined

materialNodeFromRecord

function

Build a material node from a plain { name, baseColor, … } record — the GLB-import / static-JSON-import boundary, and the ergonomic way to state a material in a fixture.

materialNodeFromRecord(record: Record<string, unknown> & { name: string; key?: string; attributes?: Record<string, unknown>; }): Operation

setMaterialArg

function

Set or replace one arg input on a material node (mutates args array).

setMaterialArg(node: Operation, key: string, input: string): void
Last updated: 📖 2 min readEdit on GitHub