material-designer-runtime 0.1.0
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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/document.d.ts +32 -0
- package/dist/graph/bake-service.d.ts +84 -0
- package/dist/graph/channel-baker.d.ts +10 -0
- package/dist/graph/compiler.d.ts +36 -0
- package/dist/graph/nodes/color/blend.d.ts +2 -0
- package/dist/graph/nodes/color/bright-contrast.d.ts +2 -0
- package/dist/graph/nodes/color/hue-sat-val.d.ts +2 -0
- package/dist/graph/nodes/color/invert.d.ts +2 -0
- package/dist/graph/nodes/color/rgb-curves.d.ts +2 -0
- package/dist/graph/nodes/converter/adapters.d.ts +4 -0
- package/dist/graph/nodes/converter/clamp.d.ts +2 -0
- package/dist/graph/nodes/converter/color-ramp.d.ts +2 -0
- package/dist/graph/nodes/converter/height-blend.d.ts +2 -0
- package/dist/graph/nodes/converter/levels.d.ts +2 -0
- package/dist/graph/nodes/converter/math.d.ts +2 -0
- package/dist/graph/nodes/converter/xyz.d.ts +3 -0
- package/dist/graph/nodes/group/group.d.ts +4 -0
- package/dist/graph/nodes/input/constant.d.ts +3 -0
- package/dist/graph/nodes/input/tex-coordinate.d.ts +2 -0
- package/dist/graph/nodes/output/material-output.d.ts +2 -0
- package/dist/graph/nodes/shader/emission.d.ts +2 -0
- package/dist/graph/nodes/shader/mix-shader.d.ts +2 -0
- package/dist/graph/nodes/shader/principled-bsdf.d.ts +2 -0
- package/dist/graph/nodes/texture/anisotropic-stripes.d.ts +2 -0
- package/dist/graph/nodes/texture/checker.d.ts +2 -0
- package/dist/graph/nodes/texture/fbm.d.ts +2 -0
- package/dist/graph/nodes/texture/gradient.d.ts +2 -0
- package/dist/graph/nodes/texture/scatter.d.ts +2 -0
- package/dist/graph/nodes/texture/screen-noise.d.ts +2 -0
- package/dist/graph/nodes/texture/shape.d.ts +2 -0
- package/dist/graph/nodes/texture/tile.d.ts +2 -0
- package/dist/graph/nodes/texture/tileable-noise.d.ts +2 -0
- package/dist/graph/nodes/texture/voronoi.d.ts +2 -0
- package/dist/graph/nodes/texture/wave.d.ts +2 -0
- package/dist/graph/nodes/vector/domain-warp.d.ts +2 -0
- package/dist/graph/nodes/vector/mapping.d.ts +2 -0
- package/dist/graph/nodes/vector/normal-from-height.d.ts +2 -0
- package/dist/graph/nodes/vector/normal-map.d.ts +2 -0
- package/dist/graph/nodes/vector/tileable-warp.d.ts +2 -0
- package/dist/graph/nodes/vector/vector-math.d.ts +2 -0
- package/dist/graph/registry.d.ts +15 -0
- package/dist/graph/textured-surface.d.ts +60 -0
- package/dist/graph/tiling-test.d.ts +21 -0
- package/dist/graph/types.d.ts +153 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4437 -0
- package/dist/runtime.d.ts +36 -0
- package/dist/topology.d.ts +3 -0
- package/dist/tsl/blender-color.d.ts +5 -0
- package/dist/tsl/blender-gradient.d.ts +4 -0
- package/dist/tsl/blender-mapping.d.ts +4 -0
- package/dist/tsl/blender-noise.d.ts +5 -0
- package/dist/tsl/blender-voronoi.d.ts +13 -0
- package/dist/tsl/blender-wave.d.ts +14 -0
- package/dist/tsl/curve.d.ts +4 -0
- package/dist/tsl/lloyd-points.d.ts +9 -0
- package/dist/tsl/noise/cellular.d.ts +5 -0
- package/dist/tsl/noise/erosion.d.ts +4 -0
- package/dist/tsl/noise/fbm.d.ts +5 -0
- package/dist/tsl/noise/flow.d.ts +8 -0
- package/dist/tsl/noise/gabor.d.ts +1 -0
- package/dist/tsl/noise/hash.d.ts +8 -0
- package/dist/tsl/noise/index.d.ts +8 -0
- package/dist/tsl/noise/screen.d.ts +8 -0
- package/dist/tsl/noise/simplex.d.ts +4 -0
- package/dist/tsl/noise/value.d.ts +4 -0
- package/dist/tsl/noise/wavelet.d.ts +4 -0
- package/dist/tsl/parallax.d.ts +5 -0
- package/dist/tsl/relaxed-voronoi.d.ts +7 -0
- package/dist/tsl/scatter.d.ts +16 -0
- package/dist/tsl/shape.d.ts +13 -0
- package/dist/tsl/tile.d.ts +23 -0
- package/dist/tsl/tileable-noise.d.ts +6 -0
- package/dist/tsl/triplanar-normal.d.ts +5 -0
- package/dist/tsl/triplanar.d.ts +6 -0
- package/dist/tsl/uv-debug-material.d.ts +2 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vanrez Nez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# material-designer-runtime
|
|
2
|
+
|
|
3
|
+
Lightweight runtime for loading Material Designer node graph documents and applying them to Three.js meshes.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install material-designer-runtime three@0.184.0
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`three` is a peer dependency — this package uses its WebGPU renderer and TSL, so install the exact
|
|
12
|
+
supported version alongside it.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { MaterialGraphRuntime } from "material-designer-runtime";
|
|
18
|
+
|
|
19
|
+
const runtime = new MaterialGraphRuntime()
|
|
20
|
+
.setRenderer(renderer)
|
|
21
|
+
.setBackend("offline")
|
|
22
|
+
.fromDocument(document);
|
|
23
|
+
|
|
24
|
+
await runtime.refresh();
|
|
25
|
+
mesh.material = runtime.material;
|
|
26
|
+
|
|
27
|
+
runtime.setOutputResolution(1024);
|
|
28
|
+
runtime.setNodeParam("noise", "scale", 18);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The editor owns UI state, selection, storage, presets, and undo history. This package owns only graph document loading, compilation, baking, direct parameter updates, and the material surface.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type NodeRegistry } from "./graph/registry";
|
|
2
|
+
import { type GraphChange, type MaterialGraphDocument, type MaterialGraphSource } from "./graph/types";
|
|
3
|
+
export declare const MATERIAL_DOCUMENT_VERSION = 2;
|
|
4
|
+
export declare function cloneMaterialDocument(doc: MaterialGraphDocument): MaterialGraphDocument;
|
|
5
|
+
export declare function createDefaultMaterialDocument(): MaterialGraphDocument;
|
|
6
|
+
export declare function migrateMaterialDocument(doc: MaterialGraphDocument): MaterialGraphDocument;
|
|
7
|
+
export declare class MaterialGraphSession implements MaterialGraphSource {
|
|
8
|
+
private readonly registry;
|
|
9
|
+
private doc;
|
|
10
|
+
private readonly listeners;
|
|
11
|
+
private lastError_;
|
|
12
|
+
private soloNode_;
|
|
13
|
+
constructor(doc?: MaterialGraphDocument, registry?: NodeRegistry);
|
|
14
|
+
get document(): MaterialGraphDocument;
|
|
15
|
+
get lastError(): string | null;
|
|
16
|
+
get soloNode(): string | null;
|
|
17
|
+
getRegistry(): NodeRegistry;
|
|
18
|
+
compileBundle(opts: import("./graph/compiler").CompileOptions): import("./graph/compiler").CompiledSockets;
|
|
19
|
+
onChange(fn: (change: GraphChange) => void): () => void;
|
|
20
|
+
setDocument(doc: MaterialGraphDocument): void;
|
|
21
|
+
getDocument(): MaterialGraphDocument;
|
|
22
|
+
setSoloNode(nodeId: string | null): void;
|
|
23
|
+
setOutputResolution(size: number): void;
|
|
24
|
+
setOutputTargets(targets: {
|
|
25
|
+
resolution?: number;
|
|
26
|
+
size?: number;
|
|
27
|
+
}): void;
|
|
28
|
+
setNodeParam(nodeId: string, key: string, value: unknown): boolean;
|
|
29
|
+
updateNodeParams(nodeId: string, patch: Record<string, unknown>): boolean;
|
|
30
|
+
private validate;
|
|
31
|
+
private emit;
|
|
32
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { RenderTarget, type WebGPURenderer, type MeshBasicNodeMaterial } from "three/webgpu";
|
|
3
|
+
import { type CacheEntry } from "./compiler";
|
|
4
|
+
import type { MaterialGraphSource, MaterialValue, PbrSocket } from "./types";
|
|
5
|
+
export declare const SURFACE_CHANNELS: PbrSocket[];
|
|
6
|
+
export interface BakeOptions {
|
|
7
|
+
channels?: PbrSocket[];
|
|
8
|
+
size?: number;
|
|
9
|
+
soloNodeId?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
source?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BakeReport {
|
|
14
|
+
runId: number;
|
|
15
|
+
source: string | undefined;
|
|
16
|
+
phase: "nodes" | "shaders" | "render" | "done";
|
|
17
|
+
nodeCount: number;
|
|
18
|
+
compileMs: number;
|
|
19
|
+
texturesTotal: number;
|
|
20
|
+
totalMs: number;
|
|
21
|
+
}
|
|
22
|
+
export declare class BakedTextureSet {
|
|
23
|
+
readonly channels: PbrSocket[];
|
|
24
|
+
private readonly targets;
|
|
25
|
+
private readonly mats;
|
|
26
|
+
private readonly cacheTargets;
|
|
27
|
+
private readonly cacheMats;
|
|
28
|
+
cachePlan: CacheEntry[];
|
|
29
|
+
uniforms: Map<string, Record<string, MaterialValue>>;
|
|
30
|
+
heightTarget: RenderTarget | null;
|
|
31
|
+
hasHeight: boolean;
|
|
32
|
+
present: Set<"roughness" | "normal" | "baseColor" | "metallic" | "emission" | "ambientOcclusion">;
|
|
33
|
+
signature: string;
|
|
34
|
+
size: number;
|
|
35
|
+
constructor(size: number, channels: PbrSocket[]);
|
|
36
|
+
resize(size: number): void;
|
|
37
|
+
target(ch: PbrSocket): RenderTarget;
|
|
38
|
+
channelMaterial(ch: PbrSocket | "height"): MeshBasicNodeMaterial;
|
|
39
|
+
cacheTarget(cacheId: string, size?: number, mips?: boolean): RenderTarget;
|
|
40
|
+
cacheMaterial(cacheId: string): MeshBasicNodeMaterial;
|
|
41
|
+
cacheTexture(cacheId: string, size?: number, mips?: boolean): THREE.Texture;
|
|
42
|
+
firstTarget(): RenderTarget | null;
|
|
43
|
+
ensureHeightTarget(): RenderTarget;
|
|
44
|
+
texture(ch: PbrSocket): THREE.Texture | null;
|
|
45
|
+
flushCaches(): void;
|
|
46
|
+
dispose(): void;
|
|
47
|
+
}
|
|
48
|
+
export interface BakeProgress {
|
|
49
|
+
completed: number;
|
|
50
|
+
total: number;
|
|
51
|
+
active: string | null;
|
|
52
|
+
}
|
|
53
|
+
export declare class MaterialBakeService {
|
|
54
|
+
private renderer;
|
|
55
|
+
private compileGateDepth;
|
|
56
|
+
get rendererBusy(): boolean;
|
|
57
|
+
private queue;
|
|
58
|
+
private completed;
|
|
59
|
+
private total;
|
|
60
|
+
private active;
|
|
61
|
+
private readonly progressListeners;
|
|
62
|
+
private readonly reportListeners;
|
|
63
|
+
private bakeRunId;
|
|
64
|
+
private scratch;
|
|
65
|
+
private scratchSize;
|
|
66
|
+
private readonly scratchCaches;
|
|
67
|
+
private scratchCacheSize;
|
|
68
|
+
attachRenderer(renderer: WebGPURenderer): void;
|
|
69
|
+
get hasRenderer(): boolean;
|
|
70
|
+
onProgress(cb: (p: BakeProgress) => void): () => void;
|
|
71
|
+
private emitProgress;
|
|
72
|
+
onBakeReport(cb: (r: BakeReport) => void): () => void;
|
|
73
|
+
private emitReport;
|
|
74
|
+
private enqueue;
|
|
75
|
+
createTextureSet(channels?: PbrSocket[], size?: number): BakedTextureSet;
|
|
76
|
+
bakeInto(set: BakedTextureSet, graph: MaterialGraphSource, opts?: BakeOptions): Promise<boolean>;
|
|
77
|
+
private gpuSync;
|
|
78
|
+
rerenderInto(set: BakedTextureSet, source?: string): Promise<void>;
|
|
79
|
+
bake(graph: MaterialGraphSource, opts?: BakeOptions): Promise<BakedTextureSet>;
|
|
80
|
+
readImage(graph: MaterialGraphSource, channel: PbrSocket, size?: number): Promise<ImageData | null>;
|
|
81
|
+
private scratchTarget;
|
|
82
|
+
private scratchCache;
|
|
83
|
+
}
|
|
84
|
+
export declare const bakeService: MaterialBakeService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RenderTarget, MeshBasicNodeMaterial, type WebGPURenderer } from "three/webgpu";
|
|
2
|
+
import type { MaterialValue, PbrSocket } from "./types";
|
|
3
|
+
export declare const FIELD_CHANNELS: PbrSocket[];
|
|
4
|
+
export declare const COLOR_CHANNELS: PbrSocket[];
|
|
5
|
+
export declare function encodeChannel(node: MaterialValue, channel: PbrSocket): MaterialValue;
|
|
6
|
+
export declare function makeChannelMaterial(): MeshBasicNodeMaterial;
|
|
7
|
+
export declare function compileMaterialsAsync(renderer: WebGPURenderer, materials: MeshBasicNodeMaterial[]): Promise<void>;
|
|
8
|
+
export declare function renderCacheToTarget(renderer: WebGPURenderer, material: MeshBasicNodeMaterial, rt: RenderTarget): void;
|
|
9
|
+
export declare function renderMaterialToTarget(renderer: WebGPURenderer, material: MeshBasicNodeMaterial, rt: RenderTarget, isNormal?: boolean): void;
|
|
10
|
+
export declare function renderColorNodeToTarget(renderer: WebGPURenderer, colorNode: MaterialValue, rt: RenderTarget, isNormal?: boolean): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { MeshStandardNodeMaterial, MeshPhysicalNodeMaterial } from "three/webgpu";
|
|
3
|
+
import { type MaterialBackend, type MaterialBundle, type MaterialGraphDocument, type MaterialValue, type PortKind } from "./types";
|
|
4
|
+
import { type NodeRegistry } from "./registry";
|
|
5
|
+
export interface CompiledMaterial {
|
|
6
|
+
material: MeshStandardNodeMaterial;
|
|
7
|
+
uniforms: Map<string, Record<string, MaterialValue>>;
|
|
8
|
+
}
|
|
9
|
+
export interface CacheSizing {
|
|
10
|
+
minSize?: number;
|
|
11
|
+
size?: number;
|
|
12
|
+
}
|
|
13
|
+
export type CacheAlloc = (cacheId: string, kind: PortKind, sizing?: CacheSizing) => THREE.Texture;
|
|
14
|
+
export interface CacheEntry {
|
|
15
|
+
cacheId: string;
|
|
16
|
+
kind: PortKind;
|
|
17
|
+
colorNode: MaterialValue;
|
|
18
|
+
sizing?: CacheSizing;
|
|
19
|
+
}
|
|
20
|
+
export interface CompileOptions {
|
|
21
|
+
backend: MaterialBackend;
|
|
22
|
+
soloNodeId?: string;
|
|
23
|
+
allocCache?: CacheAlloc;
|
|
24
|
+
outputResolution?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface CompiledSockets {
|
|
27
|
+
bundle: MaterialBundle;
|
|
28
|
+
uniforms: Map<string, Record<string, MaterialValue>>;
|
|
29
|
+
cachePlan: CacheEntry[];
|
|
30
|
+
}
|
|
31
|
+
export declare function readOutputResolution(doc: MaterialGraphDocument): number;
|
|
32
|
+
export declare function countGraphNodes(doc: MaterialGraphDocument): number;
|
|
33
|
+
export declare function compileSockets(doc: MaterialGraphDocument, registry: NodeRegistry, optsIn: CompileOptions): CompiledSockets;
|
|
34
|
+
export declare function newSurfaceMaterial(): MeshPhysicalNodeMaterial;
|
|
35
|
+
export declare function applyBundle(material: MeshPhysicalNodeMaterial, bundle: MaterialBundle): void;
|
|
36
|
+
export declare function compileGraph(doc: MaterialGraphDocument, registry: NodeRegistry, opts: CompileOptions): CompiledMaterial;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GraphNode, MaterialNodeDef, ParamDef, PortDef } from "./types";
|
|
2
|
+
export declare function nodePorts(node: GraphNode, registry: NodeRegistry): {
|
|
3
|
+
inputs: PortDef[];
|
|
4
|
+
outputs: PortDef[];
|
|
5
|
+
};
|
|
6
|
+
export declare function nodeParamDefs(node: GraphNode, registry: NodeRegistry): ParamDef[];
|
|
7
|
+
export declare class NodeRegistry {
|
|
8
|
+
private readonly defs;
|
|
9
|
+
register(def: MaterialNodeDef): this;
|
|
10
|
+
get(type: string): MaterialNodeDef;
|
|
11
|
+
has(type: string): boolean;
|
|
12
|
+
all(): MaterialNodeDef[];
|
|
13
|
+
}
|
|
14
|
+
export declare function createDefaultRegistry(): NodeRegistry;
|
|
15
|
+
export declare const defaultRegistry: NodeRegistry;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import type { MeshStandardNodeMaterial } from "three/webgpu";
|
|
3
|
+
import { type MaterialBackend, type MaterialGraphSource } from "./types";
|
|
4
|
+
import { type MaterialBakeService } from "./bake-service";
|
|
5
|
+
export declare class TexturedSurface {
|
|
6
|
+
private readonly graph;
|
|
7
|
+
private readonly service;
|
|
8
|
+
private readonly source?;
|
|
9
|
+
private readonly offlineMat;
|
|
10
|
+
private liveUniforms;
|
|
11
|
+
private material_;
|
|
12
|
+
readonly scaleUniform: import("three/webgpu").UniformNode<"float", number>;
|
|
13
|
+
readonly sharpnessUniform: import("three/webgpu").UniformNode<"float", number>;
|
|
14
|
+
readonly roughnessFactor: import("three/webgpu").UniformNode<"float", number>;
|
|
15
|
+
readonly metalnessFactor: import("three/webgpu").UniformNode<"float", number>;
|
|
16
|
+
readonly colorTint: import("three/webgpu").UniformNode<"color", THREE.Color>;
|
|
17
|
+
readonly parallaxScale: import("three/webgpu").UniformNode<"float", number>;
|
|
18
|
+
lastBakeMs: number;
|
|
19
|
+
private set;
|
|
20
|
+
private backend;
|
|
21
|
+
private debugNormals;
|
|
22
|
+
private triplanar;
|
|
23
|
+
private wiredOnce;
|
|
24
|
+
private lastPresent;
|
|
25
|
+
private updateInFlight;
|
|
26
|
+
private pendingKind;
|
|
27
|
+
private flushRequested;
|
|
28
|
+
private readonly listeners;
|
|
29
|
+
private lastError_;
|
|
30
|
+
constructor(graph: MaterialGraphSource, service: MaterialBakeService, source?: string | undefined);
|
|
31
|
+
get material(): MeshStandardNodeMaterial;
|
|
32
|
+
get lastError(): string | null;
|
|
33
|
+
getLastBakeMs(): number;
|
|
34
|
+
onRebuilt(fn: () => void): () => void;
|
|
35
|
+
private notify;
|
|
36
|
+
refresh(): Promise<void>;
|
|
37
|
+
regenerate(): void;
|
|
38
|
+
setScale(value: number): void;
|
|
39
|
+
setSharpness(value: number): void;
|
|
40
|
+
setRoughnessFactor(value: number): void;
|
|
41
|
+
setMetalnessFactor(value: number): void;
|
|
42
|
+
setColorTint(hex: string): void;
|
|
43
|
+
setParallaxScale(value: number): void;
|
|
44
|
+
setTriplanar(on: boolean): void;
|
|
45
|
+
setNormalDebug(on: boolean): void;
|
|
46
|
+
setBackend(backend: MaterialBackend): void;
|
|
47
|
+
getBackend(): MaterialBackend;
|
|
48
|
+
private onGraphChange;
|
|
49
|
+
private applyUniformValue;
|
|
50
|
+
private updateLiveUniform;
|
|
51
|
+
private updateOfflineUniform;
|
|
52
|
+
private requestUpdate;
|
|
53
|
+
private pump;
|
|
54
|
+
private rerenderOffline;
|
|
55
|
+
private surfaceBakeSize;
|
|
56
|
+
private rebuild;
|
|
57
|
+
private buildLive;
|
|
58
|
+
private wire;
|
|
59
|
+
dispose(): void;
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MaterialBakeService } from "./bake-service";
|
|
2
|
+
import type { NodeRegistry } from "./registry";
|
|
3
|
+
import type { PbrSocket } from "./types";
|
|
4
|
+
export interface SeamMetrics {
|
|
5
|
+
type: string;
|
|
6
|
+
ratioH: number;
|
|
7
|
+
ratioV: number;
|
|
8
|
+
wrapH: number;
|
|
9
|
+
wrapV: number;
|
|
10
|
+
interiorH: number;
|
|
11
|
+
interiorV: number;
|
|
12
|
+
pass: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface TilingTestOptions {
|
|
15
|
+
size?: number;
|
|
16
|
+
threshold?: number;
|
|
17
|
+
channel?: PbrSocket;
|
|
18
|
+
types?: string[];
|
|
19
|
+
onTile?: (type: string, img: ImageData) => void | Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare function runTilingTest(service: MaterialBakeService, registry: NodeRegistry, options?: TilingTestOptions): Promise<SeamMetrics[]>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export type MaterialValue = any;
|
|
2
|
+
export type PortKind = "float" | "vector" | "color" | "shader";
|
|
3
|
+
export interface PortDef {
|
|
4
|
+
key: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
kind: PortKind;
|
|
7
|
+
}
|
|
8
|
+
export type NodeClass = "input" | "output" | "shader" | "texture" | "color" | "vector" | "converter" | "group";
|
|
9
|
+
export type ParamType = "float" | "int" | "bool" | "color" | "select" | "vec3" | "curve";
|
|
10
|
+
export interface Vec3Value {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
z: number;
|
|
14
|
+
}
|
|
15
|
+
export interface CurveValue {
|
|
16
|
+
C: number[];
|
|
17
|
+
R: number[];
|
|
18
|
+
G: number[];
|
|
19
|
+
B: number[];
|
|
20
|
+
}
|
|
21
|
+
export declare const CURVE_IDENTITY: readonly number[];
|
|
22
|
+
export declare const CURVE_CHANNELS: readonly ["C", "R", "G", "B"];
|
|
23
|
+
export declare function curveToArray(v: CurveValue | undefined): number[];
|
|
24
|
+
export interface ParamDef {
|
|
25
|
+
key: string;
|
|
26
|
+
label: string;
|
|
27
|
+
type: ParamType;
|
|
28
|
+
min?: number;
|
|
29
|
+
max?: number;
|
|
30
|
+
step?: number;
|
|
31
|
+
options?: string[];
|
|
32
|
+
default: unknown;
|
|
33
|
+
bakeStructural?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export type MaterialBackend = "live" | "offline";
|
|
36
|
+
export type GraphChange = {
|
|
37
|
+
kind: "structural";
|
|
38
|
+
} | {
|
|
39
|
+
kind: "layout";
|
|
40
|
+
} | {
|
|
41
|
+
kind: "param";
|
|
42
|
+
nodeId: string;
|
|
43
|
+
key: string;
|
|
44
|
+
paramType: ParamType;
|
|
45
|
+
value: unknown;
|
|
46
|
+
bakeStructural?: boolean;
|
|
47
|
+
};
|
|
48
|
+
export interface BuildCtx {
|
|
49
|
+
inputs: Record<string, MaterialValue | undefined>;
|
|
50
|
+
uniforms: Record<string, MaterialValue>;
|
|
51
|
+
params: Record<string, unknown>;
|
|
52
|
+
coord: MaterialValue;
|
|
53
|
+
backend: MaterialBackend;
|
|
54
|
+
tileRepeat?: number;
|
|
55
|
+
}
|
|
56
|
+
export interface MaterialNodeDef {
|
|
57
|
+
type: string;
|
|
58
|
+
nodeClass: NodeClass;
|
|
59
|
+
label: string;
|
|
60
|
+
inputs: PortDef[];
|
|
61
|
+
outputs: PortDef[];
|
|
62
|
+
params: ParamDef[];
|
|
63
|
+
declare?(params: Record<string, unknown>): {
|
|
64
|
+
inputs: PortDef[];
|
|
65
|
+
outputs: PortDef[];
|
|
66
|
+
};
|
|
67
|
+
paramsFor?(params: Record<string, unknown>): ParamDef[];
|
|
68
|
+
bakeDerivative?: boolean;
|
|
69
|
+
bakeTileable?: boolean;
|
|
70
|
+
build(ctx: BuildCtx): Record<string, MaterialValue>;
|
|
71
|
+
}
|
|
72
|
+
export interface GraphNode {
|
|
73
|
+
id: string;
|
|
74
|
+
type: string;
|
|
75
|
+
params: Record<string, unknown>;
|
|
76
|
+
position?: {
|
|
77
|
+
x: number;
|
|
78
|
+
y: number;
|
|
79
|
+
};
|
|
80
|
+
enabled: boolean;
|
|
81
|
+
label?: string;
|
|
82
|
+
ports?: {
|
|
83
|
+
inputs: PortDef[];
|
|
84
|
+
outputs: PortDef[];
|
|
85
|
+
};
|
|
86
|
+
subgraph?: MaterialGraphDocument;
|
|
87
|
+
}
|
|
88
|
+
export declare const GROUP_TYPE = "group";
|
|
89
|
+
export declare const GROUP_INPUT_TYPE = "group-input";
|
|
90
|
+
export declare const GROUP_OUTPUT_TYPE = "group-output";
|
|
91
|
+
export interface GraphEdge {
|
|
92
|
+
fromNode: string;
|
|
93
|
+
fromOutput: string;
|
|
94
|
+
toNode: string;
|
|
95
|
+
toInput: string;
|
|
96
|
+
}
|
|
97
|
+
export interface MaterialGraphDocument {
|
|
98
|
+
version: number;
|
|
99
|
+
nodes: GraphNode[];
|
|
100
|
+
edges: GraphEdge[];
|
|
101
|
+
metadata?: MaterialGraphDocumentMetadata;
|
|
102
|
+
ui?: MaterialGraphDocumentUiState;
|
|
103
|
+
}
|
|
104
|
+
export interface MaterialGraphDocumentMetadata {
|
|
105
|
+
title?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface MaterialGraphEditorViewState {
|
|
108
|
+
layoutArrangement?: "down" | "right" | "up" | "left";
|
|
109
|
+
transform?: {
|
|
110
|
+
k: number;
|
|
111
|
+
x: number;
|
|
112
|
+
y: number;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export interface MaterialGraphEditorUiState {
|
|
116
|
+
activeGroupPath?: string[];
|
|
117
|
+
soloNode?: string | null;
|
|
118
|
+
view?: MaterialGraphEditorViewState;
|
|
119
|
+
}
|
|
120
|
+
export interface MaterialGraphDocumentUiState {
|
|
121
|
+
editor?: MaterialGraphEditorUiState;
|
|
122
|
+
settings?: Record<string, unknown>;
|
|
123
|
+
}
|
|
124
|
+
export interface MaterialGraphSource {
|
|
125
|
+
readonly document: MaterialGraphDocument;
|
|
126
|
+
readonly lastError: string | null;
|
|
127
|
+
readonly soloNode: string | null;
|
|
128
|
+
compileBundle(opts: import("./compiler").CompileOptions): import("./compiler").CompiledSockets;
|
|
129
|
+
getRegistry(): import("./registry").NodeRegistry;
|
|
130
|
+
onChange(fn: (change: GraphChange) => void): () => void;
|
|
131
|
+
}
|
|
132
|
+
export declare const MATERIAL_OUTPUT_TYPE = "material-output";
|
|
133
|
+
export declare const PBR_SOCKETS: readonly ["baseColor", "normal", "emission", "roughness", "metallic", "ambientOcclusion"];
|
|
134
|
+
export type PbrSocket = (typeof PBR_SOCKETS)[number];
|
|
135
|
+
export interface MaterialBundle {
|
|
136
|
+
baseColor?: MaterialValue;
|
|
137
|
+
metallic?: MaterialValue;
|
|
138
|
+
roughness?: MaterialValue;
|
|
139
|
+
ior?: MaterialValue;
|
|
140
|
+
alpha?: MaterialValue;
|
|
141
|
+
normal?: MaterialValue;
|
|
142
|
+
height?: MaterialValue;
|
|
143
|
+
ambientOcclusion?: MaterialValue;
|
|
144
|
+
emission?: MaterialValue;
|
|
145
|
+
coat?: MaterialValue;
|
|
146
|
+
coatRoughness?: MaterialValue;
|
|
147
|
+
sheen?: MaterialValue;
|
|
148
|
+
sheenRoughness?: MaterialValue;
|
|
149
|
+
transmission?: MaterialValue;
|
|
150
|
+
}
|
|
151
|
+
export type Coercion = "identity" | "float-to-vector" | "float-to-color" | "vector-to-float" | "vector-to-color" | "color-to-float" | "color-to-vector";
|
|
152
|
+
export declare const COERCION_MATRIX: Record<PortKind, Partial<Record<PortKind, Coercion>>>;
|
|
153
|
+
export declare function coercionFor(from: PortKind, to: PortKind): Coercion | undefined;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { MaterialGraphRuntime, type MaterialGraphRuntimeOptions } from "./runtime";
|
|
2
|
+
export { MATERIAL_DOCUMENT_VERSION, MaterialGraphSession, cloneMaterialDocument, createDefaultMaterialDocument, migrateMaterialDocument, } from "./document";
|
|
3
|
+
export { createMaterialTopologyKey } from "./topology";
|
|
4
|
+
export { MaterialBakeService, BakedTextureSet, SURFACE_CHANNELS, bakeService, type BakeOptions, type BakeReport, } from "./graph/bake-service";
|
|
5
|
+
export { compileGraph, compileSockets, countGraphNodes, newSurfaceMaterial, readOutputResolution, type CompileOptions, type CompiledSockets, } from "./graph/compiler";
|
|
6
|
+
export { NodeRegistry, createDefaultRegistry, defaultRegistry, nodeParamDefs, nodePorts, } from "./graph/registry";
|
|
7
|
+
export { TexturedSurface } from "./graph/textured-surface";
|
|
8
|
+
export { runTilingTest } from "./graph/tiling-test";
|
|
9
|
+
export * from "./graph/types";
|