@kvyverse/world-runtime 0.6.8 → 0.9.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/README.md +6 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +161 -47
- package/dist/main-camera.d.ts +12 -0
- package/dist/rendering/material-shader.d.ts +29 -0
- package/dist/rendering/renderer-apply.d.ts +2 -0
- package/dist/rendering/tsl-uniforms.d.ts +7 -0
- package/dist/types.d.ts +3 -2
- package/dist/version.gen.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -81,6 +81,12 @@ world.ctx.scene, world.ctx.camera, world.ctx.renderer
|
|
|
81
81
|
world.unmount(), world.runLoop(), world.stopLoop(), world.dispose()
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
`world.ctx.camera` starts as the world's main camera: the one picked in the
|
|
85
|
+
editor's Scene settings, otherwise the first perspective camera in the scene,
|
|
86
|
+
prefab and model contents included, otherwise the first orthographic one
|
|
87
|
+
(`resolveMainCamera`). An orthographic main camera is `world.ctx.ortho`, and
|
|
88
|
+
`world.ctx.isOrtho` is `true`.
|
|
89
|
+
|
|
84
90
|
On top of that: `world.getUrl(path)` resolves an asset URL the same way scripts
|
|
85
91
|
inside the world do, `world.events` is the world lifecycle emitter (the same
|
|
86
92
|
`world.events` your scripts use), and `world.stores` is the world's shared
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type { InstantiateOptions, PrefabFactory } from "./WorldRuntime";
|
|
|
4
4
|
export { setColor } from "./values";
|
|
5
5
|
export { RUNTIME_VERSION, WORLD_FORMAT_VERSION } from "./version";
|
|
6
6
|
export { WorldEvent } from "./world-events";
|
|
7
|
+
export { isMainCameraKind, resolveMainCamera, setActiveCamera } from "./main-camera";
|
|
7
8
|
export { lazyProxy } from "./utils/lazy";
|
|
8
9
|
export { WorldStores } from "./world-stores";
|
|
9
10
|
export type { WorldStore } from "./world-stores";
|
|
@@ -26,11 +27,13 @@ export { BUILTIN_BEHAVIOUR_LIST, BUILTIN_BEHAVIOURS, getBuiltinBehaviour, } from
|
|
|
26
27
|
export type { BuiltinBehaviour, RequiredPatch } from "./behaviours/registry";
|
|
27
28
|
export { rapierPhysicsPatch } from "./behaviours/physics/_required-patch";
|
|
28
29
|
export { AddonsRuntime } from "./addons/AddonsRuntime";
|
|
29
|
-
export { applyRendererConfig } from "./rendering/renderer-apply";
|
|
30
|
+
export { applyRendererConfig, resolveToneMapping } from "./rendering/renderer-apply";
|
|
30
31
|
export { enableSceneEmissiveMrt, SceneBloom } from "./rendering/SceneBloom";
|
|
31
32
|
export { createTslNode, TslNode } from "./rendering/tsl-node";
|
|
32
33
|
export type { TslNodeBuilder } from "./rendering/tsl-node";
|
|
33
|
-
export {
|
|
34
|
+
export { createMaterialShader, MaterialShader, readMaterialShaderOutputs, } from "./rendering/material-shader";
|
|
35
|
+
export type { MaterialShaderBuilder, MaterialShaderOutputs, } from "./rendering/material-shader";
|
|
36
|
+
export { createUniformNode, createUniformValuesView, getUniformNodeValue, isUniformType, setUniformNodeValue, UNIFORM_DEFAULTS, UNIFORM_TYPES, uniformType, } from "./rendering/tsl-uniforms";
|
|
34
37
|
export type { UniformType } from "./rendering/tsl-uniforms";
|
|
35
38
|
export { BUILTIN_LIB_DESCRIPTORS, LIB_DESCRIPTORS, LIB_IDS, LIBS, LibId, OPTIONAL_LIB_DESCRIPTORS, OPTIONAL_LIB_IDS, libByRequireKey, } from "./addons/lib-registry";
|
|
36
39
|
export { collectRequiredLibs } from "./addons/required-libs";
|
package/dist/index.js
CHANGED
|
@@ -204,11 +204,15 @@ var TONE_MAPPINGS = {
|
|
|
204
204
|
function applyRendererConfig(renderer, cfg) {
|
|
205
205
|
renderer.shadowMap.enabled = cfg.shadowMap?.enabled ?? true;
|
|
206
206
|
renderer.shadowMap.type = SHADOW_MAP_TYPES$1[cfg.shadowMap?.type ?? "PCFSoft"] ?? THREE.PCFSoftShadowMap;
|
|
207
|
-
renderer.toneMapping =
|
|
207
|
+
renderer.toneMapping = resolveToneMapping(cfg.toneMapping);
|
|
208
208
|
const pr = cfg.pixelResolution;
|
|
209
209
|
const pixelResolution = typeof pr === "number" && Number.isFinite(pr) && pr > 0 ? pr : 1;
|
|
210
210
|
renderer.setPixelRatio(window.devicePixelRatio * pixelResolution);
|
|
211
211
|
}
|
|
212
|
+
/** `RendererConfig.toneMapping` → three constant; a missing or bad name falls back to Neutral. */
|
|
213
|
+
function resolveToneMapping(name) {
|
|
214
|
+
return TONE_MAPPINGS[name ?? "Neutral"] ?? THREE.NeutralToneMapping;
|
|
215
|
+
}
|
|
212
216
|
//#endregion
|
|
213
217
|
//#region packages/world-runtime/src/rendering/SceneBloom.ts
|
|
214
218
|
/** BloomNode loads as a chunk only when bloom is enabled. */
|
|
@@ -1608,7 +1612,7 @@ function isAbsoluteUrl(url) {
|
|
|
1608
1612
|
}
|
|
1609
1613
|
//#endregion
|
|
1610
1614
|
//#region packages/world-runtime/src/version.gen.ts
|
|
1611
|
-
var RUNTIME_VERSION = "0.
|
|
1615
|
+
var RUNTIME_VERSION = "0.9.1";
|
|
1612
1616
|
//#endregion
|
|
1613
1617
|
//#region packages/world-runtime/src/version.ts
|
|
1614
1618
|
/**
|
|
@@ -1624,6 +1628,46 @@ function assertFormatVersion(version) {
|
|
|
1624
1628
|
throw new Error(`@kvyverse/world-runtime: world format v${version} is not supported by runtime (expected v1). Re-export the world or pin a matching runtime version.`);
|
|
1625
1629
|
}
|
|
1626
1630
|
//#endregion
|
|
1631
|
+
//#region packages/world-runtime/src/main-camera.ts
|
|
1632
|
+
/**
|
|
1633
|
+
* The camera a world starts from: the one picked in scene settings, otherwise the
|
|
1634
|
+
* first `PerspectiveCamera` depth-first, otherwise the first `OrthographicCamera`.
|
|
1635
|
+
* One rule for Play, the editor and export.
|
|
1636
|
+
*/
|
|
1637
|
+
function resolveMainCamera(explicit, roots) {
|
|
1638
|
+
if (isMainCameraKind(explicit)) return explicit;
|
|
1639
|
+
const found = { ortho: null };
|
|
1640
|
+
for (const root of roots) {
|
|
1641
|
+
const perspective = findCameras(root, found);
|
|
1642
|
+
if (perspective) return perspective;
|
|
1643
|
+
}
|
|
1644
|
+
return found.ortho;
|
|
1645
|
+
}
|
|
1646
|
+
/** Makes the camera active, through the accessor that matches its kind. */
|
|
1647
|
+
function setActiveCamera(ctx, camera) {
|
|
1648
|
+
if (isOrthographicCamera(camera)) ctx.ortho = camera;
|
|
1649
|
+
else ctx.camera = camera;
|
|
1650
|
+
}
|
|
1651
|
+
/** A camera that can be the main one (`ThreeStartCamera`). */
|
|
1652
|
+
function isMainCameraKind(value) {
|
|
1653
|
+
return isPerspectiveCamera(value) || isOrthographicCamera(value);
|
|
1654
|
+
}
|
|
1655
|
+
function findCameras(obj, found) {
|
|
1656
|
+
if (isPerspectiveCamera(obj)) return obj;
|
|
1657
|
+
if (!found.ortho && isOrthographicCamera(obj)) found.ortho = obj;
|
|
1658
|
+
for (const child of obj.children) {
|
|
1659
|
+
const perspective = findCameras(child, found);
|
|
1660
|
+
if (perspective) return perspective;
|
|
1661
|
+
}
|
|
1662
|
+
return null;
|
|
1663
|
+
}
|
|
1664
|
+
function isPerspectiveCamera(value) {
|
|
1665
|
+
return !!value?.isPerspectiveCamera;
|
|
1666
|
+
}
|
|
1667
|
+
function isOrthographicCamera(value) {
|
|
1668
|
+
return !!value?.isOrthographicCamera;
|
|
1669
|
+
}
|
|
1670
|
+
//#endregion
|
|
1627
1671
|
//#region packages/world-runtime/src/bootstrap.ts
|
|
1628
1672
|
/**
|
|
1629
1673
|
* World assembly order. The only place where it is fixed: the artifact supplies
|
|
@@ -1650,7 +1694,8 @@ async function bootstrapWorld(definition, options) {
|
|
|
1650
1694
|
await runtime.applyRequiredPatches(world);
|
|
1651
1695
|
runtime.reportProgress("Applying scene settings");
|
|
1652
1696
|
definition.applySceneSettings?.(runtime, world.ctx.scene);
|
|
1653
|
-
|
|
1697
|
+
const camera = resolveMainCamera(built.camera, built.children);
|
|
1698
|
+
if (camera) setActiveCamera(world.ctx, camera);
|
|
1654
1699
|
runtime.reportProgress("Running scripts");
|
|
1655
1700
|
runtime.mountFonts();
|
|
1656
1701
|
runtime.mountStyles();
|
|
@@ -2009,49 +2054,6 @@ async function createVideo(url, name) {
|
|
|
2009
2054
|
return source;
|
|
2010
2055
|
}
|
|
2011
2056
|
//#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
2057
|
//#region packages/world-runtime/src/rendering/tsl-uniforms.ts
|
|
2056
2058
|
var UNIFORM_TYPES = [
|
|
2057
2059
|
"float",
|
|
@@ -2112,6 +2114,118 @@ var UNIFORM_DEFAULTS = {
|
|
|
2112
2114
|
bool: () => false,
|
|
2113
2115
|
texture: () => getDefaultResource(DefaultResourceId.Texture)
|
|
2114
2116
|
};
|
|
2117
|
+
/** Writes a uniform value by key; an unknown key is a no-op. */
|
|
2118
|
+
function setUniformNodeValue(uniforms, key, value) {
|
|
2119
|
+
const node = uniforms[key];
|
|
2120
|
+
if (node) node.value = value;
|
|
2121
|
+
}
|
|
2122
|
+
/** Reads a uniform value by key; `undefined` for an unknown key. */
|
|
2123
|
+
function getUniformNodeValue(uniforms, key) {
|
|
2124
|
+
return uniforms[key]?.value;
|
|
2125
|
+
}
|
|
2126
|
+
/** Flat view of uniform values: reads and writes go straight to `node.value`,
|
|
2127
|
+
* so values live only in the nodes (no copy, no sync step). */
|
|
2128
|
+
function createUniformValuesView(uniforms) {
|
|
2129
|
+
return new Proxy({}, {
|
|
2130
|
+
get: (_target, key) => typeof key === "string" ? getUniformNodeValue(uniforms, key) : void 0,
|
|
2131
|
+
set: (_target, key, value) => {
|
|
2132
|
+
if (typeof key === "string") setUniformNodeValue(uniforms, key, value);
|
|
2133
|
+
return true;
|
|
2134
|
+
}
|
|
2135
|
+
});
|
|
2136
|
+
}
|
|
2137
|
+
//#endregion
|
|
2138
|
+
//#region packages/world-runtime/src/rendering/tsl-node.ts
|
|
2139
|
+
/**
|
|
2140
|
+
* World TSL node: the built graph node + its uniform nodes. This is what
|
|
2141
|
+
* `require("/Shaders/....tsl")` returns, so the method set matches the editor's
|
|
2142
|
+
* `TslNodeSource` (`setUniformValue` / `getUniformValue` / `uniformValues`).
|
|
2143
|
+
*/
|
|
2144
|
+
var TslNode = class {
|
|
2145
|
+
uniforms;
|
|
2146
|
+
node;
|
|
2147
|
+
_uniformValuesView;
|
|
2148
|
+
constructor(uniforms, build, name = "TslNode") {
|
|
2149
|
+
this.uniforms = uniforms;
|
|
2150
|
+
let node;
|
|
2151
|
+
try {
|
|
2152
|
+
node = build(TSL, uniforms);
|
|
2153
|
+
} catch (error) {
|
|
2154
|
+
console.warn(`TSL node "${name}" build failed`, error);
|
|
2155
|
+
}
|
|
2156
|
+
this.node = node ?? TSL.float(1);
|
|
2157
|
+
}
|
|
2158
|
+
/** Flat view of uniform values: reads and writes go straight to `node.value`. */
|
|
2159
|
+
get uniformValues() {
|
|
2160
|
+
return this._uniformValuesView ??= createUniformValuesView(this.uniforms);
|
|
2161
|
+
}
|
|
2162
|
+
setUniformValue(key, value) {
|
|
2163
|
+
setUniformNodeValue(this.uniforms, key, value);
|
|
2164
|
+
}
|
|
2165
|
+
getUniformValue(key) {
|
|
2166
|
+
return getUniformNodeValue(this.uniforms, key);
|
|
2167
|
+
}
|
|
2168
|
+
};
|
|
2169
|
+
/** Factory for the generated code: builds the node and wraps it. */
|
|
2170
|
+
function createTslNode(uniforms, build, name) {
|
|
2171
|
+
return new TslNode(uniforms, build, name);
|
|
2172
|
+
}
|
|
2173
|
+
//#endregion
|
|
2174
|
+
//#region packages/world-runtime/src/rendering/material-shader.ts
|
|
2175
|
+
var EMPTY_OUTPUTS = Object.freeze({});
|
|
2176
|
+
/**
|
|
2177
|
+
* Validates what a material shader assigned to `output`: a plain object whose
|
|
2178
|
+
* values are TSL nodes (`null`/`undefined` entries are skipped). Throws otherwise.
|
|
2179
|
+
*/
|
|
2180
|
+
function readMaterialShaderOutputs(raw) {
|
|
2181
|
+
if (!isPlainObject(raw)) throw new Error("material shader must assign an object of node inputs to `output`, e.g. { colorNode, emissiveNode }");
|
|
2182
|
+
const outputs = {};
|
|
2183
|
+
for (const key of Object.keys(raw)) {
|
|
2184
|
+
const value = raw[key];
|
|
2185
|
+
if (value === null || value === void 0) continue;
|
|
2186
|
+
if (!value.isNode) throw new Error(`material shader output "${key}" is not a TSL node`);
|
|
2187
|
+
outputs[key] = value;
|
|
2188
|
+
}
|
|
2189
|
+
return outputs;
|
|
2190
|
+
}
|
|
2191
|
+
/**
|
|
2192
|
+
* World material shader: one script that builds several material node inputs
|
|
2193
|
+
* with shared uniforms. `require("/Shaders/....")` returns it, so the method set
|
|
2194
|
+
* matches the editor's `MaterialShaderSource`.
|
|
2195
|
+
*/
|
|
2196
|
+
var MaterialShader = class {
|
|
2197
|
+
uniforms;
|
|
2198
|
+
/** Built outputs; empty when the build failed (the material keeps its own inputs). */
|
|
2199
|
+
outputs;
|
|
2200
|
+
_uniformValuesView;
|
|
2201
|
+
constructor(uniforms, build, name = "MaterialShader") {
|
|
2202
|
+
this.uniforms = uniforms;
|
|
2203
|
+
let outputs = EMPTY_OUTPUTS;
|
|
2204
|
+
try {
|
|
2205
|
+
outputs = readMaterialShaderOutputs(build(TSL, uniforms));
|
|
2206
|
+
} catch (error) {
|
|
2207
|
+
console.warn(`material shader "${name}" build failed`, error);
|
|
2208
|
+
}
|
|
2209
|
+
this.outputs = outputs;
|
|
2210
|
+
}
|
|
2211
|
+
/** Flat view of uniform values: reads and writes go straight to `node.value`. */
|
|
2212
|
+
get uniformValues() {
|
|
2213
|
+
return this._uniformValuesView ??= createUniformValuesView(this.uniforms);
|
|
2214
|
+
}
|
|
2215
|
+
setUniformValue(key, value) {
|
|
2216
|
+
setUniformNodeValue(this.uniforms, key, value);
|
|
2217
|
+
}
|
|
2218
|
+
getUniformValue(key) {
|
|
2219
|
+
return getUniformNodeValue(this.uniforms, key);
|
|
2220
|
+
}
|
|
2221
|
+
};
|
|
2222
|
+
/** Factory for the generated code: builds the shader and wraps it. */
|
|
2223
|
+
function createMaterialShader(uniforms, build, name) {
|
|
2224
|
+
return new MaterialShader(uniforms, build, name);
|
|
2225
|
+
}
|
|
2226
|
+
function isPlainObject(x) {
|
|
2227
|
+
return typeof x === "object" && x !== null && Object.getPrototypeOf(x) === Object.prototype;
|
|
2228
|
+
}
|
|
2115
2229
|
//#endregion
|
|
2116
2230
|
//#region packages/world-runtime/src/addons/externals.ts
|
|
2117
2231
|
var EXTERNAL_TYPES = ["umd", "module"];
|
|
@@ -2139,4 +2253,4 @@ var TONE_MAPPING_NAMES = [
|
|
|
2139
2253
|
"Neutral"
|
|
2140
2254
|
];
|
|
2141
2255
|
//#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 };
|
|
2256
|
+
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, isMainCameraKind, isMobileDevice, isUniformType, lazyProxy, libByRequireKey, loadGeometry, loadHdr, loadModel, loadTexture, normalizeChat, normalizePhysics, parseGeometryJson, parseHdr, parseModel, rapierPhysicsPatch, readMaterialShaderOutputs, resolveMainCamera, resolveToneMapping, setActiveCamera, setColor, setUniformNodeValue, uniformType };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as THREE from "three/webgpu";
|
|
2
|
+
import type { ThreeContext, ThreeStartCamera } from "three-start";
|
|
3
|
+
/**
|
|
4
|
+
* The camera a world starts from: the one picked in scene settings, otherwise the
|
|
5
|
+
* first `PerspectiveCamera` depth-first, otherwise the first `OrthographicCamera`.
|
|
6
|
+
* One rule for Play, the editor and export.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveMainCamera(explicit: unknown, roots: readonly THREE.Object3D[]): ThreeStartCamera | null;
|
|
9
|
+
/** Makes the camera active, through the accessor that matches its kind. */
|
|
10
|
+
export declare function setActiveCamera(ctx: ThreeContext, camera: ThreeStartCamera): void;
|
|
11
|
+
/** A camera that can be the main one (`ThreeStartCamera`). */
|
|
12
|
+
export declare function isMainCameraKind(value: unknown): value is ThreeStartCamera;
|
|
@@ -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;
|
|
@@ -12,3 +12,5 @@ import type { RendererConfig } from "./types";
|
|
|
12
12
|
* `undefined` constant / `NaN` (silently broken rendering).
|
|
13
13
|
*/
|
|
14
14
|
export declare function applyRendererConfig(renderer: THREE.Renderer, cfg: RendererConfig): void;
|
|
15
|
+
/** `RendererConfig.toneMapping` → three constant; a missing or bad name falls back to Neutral. */
|
|
16
|
+
export declare function resolveToneMapping(name: string | undefined): THREE.ToneMapping;
|
|
@@ -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/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Object3DBehaviourConstructor } from "three-start";
|
|
1
|
+
import type { Object3DBehaviourConstructor, ThreeStartCamera } from "three-start";
|
|
2
2
|
import type { AddonsConfig, WorldImports } from "./addons/types";
|
|
3
3
|
import type { RendererConfig } from "./rendering/types";
|
|
4
4
|
import type * as THREE from "three/webgpu";
|
|
@@ -11,7 +11,8 @@ export type ScriptTable = Record<string, ScriptModule>;
|
|
|
11
11
|
/** Result of constructing the scene hierarchy (before values are applied). */
|
|
12
12
|
export interface SceneBuildResult {
|
|
13
13
|
children: THREE.Object3D[];
|
|
14
|
-
camera
|
|
14
|
+
/** The main camera picked in scene settings; absent — the first one in `children`. */
|
|
15
|
+
camera?: ThreeStartCamera | null;
|
|
15
16
|
}
|
|
16
17
|
/** Load-step details for the user's UI. */
|
|
17
18
|
export interface WorldLoadProgress {
|
package/dist/version.gen.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const RUNTIME_VERSION = "0.
|
|
1
|
+
export declare const RUNTIME_VERSION = "0.9.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kvyverse/world-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Runtime for worlds exported from the Kvyverse platform for self-hosting",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"author": "Kvyverse, Inc.",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"nipplejs": "^0.10.2",
|
|
40
40
|
"stats.js": "^0.17.0",
|
|
41
41
|
"three": "^0.184.0",
|
|
42
|
-
"three-start": "^0.1
|
|
42
|
+
"three-start": "^0.2.1",
|
|
43
43
|
"vanjs-core": "^1.6.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependenciesMeta": {
|