@geometra/renderer-three 0.2.0 → 1.3.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/dist/host-css-coerce.d.ts +39 -0
- package/dist/host-css-coerce.d.ts.map +1 -0
- package/dist/host-css-coerce.js +69 -0
- package/dist/host-css-coerce.js.map +1 -0
- package/dist/host-layout-plain.d.ts +164 -0
- package/dist/host-layout-plain.d.ts.map +1 -0
- package/dist/host-layout-plain.js +255 -0
- package/dist/host-layout-plain.js.map +1 -0
- package/dist/index.d.ts +42 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -5
- package/dist/index.js.map +1 -1
- package/dist/layout-sync.d.ts +51 -0
- package/dist/layout-sync.d.ts.map +1 -0
- package/dist/layout-sync.js +59 -0
- package/dist/layout-sync.js.map +1 -0
- package/dist/scene3d-manager.d.ts +29 -0
- package/dist/scene3d-manager.d.ts.map +1 -0
- package/dist/scene3d-manager.js +339 -0
- package/dist/scene3d-manager.js.map +1 -0
- package/dist/split-host.d.ts +48 -9
- package/dist/split-host.d.ts.map +1 -1
- package/dist/split-host.js +74 -39
- package/dist/split-host.js.map +1 -1
- package/dist/stacked-host.d.ts +64 -14
- package/dist/stacked-host.d.ts.map +1 -1
- package/dist/stacked-host.js +77 -41
- package/dist/stacked-host.js.map +1 -1
- package/dist/three-scene-basics.d.ts +313 -2
- package/dist/three-scene-basics.d.ts.map +1 -1
- package/dist/three-scene-basics.js +418 -1
- package/dist/three-scene-basics.js.map +1 -1
- package/dist/utils.d.ts +156 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +207 -6
- package/dist/utils.js.map +1 -1
- package/package.json +15 -18
- package/LICENSE +0 -21
- package/README.md +0 -111
package/dist/split-host.d.ts
CHANGED
|
@@ -1,24 +1,49 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { type BrowserCanvasClientHandle, type BrowserCanvasClientOptions } from '@geometra/renderer-canvas';
|
|
3
3
|
import { type GeometraThreeSceneBasicsOptions } from './three-scene-basics.js';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Every {@link createBrowserCanvasClient} option except `canvas`, which split/stacked hosts create
|
|
6
|
+
* internally. Includes `url`, `binaryFraming`, optional explicit `window` for tests/iframes, and
|
|
7
|
+
* the rest of {@link BrowserCanvasClientOptions}.
|
|
8
|
+
*/
|
|
9
|
+
export type GeometraHostBrowserCanvasClientOptions = Omit<BrowserCanvasClientOptions, 'canvas'>;
|
|
10
|
+
/**
|
|
11
|
+
* Default Geometra column width for {@link createThreeGeometraSplitHost}; same value as the
|
|
12
|
+
* `geometraWidth` option fallback and README.
|
|
13
|
+
*/
|
|
14
|
+
export declare const GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS: {
|
|
15
|
+
readonly geometraWidth: 420;
|
|
16
|
+
};
|
|
17
|
+
export interface ThreeGeometraSplitHostOptions extends GeometraHostBrowserCanvasClientOptions, GeometraThreeSceneBasicsOptions {
|
|
5
18
|
/** Host element; a flex row is appended as a child (existing children are left untouched). */
|
|
6
19
|
container: HTMLElement;
|
|
7
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Geometra column width in CSS pixels. Default: 420 ({@link GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS}).
|
|
22
|
+
* Non-finite or negative values fall back to the default so layout does not emit invalid `px` styles.
|
|
23
|
+
*/
|
|
8
24
|
geometraWidth?: number;
|
|
9
25
|
/** When true, Geometra panel is on the left. Default: false (Three.js left, Geometra right). */
|
|
10
26
|
geometraOnLeft?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Upper bound for `window.devicePixelRatio` when sizing the WebGL drawing buffer (e.g. `2` on retina
|
|
29
|
+
* to cut memory and fragment cost). When omitted, the full device pixel ratio is used.
|
|
30
|
+
*/
|
|
31
|
+
maxDevicePixelRatio?: number;
|
|
11
32
|
/**
|
|
12
33
|
* Called once after scene, camera, and renderer are created.
|
|
13
34
|
* Add meshes, lights, controls, etc. Call `ctx.destroy()` to tear down immediately; the render loop
|
|
14
|
-
* will not start if the host is already destroyed.
|
|
35
|
+
* will not start if the host is already destroyed. If this callback throws, the host is fully torn
|
|
36
|
+
* down and the error is rethrown.
|
|
15
37
|
*/
|
|
16
38
|
onThreeReady?: (ctx: ThreeRuntimeContext) => void;
|
|
17
39
|
/**
|
|
18
40
|
* Called every frame before `renderer.render`.
|
|
19
|
-
* Use for animations
|
|
41
|
+
* Use for animations. Return **`false`** to skip `render` for this frame only (same idea as
|
|
42
|
+
* {@link tickGeometraThreeWebGLWithSceneBasicsFrame}). If you call {@link ThreeRuntimeContext.destroy} here,
|
|
43
|
+
* teardown runs and this frame’s `render` is skipped (avoids rendering after WebGL dispose).
|
|
44
|
+
* If this callback throws, the host is fully torn down and the error is rethrown (same as {@link onThreeReady}).
|
|
20
45
|
*/
|
|
21
|
-
onThreeFrame?: (ctx: ThreeFrameContext) => void;
|
|
46
|
+
onThreeFrame?: (ctx: ThreeFrameContext) => void | false;
|
|
22
47
|
}
|
|
23
48
|
export interface ThreeRuntimeContext {
|
|
24
49
|
renderer: THREE.WebGLRenderer;
|
|
@@ -44,7 +69,12 @@ export interface ThreeGeometraSplitHostHandle {
|
|
|
44
69
|
camera: THREE.PerspectiveCamera;
|
|
45
70
|
clock: THREE.Clock;
|
|
46
71
|
geometra: BrowserCanvasClientHandle;
|
|
47
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Stops the render loop, tears down WebGL via {@link disposeGeometraThreeWebGLWithSceneBasics} (clock stop +
|
|
74
|
+
* the same renderer registration headless {@link renderGeometraThreeWebGLWithSceneBasicsFrame} /
|
|
75
|
+
* {@link tickGeometraThreeWebGLWithSceneBasicsFrame} use to skip draws after dispose), disconnects observers,
|
|
76
|
+
* and tears down the Geometra client.
|
|
77
|
+
*/
|
|
48
78
|
destroy(): void;
|
|
49
79
|
}
|
|
50
80
|
/**
|
|
@@ -52,11 +82,20 @@ export interface ThreeGeometraSplitHostHandle {
|
|
|
52
82
|
*
|
|
53
83
|
* This is the recommended **hybrid** layout: 3D stays in Three; chrome and data panes stay in Geometra’s protocol.
|
|
54
84
|
* Geometra’s client still uses `resizeTarget: window` by default; when only the Geometra column changes size,
|
|
55
|
-
* a `ResizeObserver`
|
|
56
|
-
*
|
|
85
|
+
* a `ResizeObserver` schedules a synthetic `resize` on `window` so layout width/height track the panel.
|
|
86
|
+
* The host `root` and both flex panes are observed (same idea as {@link createThreeGeometraStackedHost} observing
|
|
87
|
+
* its `root`) so container-driven root box changes still coalesce into the same rAF pass even if a panel callback
|
|
88
|
+
* ordering quirk would otherwise miss a tick.
|
|
89
|
+
* Panel-driven updates coalesce to at most **one** animation frame per burst: a single `requestAnimationFrame`
|
|
90
|
+
* pass runs the Three.js buffer resize and (when needed) that synthetic `resize`, so both flex panes firing
|
|
91
|
+
* in the same frame do not call `renderer.setSize` twice.
|
|
92
|
+
*
|
|
93
|
+
* Real `window` `resize` events schedule the same coalesced Three.js pass **without** an extra synthetic
|
|
94
|
+
* `resize`, so the thin client is not double-notified when the browser already fired `resize`.
|
|
57
95
|
*
|
|
58
96
|
* The Three.js pane listens to `window` `resize` as well so `devicePixelRatio` updates (zoom / display changes)
|
|
59
|
-
* refresh the WebGL drawing buffer without relying on panel `ResizeObserver` alone.
|
|
97
|
+
* refresh the WebGL drawing buffer without relying on panel `ResizeObserver` alone. Optional
|
|
98
|
+
* {@link ThreeGeometraSplitHostOptions.maxDevicePixelRatio} caps the ratio used for the WebGL buffer.
|
|
60
99
|
*
|
|
61
100
|
* Pass through {@link BrowserCanvasClientOptions} from `@geometra/renderer-canvas` / `@geometra/client`
|
|
62
101
|
* (for example `binaryFraming`, `onError`, `onFrameMetrics`, `onData` for JSON side-channels on the same
|
package/dist/split-host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-host.d.ts","sourceRoot":"","sources":["../src/split-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK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SAAQ,mBAAmB;IAC5D,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,cAAc,CAAA;IACpB,UAAU,EAAE,cAAc,CAAA;IAC1B,aAAa,EAAE,cAAc,CAAA;IAC7B,WAAW,EAAE,iBAAiB,CAAA;IAC9B,cAAc,EAAE,iBAAiB,CAAA;IACjC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAA;IAC7B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;IAClB,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAA;IAC/B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;IAClB,QAAQ,EAAE,yBAAyB,CAAA;IACnC;;;;;OAKG;IACH,OAAO,IAAI,IAAI,CAAA;CAChB;AAgBD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,6BAA6B,GACrC,4BAA4B,CA0L9B"}
|
package/dist/split-host.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
1
|
import { createBrowserCanvasClient, } from '@geometra/renderer-canvas';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { GEOMETRA_THREE_HOST_SCENE_DEFAULTS, createGeometraThreeWebGLWithSceneBasics, disposeGeometraThreeWebGLWithSceneBasics, } from './three-scene-basics.js';
|
|
3
|
+
import { createGeometraHostLayoutSyncRaf } from './layout-sync.js';
|
|
4
|
+
import { coerceHostNonNegativeCssPx } from './host-css-coerce.js';
|
|
5
|
+
import { resizeGeometraThreePerspectiveView, resolveHostDevicePixelRatio } from './utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Default Geometra column width for {@link createThreeGeometraSplitHost}; same value as the
|
|
8
|
+
* `geometraWidth` option fallback and README.
|
|
9
|
+
*/
|
|
10
|
+
export const GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS = {
|
|
11
|
+
geometraWidth: 420,
|
|
12
|
+
};
|
|
5
13
|
function panelStyle(el, flex) {
|
|
6
14
|
el.style.flex = flex;
|
|
7
15
|
el.style.minWidth = '0';
|
|
@@ -19,18 +27,28 @@ function fullSizeCanvas(canvas) {
|
|
|
19
27
|
*
|
|
20
28
|
* This is the recommended **hybrid** layout: 3D stays in Three; chrome and data panes stay in Geometra’s protocol.
|
|
21
29
|
* Geometra’s client still uses `resizeTarget: window` by default; when only the Geometra column changes size,
|
|
22
|
-
* a `ResizeObserver`
|
|
23
|
-
*
|
|
30
|
+
* a `ResizeObserver` schedules a synthetic `resize` on `window` so layout width/height track the panel.
|
|
31
|
+
* The host `root` and both flex panes are observed (same idea as {@link createThreeGeometraStackedHost} observing
|
|
32
|
+
* its `root`) so container-driven root box changes still coalesce into the same rAF pass even if a panel callback
|
|
33
|
+
* ordering quirk would otherwise miss a tick.
|
|
34
|
+
* Panel-driven updates coalesce to at most **one** animation frame per burst: a single `requestAnimationFrame`
|
|
35
|
+
* pass runs the Three.js buffer resize and (when needed) that synthetic `resize`, so both flex panes firing
|
|
36
|
+
* in the same frame do not call `renderer.setSize` twice.
|
|
37
|
+
*
|
|
38
|
+
* Real `window` `resize` events schedule the same coalesced Three.js pass **without** an extra synthetic
|
|
39
|
+
* `resize`, so the thin client is not double-notified when the browser already fired `resize`.
|
|
24
40
|
*
|
|
25
41
|
* The Three.js pane listens to `window` `resize` as well so `devicePixelRatio` updates (zoom / display changes)
|
|
26
|
-
* refresh the WebGL drawing buffer without relying on panel `ResizeObserver` alone.
|
|
42
|
+
* refresh the WebGL drawing buffer without relying on panel `ResizeObserver` alone. Optional
|
|
43
|
+
* {@link ThreeGeometraSplitHostOptions.maxDevicePixelRatio} caps the ratio used for the WebGL buffer.
|
|
27
44
|
*
|
|
28
45
|
* Pass through {@link BrowserCanvasClientOptions} from `@geometra/renderer-canvas` / `@geometra/client`
|
|
29
46
|
* (for example `binaryFraming`, `onError`, `onFrameMetrics`, `onData` for JSON side-channels on the same
|
|
30
47
|
* socket as layout; channel names are defined by your app and the Geometra server).
|
|
31
48
|
*/
|
|
32
49
|
export function createThreeGeometraSplitHost(options) {
|
|
33
|
-
const { container, geometraWidth =
|
|
50
|
+
const { container, geometraWidth: geometraWidthOpt = GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS.geometraWidth, geometraOnLeft = false, maxDevicePixelRatio, threeBackground = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.threeBackground, cameraFov = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraFov, cameraNear = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraNear, cameraFar = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraFar, cameraPosition = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraPosition, onThreeReady, onThreeFrame, window: providedWindow, ...browserOptions } = options;
|
|
51
|
+
const geometraWidth = coerceHostNonNegativeCssPx(geometraWidthOpt, GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS.geometraWidth);
|
|
34
52
|
const doc = container.ownerDocument;
|
|
35
53
|
const win = providedWindow ?? doc.defaultView;
|
|
36
54
|
if (!win) {
|
|
@@ -62,12 +80,7 @@ export function createThreeGeometraSplitHost(options) {
|
|
|
62
80
|
const geometraCanvas = doc.createElement('canvas');
|
|
63
81
|
fullSizeCanvas(geometraCanvas);
|
|
64
82
|
geometraPanel.appendChild(geometraCanvas);
|
|
65
|
-
const glRenderer =
|
|
66
|
-
canvas: threeCanvas,
|
|
67
|
-
antialias: true,
|
|
68
|
-
alpha: false,
|
|
69
|
-
});
|
|
70
|
-
const { scene, camera, clock } = createGeometraThreeSceneBasics({
|
|
83
|
+
const { renderer: glRenderer, scene, camera, clock } = createGeometraThreeWebGLWithSceneBasics(threeCanvas, {
|
|
71
84
|
threeBackground,
|
|
72
85
|
cameraFov,
|
|
73
86
|
cameraNear,
|
|
@@ -75,35 +88,44 @@ export function createThreeGeometraSplitHost(options) {
|
|
|
75
88
|
cameraPosition,
|
|
76
89
|
});
|
|
77
90
|
const resizeThree = () => {
|
|
78
|
-
resizeGeometraThreePerspectiveView(glRenderer, camera, threePanel.clientWidth, threePanel.clientHeight, win.devicePixelRatio || 1);
|
|
91
|
+
resizeGeometraThreePerspectiveView(glRenderer, camera, threePanel.clientWidth, threePanel.clientHeight, resolveHostDevicePixelRatio(win.devicePixelRatio || 1, maxDevicePixelRatio));
|
|
79
92
|
};
|
|
93
|
+
let destroyed = false;
|
|
94
|
+
const layoutSync = createGeometraHostLayoutSyncRaf(win, {
|
|
95
|
+
isDestroyed: () => destroyed,
|
|
96
|
+
syncLayout: resizeThree,
|
|
97
|
+
dispatchGeometraResize: () => {
|
|
98
|
+
win.dispatchEvent(new Event('resize'));
|
|
99
|
+
},
|
|
100
|
+
});
|
|
80
101
|
const onWindowResize = () => {
|
|
81
|
-
|
|
102
|
+
layoutSync.schedule(false);
|
|
82
103
|
};
|
|
83
104
|
win.addEventListener('resize', onWindowResize, { passive: true });
|
|
84
105
|
resizeThree();
|
|
85
|
-
const geometraHandle =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
const geometraHandle = (() => {
|
|
107
|
+
try {
|
|
108
|
+
return createBrowserCanvasClient({
|
|
109
|
+
...browserOptions,
|
|
110
|
+
canvas: geometraCanvas,
|
|
111
|
+
window: win,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
layoutSync.cancel();
|
|
116
|
+
win.removeEventListener('resize', onWindowResize);
|
|
117
|
+
disposeGeometraThreeWebGLWithSceneBasics({ renderer: glRenderer, clock });
|
|
118
|
+
root.remove();
|
|
119
|
+
throw err;
|
|
120
|
+
}
|
|
121
|
+
})();
|
|
99
122
|
const roContainer = new ResizeObserver(() => {
|
|
100
|
-
|
|
101
|
-
triggerGeometraResize();
|
|
123
|
+
layoutSync.schedule(true);
|
|
102
124
|
});
|
|
125
|
+
roContainer.observe(root);
|
|
103
126
|
roContainer.observe(threePanel);
|
|
104
127
|
roContainer.observe(geometraPanel);
|
|
105
128
|
let rafId;
|
|
106
|
-
let destroyed = false;
|
|
107
129
|
const destroy = () => {
|
|
108
130
|
if (destroyed)
|
|
109
131
|
return;
|
|
@@ -112,14 +134,11 @@ export function createThreeGeometraSplitHost(options) {
|
|
|
112
134
|
win.cancelAnimationFrame(rafId);
|
|
113
135
|
rafId = undefined;
|
|
114
136
|
}
|
|
115
|
-
|
|
116
|
-
win.cancelAnimationFrame(geometraResizeRafId);
|
|
117
|
-
geometraResizeRafId = undefined;
|
|
118
|
-
}
|
|
137
|
+
layoutSync.cancel();
|
|
119
138
|
win.removeEventListener('resize', onWindowResize);
|
|
120
139
|
roContainer.disconnect();
|
|
121
140
|
geometraHandle.destroy();
|
|
122
|
-
glRenderer
|
|
141
|
+
disposeGeometraThreeWebGLWithSceneBasics({ renderer: glRenderer, clock });
|
|
123
142
|
root.remove();
|
|
124
143
|
};
|
|
125
144
|
const ctxBase = {
|
|
@@ -129,14 +148,30 @@ export function createThreeGeometraSplitHost(options) {
|
|
|
129
148
|
threeCanvas,
|
|
130
149
|
destroy,
|
|
131
150
|
};
|
|
132
|
-
|
|
151
|
+
try {
|
|
152
|
+
onThreeReady?.(ctxBase);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
destroy();
|
|
156
|
+
throw err;
|
|
157
|
+
}
|
|
133
158
|
const loop = () => {
|
|
134
159
|
if (destroyed)
|
|
135
160
|
return;
|
|
136
161
|
rafId = win.requestAnimationFrame(loop);
|
|
137
162
|
const delta = clock.getDelta();
|
|
138
163
|
const elapsed = clock.elapsedTime;
|
|
139
|
-
|
|
164
|
+
try {
|
|
165
|
+
if (onThreeFrame?.({ ...ctxBase, clock, delta, elapsed }) === false) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
destroy();
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
173
|
+
if (destroyed)
|
|
174
|
+
return;
|
|
140
175
|
glRenderer.render(scene, camera);
|
|
141
176
|
};
|
|
142
177
|
if (!destroyed) {
|
package/dist/split-host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-host.js","sourceRoot":"","sources":["../src/split-host.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"split-host.js","sourceRoot":"","sources":["../src/split-host.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,GAG1B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,kCAAkC,EAClC,uCAAuC,EACvC,wCAAwC,GAEzC,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,kCAAkC,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAS5F;;;GAGG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG;IACjD,aAAa,EAAE,GAAG;CACV,CAAA;AAuEV,SAAS,UAAU,CAAC,EAAe,EAAE,IAAY;IAC/C,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAA;IACvB,EAAE,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,CAAA;IACxB,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAA;IAC9B,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAA;AAC9B,CAAC;AAED,SAAS,cAAc,CAAC,MAAyB;IAC/C,MAAM,CA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AM,OAAO,GAAG,KAAK,CAAC,WAAW,CAAA;QACjC,IAAI,CAAC;YACH,IAAI,YAAY,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC;gBACpE,OAAM;YACR,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,CAAA;YACT,MAAM,GAAG,CAAA;QACX,CAAC;QACD,IAAI,SAAS;YAAE,OAAM;QACrB,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IAClC,CAAC,CAAA;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,KAAK,GAAG,GAAG,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAA;IACzC,CAAC;IAED,OAAO;QACL,IAAI;QACJ,UAAU;QACV,aAAa;QACb,WAAW;QACX,cAAc;QACd,QAAQ,EAAE,UAAU;QACpB,KAAK;QACL,MAAM;QACN,KAAK;QACL,QAAQ,EAAE,cAAc;QACxB,OAAO;KACR,CAAA;AACH,CAAC"}
|
package/dist/stacked-host.d.ts
CHANGED
|
@@ -1,34 +1,74 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import { type BrowserCanvasClientHandle
|
|
3
|
-
import type { ThreeFrameContext, ThreeRuntimeContext } from './split-host.js';
|
|
2
|
+
import { type BrowserCanvasClientHandle } from '@geometra/renderer-canvas';
|
|
3
|
+
import type { GeometraHostBrowserCanvasClientOptions, ThreeFrameContext, ThreeRuntimeContext } from './split-host.js';
|
|
4
4
|
import { type GeometraThreeSceneBasicsOptions } from './three-scene-basics.js';
|
|
5
|
-
|
|
6
|
-
export type GeometraHudPlacement
|
|
7
|
-
|
|
5
|
+
import { type GeometraHudPlacement } from './host-css-coerce.js';
|
|
6
|
+
export type { GeometraHudPlacement } from './host-css-coerce.js';
|
|
7
|
+
/**
|
|
8
|
+
* Default HUD width, height, corner, and margin for {@link createThreeGeometraStackedHost}; same as
|
|
9
|
+
* those option fallbacks and README.
|
|
10
|
+
*/
|
|
11
|
+
export declare const GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS: {
|
|
12
|
+
readonly geometraHudWidth: 420;
|
|
13
|
+
readonly geometraHudHeight: 320;
|
|
14
|
+
readonly geometraHudPlacement: "bottom-right";
|
|
15
|
+
readonly geometraHudMargin: 12;
|
|
16
|
+
};
|
|
17
|
+
export interface ThreeGeometraStackedHostOptions extends GeometraHostBrowserCanvasClientOptions, GeometraThreeSceneBasicsOptions {
|
|
8
18
|
/** Host element; a full-size stacking context is appended (existing children are left untouched). */
|
|
9
19
|
container: HTMLElement;
|
|
10
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* HUD width in CSS pixels. Default: {@link GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudWidth}.
|
|
22
|
+
* Non-finite or negative values fall back to the default so layout does not emit invalid `px` styles.
|
|
23
|
+
*/
|
|
11
24
|
geometraHudWidth?: number;
|
|
12
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* HUD height in CSS pixels. Default: {@link GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudHeight}.
|
|
27
|
+
* Non-finite or negative values fall back to the default.
|
|
28
|
+
*/
|
|
13
29
|
geometraHudHeight?: number;
|
|
14
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* HUD corner. Default: {@link GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudPlacement}.
|
|
32
|
+
* Runtime strings (e.g. from JSON or agents) are normalized with {@link coerceGeometraHudPlacement}
|
|
33
|
+
* (trim + case-insensitive match for the four literals; anything else uses the default).
|
|
34
|
+
*/
|
|
15
35
|
geometraHudPlacement?: GeometraHudPlacement;
|
|
16
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Inset from the chosen corner in CSS pixels. Default: {@link GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudMargin}.
|
|
38
|
+
* Non-finite or negative values fall back to the default.
|
|
39
|
+
*/
|
|
17
40
|
geometraHudMargin?: number;
|
|
18
41
|
/**
|
|
19
42
|
* CSS `pointer-events` on the HUD wrapper (e.g. `'none'` so input falls through to the WebGL canvas).
|
|
20
|
-
* Default: `'auto'`.
|
|
43
|
+
* Default: `'auto'`. Blank or whitespace-only strings fall back to the default; use
|
|
44
|
+
* {@link coerceGeometraHudPointerEvents} in custom layouts for the same rules.
|
|
21
45
|
*/
|
|
22
46
|
geometraHudPointerEvents?: string;
|
|
47
|
+
/**
|
|
48
|
+
* CSS `z-index` on the HUD wrapper when you stack other siblings in {@link ThreeGeometraStackedHostOptions.container}
|
|
49
|
+
* or need a fixed order above the WebGL layer (Three canvas uses `0`). Default: `1`.
|
|
50
|
+
* Non-finite numbers and blank/whitespace-only strings fall back to the default so the HUD keeps a predictable stack order.
|
|
51
|
+
*/
|
|
52
|
+
geometraHudZIndex?: string | number;
|
|
53
|
+
/**
|
|
54
|
+
* Upper bound for `window.devicePixelRatio` when sizing the WebGL drawing buffer (e.g. `2` on retina
|
|
55
|
+
* to cut memory and fragment cost). When omitted, the full device pixel ratio is used.
|
|
56
|
+
*/
|
|
57
|
+
maxDevicePixelRatio?: number;
|
|
23
58
|
/**
|
|
24
59
|
* Called once after scene, camera, and renderer are created.
|
|
25
60
|
* Call `ctx.destroy()` to tear down immediately; the render loop will not start if the host is already destroyed.
|
|
61
|
+
* If this callback throws, the host is fully torn down and the error is rethrown.
|
|
26
62
|
*/
|
|
27
63
|
onThreeReady?: (ctx: ThreeRuntimeContext) => void;
|
|
28
64
|
/**
|
|
29
65
|
* Called every frame before `renderer.render`.
|
|
66
|
+
* Return **`false`** to skip `render` for this frame only (same idea as
|
|
67
|
+
* {@link tickGeometraThreeWebGLWithSceneBasicsFrame}). If you call {@link ThreeRuntimeContext.destroy} here,
|
|
68
|
+
* teardown runs and this frame’s `render` is skipped.
|
|
69
|
+
* If this callback throws, the host is fully torn down and the error is rethrown (same as {@link onThreeReady}).
|
|
30
70
|
*/
|
|
31
|
-
onThreeFrame?: (ctx: ThreeFrameContext) => void;
|
|
71
|
+
onThreeFrame?: (ctx: ThreeFrameContext) => void | false;
|
|
32
72
|
}
|
|
33
73
|
export interface ThreeGeometraStackedHostHandle {
|
|
34
74
|
root: HTMLDivElement;
|
|
@@ -41,19 +81,29 @@ export interface ThreeGeometraStackedHostHandle {
|
|
|
41
81
|
camera: THREE.PerspectiveCamera;
|
|
42
82
|
clock: THREE.Clock;
|
|
43
83
|
geometra: BrowserCanvasClientHandle;
|
|
84
|
+
/**
|
|
85
|
+
* Stops the render loop, tears down WebGL via {@link disposeGeometraThreeWebGLWithSceneBasics} (clock stop +
|
|
86
|
+
* the same renderer registration headless {@link renderGeometraThreeWebGLWithSceneBasicsFrame} /
|
|
87
|
+
* {@link tickGeometraThreeWebGLWithSceneBasicsFrame} use to skip draws after dispose), disconnects observers,
|
|
88
|
+
* and tears down the Geometra client.
|
|
89
|
+
*/
|
|
44
90
|
destroy(): void;
|
|
45
91
|
}
|
|
46
92
|
/**
|
|
47
93
|
* Stacked host: full-viewport Three.js `WebGLRenderer` with a positioned Geometra canvas **HUD** on top.
|
|
48
94
|
*
|
|
49
95
|
* Pointer routing follows normal hit-testing: events hit the Geometra canvas where it overlaps the WebGL layer
|
|
50
|
-
* (`z-index` above the Three canvas); elsewhere, the Three canvas receives input. Override with
|
|
51
|
-
* {@link ThreeGeometraStackedHostOptions.geometraHudPointerEvents} (e.g. `'none'` for a click-through HUD)
|
|
96
|
+
* (HUD `z-index` above the Three canvas, which uses `0`); elsewhere, the Three canvas receives input. Override with
|
|
97
|
+
* {@link ThreeGeometraStackedHostOptions.geometraHudPointerEvents} (e.g. `'none'` for a click-through HUD) or
|
|
98
|
+
* {@link ThreeGeometraStackedHostOptions.geometraHudZIndex} when you add other positioned siblings.
|
|
52
99
|
*
|
|
53
100
|
* Geometra’s client still uses `resizeTarget: window` by default; when only the HUD box changes size,
|
|
54
101
|
* a coalesced synthetic `resize` is dispatched on `window` (same pattern as {@link createThreeGeometraSplitHost}).
|
|
102
|
+
* `ResizeObserver` callbacks and real `window` `resize` share one rAF-coalesced Three.js buffer pass; the
|
|
103
|
+
* synthetic `resize` is emitted only from observer-driven layout changes, not from real window resizes.
|
|
55
104
|
* The Three.js layer listens to `window` `resize` for `devicePixelRatio` changes and uses the host `root` size
|
|
56
|
-
* for the drawing buffer.
|
|
105
|
+
* for the drawing buffer. Optional {@link ThreeGeometraStackedHostOptions.maxDevicePixelRatio} caps the ratio
|
|
106
|
+
* used for the WebGL buffer.
|
|
57
107
|
*/
|
|
58
108
|
export declare function createThreeGeometraStackedHost(options: ThreeGeometraStackedHostOptions): ThreeGeometraStackedHostHandle;
|
|
59
109
|
//# sourceMappingURL=stacked-host.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stacked-host.d.ts","sourceRoot":"","sources":["../src/stacked-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAEL,KAAK,yBAAyB,
|
|
1
|
+
{"version":3,"file":"stacked-host.d.ts","sourceRoot":"","sources":["../src/stacked-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EACV,sCAAsC,EACtC,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAIL,KAAK,+BAA+B,EACrC,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EAKL,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAA;AAG7B,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAEhE;;;GAGG;AACH,eAAO,MAAM,qCAAqC;;;;;CAUjD,CAAA;AAED,MAAM,WAAW,+BACf,SAAQ,sCAAsC,EAC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 'three';
|
|
2
1
|
import { createBrowserCanvasClient, } from '@geometra/renderer-canvas';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { GEOMETRA_THREE_HOST_SCENE_DEFAULTS, createGeometraThreeWebGLWithSceneBasics, disposeGeometraThreeWebGLWithSceneBasics, } from './three-scene-basics.js';
|
|
3
|
+
import { createGeometraHostLayoutSyncRaf } from './layout-sync.js';
|
|
4
|
+
import { coerceGeometraHudPlacement, coerceGeometraHudPointerEvents, coerceHostNonNegativeCssPx, coerceHostStackingZIndexCss, } from './host-css-coerce.js';
|
|
5
|
+
import { resizeGeometraThreePerspectiveView, resolveHostDevicePixelRatio } from './utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Default HUD width, height, corner, and margin for {@link createThreeGeometraStackedHost}; same as
|
|
8
|
+
* those option fallbacks and README.
|
|
9
|
+
*/
|
|
10
|
+
export const GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS = {
|
|
11
|
+
geometraHudWidth: 420,
|
|
12
|
+
geometraHudHeight: 320,
|
|
13
|
+
geometraHudPlacement: 'bottom-right',
|
|
14
|
+
geometraHudMargin: 12,
|
|
15
|
+
};
|
|
5
16
|
function fullSizeCanvas(canvas) {
|
|
6
17
|
canvas.style.display = 'block';
|
|
7
18
|
canvas.style.width = '100%';
|
|
@@ -36,16 +47,25 @@ function applyHudPlacement(wrap, placement, marginPx) {
|
|
|
36
47
|
* Stacked host: full-viewport Three.js `WebGLRenderer` with a positioned Geometra canvas **HUD** on top.
|
|
37
48
|
*
|
|
38
49
|
* Pointer routing follows normal hit-testing: events hit the Geometra canvas where it overlaps the WebGL layer
|
|
39
|
-
* (`z-index` above the Three canvas); elsewhere, the Three canvas receives input. Override with
|
|
40
|
-
* {@link ThreeGeometraStackedHostOptions.geometraHudPointerEvents} (e.g. `'none'` for a click-through HUD)
|
|
50
|
+
* (HUD `z-index` above the Three canvas, which uses `0`); elsewhere, the Three canvas receives input. Override with
|
|
51
|
+
* {@link ThreeGeometraStackedHostOptions.geometraHudPointerEvents} (e.g. `'none'` for a click-through HUD) or
|
|
52
|
+
* {@link ThreeGeometraStackedHostOptions.geometraHudZIndex} when you add other positioned siblings.
|
|
41
53
|
*
|
|
42
54
|
* Geometra’s client still uses `resizeTarget: window` by default; when only the HUD box changes size,
|
|
43
55
|
* a coalesced synthetic `resize` is dispatched on `window` (same pattern as {@link createThreeGeometraSplitHost}).
|
|
56
|
+
* `ResizeObserver` callbacks and real `window` `resize` share one rAF-coalesced Three.js buffer pass; the
|
|
57
|
+
* synthetic `resize` is emitted only from observer-driven layout changes, not from real window resizes.
|
|
44
58
|
* The Three.js layer listens to `window` `resize` for `devicePixelRatio` changes and uses the host `root` size
|
|
45
|
-
* for the drawing buffer.
|
|
59
|
+
* for the drawing buffer. Optional {@link ThreeGeometraStackedHostOptions.maxDevicePixelRatio} caps the ratio
|
|
60
|
+
* used for the WebGL buffer.
|
|
46
61
|
*/
|
|
47
62
|
export function createThreeGeometraStackedHost(options) {
|
|
48
|
-
const { container, geometraHudWidth =
|
|
63
|
+
const { container, geometraHudWidth: geometraHudWidthOpt = GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudWidth, geometraHudHeight: geometraHudHeightOpt = GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudHeight, geometraHudPlacement: geometraHudPlacementOpt = GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudPlacement, geometraHudMargin: geometraHudMarginOpt = GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudMargin, geometraHudPointerEvents: geometraHudPointerEventsOpt = 'auto', geometraHudZIndex = 1, maxDevicePixelRatio, threeBackground = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.threeBackground, cameraFov = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraFov, cameraNear = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraNear, cameraFar = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraFar, cameraPosition = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraPosition, onThreeReady, onThreeFrame, window: providedWindow, ...browserOptions } = options;
|
|
64
|
+
const geometraHudWidth = coerceHostNonNegativeCssPx(geometraHudWidthOpt, GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudWidth);
|
|
65
|
+
const geometraHudHeight = coerceHostNonNegativeCssPx(geometraHudHeightOpt, GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudHeight);
|
|
66
|
+
const geometraHudMargin = coerceHostNonNegativeCssPx(geometraHudMarginOpt, GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudMargin);
|
|
67
|
+
const geometraHudPlacement = coerceGeometraHudPlacement(geometraHudPlacementOpt, GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudPlacement);
|
|
68
|
+
const geometraHudPointerEvents = coerceGeometraHudPointerEvents(geometraHudPointerEventsOpt, 'auto');
|
|
49
69
|
const doc = container.ownerDocument;
|
|
50
70
|
const win = providedWindow ?? doc.defaultView;
|
|
51
71
|
if (!win) {
|
|
@@ -70,7 +90,7 @@ export function createThreeGeometraStackedHost(options) {
|
|
|
70
90
|
root.appendChild(threeCanvas);
|
|
71
91
|
const geometraHud = doc.createElement('div');
|
|
72
92
|
geometraHud.style.position = 'absolute';
|
|
73
|
-
geometraHud.style.zIndex =
|
|
93
|
+
geometraHud.style.zIndex = coerceHostStackingZIndexCss(geometraHudZIndex, 1);
|
|
74
94
|
geometraHud.style.width = `${geometraHudWidth}px`;
|
|
75
95
|
geometraHud.style.height = `${geometraHudHeight}px`;
|
|
76
96
|
geometraHud.style.minWidth = '0';
|
|
@@ -82,12 +102,7 @@ export function createThreeGeometraStackedHost(options) {
|
|
|
82
102
|
const geometraCanvas = doc.createElement('canvas');
|
|
83
103
|
fullSizeCanvas(geometraCanvas);
|
|
84
104
|
geometraHud.appendChild(geometraCanvas);
|
|
85
|
-
const glRenderer =
|
|
86
|
-
canvas: threeCanvas,
|
|
87
|
-
antialias: true,
|
|
88
|
-
alpha: false,
|
|
89
|
-
});
|
|
90
|
-
const { scene, camera, clock } = createGeometraThreeSceneBasics({
|
|
105
|
+
const { renderer: glRenderer, scene, camera, clock } = createGeometraThreeWebGLWithSceneBasics(threeCanvas, {
|
|
91
106
|
threeBackground,
|
|
92
107
|
cameraFov,
|
|
93
108
|
cameraNear,
|
|
@@ -95,38 +110,46 @@ export function createThreeGeometraStackedHost(options) {
|
|
|
95
110
|
cameraPosition,
|
|
96
111
|
});
|
|
97
112
|
const resizeThree = () => {
|
|
98
|
-
resizeGeometraThreePerspectiveView(glRenderer, camera, root.clientWidth, root.clientHeight, win.devicePixelRatio || 1);
|
|
113
|
+
resizeGeometraThreePerspectiveView(glRenderer, camera, root.clientWidth, root.clientHeight, resolveHostDevicePixelRatio(win.devicePixelRatio || 1, maxDevicePixelRatio));
|
|
99
114
|
};
|
|
115
|
+
let destroyed = false;
|
|
116
|
+
const layoutSync = createGeometraHostLayoutSyncRaf(win, {
|
|
117
|
+
isDestroyed: () => destroyed,
|
|
118
|
+
syncLayout: resizeThree,
|
|
119
|
+
dispatchGeometraResize: () => {
|
|
120
|
+
win.dispatchEvent(new Event('resize'));
|
|
121
|
+
},
|
|
122
|
+
});
|
|
100
123
|
const onWindowResize = () => {
|
|
101
|
-
|
|
124
|
+
layoutSync.schedule(false);
|
|
102
125
|
};
|
|
103
126
|
win.addEventListener('resize', onWindowResize, { passive: true });
|
|
104
127
|
resizeThree();
|
|
105
|
-
const geometraHandle =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
const geometraHandle = (() => {
|
|
129
|
+
try {
|
|
130
|
+
return createBrowserCanvasClient({
|
|
131
|
+
...browserOptions,
|
|
132
|
+
canvas: geometraCanvas,
|
|
133
|
+
window: win,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
layoutSync.cancel();
|
|
138
|
+
win.removeEventListener('resize', onWindowResize);
|
|
139
|
+
disposeGeometraThreeWebGLWithSceneBasics({ renderer: glRenderer, clock });
|
|
140
|
+
root.remove();
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
})();
|
|
119
144
|
const roRoot = new ResizeObserver(() => {
|
|
120
|
-
|
|
121
|
-
triggerGeometraResize();
|
|
145
|
+
layoutSync.schedule(true);
|
|
122
146
|
});
|
|
123
147
|
roRoot.observe(root);
|
|
124
148
|
const roHud = new ResizeObserver(() => {
|
|
125
|
-
|
|
149
|
+
layoutSync.schedule(true);
|
|
126
150
|
});
|
|
127
151
|
roHud.observe(geometraHud);
|
|
128
152
|
let rafId;
|
|
129
|
-
let destroyed = false;
|
|
130
153
|
const destroy = () => {
|
|
131
154
|
if (destroyed)
|
|
132
155
|
return;
|
|
@@ -135,15 +158,12 @@ export function createThreeGeometraStackedHost(options) {
|
|
|
135
158
|
win.cancelAnimationFrame(rafId);
|
|
136
159
|
rafId = undefined;
|
|
137
160
|
}
|
|
138
|
-
|
|
139
|
-
win.cancelAnimationFrame(geometraResizeRafId);
|
|
140
|
-
geometraResizeRafId = undefined;
|
|
141
|
-
}
|
|
161
|
+
layoutSync.cancel();
|
|
142
162
|
win.removeEventListener('resize', onWindowResize);
|
|
143
163
|
roRoot.disconnect();
|
|
144
164
|
roHud.disconnect();
|
|
145
165
|
geometraHandle.destroy();
|
|
146
|
-
glRenderer
|
|
166
|
+
disposeGeometraThreeWebGLWithSceneBasics({ renderer: glRenderer, clock });
|
|
147
167
|
root.remove();
|
|
148
168
|
};
|
|
149
169
|
const ctxBase = {
|
|
@@ -153,14 +173,30 @@ export function createThreeGeometraStackedHost(options) {
|
|
|
153
173
|
threeCanvas,
|
|
154
174
|
destroy,
|
|
155
175
|
};
|
|
156
|
-
|
|
176
|
+
try {
|
|
177
|
+
onThreeReady?.(ctxBase);
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
destroy();
|
|
181
|
+
throw err;
|
|
182
|
+
}
|
|
157
183
|
const loop = () => {
|
|
158
184
|
if (destroyed)
|
|
159
185
|
return;
|
|
160
186
|
rafId = win.requestAnimationFrame(loop);
|
|
161
187
|
const delta = clock.getDelta();
|
|
162
188
|
const elapsed = clock.elapsedTime;
|
|
163
|
-
|
|
189
|
+
try {
|
|
190
|
+
if (onThreeFrame?.({ ...ctxBase, clock, delta, elapsed }) === false) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
destroy();
|
|
196
|
+
throw err;
|
|
197
|
+
}
|
|
198
|
+
if (destroyed)
|
|
199
|
+
return;
|
|
164
200
|
glRenderer.render(scene, camera);
|
|
165
201
|
};
|
|
166
202
|
if (!destroyed) {
|