@kvyverse/world-runtime 0.6.8 → 0.7.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/dist/index.d.ts +3 -1
- package/dist/index.js +114 -45
- package/dist/rendering/material-shader.d.ts +29 -0
- package/dist/rendering/tsl-uniforms.d.ts +7 -0
- package/dist/version.gen.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,9 @@ export { applyRendererConfig } from "./rendering/renderer-apply";
|
|
|
30
30
|
export { enableSceneEmissiveMrt, SceneBloom } from "./rendering/SceneBloom";
|
|
31
31
|
export { createTslNode, TslNode } from "./rendering/tsl-node";
|
|
32
32
|
export type { TslNodeBuilder } from "./rendering/tsl-node";
|
|
33
|
-
export {
|
|
33
|
+
export { createMaterialShader, MaterialShader, readMaterialShaderOutputs, } from "./rendering/material-shader";
|
|
34
|
+
export type { MaterialShaderBuilder, MaterialShaderOutputs, } from "./rendering/material-shader";
|
|
35
|
+
export { createUniformNode, createUniformValuesView, getUniformNodeValue, isUniformType, setUniformNodeValue, UNIFORM_DEFAULTS, UNIFORM_TYPES, uniformType, } from "./rendering/tsl-uniforms";
|
|
34
36
|
export type { UniformType } from "./rendering/tsl-uniforms";
|
|
35
37
|
export { BUILTIN_LIB_DESCRIPTORS, LIB_DESCRIPTORS, LIB_IDS, LIBS, LibId, OPTIONAL_LIB_DESCRIPTORS, OPTIONAL_LIB_IDS, libByRequireKey, } from "./addons/lib-registry";
|
|
36
38
|
export { collectRequiredLibs } from "./addons/required-libs";
|
package/dist/index.js
CHANGED
|
@@ -1608,7 +1608,7 @@ function isAbsoluteUrl(url) {
|
|
|
1608
1608
|
}
|
|
1609
1609
|
//#endregion
|
|
1610
1610
|
//#region packages/world-runtime/src/version.gen.ts
|
|
1611
|
-
var RUNTIME_VERSION = "0.
|
|
1611
|
+
var RUNTIME_VERSION = "0.7.0";
|
|
1612
1612
|
//#endregion
|
|
1613
1613
|
//#region packages/world-runtime/src/version.ts
|
|
1614
1614
|
/**
|
|
@@ -2009,49 +2009,6 @@ async function createVideo(url, name) {
|
|
|
2009
2009
|
return source;
|
|
2010
2010
|
}
|
|
2011
2011
|
//#endregion
|
|
2012
|
-
//#region packages/world-runtime/src/rendering/tsl-node.ts
|
|
2013
|
-
/**
|
|
2014
|
-
* World TSL node: the built graph node + its uniform nodes. This is what
|
|
2015
|
-
* `require("/Shaders/....tsl")` returns, so the method set matches the editor's
|
|
2016
|
-
* `TslNodeSource` (`setUniformValue` / `getUniformValue` / `uniformValues`).
|
|
2017
|
-
*/
|
|
2018
|
-
var TslNode = class {
|
|
2019
|
-
uniforms;
|
|
2020
|
-
node;
|
|
2021
|
-
_uniformValuesView;
|
|
2022
|
-
constructor(uniforms, build, name = "TslNode") {
|
|
2023
|
-
this.uniforms = uniforms;
|
|
2024
|
-
let node;
|
|
2025
|
-
try {
|
|
2026
|
-
node = build(TSL, uniforms);
|
|
2027
|
-
} catch (error) {
|
|
2028
|
-
console.warn(`TSL node "${name}" build failed`, error);
|
|
2029
|
-
}
|
|
2030
|
-
this.node = node ?? TSL.float(1);
|
|
2031
|
-
}
|
|
2032
|
-
/** Flat view of uniform values: reads and writes go straight to `node.value`. */
|
|
2033
|
-
get uniformValues() {
|
|
2034
|
-
return this._uniformValuesView ??= new Proxy({}, {
|
|
2035
|
-
get: (_target, key) => typeof key === "string" ? this.getUniformValue(key) : void 0,
|
|
2036
|
-
set: (_target, key, value) => {
|
|
2037
|
-
if (typeof key === "string") this.setUniformValue(key, value);
|
|
2038
|
-
return true;
|
|
2039
|
-
}
|
|
2040
|
-
});
|
|
2041
|
-
}
|
|
2042
|
-
setUniformValue(key, value) {
|
|
2043
|
-
const node = this.uniforms[key];
|
|
2044
|
-
if (node) node.value = value;
|
|
2045
|
-
}
|
|
2046
|
-
getUniformValue(key) {
|
|
2047
|
-
return this.uniforms[key]?.value;
|
|
2048
|
-
}
|
|
2049
|
-
};
|
|
2050
|
-
/** Factory for the generated code: builds the node and wraps it. */
|
|
2051
|
-
function createTslNode(uniforms, build, name) {
|
|
2052
|
-
return new TslNode(uniforms, build, name);
|
|
2053
|
-
}
|
|
2054
|
-
//#endregion
|
|
2055
2012
|
//#region packages/world-runtime/src/rendering/tsl-uniforms.ts
|
|
2056
2013
|
var UNIFORM_TYPES = [
|
|
2057
2014
|
"float",
|
|
@@ -2112,6 +2069,118 @@ var UNIFORM_DEFAULTS = {
|
|
|
2112
2069
|
bool: () => false,
|
|
2113
2070
|
texture: () => getDefaultResource(DefaultResourceId.Texture)
|
|
2114
2071
|
};
|
|
2072
|
+
/** Writes a uniform value by key; an unknown key is a no-op. */
|
|
2073
|
+
function setUniformNodeValue(uniforms, key, value) {
|
|
2074
|
+
const node = uniforms[key];
|
|
2075
|
+
if (node) node.value = value;
|
|
2076
|
+
}
|
|
2077
|
+
/** Reads a uniform value by key; `undefined` for an unknown key. */
|
|
2078
|
+
function getUniformNodeValue(uniforms, key) {
|
|
2079
|
+
return uniforms[key]?.value;
|
|
2080
|
+
}
|
|
2081
|
+
/** Flat view of uniform values: reads and writes go straight to `node.value`,
|
|
2082
|
+
* so values live only in the nodes (no copy, no sync step). */
|
|
2083
|
+
function createUniformValuesView(uniforms) {
|
|
2084
|
+
return new Proxy({}, {
|
|
2085
|
+
get: (_target, key) => typeof key === "string" ? getUniformNodeValue(uniforms, key) : void 0,
|
|
2086
|
+
set: (_target, key, value) => {
|
|
2087
|
+
if (typeof key === "string") setUniformNodeValue(uniforms, key, value);
|
|
2088
|
+
return true;
|
|
2089
|
+
}
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
//#endregion
|
|
2093
|
+
//#region packages/world-runtime/src/rendering/tsl-node.ts
|
|
2094
|
+
/**
|
|
2095
|
+
* World TSL node: the built graph node + its uniform nodes. This is what
|
|
2096
|
+
* `require("/Shaders/....tsl")` returns, so the method set matches the editor's
|
|
2097
|
+
* `TslNodeSource` (`setUniformValue` / `getUniformValue` / `uniformValues`).
|
|
2098
|
+
*/
|
|
2099
|
+
var TslNode = class {
|
|
2100
|
+
uniforms;
|
|
2101
|
+
node;
|
|
2102
|
+
_uniformValuesView;
|
|
2103
|
+
constructor(uniforms, build, name = "TslNode") {
|
|
2104
|
+
this.uniforms = uniforms;
|
|
2105
|
+
let node;
|
|
2106
|
+
try {
|
|
2107
|
+
node = build(TSL, uniforms);
|
|
2108
|
+
} catch (error) {
|
|
2109
|
+
console.warn(`TSL node "${name}" build failed`, error);
|
|
2110
|
+
}
|
|
2111
|
+
this.node = node ?? TSL.float(1);
|
|
2112
|
+
}
|
|
2113
|
+
/** Flat view of uniform values: reads and writes go straight to `node.value`. */
|
|
2114
|
+
get uniformValues() {
|
|
2115
|
+
return this._uniformValuesView ??= createUniformValuesView(this.uniforms);
|
|
2116
|
+
}
|
|
2117
|
+
setUniformValue(key, value) {
|
|
2118
|
+
setUniformNodeValue(this.uniforms, key, value);
|
|
2119
|
+
}
|
|
2120
|
+
getUniformValue(key) {
|
|
2121
|
+
return getUniformNodeValue(this.uniforms, key);
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
/** Factory for the generated code: builds the node and wraps it. */
|
|
2125
|
+
function createTslNode(uniforms, build, name) {
|
|
2126
|
+
return new TslNode(uniforms, build, name);
|
|
2127
|
+
}
|
|
2128
|
+
//#endregion
|
|
2129
|
+
//#region packages/world-runtime/src/rendering/material-shader.ts
|
|
2130
|
+
var EMPTY_OUTPUTS = Object.freeze({});
|
|
2131
|
+
/**
|
|
2132
|
+
* Validates what a material shader assigned to `output`: a plain object whose
|
|
2133
|
+
* values are TSL nodes (`null`/`undefined` entries are skipped). Throws otherwise.
|
|
2134
|
+
*/
|
|
2135
|
+
function readMaterialShaderOutputs(raw) {
|
|
2136
|
+
if (!isPlainObject(raw)) throw new Error("material shader must assign an object of node inputs to `output`, e.g. { colorNode, emissiveNode }");
|
|
2137
|
+
const outputs = {};
|
|
2138
|
+
for (const key of Object.keys(raw)) {
|
|
2139
|
+
const value = raw[key];
|
|
2140
|
+
if (value === null || value === void 0) continue;
|
|
2141
|
+
if (!value.isNode) throw new Error(`material shader output "${key}" is not a TSL node`);
|
|
2142
|
+
outputs[key] = value;
|
|
2143
|
+
}
|
|
2144
|
+
return outputs;
|
|
2145
|
+
}
|
|
2146
|
+
/**
|
|
2147
|
+
* World material shader: one script that builds several material node inputs
|
|
2148
|
+
* with shared uniforms. `require("/Shaders/....")` returns it, so the method set
|
|
2149
|
+
* matches the editor's `MaterialShaderSource`.
|
|
2150
|
+
*/
|
|
2151
|
+
var MaterialShader = class {
|
|
2152
|
+
uniforms;
|
|
2153
|
+
/** Built outputs; empty when the build failed (the material keeps its own inputs). */
|
|
2154
|
+
outputs;
|
|
2155
|
+
_uniformValuesView;
|
|
2156
|
+
constructor(uniforms, build, name = "MaterialShader") {
|
|
2157
|
+
this.uniforms = uniforms;
|
|
2158
|
+
let outputs = EMPTY_OUTPUTS;
|
|
2159
|
+
try {
|
|
2160
|
+
outputs = readMaterialShaderOutputs(build(TSL, uniforms));
|
|
2161
|
+
} catch (error) {
|
|
2162
|
+
console.warn(`material shader "${name}" build failed`, error);
|
|
2163
|
+
}
|
|
2164
|
+
this.outputs = outputs;
|
|
2165
|
+
}
|
|
2166
|
+
/** Flat view of uniform values: reads and writes go straight to `node.value`. */
|
|
2167
|
+
get uniformValues() {
|
|
2168
|
+
return this._uniformValuesView ??= createUniformValuesView(this.uniforms);
|
|
2169
|
+
}
|
|
2170
|
+
setUniformValue(key, value) {
|
|
2171
|
+
setUniformNodeValue(this.uniforms, key, value);
|
|
2172
|
+
}
|
|
2173
|
+
getUniformValue(key) {
|
|
2174
|
+
return getUniformNodeValue(this.uniforms, key);
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
/** Factory for the generated code: builds the shader and wraps it. */
|
|
2178
|
+
function createMaterialShader(uniforms, build, name) {
|
|
2179
|
+
return new MaterialShader(uniforms, build, name);
|
|
2180
|
+
}
|
|
2181
|
+
function isPlainObject(x) {
|
|
2182
|
+
return typeof x === "object" && x !== null && Object.getPrototypeOf(x) === Object.prototype;
|
|
2183
|
+
}
|
|
2115
2184
|
//#endregion
|
|
2116
2185
|
//#region packages/world-runtime/src/addons/externals.ts
|
|
2117
2186
|
var EXTERNAL_TYPES = ["umd", "module"];
|
|
@@ -2139,4 +2208,4 @@ var TONE_MAPPING_NAMES = [
|
|
|
2139
2208
|
"Neutral"
|
|
2140
2209
|
];
|
|
2141
2210
|
//#endregion
|
|
2142
|
-
export { AddonsRuntime, AssetLoaders, AudioSource, BLOOM_MODES, BUILTIN_BEHAVIOURS, BUILTIN_BEHAVIOUR_LIST, BUILTIN_LIB_DESCRIPTORS, CHAT_INPUT_MODES, DEFAULT_RESOURCE_IDS, DefaultResourceId, EXTERNAL_TYPES, EnvModule, FontSource, HtmlHudModule, InputSystemModule, LIBS, LIB_DESCRIPTORS, LIB_IDS, LOADING_MANAGER, LibId, NullPlatformModule, OPTIONAL_LIB_DESCRIPTORS, OPTIONAL_LIB_IDS, OPTIONAL_MODULES, OPTIONAL_MODULE_IDS, OptionalModuleId, PHYSICS_ENGINES, RUNTIME_VERSION, SHADOW_MAP_TYPES, SceneBloom, SoundsModule, TONE_MAPPING_NAMES, TslNode, UNIFORM_DEFAULTS, UNIFORM_TYPES, UtilsModule, VideoSource, WORLD_FORMAT_VERSION, World, WorldEvent, WorldStores, applyRendererConfig, applyTextureDefaults, collectModelSubResources, collectRequiredLibs, configureAssetLoaders, createAudio, createFont, createTslNode, createUniformNode, createVideo, createWorldModules, defineWorld, enableSceneEmissiveMrt, fontFormatFromMime, getBuiltinBehaviour, getDefaultResource, getHalfheightRadiusScale, getOptionalModuleDescriptor, getRadiusScale, isDefaultResourceId, isMobileDevice, isUniformType, lazyProxy, libByRequireKey, loadGeometry, loadHdr, loadModel, loadTexture, normalizeChat, normalizePhysics, parseGeometryJson, parseHdr, parseModel, rapierPhysicsPatch, setColor, uniformType };
|
|
2211
|
+
export { AddonsRuntime, AssetLoaders, AudioSource, BLOOM_MODES, BUILTIN_BEHAVIOURS, BUILTIN_BEHAVIOUR_LIST, BUILTIN_LIB_DESCRIPTORS, CHAT_INPUT_MODES, DEFAULT_RESOURCE_IDS, DefaultResourceId, EXTERNAL_TYPES, EnvModule, FontSource, HtmlHudModule, InputSystemModule, LIBS, LIB_DESCRIPTORS, LIB_IDS, LOADING_MANAGER, LibId, MaterialShader, NullPlatformModule, OPTIONAL_LIB_DESCRIPTORS, OPTIONAL_LIB_IDS, OPTIONAL_MODULES, OPTIONAL_MODULE_IDS, OptionalModuleId, PHYSICS_ENGINES, RUNTIME_VERSION, SHADOW_MAP_TYPES, SceneBloom, SoundsModule, TONE_MAPPING_NAMES, TslNode, UNIFORM_DEFAULTS, UNIFORM_TYPES, UtilsModule, VideoSource, WORLD_FORMAT_VERSION, World, WorldEvent, WorldStores, applyRendererConfig, applyTextureDefaults, collectModelSubResources, collectRequiredLibs, configureAssetLoaders, createAudio, createFont, createMaterialShader, createTslNode, createUniformNode, createUniformValuesView, createVideo, createWorldModules, defineWorld, enableSceneEmissiveMrt, fontFormatFromMime, getBuiltinBehaviour, getDefaultResource, getHalfheightRadiusScale, getOptionalModuleDescriptor, getRadiusScale, getUniformNodeValue, isDefaultResourceId, isMobileDevice, isUniformType, lazyProxy, libByRequireKey, loadGeometry, loadHdr, loadModel, loadTexture, normalizeChat, normalizePhysics, parseGeometryJson, parseHdr, parseModel, rapierPhysicsPatch, readMaterialShaderOutputs, setColor, setUniformNodeValue, uniformType };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as TSL from "three/tsl";
|
|
2
|
+
import type { Node } from "three/webgpu";
|
|
3
|
+
/** Material shader outputs: material node input name (`colorNode`, …) → node. */
|
|
4
|
+
export type MaterialShaderOutputs = Readonly<Record<string, Node>>;
|
|
5
|
+
/** Material shader body: returns the `output` value, receiving `TSL` and the uniform nodes. */
|
|
6
|
+
export type MaterialShaderBuilder = (tsl: typeof TSL, uniforms: Record<string, Node>) => unknown;
|
|
7
|
+
/**
|
|
8
|
+
* Validates what a material shader assigned to `output`: a plain object whose
|
|
9
|
+
* values are TSL nodes (`null`/`undefined` entries are skipped). Throws otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readMaterialShaderOutputs(raw: unknown): MaterialShaderOutputs;
|
|
12
|
+
/**
|
|
13
|
+
* World material shader: one script that builds several material node inputs
|
|
14
|
+
* with shared uniforms. `require("/Shaders/....")` returns it, so the method set
|
|
15
|
+
* matches the editor's `MaterialShaderSource`.
|
|
16
|
+
*/
|
|
17
|
+
export declare class MaterialShader {
|
|
18
|
+
readonly uniforms: Record<string, Node>;
|
|
19
|
+
/** Built outputs; empty when the build failed (the material keeps its own inputs). */
|
|
20
|
+
readonly outputs: MaterialShaderOutputs;
|
|
21
|
+
private _uniformValuesView?;
|
|
22
|
+
constructor(uniforms: Record<string, Node>, build: MaterialShaderBuilder, name?: string);
|
|
23
|
+
/** Flat view of uniform values: reads and writes go straight to `node.value`. */
|
|
24
|
+
get uniformValues(): Record<string, unknown>;
|
|
25
|
+
setUniformValue(key: string, value: unknown): void;
|
|
26
|
+
getUniformValue(key: string): unknown;
|
|
27
|
+
}
|
|
28
|
+
/** Factory for the generated code: builds the shader and wraps it. */
|
|
29
|
+
export declare function createMaterialShader(uniforms: Record<string, Node>, build: MaterialShaderBuilder, name?: string): MaterialShader;
|
|
@@ -16,3 +16,10 @@ export declare function createUniformNode(type: UniformType): Node;
|
|
|
16
16
|
/** Default value per type — for `Property.setDefault` (value==default is not
|
|
17
17
|
* serialized, restored on load). Factories, since Color/Vec are mutable. */
|
|
18
18
|
export declare const UNIFORM_DEFAULTS: Record<UniformType, () => unknown>;
|
|
19
|
+
/** Writes a uniform value by key; an unknown key is a no-op. */
|
|
20
|
+
export declare function setUniformNodeValue(uniforms: Record<string, Node>, key: string, value: unknown): void;
|
|
21
|
+
/** Reads a uniform value by key; `undefined` for an unknown key. */
|
|
22
|
+
export declare function getUniformNodeValue(uniforms: Record<string, Node>, key: string): unknown;
|
|
23
|
+
/** Flat view of uniform values: reads and writes go straight to `node.value`,
|
|
24
|
+
* so values live only in the nodes (no copy, no sync step). */
|
|
25
|
+
export declare function createUniformValuesView(uniforms: Record<string, Node>): Record<string, unknown>;
|
package/dist/version.gen.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const RUNTIME_VERSION = "0.
|
|
1
|
+
export declare const RUNTIME_VERSION = "0.7.0";
|
package/package.json
CHANGED