@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.
- package/CHANGELOG.md +39 -0
- package/dist/capabilities/materials.d.ts +6 -18
- package/dist/capabilities/materials.js +23 -81
- package/dist/generated/materials-declarations.d.ts +1 -1
- package/dist/generated/materials-declarations.js +1 -1
- package/dist/intent-bench.js +6 -1
- package/dist/materials/grid-probe.d.ts +35 -0
- package/dist/materials/grid-probe.js +105 -0
- package/dist/materials/types.d.ts +2 -85
- package/dist/server/service.js +13 -3
- package/package.json +1 -1
- package/dist/generated/materials-flowir-declarations.d.ts +0 -1
- package/dist/generated/materials-flowir-declarations.js +0 -3
- package/dist/materials/composition.d.ts +0 -64
- package/dist/materials/composition.js +0 -121
- package/dist/materials/recipes.d.ts +0 -12
- package/dist/materials/recipes.js +0 -284
- package/dist/materials/reference.d.ts +0 -2
- package/dist/materials/reference.js +0 -97
- package/dist/materials/shaping.d.ts +0 -294
- package/dist/materials/shaping.js +0 -184
- package/dist/materials/structure.d.ts +0 -2
- package/dist/materials/structure.js +0 -12
- package/dist/materials/surface-recipes.d.ts +0 -78
- package/dist/materials/surface-recipes.js +0 -193
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,45 @@ Notable changes to `@womp/spark-agent`, newest first. Versions follow
|
|
|
4
4
|
[Semantic Versioning](https://semver.org/). Add an entry with each version bump; describe what
|
|
5
5
|
changed for hosts and users, and how to migrate across breaking changes.
|
|
6
6
|
|
|
7
|
+
## 15.0.1 — 2026-10-21
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Stopping a run or a goal while the model is streaming its answer ends the run as cancelled with
|
|
12
|
+
the stop's own reason. `SparkAgentService` aborted with a plain `Error`, which the AI SDK does not
|
|
13
|
+
recognise as an abort, so it reported the cut-off answer as `Failed to process successful
|
|
14
|
+
response`. Hosts showed that as an unreadable AI response until the stored run replaced it. The
|
|
15
|
+
stop, cancel and shutdown reasons are now named `AbortError`; their messages are unchanged.
|
|
16
|
+
|
|
17
|
+
## 15.0.0 — 2026-10-21
|
|
18
|
+
|
|
19
|
+
Procedural materials are FlowIR only. The native-JSON helper path and its skills are removed.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- `MaterialsHost.readProgram` and `writeProgram` are required. A host, or a wrapper around one, that
|
|
24
|
+
leaves them out no longer compiles. Before, it silently got the older helper skill instead of FlowIR:
|
|
25
|
+
crow-backend's metering and project-gate wrappers drop both methods, so Crow runs never got FlowIR
|
|
26
|
+
materials. `createSdkMaterialsHost` already provides them; wrappers must forward them.
|
|
27
|
+
- `procedural-materials` (skill version 19) has one set of instructions. Repeated guidance on the grid
|
|
28
|
+
probe, colors, units and refinement is merged into one workflow, about 550 tokens shorter with the
|
|
29
|
+
same instructions.
|
|
30
|
+
- `womp.materials.recipe` builds only the grid probe (`pattern: "grid"`); its graph is unchanged.
|
|
31
|
+
|
|
32
|
+
### Removed
|
|
33
|
+
|
|
34
|
+
- The `procedural-materials-reference` and `procedural-materials-recipes` skills, and the helper
|
|
35
|
+
variant of `procedural-materials` for hosts without `writeProgram`.
|
|
36
|
+
- `womp.materials.node`, `field`, `shape` and `compose`, the `noise`, `grain` and `woven` recipes, and
|
|
37
|
+
their types: `MaterialField`, `MaterialFieldOptions`, `MaterialCompositionOptions` and
|
|
38
|
+
`MaterialShapeOptions`. `MaterialRecipeOptions` no longer takes `detail`.
|
|
39
|
+
- `WompMaterialsFlowirApi`: `WompMaterialsApi` is now the FlowIR API.
|
|
40
|
+
|
|
41
|
+
### Migration
|
|
42
|
+
|
|
43
|
+
- Hosts: forward `readProgram` and `writeProgram` through every `MaterialsHost` wrapper, and drop the
|
|
44
|
+
two removed skill names from any skill-name lists or tests.
|
|
45
|
+
|
|
7
46
|
## 14.0.1 — 2026-10-21
|
|
8
47
|
|
|
9
48
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SparkCapability, SparkInvocationContext } from "../capabilities.js";
|
|
2
2
|
import { type MaterialInspectionOptions, type MaterialInspectionResult, type MaterialInspectionHost } from "../materials/inspection.js";
|
|
3
|
-
import type { MaterialCatalog, MaterialCatalogOptions,
|
|
3
|
+
import type { MaterialCatalog, MaterialCatalogOptions, MaterialRecipeOptions, MaterialGraph, MaterialSnapshot, MaterialWrite, MaterialWriteResult, MaterialProgramWrite, MaterialProgramRead } from "../materials/types.js";
|
|
4
4
|
export type * from "../materials/types.js";
|
|
5
5
|
export type { MaterialInspectionOptions, MaterialInspectionResult, MaterialInspectionHost } from "../materials/inspection.js";
|
|
6
6
|
export type MaterialStatus = {
|
|
@@ -22,33 +22,21 @@ export type MaterialStatus = {
|
|
|
22
22
|
export type WompMaterialsApi = {
|
|
23
23
|
catalog(options?: MaterialCatalogOptions): Promise<MaterialCatalog>;
|
|
24
24
|
read(materialId?: number): Promise<MaterialSnapshot>;
|
|
25
|
-
|
|
26
|
-
/** Build an editable starting graph; reads live descriptors internally and does not commit. */
|
|
25
|
+
/** The grid probe as a native layer for write({layers}); reads live descriptors internally and does not commit. */
|
|
27
26
|
recipe(options: MaterialRecipeOptions): Promise<MaterialGraph>;
|
|
28
|
-
/** Terminal-free scalar structure, editable before composition. */
|
|
29
|
-
field(options: MaterialFieldOptions): Promise<MaterialField>;
|
|
30
|
-
/** Merge arbitrary scalar fields and independently wire color, finish and relief. No commit. */
|
|
31
|
-
compose(options: MaterialCompositionOptions): Promise<MaterialGraph>;
|
|
32
|
-
/** Shape a field analytically with editable controls; no commit or descriptor inspection needed. */
|
|
33
|
-
shape(field: MaterialField, options: MaterialShapeOptions): Promise<MaterialField>;
|
|
34
27
|
/** Available when the host supplies scene captures. Primes, waits and returns joint inspection views. */
|
|
35
28
|
inspect?: (options: MaterialInspectionOptions) => Promise<MaterialInspectionResult>;
|
|
36
29
|
write(options: MaterialWrite): Promise<MaterialWriteResult>;
|
|
37
|
-
readProgram
|
|
38
|
-
writeProgram
|
|
30
|
+
readProgram(materialId: number, layerIndex: number): Promise<MaterialProgramRead>;
|
|
31
|
+
writeProgram(options: MaterialProgramWrite): Promise<MaterialWriteResult>;
|
|
39
32
|
status(): Promise<MaterialStatus>;
|
|
40
33
|
};
|
|
41
|
-
export type WompMaterialsFlowirApi = Pick<WompMaterialsApi, "catalog" | "read" | "write" | "readProgram" | "writeProgram" | "inspect" | "status"> & {
|
|
42
|
-
recipe(options: MaterialRecipeOptions & {
|
|
43
|
-
pattern: "grid";
|
|
44
|
-
}): Promise<MaterialGraph>;
|
|
45
|
-
};
|
|
46
34
|
export interface MaterialsHost {
|
|
47
35
|
catalog(options: MaterialCatalogOptions, context: SparkInvocationContext): Promise<MaterialCatalog>;
|
|
48
36
|
read(materialId: number | undefined, context: SparkInvocationContext): Promise<MaterialSnapshot>;
|
|
49
37
|
write(options: MaterialWrite, context: SparkInvocationContext): Promise<MaterialWriteResult>;
|
|
50
|
-
readProgram
|
|
51
|
-
writeProgram
|
|
38
|
+
readProgram(materialId: number, layerIndex: number, context: SparkInvocationContext): Promise<MaterialProgramRead>;
|
|
39
|
+
writeProgram(options: MaterialProgramWrite, context: SparkInvocationContext): Promise<MaterialWriteResult>;
|
|
52
40
|
status(context: SparkInvocationContext): Promise<MaterialStatus>;
|
|
53
41
|
}
|
|
54
42
|
export declare function createMaterialsCapability(host: MaterialsHost, captures?: MaterialInspectionHost): SparkCapability<WompMaterialsApi>;
|
|
@@ -1,108 +1,50 @@
|
|
|
1
1
|
import { WOMP_MATERIALS_DECLARATIONS } from "../generated/materials-declarations.js";
|
|
2
|
-
import {
|
|
3
|
-
import { catalogOptionsSchema, makeMaterialNode, materialId, writeSchema, } from "../materials/graph.js";
|
|
4
|
-
import { MATERIALS_REFERENCE } from "../materials/reference.js";
|
|
5
|
-
import { MATERIALS_RECIPES } from "../materials/recipes.js";
|
|
6
|
-
import { MATERIALS_STRUCTURE_GUIDANCE, MATERIALS_QUALITY_GUIDANCE } from "../materials/structure.js";
|
|
2
|
+
import { catalogOptionsSchema, materialId, writeSchema, } from "../materials/graph.js";
|
|
7
3
|
import { materialFlowirReference } from "../materials/flowir.js";
|
|
8
|
-
import { makeMaterialShape, materialShapeOperations, materialShapeSchema } from "../materials/shaping.js";
|
|
9
4
|
import { inspectMaterial, materialInspectionSchema } from "../materials/inspection.js";
|
|
10
|
-
import {
|
|
11
|
-
import { makeMaterialComposition, materialCompositionOperations, materialCompositionSchema } from "../materials/composition.js";
|
|
5
|
+
import { makeMaterialRecipe, materialRecipeOperations, materialRecipeSchema } from "../materials/grid-probe.js";
|
|
12
6
|
export function createMaterialsCapability(host, captures) {
|
|
13
7
|
return {
|
|
14
8
|
skills: [
|
|
15
9
|
{
|
|
16
10
|
name: "procedural-materials",
|
|
17
|
-
version: "
|
|
18
|
-
description:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
11
|
+
version: "19",
|
|
12
|
+
description: "Author procedural surfaces with FlowIR, calibrate mapping, edit controls, clone, assign and inspect materials.",
|
|
13
|
+
instructions: `Use womp.materials for procedural surface appearance. Supply a complete FlowIR program to writeProgram({cloneFrom,layerIndex:0,source,objectIds}) for an isolated material, or {materialId,layerIndex,source} to edit one existing layer. The FlowIR language and supported nodes are documented below; the backend resolves native operations, slot indices, enums and binary payloads, so supported nodes need no descriptor inspection.
|
|
14
|
+
read() lists material IDs and direct users. Editing an existing material affects every reference, including procedural geometry references that are not listed; cloneFrom creates an independent copy and isolates shared shader storage automatically. writeProgram preserves base properties and unrelated layers. readProgram(materialId,layerIndex) returns editable source, or null with diagnostics when the native graph cannot be represented safely. Preserve unrelated statements and parameter names. Compatible panel overrides migrate by name and type; reset overrides are reported. Each write returns the current parameter handles (reference IDs with complete value/color pairs): use them after every writeProgram, replacement or reset, and refine controls alone with write({materialId,constants}), preserving the counterpart field. A null constant resets it and returns a new handle.
|
|
15
|
+
Coordinates: public X maps to negative renderer Z, public Y to renderer Y, public Z to negative renderer X. World positions use native scene units (1 unit is 25 mm); object positions follow carrier coordinates and ancestor transforms. Compensate non-uniform dimensions and transforms in the mapping, never by modifying geometry, and keep physical feature size consistent with all channels aligned; distinguish intended directional anatomy from smeared stretching.
|
|
16
|
+
Colors: author linear RGB in 0..1. Decode display/reference colors with (channel/255)**2.2; preserve already-linear colors and scalar channels. IncomingMaterial's primary, secondary and subsurface colors are display-encoded in layer 0 (decode with MathPower Second=2.2 before calculating with them or writing them back) and linear in later layers; connect decoded colors to keep color while changing only finish. Linear literals and decoded texture colors need no layer correction.
|
|
17
|
+
Nodes: ScalarNoise for grayscale fields, VectorNoise for coordinate distortion, ScalarAdd/Subtract/Multiply/Divide for scalar controls. catalog({includeTextures:true}) lists texture paths for PredefinedTexture; refresh it after resource changes. Ports marked literal require written values: ColorRamp stops and ProjectionModeSelector options cannot be wired. Parameters become editable panel controls; const values stay internal; OutputMaterial literals are lowered to connected values automatically.
|
|
18
|
+
Aim for the highest fidelity, quality and detail resolution these capabilities support.
|
|
19
|
+
1. Inspect: in one execution, collect target IDs, material users, units, dimensions, bounds and ancestor transforms.
|
|
20
|
+
2. Probe every new material before building its final structure. Create, assign and inspect in one execution recipe({pattern:'grid',coordinateSpace:'object',featureSize:1,colorA:{x:0.45,y:0.35,z:0.2},colorB:{x:0.02,y:0.02,z:0.02},roughnessA:0.45,roughnessB:0.45,relief:'height',reliefScale:0.0003}) written with write({cloneFrom:materialId,layers:[graph],objectIds}); choose the base color for the target. Its major lines every 1 unit and lower-contrast minor lines every 0.1 unit show spacing, stretch, orientation and relief on the relevant faces; correct unintended distortion without changing geometry or transforms. reliefScale is native shading-normal strength, not millimeters (0.0003 is the tested starting strength for this grid); the final OutputHeight.Scale depends on height slope and feature spacing, not on probe values. Replace the probe completely, preserving other material users and assignments.
|
|
21
|
+
3. Plan: decompose the description or reference into broad variation, defining structure and fine grain, recording each component's relative scale, shape, direction, distribution, edge character, contrast and color/roughness/relief contribution. Apply text overrides while keeping the remaining reference features, and separate reference illumination from intrinsic structure. Give microstructure its own scale and strength so dominant motifs do not obscure it.
|
|
22
|
+
4. Build all components and finish channels together in one FlowIR program, using explicit math, palettes and masks for defining features. For textured surfaces, apply the tested readability adjustment once in this first construction: bump scale ×1.25, palette saturation ×1.15, palette lightness ×0.95 and scalar feature contrast ×1.15 around 0.5, clamped to 0..1. Apply color factors in display encoding, then decode back to linear RGB; native HSL inputs are additive offsets. Never compound it during refinement or add a pass for it. Explicit flat, muted or pale requests take precedence; keep reference hues, defining features and the requested finish. These factors are a starting point, not optimum values.
|
|
23
|
+
Weight defining height and fine-noise height independently: raising all bump together can erase coherent highlights and turn gloss matte. Relief follows height slope, so finer spacing, sharper edges and more octaves strengthen normals at the same scale; calibrated ranges describe particular fields, not quality ceilings. Adjust palette saturation/lightness separately from feature coverage and edge contrast, using bounded scalar remaps before palettes or masked blends and checking for clipped colors and changed coverage. Keep intrinsic color separate from illumination, preserving natural low-saturation features and coherent highlights. Use roughness variation for finish breakup and signed height profiles for real ridges and cavities; a dark spot alone is not a pit.
|
|
24
|
+
5. Inspect: write each candidate and inspect it jointly in one execution. inspect() waits for compilation and returns joint views when available; status() reports only global queues and does not prove visual success. Read only queueSettled, timedOut, status and the emitted frames. Look at complementary overall, close and grazing views under the existing lighting, geometry and render settings. Match tonal contrast and reflectivity through highlight width, strength and breakup. Confirm every planned feature is visibly resolved (a fine-noise node does not prove fine grain) and that defining relief reads through lighting at the intended viewing distance, not only through its color mask. Subpixel features cannot be resolved by more strength or octaves. If relief destroys the requested sheen, rebalance that feature's height or frequency before compensating with roughness.
|
|
25
|
+
6. Refine: name the largest visible mismatch, its relevant scales and the expected correction. Wrong topology or shape needs construction changes; wrong spacing, color, roughness or relief needs parameter changes. Change related controls together with the returned handles and inspect once. For a structural edit, read, patch, write and inspect in the same execution; read graphs only for a previously unknown material or to recover stale handles. Compare each candidate with the best inspected version at the same views and restore the better graph if a change weakens a defining feature. If tuning does not improve a mismatch, change its construction instead of repeating strength changes. Continue while a specific supported correction is likely to fix a substantial mismatch; stop when the result meets the request or edits stop helping. Never end on an uninspected edit; include final assignment and preservation checks in the final inspection.
|
|
26
|
+
Print only the IDs, diagnostics, controls and observations needed for the next step; keep full graphs and source local.
|
|
29
27
|
|
|
30
|
-
${materialFlowirReference()}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
recipe() builds editable grid, noise, grain and woven starting graphs and resolves live operation selectors internally. Use it directly for these patterns; no preliminary descriptor dump is needed. It does not write or assign a material. featureSize is in object-coordinate units for coordinateSpace:'object', or physical millimeters for 'world'; vector components use graph axes. Object mapping follows the owning carrier and its transforms; world mapping stays fixed in the scene. Grid includes major cells at featureSize and minor cells at one tenth of it, with lower minor contrast. colorA is the base and colorB the grid-line color. Use shallow relief for probes.
|
|
34
|
-
field() builds terminal-free noise, grain, woven, grid or cellular structures. It shares the recipe coordinate/feature-size convention; rotation is in degrees. cellMode selects a cellular pattern or boundary mask; remap controls contrast and can invert a mask. compose() merges these fields or arbitrary custom {graph,source:{node,slot}} fields, wiring independent color, roughness and combined height/bump weights. Color/roughness weights are nonnegative and sum to at most 1; fields must be normalized to 0..1. Relief weights may be signed. This is generic construction, not a finished material preset. Keep broad variation, defining shapes and fine roughness/relief separate. Independent feature colors use shape palette and blend; compose preserves their RGB with color low zero, high one, and weight one. Scalar channels consume X.
|
|
35
|
-
Coordinate axes are known: scene.access public X corresponds to negative renderer Z, public Y to renderer Y, public Z to negative renderer X. World-space featureSize uses renderer axes in physical mm: for grain running along public X, make Z the largest feature-size component, such as {x:1,y:1,z:40}; public Z uses the largest X component. These are orientation examples; choose sizes from the target. Object-space coordinates additionally follow carrier transforms and primitive/mesh mapping. A symmetric grid measures spacing/stretch but cannot establish axis identity. Use the known basis plus carrier transforms, or physical world mapping when local axis identity is uncertain; world mapping remains scene anchored.
|
|
36
|
-
${MATERIALS_STRUCTURE_GUIDANCE}
|
|
37
|
-
Composed controls are named Constants. Palette colors, roughness endpoints, metalness and overall relief are exposed for editing; structural weights and centering stay internal. SDK write results include parameters with current referenceId, value and color; print only the controls relevant to refinement. Change those through constants without rebuilding the graph, preserving the counterpart value/color. Use the new handles after resets/replacements; when a host omits parameters, recover them from read().
|
|
38
|
-
${MATERIAL_RECIPE_RELIEF_GUIDANCE}
|
|
39
|
-
${MATERIALS_QUALITY_GUIDANCE}
|
|
40
|
-
For custom operations, use exact names from catalog().operations; request catalog({operations:[...]}) only for descriptors not already known in this conversation. Request includeTextures:true when you need texture resource names. Request refreshTextures:true after adding/replacing texture resources or switching resource context. Never infer availability from files on the agent's machine or persist catalogue indices as texture identity.
|
|
41
|
-
read() lists materials and direct users; read(id) returns native base data and graph layers. Existing material edits affect every reference, including Geometry Nodes/OpenSCAD references not listed as direct users. To isolate an edit, use cloneFrom with objectIds. Shader storage shared with another material is copied automatically.
|
|
42
|
-
Use node() to construct literals and encode ramps, texture names and option payloads. For custom nodes, discover unfamiliar descriptors before connecting output slots to input slots. OutputMaterial needs connections; its unconnected ports inherit the incoming material.
|
|
43
|
-
write replaces the full layers array when supplied. Preserve unrelated layers, nodes and references from read. Omit layers for assignment/constant-only edits. When rebuilding an existing graph, carry forward intended Constant overrides; omitted overrides reset with replacement nodes, including finish controls. constants entries require both value and color; preserve the counterpart when editing one. A null entry resets a Constant and returns its new reference ID: read again before further edits.
|
|
44
|
-
Base properties and names remain available through scene.access; material names have a 63-character limit. Procedural colors, including recipe palettes, Constant colors and ramp stops, are linear RGB in 0..1. Decode display RGB before supplying it; for this renderer's gamma-2.2 base colors use (channel/255)**2.2. Do not apply this conversion to roughness, metalness, height or normals, or to colors already linear. Graph coordinates use native conventions, not scene.access's mm convenience API.
|
|
45
|
-
Writes use the host's protected scene access, persistence, permissions and receipts. Read current layers before replacing them. After an uncertain commit/save, inspect receipts and scene state; do not replay blindly.
|
|
46
|
-
status() reports independent global compiler-queue and pending-resource observations. A null field means its query failed; errors identifies the source. Per-shader diagnostics are unavailable. Catalogue names do not establish texture channels, color space or normal convention; choose decoding only when the resource encoding is known. Applied means committed. When inspect is available, use inspect({views:[...]}) after writes; it primes registration once, polls status without screenshot loops and captures the angles sequentially. Emit every returned frame within the same execution for joint comparison. queueSettled describes observations, not visual correctness; Report pending/unavailable observations honestly; fewer frames than requested means inspection is incomplete. When inspect is unavailable, prime with a screenshot, then observe status and capture the needed angles.`,
|
|
47
|
-
declarations: host.writeProgram ? WOMP_MATERIALS_FLOWIR_DECLARATIONS : WOMP_MATERIALS_DECLARATIONS,
|
|
48
|
-
examples: host.writeProgram ? [
|
|
28
|
+
${materialFlowirReference()}`,
|
|
29
|
+
declarations: WOMP_MATERIALS_DECLARATIONS,
|
|
30
|
+
examples: [
|
|
49
31
|
"const source = 'param Vec3 tint = Vec3(0.2,0.08,0.03)\\nparam Float finish = 0.5 min=0 max=1 step=0.01\\nnode output OutputMaterial PrimaryColor=tint Roughness=finish'; print(await womp.materials.writeProgram({cloneFrom:materialId,layerIndex:0,source,objectIds:[objectId]}));",
|
|
50
32
|
"const layer = await womp.materials.readProgram(materialId,0); print({source:layer.source,diagnostics:layer.diagnostics});",
|
|
51
|
-
] : [
|
|
52
|
-
"const fields = await Promise.all([womp.materials.field({pattern:'noise',coordinateSpace:'world',featureSize:8}),womp.materials.field({pattern:'noise',coordinateSpace:'world',featureSize:0.2})]); const graph = await womp.materials.compose({fields,color:{low:{x:0.2,y:0.15,z:0.1},high:{x:0.4,y:0.3,z:0.2},weights:[0.7,0.1]},roughness:{low:0.6,high:0.9,weights:[0.1,0.8]},relief:{mode:'height',scale:0.003,weights:[0.3,0.05]}}); const result = await womp.materials.write({materialId,layers:[graph]}); print({materialId:result.materialId,parameters:result.parameters?.filter(p=>['relief.scale','color.low','color.high','roughness.low','roughness.high'].includes(p.name))});",
|
|
53
|
-
"const graph = await womp.materials.recipe({pattern:'grid',coordinateSpace:'object',featureSize:1,colorA:{x:0.45,y:0.35,z:0.2},colorB:{x:0.02,y:0.02,z:0.02},roughnessA:0.45,roughnessB:0.45,relief:'height',reliefScale:0.0003}); print(await womp.materials.write({cloneFrom:materialId,layers:[graph],objectIds:[objectId]}));",
|
|
54
|
-
"const graph = await womp.materials.recipe({pattern:'noise',coordinateSpace:'world',featureSize:2,colorA:{x:0.6,y:0.55,z:0.45},colorB:{x:0.65,y:0.6,z:0.5},roughnessA:0.8,roughnessB:0.85,relief:'height',reliefScale:0.003}); print(await womp.materials.write({materialId,layers:[graph],objectIds:[objectId]}));",
|
|
55
|
-
"print(await womp.materials.write({cloneFrom: materialId, objectIds: [objectId]}));",
|
|
56
33
|
],
|
|
57
34
|
},
|
|
58
|
-
{
|
|
59
|
-
name: "procedural-materials-reference",
|
|
60
|
-
version: "9",
|
|
61
|
-
description: "Low-level native JSON shader graphs: numeric ports, binary payloads and direct node construction.",
|
|
62
|
-
instructions: MATERIALS_REFERENCE,
|
|
63
|
-
declarations: host.writeProgram ? WOMP_MATERIALS_DECLARATIONS : "",
|
|
64
|
-
examples: [],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "procedural-materials-recipes",
|
|
68
|
-
version: "10",
|
|
69
|
-
description: "Native JSON graph helper snippets for field, shape and compose, texture mapping and normal composition.",
|
|
70
|
-
instructions: MATERIALS_RECIPES,
|
|
71
|
-
declarations: "",
|
|
72
|
-
examples: [],
|
|
73
|
-
},
|
|
74
35
|
],
|
|
75
36
|
createApi: (context) => ({
|
|
76
37
|
catalog: (options) => host.catalog(catalogOptionsSchema.parse(options ?? {}), context),
|
|
77
38
|
read: (id) => host.read(id === undefined ? undefined : materialId.parse(id), context),
|
|
78
|
-
node: (options) => {
|
|
79
|
-
context.signal.throwIfAborted();
|
|
80
|
-
return makeMaterialNode(options);
|
|
81
|
-
},
|
|
82
39
|
recipe: async (options) => {
|
|
83
40
|
const parsed = materialRecipeSchema.parse(options);
|
|
84
41
|
const catalogue = await host.catalog({ operations: materialRecipeOperations(parsed) }, context);
|
|
85
42
|
return makeMaterialRecipe(parsed, catalogue);
|
|
86
43
|
},
|
|
87
|
-
field: async (options) => {
|
|
88
|
-
const parsed = materialFieldSchema.parse(options);
|
|
89
|
-
const catalogue = await host.catalog({ operations: materialFieldOperations(parsed) }, context);
|
|
90
|
-
return makeMaterialField(parsed, catalogue);
|
|
91
|
-
},
|
|
92
|
-
compose: async (options) => {
|
|
93
|
-
const parsed = materialCompositionSchema.parse(options);
|
|
94
|
-
const catalogue = await host.catalog({ operations: materialCompositionOperations(parsed) }, context);
|
|
95
|
-
return makeMaterialComposition(parsed, catalogue);
|
|
96
|
-
},
|
|
97
|
-
shape: async (field, options) => {
|
|
98
|
-
const parsed = materialShapeSchema.parse({ ...options, field });
|
|
99
|
-
const catalogue = await host.catalog({ operations: materialShapeOperations(parsed) }, context);
|
|
100
|
-
return makeMaterialShape(parsed, catalogue);
|
|
101
|
-
},
|
|
102
44
|
...(captures ? { inspect: (options) => inspectMaterial(host, captures, materialInspectionSchema.parse(options), context) } : {}),
|
|
103
45
|
write: (options) => host.write(writeSchema.parse(options), context),
|
|
104
|
-
|
|
105
|
-
|
|
46
|
+
readProgram: (id, layerIndex) => host.readProgram(id, layerIndex, context),
|
|
47
|
+
writeProgram: (options) => host.writeProgram(options, context),
|
|
106
48
|
status: () => host.status(context),
|
|
107
49
|
}),
|
|
108
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WOMP_MATERIALS_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\"node\": ((options: {\n\"op\": string;\n\"name\"?: undefined | string;\n\"reference_id\"?: undefined | number;\n\"inputs\"?: undefined | {\n[key: string]: number | {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n};\n\"texture\"?: undefined | string;\n\"ramp\"?: undefined | Array<{\n\"position\": number;\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n}>;\n\"options\"?: undefined | Array<{\n\"name\": string;\n\"value\": number;\n}>;\n}) => {\n\"op\": string;\n[key: string]: unknown;\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}) => 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\"field\": ((options: {\n\"pattern\": \"noise\" | \"grain\" | \"woven\" | \"grid\" | \"cells\";\n\"coordinateSpace\": \"object\" | \"world\";\n\"featureSize\": number | {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"detail\"?: undefined | number;\n\"rotation\"?: undefined | {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"cellMode\"?: undefined | \"Distance\" | \"Edge distance\" | \"Color\" | \"Smooth Distance\" | \"Smooth Color\";\n\"remap\"?: undefined | {\n\"low\": number;\n\"high\": number;\n};\n}) => Promise<{\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n}>);\n\"compose\": ((options: {\n\"fields\": Array<{\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n}>;\n\"color\"?: undefined | {\n\"low\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"high\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"weights\": Array<number>;\n};\n\"roughness\"?: undefined | {\n\"low\": number;\n\"high\": number;\n\"weights\": Array<number>;\n};\n\"metalness\"?: undefined | number;\n\"relief\"?: undefined | {\n\"mode\": \"height\" | \"bump\";\n\"scale\": number;\n\"weights\": Array<number>;\n\"center\"?: undefined | number;\n};\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\"shape\": ((field: {\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n}, options: {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"remap\";\n\"low\": number;\n\"high\": number;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"ridge\";\n\"center\": number;\n\"width\": number;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"periodic\";\n\"coordinates\"?: undefined | number;\n\"axis\": 0 | 1 | 2;\n\"sharpness\": number;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"warp\";\n\"coordinates\"?: undefined | number;\n\"frequency\": number;\n\"amplitude\": number;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"palette\";\n\"mode\": \"Constant\" | \"Linear\" | \"Smooth\";\n\"stops\": Array<{\n\"position\": number;\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n}>;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"blend\";\n\"overlay\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n} | {\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n};\n\"mask\": number | {\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n};\n}) => Promise<{\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\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\"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\"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} };\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
|
+
export declare const WOMP_MATERIALS_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\"recipe\": ((options: {\n\"pattern\": \"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\"relief\": \"height\" | \"bump\";\n\"reliefScale\": number;\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\"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\"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\": ((materialId: number, layerIndex: number) => Promise<{\n\"materialId\": number;\n\"layerIndex\": number;\n\"source\": null | string;\n\"diagnostics\": Array<string>;\n}>);\n\"writeProgram\": ((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\"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} };\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 +1,3 @@
|
|
|
1
1
|
// Generated by scripts/generate-skill-declarations.mjs.
|
|
2
2
|
// prettier-ignore
|
|
3
|
-
export const WOMP_MATERIALS_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\"node\": ((options: {\n\"op\": string;\n\"name\"?: undefined | string;\n\"reference_id\"?: undefined | number;\n\"inputs\"?: undefined | {\n[key: string]: number | {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n};\n\"texture\"?: undefined | string;\n\"ramp\"?: undefined | Array<{\n\"position\": number;\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n}>;\n\"options\"?: undefined | Array<{\n\"name\": string;\n\"value\": number;\n}>;\n}) => {\n\"op\": string;\n[key: string]: unknown;\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}) => 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\"field\": ((options: {\n\"pattern\": \"noise\" | \"grain\" | \"woven\" | \"grid\" | \"cells\";\n\"coordinateSpace\": \"object\" | \"world\";\n\"featureSize\": number | {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"detail\"?: undefined | number;\n\"rotation\"?: undefined | {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"cellMode\"?: undefined | \"Distance\" | \"Edge distance\" | \"Color\" | \"Smooth Distance\" | \"Smooth Color\";\n\"remap\"?: undefined | {\n\"low\": number;\n\"high\": number;\n};\n}) => Promise<{\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n}>);\n\"compose\": ((options: {\n\"fields\": Array<{\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n}>;\n\"color\"?: undefined | {\n\"low\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"high\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n\"weights\": Array<number>;\n};\n\"roughness\"?: undefined | {\n\"low\": number;\n\"high\": number;\n\"weights\": Array<number>;\n};\n\"metalness\"?: undefined | number;\n\"relief\"?: undefined | {\n\"mode\": \"height\" | \"bump\";\n\"scale\": number;\n\"weights\": Array<number>;\n\"center\"?: undefined | number;\n};\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\"shape\": ((field: {\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n}, options: {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"remap\";\n\"low\": number;\n\"high\": number;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"ridge\";\n\"center\": number;\n\"width\": number;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"periodic\";\n\"coordinates\"?: undefined | number;\n\"axis\": 0 | 1 | 2;\n\"sharpness\": number;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"warp\";\n\"coordinates\"?: undefined | number;\n\"frequency\": number;\n\"amplitude\": number;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"palette\";\n\"mode\": \"Constant\" | \"Linear\" | \"Smooth\";\n\"stops\": Array<{\n\"position\": number;\n\"color\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n};\n}>;\n} | {\n\"name\"?: undefined | string;\n} & {\n\"kind\": \"blend\";\n\"overlay\": {\n\"x\": number;\n\"y\": number;\n\"z\": number;\n} | {\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n};\n\"mask\": number | {\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\n};\n}) => Promise<{\n\"graph\": {\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\"source\": {\n\"node\": number;\n\"slot\": number;\n};\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\"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\"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} };\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";
|
|
3
|
+
export const WOMP_MATERIALS_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\"recipe\": ((options: {\n\"pattern\": \"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\"relief\": \"height\" | \"bump\";\n\"reliefScale\": number;\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\"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\"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\": ((materialId: number, layerIndex: number) => Promise<{\n\"materialId\": number;\n\"layerIndex\": number;\n\"source\": null | string;\n\"diagnostics\": Array<string>;\n}>);\n\"writeProgram\": ((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\"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} };\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";
|
package/dist/intent-bench.js
CHANGED
|
@@ -385,7 +385,7 @@ async function intentFixtures(testCase, controller) {
|
|
|
385
385
|
},
|
|
386
386
|
}),
|
|
387
387
|
materials: createMaterialsCapability({
|
|
388
|
-
// An empty node catalog: enough to plan plain colors, not
|
|
388
|
+
// An empty node catalog: enough to plan plain colors, not the grid probe.
|
|
389
389
|
catalog: async () => {
|
|
390
390
|
note("materials.catalog");
|
|
391
391
|
fixtureErrors.push("materials.catalog (no shader nodes)");
|
|
@@ -400,6 +400,11 @@ async function intentFixtures(testCase, controller) {
|
|
|
400
400
|
};
|
|
401
401
|
},
|
|
402
402
|
write: async (options) => decide("scene", "materials.write", options),
|
|
403
|
+
readProgram: async (materialId, layerIndex) => {
|
|
404
|
+
note("materials.readProgram");
|
|
405
|
+
return { materialId, layerIndex, source: null, diagnostics: ["This layer is empty."] };
|
|
406
|
+
},
|
|
407
|
+
writeProgram: async (options) => decide("scene", "materials.writeProgram", options),
|
|
403
408
|
status: async () => {
|
|
404
409
|
note("materials.status");
|
|
405
410
|
return { remaining: 0, pendingResources: {}, rendering: "unverified", explanation: "No material work is pending." };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { MaterialCatalog, MaterialGraph, MaterialRecipeOptions } from "./types.js";
|
|
3
|
+
export declare const materialRecipeSchema: z.ZodObject<{
|
|
4
|
+
pattern: z.ZodLiteral<"grid">;
|
|
5
|
+
coordinateSpace: z.ZodEnum<{
|
|
6
|
+
object: "object";
|
|
7
|
+
world: "world";
|
|
8
|
+
}>;
|
|
9
|
+
featureSize: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
10
|
+
x: z.ZodNumber;
|
|
11
|
+
y: z.ZodNumber;
|
|
12
|
+
z: z.ZodNumber;
|
|
13
|
+
}, z.core.$strict>]>;
|
|
14
|
+
colorA: z.ZodObject<{
|
|
15
|
+
x: z.ZodNumber;
|
|
16
|
+
y: z.ZodNumber;
|
|
17
|
+
z: z.ZodNumber;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
colorB: z.ZodObject<{
|
|
20
|
+
x: z.ZodNumber;
|
|
21
|
+
y: z.ZodNumber;
|
|
22
|
+
z: z.ZodNumber;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
roughnessA: z.ZodNumber;
|
|
25
|
+
roughnessB: z.ZodNumber;
|
|
26
|
+
metalness: z.ZodOptional<z.ZodNumber>;
|
|
27
|
+
relief: z.ZodEnum<{
|
|
28
|
+
height: "height";
|
|
29
|
+
bump: "bump";
|
|
30
|
+
}>;
|
|
31
|
+
reliefScale: z.ZodNumber;
|
|
32
|
+
}, z.core.$strict>;
|
|
33
|
+
export declare function materialRecipeOperations(options: MaterialRecipeOptions): string[];
|
|
34
|
+
/** The grid probe as a native graph, with operation selectors resolved from the live catalogue. */
|
|
35
|
+
export declare function makeMaterialRecipe(options: MaterialRecipeOptions, catalogue: MaterialCatalog): MaterialGraph;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { INTERNAL_UNITS_PER_MM } from "../coordinates.js";
|
|
3
|
+
import { makeMaterialNode } from "./graph.js";
|
|
4
|
+
const positiveVector = z.object({ x: z.number().finite().positive(), y: z.number().finite().positive(), z: z.number().finite().positive() }).strict();
|
|
5
|
+
const color = z.object({ x: z.number().min(0).max(1), y: z.number().min(0).max(1), z: z.number().min(0).max(1) }).strict();
|
|
6
|
+
export const materialRecipeSchema = z.object({
|
|
7
|
+
pattern: z.literal("grid"),
|
|
8
|
+
coordinateSpace: z.enum(["object", "world"]),
|
|
9
|
+
featureSize: z.union([z.number().finite().positive(), positiveVector]),
|
|
10
|
+
colorA: color,
|
|
11
|
+
colorB: color,
|
|
12
|
+
roughnessA: z.number().min(0).max(1),
|
|
13
|
+
roughnessB: z.number().min(0).max(1),
|
|
14
|
+
metalness: z.number().min(0).max(1).optional(),
|
|
15
|
+
relief: z.enum(["height", "bump"]),
|
|
16
|
+
reliefScale: z.number().finite(),
|
|
17
|
+
}).strict();
|
|
18
|
+
export function materialRecipeOperations(options) {
|
|
19
|
+
return [options.coordinateSpace === "object" ? "InputPosition" : "InputWorldPosition", "Mapping", "MathLerp",
|
|
20
|
+
options.coordinateSpace === "object" ? "InputNormal" : "InputWorldNormal", "Projection", "GetComponent", "Math",
|
|
21
|
+
"Constant", "OutputMaterial", ...(options.relief === "height" ? ["OutputHeight"] : ["Bump", "OutputSurfaceNormal"])];
|
|
22
|
+
}
|
|
23
|
+
/** The grid probe as a native graph, with operation selectors resolved from the live catalogue. */
|
|
24
|
+
export function makeMaterialRecipe(options, catalogue) {
|
|
25
|
+
const graph = { nodes: [], connections: [] };
|
|
26
|
+
const node = (op, inputs, name) => {
|
|
27
|
+
if (!catalogue.nodes[op])
|
|
28
|
+
throw new Error("Recipe operation unavailable: " + op);
|
|
29
|
+
graph.nodes.push(makeMaterialNode({ op, inputs, name }));
|
|
30
|
+
return graph.nodes.length - 1;
|
|
31
|
+
};
|
|
32
|
+
const connect = (source, target, port, output = 0) => {
|
|
33
|
+
graph.connections.push({ input_node: source, input_slot: output, output_node: target, output_slot: port, flags: 0 });
|
|
34
|
+
};
|
|
35
|
+
const selector = (op, port, label) => {
|
|
36
|
+
const index = catalogue.nodes[op]?.inputs[port]?.values?.indexOf(label) ?? -1;
|
|
37
|
+
if (index < 0)
|
|
38
|
+
throw new Error("Recipe requires " + op + " option " + label);
|
|
39
|
+
return index;
|
|
40
|
+
};
|
|
41
|
+
const size = typeof options.featureSize === "number" ? { x: options.featureSize, y: options.featureSize, z: options.featureSize } : options.featureSize;
|
|
42
|
+
const coordinateUnit = options.coordinateSpace === "world" ? 1 / INTERNAL_UNITS_PER_MM : 1;
|
|
43
|
+
const frequency = { x: coordinateUnit / size.x, y: coordinateUnit / size.y, z: coordinateUnit / size.z };
|
|
44
|
+
const position = node(options.coordinateSpace === "object" ? "InputPosition" : "InputWorldPosition", {}, options.coordinateSpace + " coordinates");
|
|
45
|
+
const normal = node(options.coordinateSpace === "object" ? "InputNormal" : "InputWorldNormal", {}, "Matching projection normal");
|
|
46
|
+
const projected = node("Projection", { 0: selector("Projection", 0, "Cubic"), 3: 1, 4: 0, 5: 0 }, "Physical face coordinates");
|
|
47
|
+
connect(position, projected, 1);
|
|
48
|
+
connect(normal, projected, 2);
|
|
49
|
+
const mapping = node("Mapping", { 1: 0, 2: 0, 3: frequency }, "Feature size in selected coordinates");
|
|
50
|
+
connect(projected, mapping, 0);
|
|
51
|
+
const lines = (coordinates, label) => {
|
|
52
|
+
const fraction = node("Math", { 0: selector("Math", 0, "Fraction"), 3: 0 }, "Grid cell coordinates");
|
|
53
|
+
connect(coordinates, fraction, 1);
|
|
54
|
+
const edges = [0, 1].map(axis => {
|
|
55
|
+
const component = node("GetComponent", { 1: axis }, "Grid axis");
|
|
56
|
+
connect(fraction, component, 0);
|
|
57
|
+
const reverse = node("Math", { 0: selector("Math", 0, "Subtract"), 1: 1, 3: 0 }, "Opposite cell edge");
|
|
58
|
+
connect(component, reverse, 2);
|
|
59
|
+
const edge = node("Math", { 0: selector("Math", 0, "Min"), 3: 0 }, "Nearest cell edge");
|
|
60
|
+
connect(component, edge, 1);
|
|
61
|
+
connect(reverse, edge, 2);
|
|
62
|
+
return edge;
|
|
63
|
+
});
|
|
64
|
+
const edge = node("Math", { 0: selector("Math", 0, "Min"), 3: 0 }, "Grid line distance");
|
|
65
|
+
connect(edges[0], edge, 1);
|
|
66
|
+
connect(edges[1], edge, 2);
|
|
67
|
+
const coverage = node("Math", { 0: selector("Math", 0, "Divide"), 2: 0.04, 3: 1 }, "Grid line coverage");
|
|
68
|
+
connect(edge, coverage, 1);
|
|
69
|
+
const mask = node("Math", { 0: selector("Math", 0, "Subtract"), 1: 1, 3: 0 }, label);
|
|
70
|
+
connect(coverage, mask, 2);
|
|
71
|
+
return mask;
|
|
72
|
+
};
|
|
73
|
+
const major = lines(mapping, "Major grid lines");
|
|
74
|
+
const minorCoordinates = node("Mapping", { 1: 0, 2: 0, 3: 10 }, "One-tenth-unit grid coordinates");
|
|
75
|
+
connect(mapping, minorCoordinates, 0);
|
|
76
|
+
const minor = lines(minorCoordinates, "Minor grid lines");
|
|
77
|
+
const minorContrast = node("Math", { 0: selector("Math", 0, "Mulitiply"), 2: 0.35, 3: 0 }, "Lower-contrast minor grid");
|
|
78
|
+
connect(minor, minorContrast, 1);
|
|
79
|
+
const pattern = node("Math", { 0: selector("Math", 0, "Max"), 3: 0 }, "Combined two-scale grid");
|
|
80
|
+
connect(major, pattern, 1);
|
|
81
|
+
connect(minorContrast, pattern, 2);
|
|
82
|
+
const colorMix = node("MathLerp", { 0: options.colorA, 1: options.colorB }, "Structure-correlated color");
|
|
83
|
+
connect(pattern, colorMix, 2);
|
|
84
|
+
const roughness = node("MathLerp", { 0: options.roughnessA, 1: options.roughnessB }, "Structure-correlated roughness");
|
|
85
|
+
connect(pattern, roughness, 2);
|
|
86
|
+
const metal = node("Constant", { 1: options.metalness ?? 0 }, "Metalness");
|
|
87
|
+
const output = node("OutputMaterial", {}, "Editable surface material");
|
|
88
|
+
connect(colorMix, output, 0);
|
|
89
|
+
connect(roughness, output, 4);
|
|
90
|
+
connect(metal, output, 3, 1);
|
|
91
|
+
const strength = node("Constant", { 1: options.reliefScale, 3: 3 }, "Surface relief strength");
|
|
92
|
+
if (options.relief === "height") {
|
|
93
|
+
const height = node("OutputHeight", {}, "Height shading");
|
|
94
|
+
connect(pattern, height, 0);
|
|
95
|
+
connect(strength, height, 2, 1);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const bump = node("Bump", {}, "Procedural bump normal");
|
|
99
|
+
connect(pattern, bump, 0);
|
|
100
|
+
connect(strength, bump, 1, 1);
|
|
101
|
+
const normalOutput = node("OutputSurfaceNormal", {}, "Tangent normal output");
|
|
102
|
+
connect(bump, normalOutput, 0);
|
|
103
|
+
}
|
|
104
|
+
return graph;
|
|
105
|
+
}
|