@opsydyn/effect-three 0.0.0-stage → 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/CHANGELOG.md +58 -0
- package/LICENSE +21 -0
- package/README.md +191 -2
- package/dist/index-4045wme0.js +129 -0
- package/dist/index-4045wme0.js.map +10 -0
- package/dist/index-ef8pbv9g.js +5118 -0
- package/dist/index-ef8pbv9g.js.map +40 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1361 -0
- package/dist/index.js.map +14 -0
- package/dist/kernel/animation.d.ts +14 -0
- package/dist/kernel/animation.d.ts.map +1 -0
- package/dist/kernel/behaviours.d.ts +16 -0
- package/dist/kernel/behaviours.d.ts.map +1 -0
- package/dist/kernel/bodies.d.ts +60 -0
- package/dist/kernel/bodies.d.ts.map +1 -0
- package/dist/kernel/bodySources.d.ts +47 -0
- package/dist/kernel/bodySources.d.ts.map +1 -0
- package/dist/kernel/build.d.ts +564 -0
- package/dist/kernel/build.d.ts.map +1 -0
- package/dist/kernel/cameraMotion.d.ts +39 -0
- package/dist/kernel/cameraMotion.d.ts.map +1 -0
- package/dist/kernel/clock.d.ts +17 -0
- package/dist/kernel/clock.d.ts.map +1 -0
- package/dist/kernel/contactShadowPasses.d.ts +47 -0
- package/dist/kernel/contactShadowPasses.d.ts.map +1 -0
- package/dist/kernel/description.d.ts +1120 -0
- package/dist/kernel/description.d.ts.map +1 -0
- package/dist/kernel/diff.d.ts +90 -0
- package/dist/kernel/diff.d.ts.map +1 -0
- package/dist/kernel/environmentPresets.d.ts +30 -0
- package/dist/kernel/environmentPresets.d.ts.map +1 -0
- package/dist/kernel/equality.d.ts +64 -0
- package/dist/kernel/equality.d.ts.map +1 -0
- package/dist/kernel/frames.d.ts +55 -0
- package/dist/kernel/frames.d.ts.map +1 -0
- package/dist/kernel/index.d.ts +37 -0
- package/dist/kernel/index.d.ts.map +1 -0
- package/dist/kernel/index.js +335 -0
- package/dist/kernel/index.js.map +9 -0
- package/dist/kernel/instances.d.ts +26 -0
- package/dist/kernel/instances.d.ts.map +1 -0
- package/dist/kernel/labels.d.ts +45 -0
- package/dist/kernel/labels.d.ts.map +1 -0
- package/dist/kernel/loop.d.ts +49 -0
- package/dist/kernel/loop.d.ts.map +1 -0
- package/dist/kernel/materials.d.ts +24 -0
- package/dist/kernel/materials.d.ts.map +1 -0
- package/dist/kernel/motion.d.ts +36 -0
- package/dist/kernel/motion.d.ts.map +1 -0
- package/dist/kernel/orbit.d.ts +127 -0
- package/dist/kernel/orbit.d.ts.map +1 -0
- package/dist/kernel/overlays.d.ts +16 -0
- package/dist/kernel/overlays.d.ts.map +1 -0
- package/dist/kernel/performance.d.ts +41 -0
- package/dist/kernel/performance.d.ts.map +1 -0
- package/dist/kernel/physics.d.ts +166 -0
- package/dist/kernel/physics.d.ts.map +1 -0
- package/dist/kernel/physicsDebug.d.ts +18 -0
- package/dist/kernel/physicsDebug.d.ts.map +1 -0
- package/dist/kernel/pointer.d.ts +357 -0
- package/dist/kernel/pointer.d.ts.map +1 -0
- package/dist/kernel/renderKit.d.ts +48 -0
- package/dist/kernel/renderKit.d.ts.map +1 -0
- package/dist/kernel/renderer.d.ts +83 -0
- package/dist/kernel/renderer.d.ts.map +1 -0
- package/dist/kernel/resources.d.ts +112 -0
- package/dist/kernel/resources.d.ts.map +1 -0
- package/dist/kernel/sceneGraph.d.ts +155 -0
- package/dist/kernel/sceneGraph.d.ts.map +1 -0
- package/dist/kernel/sceneIndex.d.ts +90 -0
- package/dist/kernel/sceneIndex.d.ts.map +1 -0
- package/dist/kernel/stage.d.ts +87 -0
- package/dist/kernel/stage.d.ts.map +1 -0
- package/dist/kernel/textLayout.d.ts +29 -0
- package/dist/kernel/textLayout.d.ts.map +1 -0
- package/dist/kernel/tween.d.ts +35 -0
- package/dist/kernel/tween.d.ts.map +1 -0
- package/dist/kernel/xrInput.d.ts +107 -0
- package/dist/kernel/xrInput.d.ts.map +1 -0
- package/dist/kernel/xrLocomotion.d.ts +38 -0
- package/dist/kernel/xrLocomotion.d.ts.map +1 -0
- package/dist/runtime/FrameSource.d.ts +29 -0
- package/dist/runtime/FrameSource.d.ts.map +1 -0
- package/dist/runtime/ResourceRegistry.d.ts +18 -0
- package/dist/runtime/ResourceRegistry.d.ts.map +1 -0
- package/dist/runtime/SceneRuntime.d.ts +68 -0
- package/dist/runtime/SceneRuntime.d.ts.map +1 -0
- package/dist/runtime/SceneSchema.d.ts +2536 -0
- package/dist/runtime/SceneSchema.d.ts.map +1 -0
- package/dist/runtime/errors.d.ts +19 -0
- package/dist/runtime/errors.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +11 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/webgl/contactShadows.d.ts +5 -0
- package/dist/webgl/contactShadows.d.ts.map +1 -0
- package/dist/webgl/index.d.ts +11 -0
- package/dist/webgl/index.d.ts.map +1 -0
- package/dist/webgl/index.js +239 -0
- package/dist/webgl/index.js.map +13 -0
- package/dist/webgl/shaderGrid.d.ts +27 -0
- package/dist/webgl/shaderGrid.d.ts.map +1 -0
- package/dist/webgl/sky.d.ts +4 -0
- package/dist/webgl/sky.d.ts.map +1 -0
- package/dist/webgpu/contactShadows.d.ts +5 -0
- package/dist/webgpu/contactShadows.d.ts.map +1 -0
- package/dist/webgpu/index.d.ts +10 -0
- package/dist/webgpu/index.d.ts.map +1 -0
- package/dist/webgpu/index.js +216 -0
- package/dist/webgpu/index.js.map +13 -0
- package/dist/webgpu/shaderGrid.d.ts +5 -0
- package/dist/webgpu/shaderGrid.d.ts.map +1 -0
- package/dist/webgpu/sky.d.ts +4 -0
- package/dist/webgpu/sky.d.ts.map +1 -0
- package/package.json +82 -4
- package/src/index.ts +11 -0
- package/src/kernel/animation.ts +24 -0
- package/src/kernel/behaviours.ts +36 -0
- package/src/kernel/bodies.ts +338 -0
- package/src/kernel/bodySources.ts +203 -0
- package/src/kernel/build.ts +1325 -0
- package/src/kernel/cameraMotion.ts +202 -0
- package/src/kernel/clock.ts +35 -0
- package/src/kernel/contactShadowPasses.ts +207 -0
- package/src/kernel/description.ts +1197 -0
- package/src/kernel/diff.ts +383 -0
- package/src/kernel/environmentPresets.ts +38 -0
- package/src/kernel/equality.ts +604 -0
- package/src/kernel/frames.ts +124 -0
- package/src/kernel/index.ts +274 -0
- package/src/kernel/instances.ts +97 -0
- package/src/kernel/labels.ts +48 -0
- package/src/kernel/loop.ts +248 -0
- package/src/kernel/materials.ts +258 -0
- package/src/kernel/motion.ts +75 -0
- package/src/kernel/orbit.ts +554 -0
- package/src/kernel/overlays.ts +130 -0
- package/src/kernel/performance.ts +101 -0
- package/src/kernel/physics.ts +361 -0
- package/src/kernel/physicsDebug.ts +68 -0
- package/src/kernel/pointer.ts +785 -0
- package/src/kernel/renderKit.ts +53 -0
- package/src/kernel/renderer.ts +136 -0
- package/src/kernel/resources.ts +504 -0
- package/src/kernel/sceneGraph.ts +1440 -0
- package/src/kernel/sceneIndex.ts +219 -0
- package/src/kernel/stage.ts +157 -0
- package/src/kernel/textLayout.ts +102 -0
- package/src/kernel/tween.ts +80 -0
- package/src/kernel/xrInput.ts +230 -0
- package/src/kernel/xrLocomotion.ts +72 -0
- package/src/runtime/FrameSource.ts +41 -0
- package/src/runtime/ResourceRegistry.ts +24 -0
- package/src/runtime/SceneRuntime.ts +229 -0
- package/src/runtime/SceneSchema.ts +983 -0
- package/src/runtime/errors.ts +18 -0
- package/src/runtime/index.ts +10 -0
- package/src/webgl/contactShadows.ts +67 -0
- package/src/webgl/index.ts +19 -0
- package/src/webgl/shaderGrid.ts +196 -0
- package/src/webgl/sky.ts +42 -0
- package/src/webgpu/contactShadows.ts +83 -0
- package/src/webgpu/index.ts +19 -0
- package/src/webgpu/shaderGrid.ts +158 -0
- package/src/webgpu/sky.ts +35 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a renderer brings to a scene graph besides drawing: the parts of a scene written
|
|
3
|
+
* in its shading language. The kernel stays free of shader code (ADR-003): it describes a
|
|
4
|
+
* sky, a shader grid or contact shadows, and the renderer's kit makes them. The WebGL kit
|
|
5
|
+
* is `webglKit` from `@opsydyn/effect-three/webgl`, which `webglRendererFactory` carries;
|
|
6
|
+
* without a kit these parts are not drawn.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { Object3D, Scene } from 'three';
|
|
11
|
+
import type { ContactShadows, ShaderGridNode, Sky } from './description.ts';
|
|
12
|
+
import type { SceneRenderer } from './renderer.ts';
|
|
13
|
+
/** A sky as a kit draws it: the object the graph adds to its scene, never picked. */
|
|
14
|
+
export type HostedSky = {
|
|
15
|
+
readonly object: Object3D;
|
|
16
|
+
readonly update: (sky: Sky) => void;
|
|
17
|
+
readonly dispose: () => void;
|
|
18
|
+
};
|
|
19
|
+
/** A shader grid as a kit draws it, placed by the kit from its description. */
|
|
20
|
+
export type HostedShaderGrid = {
|
|
21
|
+
readonly object: Object3D;
|
|
22
|
+
readonly update: (previous: ShaderGridNode, next: ShaderGridNode) => void;
|
|
23
|
+
readonly dispose: () => void;
|
|
24
|
+
};
|
|
25
|
+
/** The contact shadow passes for one scene, drawn by the frame loop before each frame. */
|
|
26
|
+
export type ContactShadowPasses = {
|
|
27
|
+
/** Draws the scene's contact shadows, if it has any, before the frame is drawn. */
|
|
28
|
+
readonly draw: () => void;
|
|
29
|
+
readonly dispose: () => void;
|
|
30
|
+
};
|
|
31
|
+
/** What contact shadows need from a scene graph: its scene and their description. */
|
|
32
|
+
export type ShadowedScene = {
|
|
33
|
+
readonly scene: Scene;
|
|
34
|
+
readonly contactShadows: () => ContactShadows | null;
|
|
35
|
+
};
|
|
36
|
+
/** A renderer's shaded parts. */
|
|
37
|
+
export type RenderKit = {
|
|
38
|
+
/**
|
|
39
|
+
* Whether the renderer can draw a label engine's labels. troika's are WebGL materials:
|
|
40
|
+
* the WebGPU renderer cannot (on real WebGPU they break the frame), so its kit says no
|
|
41
|
+
* and labels stay empty.
|
|
42
|
+
*/
|
|
43
|
+
readonly drawsLabels: boolean;
|
|
44
|
+
readonly sky: () => HostedSky;
|
|
45
|
+
readonly shaderGrid: (node: ShaderGridNode) => HostedShaderGrid;
|
|
46
|
+
readonly contactShadows: (graph: ShadowedScene, renderer: SceneRenderer) => ContactShadowPasses;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=renderKit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderKit.d.ts","sourceRoot":"","sources":["../../src/kernel/renderKit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,qFAAqF;AACrF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1E,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,0FAA0F;AAC1F,MAAM,MAAM,mBAAmB,GAAG;IAChC,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,qFAAqF;AACrF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,cAAc,EAAE,MAAM,cAAc,GAAG,IAAI,CAAC;CACtD,CAAC;AAEF,iCAAiC;AACjC,MAAM,MAAM,SAAS,GAAG;IACtB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,SAAS,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,gBAAgB,CAAC;IAChE,QAAQ,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,KAAK,mBAAmB,CAAC;CACjG,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The renderer boundary (requirement 7). Synchronous and backend-neutral: a WebGL or
|
|
3
|
+
* WebGPU implementation lives outside the DOM-free core and is handed in as a factory.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { type Camera, type Scene, Texture } from 'three';
|
|
8
|
+
import type { RenderSettings } from './description.ts';
|
|
9
|
+
import type { RenderKit } from './renderKit.ts';
|
|
10
|
+
/** Size of the drawing surface in CSS pixels, plus the device pixel ratio. */
|
|
11
|
+
export type Viewport = {
|
|
12
|
+
readonly width: number;
|
|
13
|
+
readonly height: number;
|
|
14
|
+
readonly pixelRatio: number;
|
|
15
|
+
};
|
|
16
|
+
/** GPU memory counters, as reported by three.js `renderer.info.memory`. */
|
|
17
|
+
export type RendererMemory = {
|
|
18
|
+
readonly geometries: number;
|
|
19
|
+
readonly textures: number;
|
|
20
|
+
};
|
|
21
|
+
/** A live renderer bound to one drawing surface. */
|
|
22
|
+
/** A rectangle of the drawing surface in CSS pixels, from the top left. */
|
|
23
|
+
export type RenderArea = {
|
|
24
|
+
readonly x: number;
|
|
25
|
+
readonly y: number;
|
|
26
|
+
readonly width: number;
|
|
27
|
+
readonly height: number;
|
|
28
|
+
};
|
|
29
|
+
/** An offscreen surface: render into it, then use its texture. Dispose exactly once. */
|
|
30
|
+
export type RenderTarget = {
|
|
31
|
+
readonly texture: Texture;
|
|
32
|
+
readonly dispose: () => void;
|
|
33
|
+
};
|
|
34
|
+
export type SceneRenderer = {
|
|
35
|
+
/**
|
|
36
|
+
* Draws the scene through `camera`, into `area` when given (clearing only that area),
|
|
37
|
+
* otherwise across the whole surface.
|
|
38
|
+
*/
|
|
39
|
+
readonly render: (scene: Scene, camera: Camera, area?: RenderArea, target?: RenderTarget) => void;
|
|
40
|
+
/** Creates an offscreen target of `width` × `height` pixels to render into. */
|
|
41
|
+
readonly createTarget: (width: number, height: number) => RenderTarget;
|
|
42
|
+
/**
|
|
43
|
+
* Creates the environment map of three.js's `RoomEnvironment`, prefiltered for this
|
|
44
|
+
* renderer (WebGL: `PMREMGenerator.fromScene(new RoomEnvironment(), 0.04)`).
|
|
45
|
+
*/
|
|
46
|
+
readonly createEnvironment: () => RenderTarget;
|
|
47
|
+
/** Applies scene-wide render settings. Called before the first frame and on each change. */
|
|
48
|
+
readonly configure: (settings: RenderSettings) => void;
|
|
49
|
+
readonly setViewport: (viewport: Viewport) => void;
|
|
50
|
+
readonly memory: () => RendererMemory;
|
|
51
|
+
/** Releases the renderer and its drawing context. Called exactly once. */
|
|
52
|
+
readonly dispose: () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Settles when the renderer can draw, for renderers that start asynchronously (three's
|
|
55
|
+
* `WebGPURenderer.init()`); the runtime waits for it before the first frame. Absent for
|
|
56
|
+
* renderers ready at once.
|
|
57
|
+
*/
|
|
58
|
+
readonly ready?: (() => Promise<void>) | undefined;
|
|
59
|
+
};
|
|
60
|
+
/** Creates a renderer. `create` may throw when the backend is unavailable. */
|
|
61
|
+
export type RendererFactory = {
|
|
62
|
+
readonly create: () => SceneRenderer;
|
|
63
|
+
/**
|
|
64
|
+
* The renderer's shaded parts, given to the scene graphs it draws (the sky, shader
|
|
65
|
+
* grids, contact shadows). A factory wrapping another keeps its kit (`...factory`).
|
|
66
|
+
*/
|
|
67
|
+
readonly kit?: RenderKit | undefined;
|
|
68
|
+
};
|
|
69
|
+
/** A renderer that records calls instead of drawing. For headless tests. */
|
|
70
|
+
export type RecordingRenderer = SceneRenderer & {
|
|
71
|
+
readonly renders: () => number;
|
|
72
|
+
/** Every `configure` call, in order. */
|
|
73
|
+
readonly configured: () => ReadonlyArray<RenderSettings>;
|
|
74
|
+
readonly viewport: () => Viewport | undefined;
|
|
75
|
+
readonly disposed: () => boolean;
|
|
76
|
+
};
|
|
77
|
+
/** A factory of recording renderers that remembers every renderer it created. */
|
|
78
|
+
export type RecordingRendererFactory = RendererFactory & {
|
|
79
|
+
readonly created: () => ReadonlyArray<RecordingRenderer>;
|
|
80
|
+
};
|
|
81
|
+
/** Creates a factory of recording renderers. */
|
|
82
|
+
export declare const recordingRendererFactory: () => RecordingRendererFactory;
|
|
83
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/kernel/renderer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,8EAA8E;AAC9E,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,2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AC,KAAK,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;CACpD,CAAC;AAEF,8EAA8E;AAC9E,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,aAAa,CAAC;IACrC;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CACtC,CAAC;AAEF,4EAA4E;AAC5E,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,MAAM,CAAC;IAC/B,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,aAAa,CAAC,cAAc,CAAC,CAAC;IACzD,QAAQ,CAAC,QAAQ,EAAE,MAAM,QAAQ,GAAG,SAAS,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC;CAClC,CAAC;AAEF,iFAAiF;AACjF,MAAM,MAAM,wBAAwB,GAAG,eAAe,GAAG;IACvD,QAAQ,CAAC,OAAO,EAAE,MAAM,aAAa,CAAC,iBAAiB,CAAC,CAAC;CAC1D,CAAC;AAoCF,gDAAgD;AAChD,eAAO,MAAM,wBAAwB,QAAO,wBAU3C,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GPU resource ownership (PLAN D5).
|
|
3
|
+
*
|
|
4
|
+
* - Owned: created for one mesh, disposed when that mesh releases it.
|
|
5
|
+
* - Shared: defined by id, created on first use, reference-counted by the meshes using
|
|
6
|
+
* it, disposed when the last user releases it. Several scene graphs may share one store.
|
|
7
|
+
*
|
|
8
|
+
* Definitions are upserts. Changing a live shared material within its kind updates it in
|
|
9
|
+
* place. Changing a live shared geometry, or a shared material's kind, creates a
|
|
10
|
+
* replacement, notifies subscribers (each scene graph swaps it onto its meshes) and
|
|
11
|
+
* disposes the old one.
|
|
12
|
+
*
|
|
13
|
+
* The store is synchronous so the applier stays synchronous. The Effect runtime owns the
|
|
14
|
+
* store's lifetime and calls `dispose` from a scope finalizer.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import { BufferGeometry, type Object3D, type Texture } from 'three';
|
|
19
|
+
import type { Font } from 'three/addons/loaders/FontLoader.js';
|
|
20
|
+
import type { GeometryRef, MaterialRef, ResourceDefinitions, SurfaceMaterial } from './description.ts';
|
|
21
|
+
import { type HostMaterial } from './materials.ts';
|
|
22
|
+
/** Lifetime counters for one resource type. `live` is `created - disposed`. */
|
|
23
|
+
export type ResourceCounts = {
|
|
24
|
+
readonly created: number;
|
|
25
|
+
readonly disposed: number;
|
|
26
|
+
readonly live: number;
|
|
27
|
+
};
|
|
28
|
+
export type ResourceStats = {
|
|
29
|
+
readonly geometries: ResourceCounts;
|
|
30
|
+
readonly materials: ResourceCounts;
|
|
31
|
+
/** Acquisitions per live shared resource id. */
|
|
32
|
+
readonly sharedGeometryUsers: ReadonlyMap<string, number>;
|
|
33
|
+
readonly sharedMaterialUsers: ReadonlyMap<string, number>;
|
|
34
|
+
};
|
|
35
|
+
/** A loan that changed: an object for `borrowed` nodes, or a texture for materials. */
|
|
36
|
+
export type Loan = {
|
|
37
|
+
readonly kind: 'object' | 'texture' | 'font' | 'geometry';
|
|
38
|
+
readonly id: string;
|
|
39
|
+
};
|
|
40
|
+
/** Raised when a live shared geometry is replaced because its definition changed. */
|
|
41
|
+
export type GeometryReplaced = {
|
|
42
|
+
readonly previous: BufferGeometry;
|
|
43
|
+
readonly next: BufferGeometry;
|
|
44
|
+
};
|
|
45
|
+
/** Raised when a live shared material is replaced because its kind changed. */
|
|
46
|
+
export type MaterialReplaced = {
|
|
47
|
+
readonly previous: HostMaterial;
|
|
48
|
+
readonly next: HostMaterial;
|
|
49
|
+
};
|
|
50
|
+
export type ResourceStore = {
|
|
51
|
+
readonly define: (definitions: ResourceDefinitions) => void;
|
|
52
|
+
readonly acquireGeometry: (ref: GeometryRef) => BufferGeometry;
|
|
53
|
+
/** Releases one acquisition. `geometry` is the value currently held for `ref`. */
|
|
54
|
+
readonly releaseGeometry: (ref: GeometryRef, geometry: BufferGeometry) => void;
|
|
55
|
+
readonly acquireMaterial: (ref: MaterialRef) => HostMaterial;
|
|
56
|
+
/** Releases one acquisition. `material` is the value currently held for `ref`. */
|
|
57
|
+
readonly releaseMaterial: (ref: MaterialRef, material: HostMaterial) => void;
|
|
58
|
+
/** Subscribes to shared geometry replacement. Returns an unsubscribe function. */
|
|
59
|
+
readonly onGeometryReplaced: (listener: (event: GeometryReplaced) => void) => () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Subscribes to any change to a live shared resource (updated in place or replaced),
|
|
62
|
+
* so scenes using it know to draw again. Returns an unsubscribe function.
|
|
63
|
+
*/
|
|
64
|
+
readonly onSharedChanged: (listener: () => void) => () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Lends an application-owned three.js object under `id`, replacing any earlier loan.
|
|
67
|
+
* Scenes show it wherever a `borrowed` node names `id`. The store never disposes it.
|
|
68
|
+
* Returns a function that withdraws this loan (and nothing lent since).
|
|
69
|
+
*/
|
|
70
|
+
readonly lend: (id: string, object: Object3D) => () => void;
|
|
71
|
+
/** The object lent under `id`, if any. */
|
|
72
|
+
readonly lent: (id: string) => Object3D | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Lends an application-owned texture under `id`, for materials' `map`. Materials using
|
|
75
|
+
* it update at once, owned and shared alike. The store never disposes it. Returns a
|
|
76
|
+
* function that withdraws this loan.
|
|
77
|
+
*/
|
|
78
|
+
readonly lendTexture: (id: string, texture: Texture) => () => void;
|
|
79
|
+
/** The texture lent under `id`, if any. */
|
|
80
|
+
readonly texture: (id: string) => Texture | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Lends a typeface font under `id` for text geometries naming it. Text already shown
|
|
83
|
+
* is rebuilt. Returns a function that withdraws the loan.
|
|
84
|
+
*/
|
|
85
|
+
readonly lendFont: (id: string, font: Font) => () => void;
|
|
86
|
+
/** The font lent under `id`, if any. */
|
|
87
|
+
readonly font: (id: string) => Font | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Lends an application-owned geometry under `id`, for meshes whose geometry is
|
|
90
|
+
* `lentGeometry(id)`; they show it at once, and nothing once it is withdrawn. The store
|
|
91
|
+
* never disposes it. Returns a function that withdraws this loan.
|
|
92
|
+
*/
|
|
93
|
+
readonly lendGeometry: (id: string, geometry: BufferGeometry) => () => void;
|
|
94
|
+
/** Subscribes to loans and withdrawals of objects and textures. Returns an unsubscribe. */
|
|
95
|
+
readonly onLoanChanged: (listener: (loan: Loan) => void) => () => void;
|
|
96
|
+
/** Subscribes to shared material replacement. Returns an unsubscribe function. */
|
|
97
|
+
readonly onMaterialReplaced: (listener: (event: MaterialReplaced) => void) => () => void;
|
|
98
|
+
/**
|
|
99
|
+
* Applies new parameters to an owned material in place. Returns `false`, changing
|
|
100
|
+
* nothing, when `next` is a different kind: release it and acquire a new one instead.
|
|
101
|
+
*/
|
|
102
|
+
readonly updateOwnedMaterial: (material: HostMaterial, next: SurfaceMaterial) => boolean;
|
|
103
|
+
/** The shared id of a live geometry, or `undefined` if it is owned or unknown. */
|
|
104
|
+
readonly sharedGeometryId: (geometry: BufferGeometry) => string | undefined;
|
|
105
|
+
/** The shared id of a live material, or `undefined` if it is owned or unknown. */
|
|
106
|
+
readonly sharedMaterialId: (material: HostMaterial) => string | undefined;
|
|
107
|
+
readonly stats: () => ResourceStats;
|
|
108
|
+
/** Disposes every live resource. Idempotent. */
|
|
109
|
+
readonly dispose: () => void;
|
|
110
|
+
};
|
|
111
|
+
export declare const createResourceStore: () => ResourceStore;
|
|
112
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/kernel/resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAEL,cAAc,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,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,MAAM,IAAI,CAAC;IAC1D,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,GAAG,SAAS,CAAC;IAChD;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,KAAK,MAAM,IAAI,CAAC;IAC5E,2FAA2F;IAC3F,QAAQ,CAAC,aAAa,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IACvE,kFAAkF;IAClF,QAAQ,CAAC,kBAAkB,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IACzF;;;OAGG;IACH,QAAQ,CAAC,mBAAmB,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC;IACzF,kFAAkF;IAClF,QAAQ,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,MAAM,GAAG,SAAS,CAAC;IAC5E,kFAAkF;IAClF,QAAQ,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,CAAC;IAC1E,QAAQ,CAAC,KAAK,EAAE,MAAM,aAAa,CAAC;IACpC,gDAAgD;IAChD,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAoGF,eAAO,MAAM,mBAAmB,QAAO,aAsQtC,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hosted three.js scene graph: applies diff operations to real three.js objects.
|
|
3
|
+
*
|
|
4
|
+
* `reconcile` is atomic: an invalid description is rejected before anything changes.
|
|
5
|
+
* Objects keep their identity across updates; only a change of node kind replaces one.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { type BufferGeometry, Mesh, type Object3D, OrthographicCamera, PerspectiveCamera, Scene } from 'three';
|
|
10
|
+
import { type BodyCollision, type BodyContactForce } from './bodies.ts';
|
|
11
|
+
import type { RenderSettings, SceneDescription, ContactShadows, Environment, Gestures, Overlay, Xr, XrSpace, Vec3 } from './description.ts';
|
|
12
|
+
import { type Op } from './diff.ts';
|
|
13
|
+
import type { LabelEngine, LabelLayout } from './labels.ts';
|
|
14
|
+
import type { HostMaterial } from './materials.ts';
|
|
15
|
+
import { type Behaviour } from './motion.ts';
|
|
16
|
+
import type { BodyPose, PhysicsEngine } from './physics.ts';
|
|
17
|
+
import type { RenderKit } from './renderKit.ts';
|
|
18
|
+
import { type ResourceStore } from './resources.ts';
|
|
19
|
+
import { type DescriptionError } from './sceneIndex.ts';
|
|
20
|
+
/** The mesh type the kernel hosts. */
|
|
21
|
+
export type HostMesh = Mesh<BufferGeometry, HostMaterial>;
|
|
22
|
+
/** A render texture as hosted: its id, size and the nested graph that draws it. */
|
|
23
|
+
export type HostedTexture = {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly graph: SceneGraph;
|
|
26
|
+
readonly width: number;
|
|
27
|
+
readonly height: number;
|
|
28
|
+
};
|
|
29
|
+
/** A view as hosted: its key, its camera and its rectangle in CSS pixels from the top left. */
|
|
30
|
+
export type HostedView = {
|
|
31
|
+
readonly key: string;
|
|
32
|
+
readonly camera: HostCamera;
|
|
33
|
+
readonly area: {
|
|
34
|
+
readonly x: number;
|
|
35
|
+
readonly y: number;
|
|
36
|
+
readonly width: number;
|
|
37
|
+
readonly height: number;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export type ReconcileResult = {
|
|
41
|
+
readonly _tag: 'Applied';
|
|
42
|
+
readonly ops: ReadonlyArray<Op>;
|
|
43
|
+
} | {
|
|
44
|
+
readonly _tag: 'Invalid';
|
|
45
|
+
readonly error: DescriptionError;
|
|
46
|
+
};
|
|
47
|
+
export type SceneGraphOptions = {
|
|
48
|
+
/** A store shared with other graphs. When omitted the graph owns a private store. */
|
|
49
|
+
readonly store?: ResourceStore;
|
|
50
|
+
/** Behaviours nodes may name, in addition to the built-in ones (`float`). */
|
|
51
|
+
readonly behaviours?: Readonly<Record<string, Behaviour>>;
|
|
52
|
+
/** Simulates meshes with a `body` when the scene has `physics`; without it they stay put. */
|
|
53
|
+
readonly physics?: PhysicsEngine | undefined;
|
|
54
|
+
/** Draws `label` nodes (distance-field text); without it they are empty. */
|
|
55
|
+
readonly labels?: LabelEngine | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* The renderer's shaded parts (sky, shader grids, contact shadows); without it they are
|
|
58
|
+
* not drawn. `webglKit` from `@opsydyn/effect-three/webgl` for three's WebGL renderer.
|
|
59
|
+
*/
|
|
60
|
+
readonly kit?: RenderKit | undefined;
|
|
61
|
+
};
|
|
62
|
+
export type SceneGraph = {
|
|
63
|
+
readonly scene: Scene;
|
|
64
|
+
/** The render kit the graph was made with, for the frame loop's contact shadows. */
|
|
65
|
+
readonly kit: RenderKit | undefined;
|
|
66
|
+
/** The active camera. Changing the description's camera kind replaces it. */
|
|
67
|
+
readonly camera: HostCamera;
|
|
68
|
+
/** The scene's views, fitted to the viewport; empty when `camera` fills the canvas. */
|
|
69
|
+
readonly views: () => ReadonlyArray<HostedView>;
|
|
70
|
+
/** Holds every camera's turning (`autoRotate`) still while a gesture is pressed. */
|
|
71
|
+
readonly holdCameras: (held: boolean) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Where turning has taken the camera of `view` (or, without one, the scene's camera),
|
|
74
|
+
* when it has turned since its description: for an `AutoRotated` event.
|
|
75
|
+
*/
|
|
76
|
+
readonly turned: (view: string | undefined) => Vec3 | undefined;
|
|
77
|
+
/** Render textures, each a nested graph to draw into its texture (by the frame loop). */
|
|
78
|
+
readonly renderTextures: () => ReadonlyArray<HostedTexture>;
|
|
79
|
+
/** Whether the scene claims the pointer's gestures from the page. */
|
|
80
|
+
readonly gestures: () => Gestures;
|
|
81
|
+
/** Points to show HTML at; the frame loop places them after drawing. */
|
|
82
|
+
readonly overlays: () => ReadonlyArray<Overlay>;
|
|
83
|
+
/** Image-based lighting and background; the frame loop applies it. */
|
|
84
|
+
readonly environment: () => Environment | null;
|
|
85
|
+
/** Soft ground shadows; the frame loop draws them. */
|
|
86
|
+
readonly contactShadows: () => ContactShadows | null;
|
|
87
|
+
/** Collisions between bodies since the last call, for the frame loop to report. */
|
|
88
|
+
readonly collisions: () => ReadonlyArray<BodyCollision>;
|
|
89
|
+
/** Contact forces over their bodies' thresholds since the last call. */
|
|
90
|
+
readonly contactForces: () => ReadonlyArray<BodyContactForce>;
|
|
91
|
+
/** How the scene is presented immersively, for the host; `null` if it never is. */
|
|
92
|
+
readonly xr: () => Xr | null;
|
|
93
|
+
/** Keys of the nodes whose bounds the frame loop reports. */
|
|
94
|
+
readonly measured: () => ReadonlyArray<string>;
|
|
95
|
+
/** A label's laid-out size, once its engine has laid it out. */
|
|
96
|
+
readonly labelLayout: (key: string) => LabelLayout | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Places the groups that follow tracked spaces where `locate` says each space is (in the
|
|
99
|
+
* scene), hiding those it cannot find. A presenting session calls it every frame, and
|
|
100
|
+
* once with nothing found when it ends.
|
|
101
|
+
*/
|
|
102
|
+
readonly follow: (locate: (space: XrSpace) => BodyPose | undefined) => void;
|
|
103
|
+
readonly store: ResourceStore;
|
|
104
|
+
/** Diffs against the last applied description and applies the result. */
|
|
105
|
+
readonly reconcile: (next: SceneDescription) => ReconcileResult;
|
|
106
|
+
/** Advances behaviours to `elapsedSeconds` of scene time. Allocation-free. */
|
|
107
|
+
readonly tick: (elapsedSeconds: number) => void;
|
|
108
|
+
/** Scene time of the last `tick`. */
|
|
109
|
+
readonly elapsedSeconds: () => number;
|
|
110
|
+
/**
|
|
111
|
+
* The scene's current render settings. A new value (by reference) means they changed,
|
|
112
|
+
* so the frame loop can reconfigure the renderer without comparing fields.
|
|
113
|
+
*/
|
|
114
|
+
readonly renderSettings: () => RenderSettings;
|
|
115
|
+
/**
|
|
116
|
+
* While not animating (reduced motion, a paused debugger), transitions land at once and
|
|
117
|
+
* any in flight finish, because frozen scene time would otherwise strand them mid-way.
|
|
118
|
+
*/
|
|
119
|
+
readonly setAnimating: (animating: boolean) => void;
|
|
120
|
+
/**
|
|
121
|
+
* Whether the next frame would draw something new: after any change (reconcile, resize,
|
|
122
|
+
* animation toggle, a shared resource changed elsewhere) or while something animates.
|
|
123
|
+
*/
|
|
124
|
+
readonly needsFrame: () => boolean;
|
|
125
|
+
/** Marks the current state as drawn. The frame loop calls it after each render. */
|
|
126
|
+
readonly drawn: () => void;
|
|
127
|
+
/** Calls `listener` whenever the graph changes in a way that needs a frame. */
|
|
128
|
+
readonly onInvalidated: (listener: () => void) => () => void;
|
|
129
|
+
/** The hosted object for a key. */
|
|
130
|
+
readonly object: (key: string) => Object3D | undefined;
|
|
131
|
+
/** The key of a hosted object. */
|
|
132
|
+
readonly keyOf: (object: Object3D) => string | undefined;
|
|
133
|
+
/** The key of instance `instanceId` of a hosted instances node, if it has one. */
|
|
134
|
+
readonly instanceKeyOf: (object: Object3D, instanceId: number) => string | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Hosted objects of interactive meshes and groups (picking descends into groups). The
|
|
137
|
+
* array is cached until the set changes and is mutable only because three's
|
|
138
|
+
* `Raycaster.intersectObjects` requires it: don't modify it.
|
|
139
|
+
*/
|
|
140
|
+
readonly interactiveObjects: () => Array<Object3D>;
|
|
141
|
+
/** Fits the camera to a viewport of `width` by `height` CSS pixels. */
|
|
142
|
+
readonly resize: (width: number, height: number) => void;
|
|
143
|
+
/** The last `resize`, in CSS pixels. `1 × 1` until the first resize. */
|
|
144
|
+
readonly viewport: () => {
|
|
145
|
+
readonly width: number;
|
|
146
|
+
readonly height: number;
|
|
147
|
+
};
|
|
148
|
+
/** Removes every node and releases its resources. Disposes the store if the graph owns it. */
|
|
149
|
+
readonly dispose: () => void;
|
|
150
|
+
};
|
|
151
|
+
/** The three.js camera kinds the kernel hosts. */
|
|
152
|
+
export type HostCamera = PerspectiveCamera | OrthographicCamera;
|
|
153
|
+
/** Creates an empty scene graph. */
|
|
154
|
+
export declare const createSceneGraph: (options?: SceneGraphOptions) => SceneGraph;
|
|
155
|
+
//# sourceMappingURL=sceneGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sceneGraph.d.ts","sourceRoot":"","sources":["../../src/kernel/sceneGraph.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAKL,KAAK,cAAc,EAKnB,IAAI,EACJ,KAAK,QAAQ,EACb,kBAAkB,EAClB,iBAAiB,EAEjB,KAAK,EAGN,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAkB,MAAM,aAAa,CAAC;AAIxF,OAAO,KAAK,EAeV,cAAc,EACd,gBAAgB,EAGhB,cAAc,EACd,WAAW,EACX,QAAQ,EACR,OAAO,EAGP,EAAE,EACF,OAAO,EAEP,IAAI,EAGL,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAoB,KAAK,EAAE,EAAE,MAAM,WAAW,CAAC;AAGtD,OAAO,KAAK,EAAe,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,KAAK,SAAS,EAKf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAA+B,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EACL,KAAK,gBAAgB,EAKtB,MAAM,iBAAiB,CAAC;AAGzB,sC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kF;IAClF,QAAQ,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IACrF;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,EAAE,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;IACnD,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,MAAM;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7E,8FAA8F;IAC9F,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAqFF,kDAAkD;AAClD,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AA0ChE,oCAAoC;AACpC,eAAO,MAAM,gBAAgB,aAAa,iBAAiB,KAAQ,UAm/BlE,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flattened, validated view of a scene description, used by the diff.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { SceneDescription, SceneNode } from './description.ts';
|
|
7
|
+
/** Parent of a node: another node's key, or `null` for the scene root. */
|
|
8
|
+
export type ParentKey = string | null;
|
|
9
|
+
/** A node with its position in the tree. */
|
|
10
|
+
export type IndexedNode = {
|
|
11
|
+
readonly node: SceneNode;
|
|
12
|
+
readonly parent: ParentKey;
|
|
13
|
+
};
|
|
14
|
+
/** A description is rejected as a whole; nothing is applied (no partial updates). */
|
|
15
|
+
export type DescriptionError = {
|
|
16
|
+
readonly _tag: 'DuplicateKey';
|
|
17
|
+
readonly key: string;
|
|
18
|
+
} | {
|
|
19
|
+
readonly _tag: 'DuplicateResourceId';
|
|
20
|
+
readonly resource: 'geometry' | 'material';
|
|
21
|
+
readonly id: string;
|
|
22
|
+
} | {
|
|
23
|
+
readonly _tag: 'UnknownSharedGeometry';
|
|
24
|
+
readonly nodeKey: string;
|
|
25
|
+
readonly id: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly _tag: 'UnknownSharedMaterial';
|
|
28
|
+
readonly nodeKey: string;
|
|
29
|
+
readonly id: string;
|
|
30
|
+
} | {
|
|
31
|
+
readonly _tag: 'DuplicateInstanceKey';
|
|
32
|
+
readonly nodeKey: string;
|
|
33
|
+
readonly key: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly _tag: 'UnknownBehaviour';
|
|
36
|
+
readonly nodeKey: string;
|
|
37
|
+
readonly name: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly _tag: 'DuplicateViewKey';
|
|
40
|
+
readonly key: string;
|
|
41
|
+
} | {
|
|
42
|
+
readonly _tag: 'DuplicateRenderTextureId';
|
|
43
|
+
readonly id: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly _tag: 'DuplicateOverlayKey';
|
|
46
|
+
readonly key: string;
|
|
47
|
+
} | {
|
|
48
|
+
readonly _tag: 'UnknownOverlayNode';
|
|
49
|
+
readonly key: string;
|
|
50
|
+
readonly node: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly _tag: 'UnknownOverlayView';
|
|
53
|
+
readonly key: string;
|
|
54
|
+
readonly view: string;
|
|
55
|
+
} | {
|
|
56
|
+
readonly _tag: 'UnknownMeasuredNode';
|
|
57
|
+
readonly key: string;
|
|
58
|
+
}
|
|
59
|
+
/** Two joints share a key. */
|
|
60
|
+
| {
|
|
61
|
+
readonly _tag: 'DuplicateJointKey';
|
|
62
|
+
readonly key: string;
|
|
63
|
+
}
|
|
64
|
+
/** A joint names a node that is not in the scene. */
|
|
65
|
+
| {
|
|
66
|
+
readonly _tag: 'UnknownJointBody';
|
|
67
|
+
readonly joint: string;
|
|
68
|
+
readonly body: string;
|
|
69
|
+
};
|
|
70
|
+
/** A validated scene. Keys are unique across the whole scene. */
|
|
71
|
+
export type SceneIndex = {
|
|
72
|
+
readonly description: SceneDescription | null;
|
|
73
|
+
readonly nodes: ReadonlyMap<string, IndexedNode>;
|
|
74
|
+
/** Child keys per parent, in description order. Includes the root (`null`). */
|
|
75
|
+
readonly children: ReadonlyMap<ParentKey, ReadonlyArray<string>>;
|
|
76
|
+
/** Keys in depth-first pre-order: parents always precede their children. */
|
|
77
|
+
readonly preOrder: ReadonlyArray<string>;
|
|
78
|
+
};
|
|
79
|
+
/** The index of the empty scene that every graph starts from. */
|
|
80
|
+
export declare const emptyIndex: SceneIndex;
|
|
81
|
+
export type IndexResult = {
|
|
82
|
+
readonly _tag: 'Indexed';
|
|
83
|
+
readonly index: SceneIndex;
|
|
84
|
+
} | {
|
|
85
|
+
readonly _tag: 'Invalid';
|
|
86
|
+
readonly error: DescriptionError;
|
|
87
|
+
};
|
|
88
|
+
/** Validates and flattens a description. */
|
|
89
|
+
export declare const indexScene: (description: SceneDescription, behaviours?: ReadonlySet<string>) => IndexResult;
|
|
90
|
+
//# sourceMappingURL=sceneIndex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sceneIndex.d.ts","sourceRoot":"","sources":["../../src/kernel/sceneIndex.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAS,gBAAgB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE3E,0EAA0E;AAC1E,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,IAAI,CAAC;AAEtC,4CAA4C;AAC5C,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;CAC5B,CAAC;AAEF,qFAAqF;AACrF,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;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AAU,gBACR,gBAAgB,eACjB,WAAW,CAAC,MAAM,CAAC,KAC9B,WA2HF,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ContactShadows, Environment, SceneNode, Vec3 } from './description.ts';
|
|
2
|
+
import type { Box } from './orbit.ts';
|
|
3
|
+
/** Where the main and fill lights sit, in multiples of the content's radius. */
|
|
4
|
+
export type StageLighting = {
|
|
5
|
+
readonly main: Vec3;
|
|
6
|
+
readonly fill: Vec3;
|
|
7
|
+
};
|
|
8
|
+
/** Drei's lighting presets. */
|
|
9
|
+
export declare const stagePresets: {
|
|
10
|
+
rembrandt: {
|
|
11
|
+
main: [number, number, number];
|
|
12
|
+
fill: [number, number, number];
|
|
13
|
+
};
|
|
14
|
+
portrait: {
|
|
15
|
+
main: [number, number, number];
|
|
16
|
+
fill: [number, number, number];
|
|
17
|
+
};
|
|
18
|
+
upfront: {
|
|
19
|
+
main: [number, number, number];
|
|
20
|
+
fill: [number, number, number];
|
|
21
|
+
};
|
|
22
|
+
soft: {
|
|
23
|
+
main: [number, number, number];
|
|
24
|
+
fill: [number, number, number];
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type StagePreset = keyof typeof stagePresets;
|
|
28
|
+
/** The scene parts a stage contributes: spread them into `scene`. */
|
|
29
|
+
export type Stage = {
|
|
30
|
+
/** The stage's lights; add them to the scene's children. */
|
|
31
|
+
readonly lights: ReadonlyArray<SceneNode>;
|
|
32
|
+
readonly contactShadows: ContactShadows | null;
|
|
33
|
+
readonly environment: Environment | null;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Lights, ground shadows and an environment for content centred on the origin with
|
|
37
|
+
* bounding radius `radius` and height `height`. Defaults as Drei's `Stage`: the
|
|
38
|
+
* Rembrandt preset, intensity 0.5, contact shadows (`radius × 4` across, reaching
|
|
39
|
+
* `radius` up, blur 2) and a spot light that casts shadow maps when the scene enables
|
|
40
|
+
* them (bias −0.0001, 1024 texels). Drei's default environment is the "city" HDR from a
|
|
41
|
+
* CDN; here it is three.js's `RoomEnvironment`, built in code. `keyPrefix` names the
|
|
42
|
+
* lights (`stage-ambient`, `stage-main`, `stage-fill` by default).
|
|
43
|
+
*/
|
|
44
|
+
export declare const stage: (options: {
|
|
45
|
+
readonly radius: number;
|
|
46
|
+
readonly height: number;
|
|
47
|
+
readonly preset?: StagePreset | StageLighting;
|
|
48
|
+
readonly intensity?: number;
|
|
49
|
+
readonly shadows?: 'contact' | 'none';
|
|
50
|
+
readonly environment?: Environment | null;
|
|
51
|
+
readonly keyPrefix?: string;
|
|
52
|
+
}) => Stage;
|
|
53
|
+
/**
|
|
54
|
+
* Which way to align content instead of centring it, per axis, as Drei's `Center` props:
|
|
55
|
+
* `top` stands it on y = 0 (on top of the origin), `bottom` hangs it below; `left` puts
|
|
56
|
+
* it left of x = 0, `right` right of it; `front` before z = 0, `back` behind. `disableY`
|
|
57
|
+
* leaves that axis as it is.
|
|
58
|
+
*/
|
|
59
|
+
export type CenterAlign = {
|
|
60
|
+
readonly top?: boolean;
|
|
61
|
+
readonly bottom?: boolean;
|
|
62
|
+
readonly left?: boolean;
|
|
63
|
+
readonly right?: boolean;
|
|
64
|
+
readonly front?: boolean;
|
|
65
|
+
readonly back?: boolean;
|
|
66
|
+
readonly disableX?: boolean;
|
|
67
|
+
readonly disableY?: boolean;
|
|
68
|
+
readonly disableZ?: boolean;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Where to put content whose box (as measured where it is drawn now, at no offset) is
|
|
72
|
+
* `box` so that it is centred on the origin, or aligned by `align`: Drei's `Center`
|
|
73
|
+
* (`src/core/Center.tsx` at `bf6f4ad`), which sets its inner group to this position.
|
|
74
|
+
*/
|
|
75
|
+
export declare const centerOffset: (box: Box, align?: CenterAlign) => Vec3;
|
|
76
|
+
/**
|
|
77
|
+
* The sizes Drei's `Stage` takes from `Center`'s report: the box's bounding sphere radius
|
|
78
|
+
* (half its diagonal) and its width, height and depth. Pass to `stage` for lights and
|
|
79
|
+
* shadows scaled to the content.
|
|
80
|
+
*/
|
|
81
|
+
export declare const stageBounds: (box: Box) => {
|
|
82
|
+
readonly radius: number;
|
|
83
|
+
readonly width: number;
|
|
84
|
+
readonly height: number;
|
|
85
|
+
readonly depth: number;
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=stage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage.d.ts","sourceRoot":"","sources":["../../src/kernel/stage.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,gFAAgF;AAChF,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC;AAEzE,+BAA+B;AAC/B,eAAO,MAAM,YAAY;;QACV,IAAI;QAAa,IAAI;;;QACtB,IAAI;QAAgB,IAAI;;;QACzB,IAAI;QAAa,IAAI;;;QACxB,IAAI;QAAc,IAAI;;CACS,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,YAAY,CAAC;AAEpD,qEAAqE;AACrE,MAAM,MAAM,KAAK,GAAG;IAClB,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IAC1C,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IAC/C,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;CAC1C,CAAC;AAIF;;;;;;;;GAQG;AACH,eAAO,MAAM,KAAK,YAAa;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ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3
|
+
* alignment.
|
|
4
|
+
*
|
|
5
|
+
* Behavioural reference: three.js `FontLoader.js` `createPaths` at 0.186.1 (each glyph
|
|
6
|
+
* advanced by its `ha`, a new line down by the font's bounding box height plus its
|
|
7
|
+
* underline thickness, a missing glyph drawn as `?`). Drei's `Text3D` (`bf6f4ad`) takes
|
|
8
|
+
* `letterSpacing` and `lineHeight` and hands them to `TextGeometry`, which ignores them;
|
|
9
|
+
* here they are applied, in the units troika's `Text` uses: letter spacing in ems, line
|
|
10
|
+
* height as a multiple of the font's own. At the defaults the shapes are three's.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { type Shape } from 'three';
|
|
15
|
+
import type { Font } from 'three/addons/loaders/FontLoader.js';
|
|
16
|
+
import type { TextAlign } from './description.ts';
|
|
17
|
+
/** How to lay the text out. */
|
|
18
|
+
export type TextLayout = {
|
|
19
|
+
readonly size: number;
|
|
20
|
+
/** Extra space after each glyph, in ems (multiples of `size`). */
|
|
21
|
+
readonly letterSpacing: number;
|
|
22
|
+
/** Line spacing as a multiple of the font's. */
|
|
23
|
+
readonly lineHeight: number;
|
|
24
|
+
/** Where each line sits within the widest. */
|
|
25
|
+
readonly align: TextAlign;
|
|
26
|
+
};
|
|
27
|
+
/** The shapes of `text` laid out by `layout`, the first line's baseline at y = 0. */
|
|
28
|
+
export declare const layoutText: (font: Font, text: string, layout: TextLayout) => ReadonlyArray<Shape>;
|
|
29
|
+
//# sourceMappingURL=textLayout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textLayout.d.ts","sourceRoot":"","sources":["../../src/kernel/textLayout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAsB,KAAK,KAAK,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,+BAA+B;AAC/B,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,gDAAgD;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;CAC3B,CAAC;AAoDF,qFAAqF;AACrF,eAAO,MAAM,UAAU,SAAU,IAAI,QAAQ,MAAM,UAAU,UAAU,KAAG,aAAa,CAAC,KAAK,CAqB5F,CAAC"}
|