@womp/spark-agent 14.0.1 → 15.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -135,9 +135,9 @@ export type MaterialNodeOptions = {
135
135
  value: number;
136
136
  }[];
137
137
  };
138
- /** Editable starting graphs with explicit coordinate space; not complete reference matches. */
138
+ /** The two-scale grid probe: major lines every featureSize, lower-contrast minor lines every tenth. */
139
139
  export type MaterialRecipeOptions = {
140
- pattern: "noise" | "grain" | "woven" | "grid";
140
+ pattern: "grid";
141
141
  coordinateSpace: "object" | "world";
142
142
  /** Object-space units, or physical millimeters for world space. Vectors use graph axes. */
143
143
  featureSize: number | MaterialVector;
@@ -148,90 +148,7 @@ export type MaterialRecipeOptions = {
148
148
  roughnessA: number;
149
149
  roughnessB: number;
150
150
  metalness?: number;
151
- detail?: number;
152
151
  relief: "height" | "bump";
153
152
  /** Native shading-normal strength, not displacement distance. */
154
153
  reliefScale: number;
155
154
  };
156
- /** Numeric structure without surface outputs. Scalars drive finish/relief; RGB fields preserve color components. */
157
- export type MaterialField = {
158
- graph: MaterialGraph;
159
- source: {
160
- node: number;
161
- slot: number;
162
- };
163
- };
164
- export type MaterialFieldOptions = {
165
- pattern: "noise" | "grain" | "woven" | "grid" | "cells";
166
- coordinateSpace: "object" | "world";
167
- /** Object-coordinate units, or millimeters for world space. */
168
- featureSize: number | MaterialVector;
169
- detail?: number;
170
- /** Rotation in degrees, applied to paired position/normal coordinates. */
171
- rotation?: MaterialVector;
172
- /** Cellular output; defaults to Distance. */
173
- cellMode?: "Distance" | "Edge distance" | "Color" | "Smooth Distance" | "Smooth Color";
174
- /** Clamp (field - low) / (high - low) to 0..1. Reversed endpoints invert the mask. */
175
- remap?: {
176
- low: number;
177
- high: number;
178
- };
179
- };
180
- export type MaterialCompositionOptions = {
181
- /** Copied fields get independent Constant handles on write; source handles are not retained. */
182
- fields: MaterialField[];
183
- /** Linear RGB endpoints. Weights correspond to fields and sum to at most 1. */
184
- color?: {
185
- low: MaterialVector;
186
- high: MaterialVector;
187
- weights: number[];
188
- };
189
- roughness?: {
190
- low: number;
191
- high: number;
192
- weights: number[];
193
- };
194
- metalness?: number;
195
- /** Combine scalar height fields before deriving normals. Weights may be signed. */
196
- relief?: {
197
- mode: "height" | "bump";
198
- scale: number;
199
- weights: number[];
200
- center?: number;
201
- };
202
- };
203
- /** Generic analytic shaping; coordinates default to the field's feature-size Mapping. */
204
- export type MaterialShapeOptions = {
205
- name?: string;
206
- } & ({
207
- kind: "remap";
208
- low: number;
209
- high: number;
210
- } | {
211
- kind: "ridge";
212
- center: number;
213
- width: number;
214
- } | {
215
- kind: "periodic";
216
- coordinates?: number;
217
- axis: 0 | 1 | 2;
218
- sharpness: number;
219
- } | {
220
- kind: "warp";
221
- coordinates?: number;
222
- frequency: number;
223
- amplitude: number;
224
- } | {
225
- kind: "palette";
226
- mode: "Constant" | "Linear" | "Smooth";
227
- stops: {
228
- position: number;
229
- color: MaterialVector;
230
- }[];
231
- }
232
- /** Linear interpolation from this field to overlay. A mask field uses its X component, clamped to 0..1. */
233
- | {
234
- kind: "blend";
235
- overlay: MaterialField | MaterialVector;
236
- mask: MaterialField | number;
237
- });
@@ -24,6 +24,16 @@ function sleep(ms) {
24
24
  timer.unref();
25
25
  });
26
26
  }
27
+ /**
28
+ * The reason a run is stopped with on purpose. It must be NAMED `AbortError`:
29
+ * the AI SDK recognises an abort by that name only, so a plain Error that cuts
30
+ * off a streaming model response is reported as the response failing
31
+ * (`AI_APICallError: Failed to process successful response`), and a user's
32
+ * stop reached their chat as "a response that couldn't be read".
33
+ */
34
+ function stopReason(message) {
35
+ return Object.assign(new Error(message), { name: "AbortError" });
36
+ }
27
37
  function runNotSaved(cause) {
28
38
  return new Error(RUN_NOT_SAVED_ERROR, { cause });
29
39
  }
@@ -281,7 +291,7 @@ export class SparkAgentService {
281
291
  }
282
292
  });
283
293
  if (interrupt) {
284
- this.controllers.get(interrupt)?.abort(new Error("Goal stopped by the user."));
294
+ this.controllers.get(interrupt)?.abort(stopReason("Goal stopped by the user."));
285
295
  await this.executions.get(interrupt);
286
296
  result.goal = (await this.getConversation(ownerId, conversationId)).goal;
287
297
  }
@@ -330,7 +340,7 @@ export class SparkAgentService {
330
340
  async close() {
331
341
  this.closing = true;
332
342
  for (const controller of this.controllers.values())
333
- controller.abort(new Error("Standalone host is shutting down"));
343
+ controller.abort(stopReason("Standalone host is shutting down"));
334
344
  await Promise.all([...this.executions.values()]);
335
345
  }
336
346
  async submitMessage(input) {
@@ -458,7 +468,7 @@ export class SparkAgentService {
458
468
  return this.getRun(ownerId, runId);
459
469
  throw new Error("The run's executor is unavailable; cancellation could not be confirmed.");
460
470
  }
461
- controller.abort(new Error("Run cancelled by the user."));
471
+ controller.abort(stopReason("Run cancelled by the user."));
462
472
  // Drain receipts and pending host work before publishing a terminal state.
463
473
  await execution;
464
474
  return this.getRun(ownerId, runId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@womp/spark-agent",
3
- "version": "14.0.1",
3
+ "version": "15.0.1",
4
4
  "description": "Portable skills-based AI agent with local and durable chat transports for Womp",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1 +0,0 @@
1
- export declare const WOMP_MATERIALS_FLOWIR_DECLARATIONS = "declare const womp: { materials: {\n\"catalog\": ((options?: undefined | {\n\"refreshTextures\"?: undefined | false | true;\n\"includeTextures\"?: undefined | false | true;\n\"operations\"?: undefined | Array<string>;\n}) => Promise<{\n\"operations\": Array<{\n\"op\": string;\n\"category\": string;\n\"title\": string;\n}>;\n\"nodes\": {\n[key: string]: {\n\"type\": string;\n\"title\": string;\n\"description\": string;\n\"inputs\": Array<{\n\"title\": string;\n\"type\": string;\n\"values\"?: undefined | Array<string>;\n}>;\n\"outputs\": Array<{\n\"title\": string;\n\"type\": string;\n\"values\"?: undefined | Array<string>;\n}>;\n};\n};\n\"textureCount\": number;\n\"textures\"?: undefined | Array<string>;\n\"textureMetadata\"?: undefined | {\n\"channels\": \"unknown\";\n\"colorSpace\": \"unknown\";\n\"normalConvention\": \"unknown\";\n\"reason\": string;\n};\n}>);\n\"read\": ((materialId?: undefined | number) => Promise<{\n\"materials\": Array<{\n\"id\": number;\n\"shaderIds\": Array<number>;\n\"objectIds\": Array<number>;\n}>;\n\"material\"?: undefined | {\n\"id\": number;\n\"data\": {\n[key: string]: unknown;\n};\n\"layers\": Array<null | {\n\"nodes\": Array<{\n\"op\": string;\n[key: string]: unknown;\n}>;\n\"connections\": Array<{\n\"input_node\": number;\n\"input_slot\": number;\n\"output_node\": number;\n\"output_slot\": number;\n\"flags\"?: undefined | number;\n}>;\n}>;\n};\n\"diagnostics\": Array<string>;\n}>);\n\"write\": ((options: {\n\"materialId\"?: undefined | number;\n\"cloneFrom\"?: undefined | number;\n\"layers\"?: undefined | Array<null | {\n\"nodes\": Array<{\n\"op\": string;\n[key: string]: unknown;\n}>;\n\"connections\": Array<{\n\"input_node\": number;\n\"input_slot\": number;\n\"output_node\": number;\n\"output_slot\": number;\n\"flags\"?: undefined | number;\n}>;\n}>;\n\"constants\"?: undefined | {\n[key: string]: null | {\n\"value\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n};\n};\n\"objectIds\"?: undefined | Array<number>;\n}) => Promise<{\n\"materialId\": number;\n\"objectIds\": Array<number>;\n\"referenceIdChanges\": {\n[key: string]: number;\n};\n\"parameters\"?: undefined | Array<{\n\"name\": string;\n\"referenceId\": number;\n\"value\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"exposed\"?: undefined | false | true;\n}>;\n\"diagnostics\"?: undefined | Array<string>;\n\"status\": \"applied\";\n\"rendering\": \"unverified\";\n}>);\n\"readProgram\"?: undefined | ((materialId: number, layerIndex: number) => Promise<{\n\"materialId\": number;\n\"layerIndex\": number;\n\"source\": null | string;\n\"diagnostics\": Array<string>;\n}>);\n\"writeProgram\"?: undefined | ((options: {\n\"materialId\"?: undefined | number;\n\"cloneFrom\"?: undefined | number;\n\"layerIndex\": number;\n\"source\": string;\n\"objectIds\"?: undefined | Array<number>;\n}) => Promise<{\n\"materialId\": number;\n\"objectIds\": Array<number>;\n\"referenceIdChanges\": {\n[key: string]: number;\n};\n\"parameters\"?: undefined | Array<{\n\"name\": string;\n\"referenceId\": number;\n\"value\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"exposed\"?: undefined | false | true;\n}>;\n\"diagnostics\"?: undefined | Array<string>;\n\"status\": \"applied\";\n\"rendering\": \"unverified\";\n}>);\n\"inspect\"?: undefined | ((options: {\n\"views\": Array<{\n\"camera\"?: undefined | {\n\"position\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"target\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"projection\"?: undefined | \"perspective\" | \"orthographic\";\n\"horizontalFovDegrees\"?: undefined | number;\n\"orthographicWidth\"?: undefined | number;\n};\n}>;\n\"timeoutMs\"?: undefined | number;\n}) => Promise<{\n\"frames\": Array<{\n\"id\": string;\n\"mediaType\": string;\n\"name\"?: undefined | string;\n}>;\n\"queueSettled\": false | true;\n\"timedOut\": false | true;\n\"status\": {\n\"remaining\": null | number;\n\"pendingResources\": null | {\n[key: string]: Array<string>;\n};\n\"errors\"?: undefined | Array<{\n\"source\": \"compiler-progress\" | \"pending-resources\";\n\"message\": string;\n}>;\n\"shaderDiagnostics\"?: undefined | {\n\"status\": \"unavailable\";\n\"reason\": string;\n};\n\"rendering\": \"unverified\";\n\"explanation\": string;\n};\n}>);\n\"status\": (() => Promise<{\n\"remaining\": null | number;\n\"pendingResources\": null | {\n[key: string]: Array<string>;\n};\n\"errors\"?: undefined | Array<{\n\"source\": \"compiler-progress\" | \"pending-resources\";\n\"message\": string;\n}>;\n\"shaderDiagnostics\"?: undefined | {\n\"status\": \"unavailable\";\n\"reason\": string;\n};\n\"rendering\": \"unverified\";\n\"explanation\": string;\n}>);\n} & {\n\"recipe\": ((options: {\n\"pattern\": \"noise\" | \"grain\" | \"woven\" | \"grid\";\n\"coordinateSpace\": \"object\" | \"world\";\n\"featureSize\": number | {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"colorA\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"colorB\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"roughnessA\": number;\n\"roughnessB\": number;\n\"metalness\"?: undefined | number;\n\"detail\"?: undefined | number;\n\"relief\": \"height\" | \"bump\";\n\"reliefScale\": number;\n} & {\n\"pattern\": \"grid\";\n}) => Promise<{\n\"nodes\": Array<{\n\"op\": string;\n[key: string]: unknown;\n}>;\n\"connections\": Array<{\n\"input_node\": number;\n\"input_slot\": number;\n\"output_node\": number;\n\"output_slot\": number;\n\"flags\"?: undefined | number;\n}>;\n}>);\n} };\ndeclare function print(...values: unknown[]): void;\ndeclare function emitImage(ref: { id: string; mediaType: string; name?: string }, options?: { inspect?: boolean }): Promise<void>;\ndeclare function emitFile(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\n";
@@ -1,3 +0,0 @@
1
- // Generated by scripts/generate-skill-declarations.mjs.
2
- // prettier-ignore
3
- export const WOMP_MATERIALS_FLOWIR_DECLARATIONS = "declare const womp: { materials: {\n\"catalog\": ((options?: undefined | {\n\"refreshTextures\"?: undefined | false | true;\n\"includeTextures\"?: undefined | false | true;\n\"operations\"?: undefined | Array<string>;\n}) => Promise<{\n\"operations\": Array<{\n\"op\": string;\n\"category\": string;\n\"title\": string;\n}>;\n\"nodes\": {\n[key: string]: {\n\"type\": string;\n\"title\": string;\n\"description\": string;\n\"inputs\": Array<{\n\"title\": string;\n\"type\": string;\n\"values\"?: undefined | Array<string>;\n}>;\n\"outputs\": Array<{\n\"title\": string;\n\"type\": string;\n\"values\"?: undefined | Array<string>;\n}>;\n};\n};\n\"textureCount\": number;\n\"textures\"?: undefined | Array<string>;\n\"textureMetadata\"?: undefined | {\n\"channels\": \"unknown\";\n\"colorSpace\": \"unknown\";\n\"normalConvention\": \"unknown\";\n\"reason\": string;\n};\n}>);\n\"read\": ((materialId?: undefined | number) => Promise<{\n\"materials\": Array<{\n\"id\": number;\n\"shaderIds\": Array<number>;\n\"objectIds\": Array<number>;\n}>;\n\"material\"?: undefined | {\n\"id\": number;\n\"data\": {\n[key: string]: unknown;\n};\n\"layers\": Array<null | {\n\"nodes\": Array<{\n\"op\": string;\n[key: string]: unknown;\n}>;\n\"connections\": Array<{\n\"input_node\": number;\n\"input_slot\": number;\n\"output_node\": number;\n\"output_slot\": number;\n\"flags\"?: undefined | number;\n}>;\n}>;\n};\n\"diagnostics\": Array<string>;\n}>);\n\"write\": ((options: {\n\"materialId\"?: undefined | number;\n\"cloneFrom\"?: undefined | number;\n\"layers\"?: undefined | Array<null | {\n\"nodes\": Array<{\n\"op\": string;\n[key: string]: unknown;\n}>;\n\"connections\": Array<{\n\"input_node\": number;\n\"input_slot\": number;\n\"output_node\": number;\n\"output_slot\": number;\n\"flags\"?: undefined | number;\n}>;\n}>;\n\"constants\"?: undefined | {\n[key: string]: null | {\n\"value\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n};\n};\n\"objectIds\"?: undefined | Array<number>;\n}) => Promise<{\n\"materialId\": number;\n\"objectIds\": Array<number>;\n\"referenceIdChanges\": {\n[key: string]: number;\n};\n\"parameters\"?: undefined | Array<{\n\"name\": string;\n\"referenceId\": number;\n\"value\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"exposed\"?: undefined | false | true;\n}>;\n\"diagnostics\"?: undefined | Array<string>;\n\"status\": \"applied\";\n\"rendering\": \"unverified\";\n}>);\n\"readProgram\"?: undefined | ((materialId: number, layerIndex: number) => Promise<{\n\"materialId\": number;\n\"layerIndex\": number;\n\"source\": null | string;\n\"diagnostics\": Array<string>;\n}>);\n\"writeProgram\"?: undefined | ((options: {\n\"materialId\"?: undefined | number;\n\"cloneFrom\"?: undefined | number;\n\"layerIndex\": number;\n\"source\": string;\n\"objectIds\"?: undefined | Array<number>;\n}) => Promise<{\n\"materialId\": number;\n\"objectIds\": Array<number>;\n\"referenceIdChanges\": {\n[key: string]: number;\n};\n\"parameters\"?: undefined | Array<{\n\"name\": string;\n\"referenceId\": number;\n\"value\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"exposed\"?: undefined | false | true;\n}>;\n\"diagnostics\"?: undefined | Array<string>;\n\"status\": \"applied\";\n\"rendering\": \"unverified\";\n}>);\n\"inspect\"?: undefined | ((options: {\n\"views\": Array<{\n\"camera\"?: undefined | {\n\"position\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"target\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"projection\"?: undefined | \"perspective\" | \"orthographic\";\n\"horizontalFovDegrees\"?: undefined | number;\n\"orthographicWidth\"?: undefined | number;\n};\n}>;\n\"timeoutMs\"?: undefined | number;\n}) => Promise<{\n\"frames\": Array<{\n\"id\": string;\n\"mediaType\": string;\n\"name\"?: undefined | string;\n}>;\n\"queueSettled\": false | true;\n\"timedOut\": false | true;\n\"status\": {\n\"remaining\": null | number;\n\"pendingResources\": null | {\n[key: string]: Array<string>;\n};\n\"errors\"?: undefined | Array<{\n\"source\": \"compiler-progress\" | \"pending-resources\";\n\"message\": string;\n}>;\n\"shaderDiagnostics\"?: undefined | {\n\"status\": \"unavailable\";\n\"reason\": string;\n};\n\"rendering\": \"unverified\";\n\"explanation\": string;\n};\n}>);\n\"status\": (() => Promise<{\n\"remaining\": null | number;\n\"pendingResources\": null | {\n[key: string]: Array<string>;\n};\n\"errors\"?: undefined | Array<{\n\"source\": \"compiler-progress\" | \"pending-resources\";\n\"message\": string;\n}>;\n\"shaderDiagnostics\"?: undefined | {\n\"status\": \"unavailable\";\n\"reason\": string;\n};\n\"rendering\": \"unverified\";\n\"explanation\": string;\n}>);\n} & {\n\"recipe\": ((options: {\n\"pattern\": \"noise\" | \"grain\" | \"woven\" | \"grid\";\n\"coordinateSpace\": \"object\" | \"world\";\n\"featureSize\": number | {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"colorA\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"colorB\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"roughnessA\": number;\n\"roughnessB\": number;\n\"metalness\"?: undefined | number;\n\"detail\"?: undefined | number;\n\"relief\": \"height\" | \"bump\";\n\"reliefScale\": number;\n} & {\n\"pattern\": \"grid\";\n}) => Promise<{\n\"nodes\": Array<{\n\"op\": string;\n[key: string]: unknown;\n}>;\n\"connections\": Array<{\n\"input_node\": number;\n\"input_slot\": number;\n\"output_node\": number;\n\"output_slot\": number;\n\"flags\"?: undefined | number;\n}>;\n}>);\n} };\ndeclare function print(...values: unknown[]): void;\ndeclare function emitImage(ref: { id: string; mediaType: string; name?: string }, options?: { inspect?: boolean }): Promise<void>;\ndeclare function emitFile(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\n";
@@ -1,64 +0,0 @@
1
- import { z } from "zod";
2
- import type { MaterialCatalog, MaterialCompositionOptions, MaterialGraph } from "./types.js";
3
- export declare const materialCompositionSchema: z.ZodObject<{
4
- fields: z.ZodArray<z.ZodObject<{
5
- graph: z.ZodObject<{
6
- nodes: z.ZodArray<z.ZodObject<{
7
- op: z.ZodString;
8
- name: z.ZodOptional<z.ZodString>;
9
- location: z.ZodOptional<z.ZodObject<{
10
- x: z.ZodNumber;
11
- y: z.ZodNumber;
12
- }, z.core.$strict>>;
13
- editor_flags: z.ZodOptional<z.ZodNumber>;
14
- reference_id: z.ZodOptional<z.ZodNumber>;
15
- out: z.ZodOptional<z.ZodObject<{
16
- x: z.ZodNumber;
17
- y: z.ZodNumber;
18
- z: z.ZodNumber;
19
- }, z.core.$strict>>;
20
- }, z.core.$catchall<z.ZodType<import("./types.js").MaterialJson, unknown, z.core.$ZodTypeInternals<import("./types.js").MaterialJson, unknown>>>>>;
21
- connections: z.ZodArray<z.ZodObject<{
22
- input_node: z.ZodNumber;
23
- input_slot: z.ZodNumber;
24
- output_node: z.ZodNumber;
25
- output_slot: z.ZodNumber;
26
- flags: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<2>]>>;
27
- }, z.core.$strict>>;
28
- }, z.core.$catchall<z.ZodType<import("./types.js").MaterialJson, unknown, z.core.$ZodTypeInternals<import("./types.js").MaterialJson, unknown>>>>;
29
- source: z.ZodObject<{
30
- node: z.ZodNumber;
31
- slot: z.ZodNumber;
32
- }, z.core.$strict>;
33
- }, z.core.$strict>>;
34
- color: z.ZodOptional<z.ZodObject<{
35
- low: z.ZodObject<{
36
- x: z.ZodNumber;
37
- y: z.ZodNumber;
38
- z: z.ZodNumber;
39
- }, z.core.$strict>;
40
- high: z.ZodObject<{
41
- x: z.ZodNumber;
42
- y: z.ZodNumber;
43
- z: z.ZodNumber;
44
- }, z.core.$strict>;
45
- weights: z.ZodArray<z.ZodNumber>;
46
- }, z.core.$strict>>;
47
- roughness: z.ZodOptional<z.ZodObject<{
48
- low: z.ZodNumber;
49
- high: z.ZodNumber;
50
- weights: z.ZodArray<z.ZodNumber>;
51
- }, z.core.$strict>>;
52
- metalness: z.ZodOptional<z.ZodNumber>;
53
- relief: z.ZodOptional<z.ZodObject<{
54
- mode: z.ZodEnum<{
55
- height: "height";
56
- bump: "bump";
57
- }>;
58
- scale: z.ZodNumber;
59
- weights: z.ZodArray<z.ZodNumber>;
60
- center: z.ZodOptional<z.ZodNumber>;
61
- }, z.core.$strict>>;
62
- }, z.core.$strict>;
63
- export declare function materialCompositionOperations(options: MaterialCompositionOptions): string[];
64
- export declare function makeMaterialComposition(options: MaterialCompositionOptions, catalogue: MaterialCatalog): MaterialGraph;
@@ -1,121 +0,0 @@
1
- import { z } from "zod";
2
- import { graphSchema, makeMaterialNode, pruneMaterialGraph, validateMaterialGraph } from "./graph.js";
3
- const weights = z.array(z.number().finite());
4
- const mixWeights = weights.refine(values => values.every(value => value >= 0) && values.reduce((a, b) => a + b, 0) <= 1 + 1e-9, "Color/roughness weights must be nonnegative and sum to at most 1");
5
- const unit = z.number().min(0).max(1);
6
- const color = z.object({ x: unit, y: unit, z: unit }).strict();
7
- export const materialCompositionSchema = z.object({
8
- fields: z.array(z.object({ graph: graphSchema, source: z.object({ node: z.number().int().nonnegative(), slot: z.number().int().min(0).max(19) }).strict() }).strict()).min(1),
9
- color: z.object({ low: color, high: color, weights: mixWeights }).strict().optional(),
10
- roughness: z.object({ low: unit, high: unit, weights: mixWeights }).strict().optional(),
11
- metalness: unit.optional(),
12
- relief: z.object({ mode: z.enum(["height", "bump"]), scale: z.number().finite(), weights, center: z.number().finite().optional() }).strict().optional(),
13
- }).strict().superRefine((options, context) => {
14
- for (const channel of ["color", "roughness", "relief"])
15
- if (options[channel] && options[channel].weights.length !== options.fields.length)
16
- context.addIssue({ code: "custom", path: [channel, "weights"], message: "Provide one weight per field" });
17
- options.fields.forEach((field, index) => {
18
- if (!field.graph.nodes[field.source.node])
19
- context.addIssue({ code: "custom", path: ["fields", index, "source"], message: "Field output node does not exist" });
20
- if (field.graph.nodes.some(node => node.op.startsWith("Output")))
21
- context.addIssue({ code: "custom", path: ["fields", index], message: "Fields must not contain surface output nodes" });
22
- });
23
- });
24
- export function materialCompositionOperations(options) {
25
- return [...new Set([...options.fields.flatMap(field => field.graph.nodes.map(node => node.op)), "Constant", "Math", "MathLerp", "OutputMaterial",
26
- ...(options.relief ? options.relief.mode === "height" ? ["OutputHeight"] : ["Bump", "OutputSurfaceNormal"] : [])])];
27
- }
28
- export function makeMaterialComposition(options, catalogue) {
29
- const graph = { nodes: [], connections: [] };
30
- const sources = options.fields.map((field, index) => {
31
- const offset = graph.nodes.length;
32
- const output = catalogue.nodes[field.graph.nodes[field.source.node].op]?.outputs[field.source.slot];
33
- if (!output || !["Float", "Float3", "Color"].includes(output.type))
34
- throw new Error("Field requires a numeric output port");
35
- graph.nodes.push(...field.graph.nodes.map(node => {
36
- const copy = { ...structuredClone(node), name: `field.${index}.${node.name ?? node.op}` };
37
- // Composition creates independent controls; the host allocates their handles.
38
- if (copy.op === "Constant")
39
- delete copy.reference_id;
40
- return copy;
41
- }));
42
- graph.connections.push(...field.graph.connections.map(edge => ({ ...edge, input_node: edge.input_node + offset, output_node: edge.output_node + offset })));
43
- return { node: field.source.node + offset, slot: field.source.slot };
44
- });
45
- const selector = (op, slot, label) => {
46
- const index = catalogue.nodes[op]?.inputs[slot]?.values?.indexOf(label) ?? -1;
47
- if (index < 0)
48
- throw new Error(`${op} requires option ${label}`);
49
- return index;
50
- };
51
- const add = (op, inputs, name) => {
52
- graph.nodes.push(makeMaterialNode({ op, inputs, name }));
53
- return { node: graph.nodes.length - 1, slot: 0 };
54
- };
55
- const wire = (source, target, port) => graph.connections.push({ input_node: source.node, input_slot: source.slot, output_node: target.node, output_slot: port, flags: 0 });
56
- const constant = (value, name, isColor = false) => {
57
- const exposed = isColor || ["roughness.low", "roughness.high", "metalness", "relief.scale"].includes(name);
58
- const result = add("Constant", isColor ? { 2: value, 3: selector("Constant", 3, "Expose Color") } : { 1: value, 3: selector("Constant", 3, exposed ? "Expose X" : "Do not expose") }, name);
59
- return { ...result, slot: isColor ? 2 : 1 };
60
- };
61
- const combine = (values, name) => {
62
- let sum;
63
- values.forEach((value, index) => {
64
- if (value === 0)
65
- return;
66
- const weight = constant(value, `${name}.weight.${index}`);
67
- const product = add("Math", { 0: selector("Math", 0, "Mulitiply"), 3: 0 }, `${name} contribution`);
68
- wire(sources[index], product, 1);
69
- wire(weight, product, 2);
70
- if (!sum) {
71
- sum = product;
72
- return;
73
- }
74
- const combined = add("Math", { 0: selector("Math", 0, "Add"), 3: 0 }, `${name} superposition`);
75
- wire(sum, combined, 1);
76
- wire(product, combined, 2);
77
- sum = combined;
78
- });
79
- return sum;
80
- };
81
- const output = add("OutputMaterial", {}, "Composed surface");
82
- for (const channel of ["color", "roughness"]) {
83
- const settings = options[channel];
84
- if (!settings)
85
- continue;
86
- const field = combine(settings.weights, channel);
87
- if (!field)
88
- continue;
89
- const palette = add("MathLerp", {}, `${channel} range`);
90
- wire(constant(settings.low, `${channel}.low`, channel === "color"), palette, 0);
91
- wire(constant(settings.high, `${channel}.high`, channel === "color"), palette, 1);
92
- wire(field, palette, 2);
93
- wire(palette, output, channel === "color" ? 0 : 4);
94
- }
95
- if (options.metalness !== undefined)
96
- wire(constant(options.metalness, "metalness"), output, 3);
97
- if (options.relief) {
98
- let field = combine(options.relief.weights, "relief");
99
- if (field) {
100
- if (options.relief.center !== undefined) {
101
- const centered = add("Math", { 0: selector("Math", 0, "Subtract"), 3: 0 }, "Centered height");
102
- wire(field, centered, 1);
103
- wire(constant(options.relief.center, "relief.center"), centered, 2);
104
- field = centered;
105
- }
106
- const strength = constant(options.relief.scale, "relief.scale");
107
- if (options.relief.mode === "height") {
108
- const height = add("OutputHeight", {}, "Combined height");
109
- wire(field, height, 0);
110
- wire(strength, height, 2);
111
- }
112
- else {
113
- const bump = add("Bump", {}, "Combined bump");
114
- wire(field, bump, 0);
115
- wire(strength, bump, 1);
116
- wire(bump, add("OutputSurfaceNormal", {}, "Composed normal"), 0);
117
- }
118
- }
119
- }
120
- return pruneMaterialGraph(validateMaterialGraph(graph, catalogue.nodes));
121
- }
@@ -1,12 +0,0 @@
1
- export declare const MATERIALS_FIELD_COMPOSITION_SNIPPET = "const graph = await womp.materials.compose({\n fields,\n color:{low:colorLow,high:colorHigh,weights:colorWeights},\n roughness:{low:roughnessLow,high:roughnessHigh,weights:roughnessWeights},\n relief:{mode:'height',scale:reliefScale,weights:reliefWeights}\n});";
2
- export declare const MATERIALS_PROJECTION_RECIPE = "const catalogue = await womp.materials.catalog({\n operations:['InputPosition','InputNormal','Mapping','Projection','PredefinedTexture','OutputMaterial'],\n includeTextures:true, refreshTextures:true\n});\nif (!catalogue.textures?.includes(textureName)) throw new Error('Texture is not listed: ' + textureName);\nconst enumValue = (op, slot, label) => {\n const value = catalogue.nodes[op]?.inputs[slot]?.values?.indexOf(label) ?? -1;\n if (value < 0) throw new Error(op + ' input ' + slot + ' has no option: ' + label);\n return value;\n};\nconst rotation = {x:0,y:90,z:0};\nconst graph = {\n nodes:[\n womp.materials.node({op:'InputPosition'}),\n womp.materials.node({op:'InputNormal'}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:rotation,3:1}}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:rotation,3:1}}),\n womp.materials.node({op:'Projection',inputs:{0:enumValue('Projection',0,projectionName),3:4,4:{x:0.13,y:0.21,z:0.07},5:0}}),\n womp.materials.node({op:'PredefinedTexture',texture:textureName,inputs:{3:0,4:enumValue('PredefinedTexture',4,'sRGB (Color)'),5:0,6:0}}),\n womp.materials.node({op:'OutputMaterial'})\n ],\n connections:[\n {input_node:0,input_slot:0,output_node:2,output_slot:0,flags:0},\n {input_node:1,input_slot:0,output_node:3,output_slot:0,flags:0},\n {input_node:2,input_slot:0,output_node:4,output_slot:1,flags:0},\n {input_node:3,input_slot:0,output_node:4,output_slot:2,flags:0},\n {input_node:4,input_slot:0,output_node:5,output_slot:0,flags:0},\n {input_node:5,input_slot:0,output_node:6,output_slot:0,flags:0}\n ]\n};";
3
- export declare const MATERIALS_NORMAL_MAP_RECIPE = "const catalogue = await womp.materials.catalog({\n operations:['Constant','Passthrough','OutputMaterial','InputPosition','InputNormal','Projection','Mapping','PredefinedTexture','OutputSurfaceNormal'],\n includeTextures:true, refreshTextures:true\n});\nif (!catalogue.textures?.includes(textureName)) throw new Error('Texture is not listed: ' + textureName);\nconst enumValue = (op, slot, label) => {\n const value = catalogue.nodes[op]?.inputs[slot]?.values?.indexOf(label) ?? -1;\n if (value < 0) throw new Error(op + ' input ' + slot + ' has no option: ' + label);\n return value;\n};\nconst graph = {\n nodes:[\n womp.materials.node({op:'Constant',inputs:{2:0.5}}),\n womp.materials.node({op:'Passthrough',inputs:{0:0.3}}),\n womp.materials.node({op:'OutputMaterial'}),\n womp.materials.node({op:'InputPosition'}),\n womp.materials.node({op:'InputNormal'}),\n womp.materials.node({op:'Projection',inputs:{0:enumValue('Projection',0,'Equirectangular'),3:1,4:0,5:0}}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:0,3:1}}),\n womp.materials.node({op:'PredefinedTexture',texture:textureName,inputs:{3:0,4:enumValue('PredefinedTexture',4,'Normal'),5:0,6:0}}),\n womp.materials.node({op:'OutputSurfaceNormal'})\n ],\n connections:[\n {input_node:0,input_slot:2,output_node:2,output_slot:0,flags:0},\n {input_node:1,input_slot:0,output_node:2,output_slot:3,flags:0},\n {input_node:1,input_slot:0,output_node:2,output_slot:4,flags:0},\n {input_node:3,input_slot:0,output_node:5,output_slot:1,flags:0},\n {input_node:4,input_slot:0,output_node:5,output_slot:2,flags:0},\n {input_node:5,input_slot:0,output_node:6,output_slot:0,flags:0},\n {input_node:6,input_slot:0,output_node:7,output_slot:0,flags:0},\n {input_node:7,input_slot:0,output_node:8,output_slot:0,flags:0}\n ]\n};";
4
- export declare const MATERIALS_HEIGHT_MAP_RECIPE = "const catalogue = await womp.materials.catalog({\n operations:['Constant','Passthrough','OutputMaterial','InputPosition','InputNormal','Projection','Mapping','PredefinedTexture','OutputHeight'],\n includeTextures:true, refreshTextures:true\n});\nif (!catalogue.textures?.includes(textureName)) throw new Error('Texture is not listed: ' + textureName);\nif (!Number.isFinite(heightScale) || heightScale <= 0) throw new Error('Choose a finite positive heightScale');\nconst enumValue = (op, slot, label) => {\n const value = catalogue.nodes[op]?.inputs[slot]?.values?.indexOf(label) ?? -1;\n if (value < 0) throw new Error(op + ' input ' + slot + ' has no option: ' + label);\n return value;\n};\nconst graph = {\n nodes:[\n womp.materials.node({op:'Constant',inputs:{2:0.5}}),\n womp.materials.node({op:'Passthrough',inputs:{0:0.3}}),\n womp.materials.node({op:'OutputMaterial'}),\n womp.materials.node({op:'InputPosition'}),\n womp.materials.node({op:'InputNormal'}),\n womp.materials.node({op:'Projection',inputs:{0:enumValue('Projection',0,'Equirectangular'),3:1,4:0,5:0}}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:0,3:1}}),\n womp.materials.node({op:'PredefinedTexture',texture:textureName,inputs:{3:0,4:enumValue('PredefinedTexture',4,'No transform'),5:0,6:0}}),\n womp.materials.node({op:'OutputHeight',inputs:{2:heightScale}})\n ],\n connections:[\n {input_node:0,input_slot:2,output_node:2,output_slot:0,flags:0},\n {input_node:1,input_slot:0,output_node:2,output_slot:3,flags:0},\n {input_node:1,input_slot:0,output_node:2,output_slot:4,flags:0},\n {input_node:3,input_slot:0,output_node:5,output_slot:1,flags:0},\n {input_node:4,input_slot:0,output_node:5,output_slot:2,flags:0},\n {input_node:5,input_slot:0,output_node:6,output_slot:0,flags:0},\n {input_node:6,input_slot:0,output_node:7,output_slot:0,flags:0},\n {input_node:7,input_slot:0,output_node:8,output_slot:0,flags:0}\n ]\n};";
5
- export declare const MATERIALS_GENERATOR_RECIPE = "const settings = {\n Noise1D:{inputs:{1:5,2:1,3:1,4:0}, ramp:[0.2,0.8,0.025,0.92]},\n Noise3D:{inputs:{1:5,2:1,3:1,4:0}},\n NoiseFBM:{inputs:{1:4,2:2,3:1,4:0}, ramp:[0.25,0.75,0.018,0.95]},\n NoiseVoronoi:{inputs:{1:4}},\n WavesTexture:{inputs:{1:{x:10,y:0,z:0},2:1,3:0}, ramp:[0,1]},\n CheckerTexture:{inputs:{1:3,2:1}, ramp:[0,1]},\n MagicTexture:{inputs:{1:5,2:2,3:1}}\n};\nif (!Object.hasOwn(settings,generatorName)) throw new Error('No recipe for: ' + generatorName);\nconst preset = settings[generatorName];\nconst catalogue = await womp.materials.catalog({operations:['InputPosition','Mapping',generatorName,...(preset.ramp ? ['ColorRamp'] : []),'OutputMaterial']});\nif (!catalogue.nodes[generatorName]) throw new Error('Generator is not listed: ' + generatorName);\nconst enumValue = (op, slot, label) => {\n const value = catalogue.nodes[op]?.inputs[slot]?.values?.indexOf(label) ?? -1;\n if (value < 0) throw new Error(op + ' input ' + slot + ' has no option: ' + label);\n return value;\n};\nif (generatorName === 'NoiseVoronoi') {\n preset.inputs[2] = enumValue('NoiseVoronoi',2,'Color');\n preset.inputs[3] = enumValue('NoiseVoronoi',3,'Euclidean');\n}\nconst gray = value => ({x:value,y:value,z:value});\nconst nodes = [\n womp.materials.node({op:'InputPosition'}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:{x:generatorName === 'WavesTexture' ? 45 : 0,y:90,z:0},3:1}}),\n womp.materials.node({op:generatorName,inputs:preset.inputs})\n];\nif (preset.ramp) {\n const [start,end,dark,light] = preset.ramp;\n nodes.push(womp.materials.node({op:'ColorRamp',inputs:{3:enumValue('ColorRamp',3,'Linear')},ramp:[\n {position:start,color:dark === undefined ? {x:0.018,y:0.04,z:0.085} : gray(dark)},\n {position:end,color:light === undefined ? {x:0.94,y:0.78,z:0.36} : gray(light)}\n ]}));\n}\nnodes.push(womp.materials.node({op:'OutputMaterial'}));\nconst graph = {nodes,connections:nodes.slice(1).map((_,i) => ({input_node:i,input_slot:0,output_node:i+1,output_slot:0,flags:0}))};";
6
- export declare const MATERIALS_COMBINED_NORMAL_RECIPE = "const extra = await womp.materials.catalog({operations:['NoiseFBM','Bump','SplitValues','CombineValues','Math']});\nObject.assign(catalogue.nodes,extra.nodes);\ngraph.nodes.pop();\ngraph.connections.pop();\ngraph.nodes.push(\n womp.materials.node({op:'NoiseFBM',inputs:{1:4,2:3,3:1,4:0}}),\n womp.materials.node({op:'Bump',inputs:{1:0.08}}),\n womp.materials.node({op:'SplitValues'}),\n womp.materials.node({op:'SplitValues'}),\n womp.materials.node({op:'Math',inputs:{0:enumValue('Math',0,'Add'),3:0}}),\n womp.materials.node({op:'Math',inputs:{0:enumValue('Math',0,'Mulitiply'),3:0}}),\n womp.materials.node({op:'SplitValues'}),\n womp.materials.node({op:'CombineValues'}),\n womp.materials.node({op:'Math',inputs:{0:enumValue('Math',0,'Normalize'),3:0}}),\n womp.materials.node({op:'OutputSurfaceNormal'})\n);\ngraph.connections.push(\n {input_node:3,input_slot:0,output_node:8,output_slot:0,flags:0},\n {input_node:8,input_slot:0,output_node:9,output_slot:0,flags:0},\n {input_node:7,input_slot:0,output_node:10,output_slot:0,flags:0},\n {input_node:9,input_slot:0,output_node:11,output_slot:0,flags:0},\n {input_node:7,input_slot:0,output_node:12,output_slot:1,flags:0},\n {input_node:9,input_slot:0,output_node:12,output_slot:2,flags:0},\n {input_node:10,input_slot:2,output_node:13,output_slot:1,flags:0},\n {input_node:11,input_slot:2,output_node:13,output_slot:2,flags:0},\n {input_node:12,input_slot:0,output_node:14,output_slot:0,flags:0},\n {input_node:14,input_slot:0,output_node:15,output_slot:0,flags:0},\n {input_node:14,input_slot:1,output_node:15,output_slot:1,flags:0},\n {input_node:13,input_slot:0,output_node:15,output_slot:2,flags:0},\n {input_node:15,input_slot:0,output_node:16,output_slot:1,flags:0},\n {input_node:16,input_slot:0,output_node:17,output_slot:0,flags:0}\n);";
7
- export declare const MATERIALS_SCALAR_RGB_RECIPE = "await womp.materials.catalog({operations:['GetComponent','CombineValues']});\nconst colorEdge = graph.connections.find(edge => graph.nodes[edge.output_node].op === 'OutputMaterial' && edge.output_slot === 0);\nif (!colorEdge) throw new Error('Scalar-to-RGB requires an existing primary-color connection');\nconst component = graph.nodes.length;\ngraph.nodes.push(\n womp.materials.node({op:'GetComponent',inputs:{1:0}}),\n womp.materials.node({op:'CombineValues'})\n);\ngraph.connections.push(\n {input_node:colorEdge.input_node,input_slot:colorEdge.input_slot,output_node:component,output_slot:0,flags:0},\n ...[0,1,2].map(slot => ({input_node:component,input_slot:0,output_node:component+1,output_slot:slot,flags:0}))\n);\ncolorEdge.input_node = component+1;\ncolorEdge.input_slot = 0;";
8
- export declare const MATERIALS_HSL_RECIPE = "await womp.materials.catalog({operations:['HSL']});\nconst hslEdge = graph.connections.find(edge => graph.nodes[edge.output_node].op === 'OutputMaterial' && edge.output_slot === 0);\nif (!hslEdge) throw new Error('HSL adjustment requires an existing primary-color connection');\nconst hsl = graph.nodes.length;\ngraph.nodes.push(womp.materials.node({op:'HSL',inputs:{1:0.33,2:0.8,3:0}}));\ngraph.connections.push({input_node:hslEdge.input_node,input_slot:hslEdge.input_slot,output_node:hsl,output_slot:0,flags:0});\nhslEdge.input_node = hsl;\nhslEdge.input_slot = 0;";
9
- export declare const MATERIALS_COORDINATE_SPACE_RECIPE = "if (!['InputPosition','InputWorldPosition'].includes(positionOp)) throw new Error('Choose InputPosition or InputWorldPosition');\nconst coordinateCatalogue = await womp.materials.catalog({operations:[positionOp]});\nif (!coordinateCatalogue.nodes[positionOp]) throw new Error('Position source is not listed: ' + positionOp);\nconst positionNodes = graph.nodes.filter(node => ['InputPosition','InputWorldPosition'].includes(node.op));\nif (positionNodes.length !== 1) throw new Error('Choose a specific position source in this graph before changing space');\nif (positionNodes[0].op !== positionOp && graph.nodes.some(node => node.op === 'Projection')) throw new Error('Projection position and normal spaces must be changed together; build that mapping explicitly');\npositionNodes[0].op = positionOp;";
10
- export declare const MATERIALS_CLONE_COLOR_RECIPE = "const sourceMaterial = await womp.materials.read(materialId);\nconst sourceConstant = sourceMaterial.material.layers.flatMap(layer => layer?.nodes ?? []).find(node => node.op === 'Constant' && node.reference_id === referenceId);\nif (!sourceConstant) throw new Error('No Constant with reference ' + referenceId + ' in material ' + materialId);\nconst cloned = await womp.materials.write({cloneFrom:materialId,objectIds:[objectId]});\nconst clonedReference = cloned.referenceIdChanges[String(referenceId)] ?? referenceId;\nprint({clonedMaterialId:cloned.materialId,referenceId:clonedReference});\nconst cloneState = await womp.materials.read(cloned.materialId);\nconst cloneConstant = cloneState.material.layers.flatMap(layer => layer?.nodes ?? []).find(node => node.op === 'Constant' && node.reference_id === clonedReference);\nif (!cloneConstant) throw new Error('Cloned Constant changed; inspect material ' + cloned.materialId + ' before editing');\nconst override = cloneState.material.data.constants?.[String(clonedReference)];\nconst zero = {x:0,y:0,z:0};\nconst preservedValue = override === undefined ? (cloneConstant.in1 ?? zero) : (override.value ?? zero);\nprint(await womp.materials.write({materialId:cloned.materialId,constants:{[clonedReference]:{value:preservedValue,color:newColor}}}));";
11
- export declare const MATERIALS_RESET_CONSTANT_RECIPE = "const reset = await womp.materials.write({materialId,constants:{[referenceId]:null}});\nprint(reset);\nconst afterReset = await womp.materials.read(materialId);\nconst resetReference = reset.referenceIdChanges[String(referenceId)];\nprint({materialId,referenceId:resetReference,material:afterReset.material});";
12
- export declare const MATERIALS_RECIPES = "\nThe graph examples construct one shader layer with womp.materials; the clone and reset examples perform writes. recipe() resolves its own live selectors; use these known starting patterns without requesting their descriptors. For custom graphs, discover only unfamiliar operations and required texture resource names. The graph snippets leave a variable named graph for assignment.\n\nReusable surface graphs\nconst settings = {\n coordinateSpace:'object', featureSize:1,\n colorA:{x:0.45,y:0.35,z:0.2}, colorB:{x:0.02,y:0.02,z:0.02},\n roughnessA:0.45, roughnessB:0.45, relief:'height', reliefScale:0.0003\n};\nconst graph = await womp.materials.recipe({pattern:'grid',...settings});\n// This single probe includes 1-unit major cells and 0.1-unit minor cells.\nconst isolated = await womp.materials.write({cloneFrom:materialId,layers:[graph],objectIds});\n// Inspect complementary views together before replacing the probe on this isolated material.\n// Choose noise for irregular grain/pores, grain for elongated structure, woven for crossed threads.\n// Set colors, finish and feature size from the requested surface, rather than retaining probe values.\nconst surface = await womp.materials.recipe({pattern, ...surfaceSettings});\nprint(await womp.materials.write({materialId:isolated.materialId,layers:[surface],objectIds}));\n\nfeatureSize is the repeat scale in object coordinates, or physical mm with coordinateSpace:'world'. Colors in settings are linear RGB; convert display palettes before using them. An axis vector gives deliberate anisotropy; grain stretches along the largest component. Object coordinates belong to the carrier and can differ across primitives and meshes. Check the probe against actual geometry dimensions and transforms before translating its spacing into physical dimensions. World coordinates give consistent physical spacing across differently scaled carriers, but remain anchored to the scene. These graphs are editable starting structures: add the target's distinctive pores, loops, knots or irregular threads when required. Strongly stretched noise alone can look smeared; separate directional structure from broad color variation and fine roughness/relief.\nPattern-specific calibration observations (native strength, object coordinates, detail 4, height and bump tested independently):\n- Dual-scale grid, featureSize 1: height 0.0003\u20130.001; start at 0.0003.\n- Noise, featureSize 0.04: 0.01\u20130.03 produced visible fine relief.\n- Crossed periodic threads, featureSize 0.04: 0.003\u20130.03 retained rounded thread shading.\n- Noise, featureSize 0.08: 0.01\u20130.03 produced low-amplitude grain.\n- Fine directional grain, featureSize {x:0.015,y:0.015,z:2}: 0.0003\u20130.003 produced faint directional relief; 0.01 and above produced stronger ridges.\nThese observations on curved and flat fixtures under fixed lighting are starting points, not quality targets or upper limits. Use independently weighted structural and micro height fields. Choose visible relief by its actual gradient, scale and requested finish; universal bump multipliers can destroy gloss. Compare close and grazing views without changing the scene. Height and bump strengths are not generally interchangeable.\n\nCompose generic scalar fields\nBuild broad variation, defining structure and fine detail with field(), using independent scales and contrast. Custom generators, domain warping, periodic profiles or masks can supply the same {graph,source:{node,slot}} contract. Retrieve unfamiliar descriptors together. compose() remaps imported node indices and wires weighted channels; it does not prescribe a material family.\nSet fields to terminal-free fields and colorWeights, roughnessWeights and reliefWeights to arrays with one weight per field. Omitted or all-zero channels inherit the incoming material. Normalized color/roughness fields use nonnegative weights summing to at most 1 and valid linear colorLow/colorHigh and roughnessLow/roughnessHigh endpoints. Relief weights may be signed; choose reliefScale from the actual gradient. Combined scalar height is converted to normals once. Keep coordinates compatible and preserve fine detail's own scale and contrast. Named Constant handles from write() permit parameter-only refinement without rebuilding these graphs.\nconst graph = await womp.materials.compose({\n fields,\n color:{low:colorLow,high:colorHigh,weights:colorWeights},\n roughness:{low:roughnessLow,high:roughnessHigh,weights:roughnessWeights},\n relief:{mode:'height',scale:reliefScale,weights:reliefWeights}\n});\n\nTexture projection\nSet textureName to a listed RGB color resource and projectionName to a listed Projection mode. Position and normal rotations stay paired. Choose Planar, Cubic, Cylindrical, Equirectangular, Triplanar or a normalized mode for the carrier, then inspect its seams and transitions at the intended size.\nconst catalogue = await womp.materials.catalog({\n operations:['InputPosition','InputNormal','Mapping','Projection','PredefinedTexture','OutputMaterial'],\n includeTextures:true, refreshTextures:true\n});\nif (!catalogue.textures?.includes(textureName)) throw new Error('Texture is not listed: ' + textureName);\nconst enumValue = (op, slot, label) => {\n const value = catalogue.nodes[op]?.inputs[slot]?.values?.indexOf(label) ?? -1;\n if (value < 0) throw new Error(op + ' input ' + slot + ' has no option: ' + label);\n return value;\n};\nconst rotation = {x:0,y:90,z:0};\nconst graph = {\n nodes:[\n womp.materials.node({op:'InputPosition'}),\n womp.materials.node({op:'InputNormal'}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:rotation,3:1}}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:rotation,3:1}}),\n womp.materials.node({op:'Projection',inputs:{0:enumValue('Projection',0,projectionName),3:4,4:{x:0.13,y:0.21,z:0.07},5:0}}),\n womp.materials.node({op:'PredefinedTexture',texture:textureName,inputs:{3:0,4:enumValue('PredefinedTexture',4,'sRGB (Color)'),5:0,6:0}}),\n womp.materials.node({op:'OutputMaterial'})\n ],\n connections:[\n {input_node:0,input_slot:0,output_node:2,output_slot:0,flags:0},\n {input_node:1,input_slot:0,output_node:3,output_slot:0,flags:0},\n {input_node:2,input_slot:0,output_node:4,output_slot:1,flags:0},\n {input_node:3,input_slot:0,output_node:4,output_slot:2,flags:0},\n {input_node:4,input_slot:0,output_node:5,output_slot:0,flags:0},\n {input_node:5,input_slot:0,output_node:6,output_slot:0,flags:0}\n ]\n};\n\nTangent normal texture\nSet textureName to a known normal-map resource. The graph uses Normal decoding and Equirectangular projection; adapt projection and map convention to the carrier. It changes shading normals, not geometry.\nconst catalogue = await womp.materials.catalog({\n operations:['Constant','Passthrough','OutputMaterial','InputPosition','InputNormal','Projection','Mapping','PredefinedTexture','OutputSurfaceNormal'],\n includeTextures:true, refreshTextures:true\n});\nif (!catalogue.textures?.includes(textureName)) throw new Error('Texture is not listed: ' + textureName);\nconst enumValue = (op, slot, label) => {\n const value = catalogue.nodes[op]?.inputs[slot]?.values?.indexOf(label) ?? -1;\n if (value < 0) throw new Error(op + ' input ' + slot + ' has no option: ' + label);\n return value;\n};\nconst graph = {\n nodes:[\n womp.materials.node({op:'Constant',inputs:{2:0.5}}),\n womp.materials.node({op:'Passthrough',inputs:{0:0.3}}),\n womp.materials.node({op:'OutputMaterial'}),\n womp.materials.node({op:'InputPosition'}),\n womp.materials.node({op:'InputNormal'}),\n womp.materials.node({op:'Projection',inputs:{0:enumValue('Projection',0,'Equirectangular'),3:1,4:0,5:0}}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:0,3:1}}),\n womp.materials.node({op:'PredefinedTexture',texture:textureName,inputs:{3:0,4:enumValue('PredefinedTexture',4,'Normal'),5:0,6:0}}),\n womp.materials.node({op:'OutputSurfaceNormal'})\n ],\n connections:[\n {input_node:0,input_slot:2,output_node:2,output_slot:0,flags:0},\n {input_node:1,input_slot:0,output_node:2,output_slot:3,flags:0},\n {input_node:1,input_slot:0,output_node:2,output_slot:4,flags:0},\n {input_node:3,input_slot:0,output_node:5,output_slot:1,flags:0},\n {input_node:4,input_slot:0,output_node:5,output_slot:2,flags:0},\n {input_node:5,input_slot:0,output_node:6,output_slot:0,flags:0},\n {input_node:6,input_slot:0,output_node:7,output_slot:0,flags:0},\n {input_node:7,input_slot:0,output_node:8,output_slot:0,flags:0}\n ]\n};\n\nHeight texture\nSet textureName to a known scalar resource and heightScale to a finite positive value. This uses No transform decoding and OutputHeight Scale; it is not numerically equivalent to tangent-normal strength.\nconst catalogue = await womp.materials.catalog({\n operations:['Constant','Passthrough','OutputMaterial','InputPosition','InputNormal','Projection','Mapping','PredefinedTexture','OutputHeight'],\n includeTextures:true, refreshTextures:true\n});\nif (!catalogue.textures?.includes(textureName)) throw new Error('Texture is not listed: ' + textureName);\nif (!Number.isFinite(heightScale) || heightScale <= 0) throw new Error('Choose a finite positive heightScale');\nconst enumValue = (op, slot, label) => {\n const value = catalogue.nodes[op]?.inputs[slot]?.values?.indexOf(label) ?? -1;\n if (value < 0) throw new Error(op + ' input ' + slot + ' has no option: ' + label);\n return value;\n};\nconst graph = {\n nodes:[\n womp.materials.node({op:'Constant',inputs:{2:0.5}}),\n womp.materials.node({op:'Passthrough',inputs:{0:0.3}}),\n womp.materials.node({op:'OutputMaterial'}),\n womp.materials.node({op:'InputPosition'}),\n womp.materials.node({op:'InputNormal'}),\n womp.materials.node({op:'Projection',inputs:{0:enumValue('Projection',0,'Equirectangular'),3:1,4:0,5:0}}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:0,3:1}}),\n womp.materials.node({op:'PredefinedTexture',texture:textureName,inputs:{3:0,4:enumValue('PredefinedTexture',4,'No transform'),5:0,6:0}}),\n womp.materials.node({op:'OutputHeight',inputs:{2:heightScale}})\n ],\n connections:[\n {input_node:0,input_slot:2,output_node:2,output_slot:0,flags:0},\n {input_node:1,input_slot:0,output_node:2,output_slot:3,flags:0},\n {input_node:1,input_slot:0,output_node:2,output_slot:4,flags:0},\n {input_node:3,input_slot:0,output_node:5,output_slot:1,flags:0},\n {input_node:4,input_slot:0,output_node:5,output_slot:2,flags:0},\n {input_node:5,input_slot:0,output_node:6,output_slot:0,flags:0},\n {input_node:6,input_slot:0,output_node:7,output_slot:0,flags:0},\n {input_node:7,input_slot:0,output_node:8,output_slot:0,flags:0}\n ]\n};\n\nCombine normal texture and procedural bump\nAppend this immediately after the tangent-normal graph above, before writing. Its node indices depend on that graph. The whiteout composition is approximate; inspect the combined result and each component under the same light.\nconst extra = await womp.materials.catalog({operations:['NoiseFBM','Bump','SplitValues','CombineValues','Math']});\nObject.assign(catalogue.nodes,extra.nodes);\ngraph.nodes.pop();\ngraph.connections.pop();\ngraph.nodes.push(\n womp.materials.node({op:'NoiseFBM',inputs:{1:4,2:3,3:1,4:0}}),\n womp.materials.node({op:'Bump',inputs:{1:0.08}}),\n womp.materials.node({op:'SplitValues'}),\n womp.materials.node({op:'SplitValues'}),\n womp.materials.node({op:'Math',inputs:{0:enumValue('Math',0,'Add'),3:0}}),\n womp.materials.node({op:'Math',inputs:{0:enumValue('Math',0,'Mulitiply'),3:0}}),\n womp.materials.node({op:'SplitValues'}),\n womp.materials.node({op:'CombineValues'}),\n womp.materials.node({op:'Math',inputs:{0:enumValue('Math',0,'Normalize'),3:0}}),\n womp.materials.node({op:'OutputSurfaceNormal'})\n);\ngraph.connections.push(\n {input_node:3,input_slot:0,output_node:8,output_slot:0,flags:0},\n {input_node:8,input_slot:0,output_node:9,output_slot:0,flags:0},\n {input_node:7,input_slot:0,output_node:10,output_slot:0,flags:0},\n {input_node:9,input_slot:0,output_node:11,output_slot:0,flags:0},\n {input_node:7,input_slot:0,output_node:12,output_slot:1,flags:0},\n {input_node:9,input_slot:0,output_node:12,output_slot:2,flags:0},\n {input_node:10,input_slot:2,output_node:13,output_slot:1,flags:0},\n {input_node:11,input_slot:2,output_node:13,output_slot:2,flags:0},\n {input_node:12,input_slot:0,output_node:14,output_slot:0,flags:0},\n {input_node:14,input_slot:0,output_node:15,output_slot:0,flags:0},\n {input_node:14,input_slot:1,output_node:15,output_slot:1,flags:0},\n {input_node:13,input_slot:0,output_node:15,output_slot:2,flags:0},\n {input_node:15,input_slot:0,output_node:16,output_slot:1,flags:0},\n {input_node:16,input_slot:0,output_node:17,output_slot:0,flags:0}\n);\n\nScalar texture to neutral RGB\nAppend this to a graph with an existing primary-color connection only when the sampled texture is known to be single-channel. It copies X/R to all three color channels.\nawait womp.materials.catalog({operations:['GetComponent','CombineValues']});\nconst colorEdge = graph.connections.find(edge => graph.nodes[edge.output_node].op === 'OutputMaterial' && edge.output_slot === 0);\nif (!colorEdge) throw new Error('Scalar-to-RGB requires an existing primary-color connection');\nconst component = graph.nodes.length;\ngraph.nodes.push(\n womp.materials.node({op:'GetComponent',inputs:{1:0}}),\n womp.materials.node({op:'CombineValues'})\n);\ngraph.connections.push(\n {input_node:colorEdge.input_node,input_slot:colorEdge.input_slot,output_node:component,output_slot:0,flags:0},\n ...[0,1,2].map(slot => ({input_node:component,input_slot:0,output_node:component+1,output_slot:slot,flags:0}))\n);\ncolorEdge.input_node = component+1;\ncolorEdge.input_slot = 0;\n\nHSL adjustment\nAppend this to a graph with an existing primary-color connection. Lightness 0 leaves that component unchanged.\nawait womp.materials.catalog({operations:['HSL']});\nconst hslEdge = graph.connections.find(edge => graph.nodes[edge.output_node].op === 'OutputMaterial' && edge.output_slot === 0);\nif (!hslEdge) throw new Error('HSL adjustment requires an existing primary-color connection');\nconst hsl = graph.nodes.length;\ngraph.nodes.push(womp.materials.node({op:'HSL',inputs:{1:0.33,2:0.8,3:0}}));\ngraph.connections.push({input_node:hslEdge.input_node,input_slot:hslEdge.input_slot,output_node:hsl,output_slot:0,flags:0});\nhslEdge.input_node = hsl;\nhslEdge.input_slot = 0;\n\nLocal or world coordinates\nSet positionOp to InputPosition or InputWorldPosition. This changes one position source in a simple mapping graph; a Projection graph also needs a matching normal-space change.\nif (!['InputPosition','InputWorldPosition'].includes(positionOp)) throw new Error('Choose InputPosition or InputWorldPosition');\nconst coordinateCatalogue = await womp.materials.catalog({operations:[positionOp]});\nif (!coordinateCatalogue.nodes[positionOp]) throw new Error('Position source is not listed: ' + positionOp);\nconst positionNodes = graph.nodes.filter(node => ['InputPosition','InputWorldPosition'].includes(node.op));\nif (positionNodes.length !== 1) throw new Error('Choose a specific position source in this graph before changing space');\nif (positionNodes[0].op !== positionOp && graph.nodes.some(node => node.op === 'Projection')) throw new Error('Projection position and normal spaces must be changed together; build that mapping explicitly');\npositionNodes[0].op = positionOp;\n\nGenerators\nSet generatorName to Noise1D, Noise3D, NoiseFBM, NoiseVoronoi, WavesTexture, CheckerTexture or MagicTexture. The settings are starting examples, not a complete operation catalogue; adjust one control at a time.\nconst settings = {\n Noise1D:{inputs:{1:5,2:1,3:1,4:0}, ramp:[0.2,0.8,0.025,0.92]},\n Noise3D:{inputs:{1:5,2:1,3:1,4:0}},\n NoiseFBM:{inputs:{1:4,2:2,3:1,4:0}, ramp:[0.25,0.75,0.018,0.95]},\n NoiseVoronoi:{inputs:{1:4}},\n WavesTexture:{inputs:{1:{x:10,y:0,z:0},2:1,3:0}, ramp:[0,1]},\n CheckerTexture:{inputs:{1:3,2:1}, ramp:[0,1]},\n MagicTexture:{inputs:{1:5,2:2,3:1}}\n};\nif (!Object.hasOwn(settings,generatorName)) throw new Error('No recipe for: ' + generatorName);\nconst preset = settings[generatorName];\nconst catalogue = await womp.materials.catalog({operations:['InputPosition','Mapping',generatorName,...(preset.ramp ? ['ColorRamp'] : []),'OutputMaterial']});\nif (!catalogue.nodes[generatorName]) throw new Error('Generator is not listed: ' + generatorName);\nconst enumValue = (op, slot, label) => {\n const value = catalogue.nodes[op]?.inputs[slot]?.values?.indexOf(label) ?? -1;\n if (value < 0) throw new Error(op + ' input ' + slot + ' has no option: ' + label);\n return value;\n};\nif (generatorName === 'NoiseVoronoi') {\n preset.inputs[2] = enumValue('NoiseVoronoi',2,'Color');\n preset.inputs[3] = enumValue('NoiseVoronoi',3,'Euclidean');\n}\nconst gray = value => ({x:value,y:value,z:value});\nconst nodes = [\n womp.materials.node({op:'InputPosition'}),\n womp.materials.node({op:'Mapping',inputs:{1:0,2:{x:generatorName === 'WavesTexture' ? 45 : 0,y:90,z:0},3:1}}),\n womp.materials.node({op:generatorName,inputs:preset.inputs})\n];\nif (preset.ramp) {\n const [start,end,dark,light] = preset.ramp;\n nodes.push(womp.materials.node({op:'ColorRamp',inputs:{3:enumValue('ColorRamp',3,'Linear')},ramp:[\n {position:start,color:dark === undefined ? {x:0.018,y:0.04,z:0.085} : gray(dark)},\n {position:end,color:light === undefined ? {x:0.94,y:0.78,z:0.36} : gray(light)}\n ]}));\n}\nnodes.push(womp.materials.node({op:'OutputMaterial'}));\nconst graph = {nodes,connections:nodes.slice(1).map((_,i) => ({input_node:i,input_slot:0,output_node:i+1,output_slot:0,flags:0}))};\n\nAssign the selected graph\nprint(await womp.materials.write({layers:[graph],objectIds:[objectId]}));\n\nClone a material and edit one Constant\nSet materialId, objectId and referenceId from a current read, with newColor as a 0..1 RGB vector. The workflow retains the source material and the Constant's numeric value. Inspect the printed clone ID before any retry.\nconst sourceMaterial = await womp.materials.read(materialId);\nconst sourceConstant = sourceMaterial.material.layers.flatMap(layer => layer?.nodes ?? []).find(node => node.op === 'Constant' && node.reference_id === referenceId);\nif (!sourceConstant) throw new Error('No Constant with reference ' + referenceId + ' in material ' + materialId);\nconst cloned = await womp.materials.write({cloneFrom:materialId,objectIds:[objectId]});\nconst clonedReference = cloned.referenceIdChanges[String(referenceId)] ?? referenceId;\nprint({clonedMaterialId:cloned.materialId,referenceId:clonedReference});\nconst cloneState = await womp.materials.read(cloned.materialId);\nconst cloneConstant = cloneState.material.layers.flatMap(layer => layer?.nodes ?? []).find(node => node.op === 'Constant' && node.reference_id === clonedReference);\nif (!cloneConstant) throw new Error('Cloned Constant changed; inspect material ' + cloned.materialId + ' before editing');\nconst override = cloneState.material.data.constants?.[String(clonedReference)];\nconst zero = {x:0,y:0,z:0};\nconst preservedValue = override === undefined ? (cloneConstant.in1 ?? zero) : (override.value ?? zero);\nprint(await womp.materials.write({materialId:cloned.materialId,constants:{[clonedReference]:{value:preservedValue,color:newColor}}}));\n\nReset a Constant override\nSet materialId and referenceId to the current IDs. The reset returns a new reference ID; use a fresh read before further edits.\nconst reset = await womp.materials.write({materialId,constants:{[referenceId]:null}});\nprint(reset);\nconst afterReset = await womp.materials.read(materialId);\nconst resetReference = reset.referenceIdChanges[String(referenceId)];\nprint({materialId,referenceId:resetReference,material:afterReset.material});\n\nA successful write is a scene commit, not evidence that shader compilation or texture loading completed. Check status() and an inspected image separately; status() observations can be null when a query fails.\n";