@particle-academy/fancy-3d-three 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/engine.cjs +80 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +5 -0
- package/dist/engine.d.ts +5 -0
- package/dist/engine.js +58 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.cjs +788 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +283 -0
- package/dist/index.d.ts +283 -0
- package/dist/index.js +744 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +333 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +64 -0
- package/dist/react.d.ts +64 -0
- package/dist/react.js +309 -0
- package/dist/react.js.map +1 -0
- package/package.json +94 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Particle Academy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @particle-academy/fancy-3d-three
|
|
2
|
+
|
|
3
|
+
three.js adapter for [`@particle-academy/fancy-3d`](https://www.npmjs.com/package/@particle-academy/fancy-3d).
|
|
4
|
+
|
|
5
|
+
`fancy-3d` ships an engine-agnostic core (Scene types + a `CanvasEngine` interface + a DOM/CSS-3D renderer). This package adds a full WebGL renderer on top with **three.js**, plus the React components that mount onto a three `Scene`: `Stage`, `Monitor`, primitives (`Card3D`, `Monitor`, `Panel`, `Sign`, …), and layout helpers (`placeOnGrid`, `placeOnArc`, `placeOnWall`, `placeOnSphere`, `placeOnPath`).
|
|
6
|
+
|
|
7
|
+
It's the three.js sibling of `@particle-academy/fancy-3d-babylon` — same API surface (`createThreeAdapter`/`createBabylonAdapter`, the same primitive + layout functions, the same `<Stage>`/`<Monitor>`), so a scene authored for one renders recognizably on the other. They implement the same `CanvasEngine` interface from the core and don't depend on each other.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @particle-academy/fancy-3d @particle-academy/fancy-3d-three three
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You install three packages together: the core (types + `<Canvas>`), this adapter, and three.js itself. None pull in the others, so the core stays lightweight for non-three consumers.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Mount the three engine on `<Canvas>`
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { Canvas } from "@particle-academy/fancy-3d";
|
|
23
|
+
import { threeEngine } from "@particle-academy/fancy-3d-three/engine";
|
|
24
|
+
|
|
25
|
+
<Canvas engine={threeEngine} style={{ height: 480 }} />;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`EngineHandle.root` is the live `THREE.Scene` — add meshes to it alongside the 2D node graph.
|
|
29
|
+
|
|
30
|
+
### Declarative `<Stage>` + `<Monitor>` (mount mode)
|
|
31
|
+
|
|
32
|
+
Render **real, interactive React** onto a 3D display — full text crispness, accessibility, and event handling (not a rasterized texture):
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { Stage, Monitor } from "@particle-academy/fancy-3d-three/react";
|
|
36
|
+
import { Card, Button } from "@particle-academy/react-fancy";
|
|
37
|
+
|
|
38
|
+
<Stage style={{ height: 520 }}>
|
|
39
|
+
<Monitor position={[0, 1.6, 0]} width={4} height={2.4} bezel="#0b0f17">
|
|
40
|
+
<Card>
|
|
41
|
+
<Card.Header>Live dashboard</Card.Header>
|
|
42
|
+
<Card.Body>
|
|
43
|
+
<Button color="violet">Real, clickable React on a 3D screen</Button>
|
|
44
|
+
</Card.Body>
|
|
45
|
+
</Card>
|
|
46
|
+
</Monitor>
|
|
47
|
+
</Stage>;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`<Stage>` owns the renderer + `OrbitControls` camera + render loop. `<Monitor>` builds a bezel mesh and projects its corners to screen space each frame, mapping a DOM overlay onto the 3D quad via a CSS `matrix3d` homography.
|
|
51
|
+
|
|
52
|
+
### Painted scenes (texture mode)
|
|
53
|
+
|
|
54
|
+
Render a JSON `Scene` to textured planes:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { renderScene, type Scene } from "@particle-academy/fancy-3d";
|
|
58
|
+
import { createThreeAdapter, placeOnArc, sceneBounds } from "@particle-academy/fancy-3d-three";
|
|
59
|
+
import * as THREE from "three";
|
|
60
|
+
|
|
61
|
+
const scene3D = new THREE.Scene();
|
|
62
|
+
const adapter = createThreeAdapter({ scene3D, sizeFor: () => ({ w: 240, h: 150 }) });
|
|
63
|
+
const bounds = sceneBounds(scene);
|
|
64
|
+
renderScene(scene, adapter, (node) => ({ nodeId: node.id, selected: false })).forEach(({ node, rendered }) => {
|
|
65
|
+
placeOnArc(node, rendered, bounds, { radius: 6 });
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Primitives
|
|
70
|
+
|
|
71
|
+
Build content-bearing meshes directly. Each takes a `SurfaceContent` (`{ type: "color" }`, `{ type: "paint" }`, or `{ type: "widget" }`) and returns a `THREE.Mesh` (or a `Group` for composites). Pass `scene` to also add it.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { createCard3D, createMonitor, createSign, createCurvedPanel } from "@particle-academy/fancy-3d-three";
|
|
75
|
+
|
|
76
|
+
const card = createCard3D({ scene, width: 3, height: 2, front: { type: "widget", widget: kpi } });
|
|
77
|
+
const { root } = createMonitor({ scene, width: 4, height: 2.5, screen: { type: "paint", paint } });
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Available: `createPanel`, `createBillboard`, `createBuilding`, `createPillar`, `createCylinder`, `createCurvedPanel`, `createSphere`, `createDisc`, `createCard3D`, `createSign`, `createMonitor`, `createDecal`, `createWidgetTexture`.
|
|
81
|
+
|
|
82
|
+
### Layouts
|
|
83
|
+
|
|
84
|
+
Map 2D scene positions onto 3D arrangements: `placeOnGrid`, `placeOnWall`, `placeOnArc` (alias `placeOnCylinder`), `placeOnPath`, `placeOnSphere`. Each mutates `obj.position` / `obj.rotation` in place; pair with `sceneBounds(scene)`.
|
|
85
|
+
|
|
86
|
+
## Notes vs. the Babylon adapter
|
|
87
|
+
|
|
88
|
+
- `scene` is **optional** on primitives (three meshes exist independent of a scene); pass it to auto-add, matching Babylon's behavior.
|
|
89
|
+
- `createBillboard({ faceCamera: true })` flags the mesh (`userData.faceCamera`); `<Stage>` honors it each frame. Outside a Stage, call `mesh.lookAt(camera.position)` in your own loop.
|
|
90
|
+
- Panels accept `doubleSided?: boolean` instead of Babylon's `sideOrientation` enum.
|
|
91
|
+
- `@types/three` is a dev-only dependency (three ships no declarations); consumers don't need it at runtime.
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|
package/dist/engine.cjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var THREE = require('three');
|
|
4
|
+
|
|
5
|
+
function _interopNamespace(e) {
|
|
6
|
+
if (e && e.__esModule) return e;
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
24
|
+
|
|
25
|
+
// src/engine.ts
|
|
26
|
+
var threeEngine = {
|
|
27
|
+
name: "three",
|
|
28
|
+
mount(host, _viewport) {
|
|
29
|
+
const renderer = new THREE__namespace.WebGLRenderer({ alpha: true, antialias: true, preserveDrawingBuffer: true });
|
|
30
|
+
renderer.setPixelRatio(window.devicePixelRatio || 1);
|
|
31
|
+
const overlay = renderer.domElement;
|
|
32
|
+
overlay.style.position = "absolute";
|
|
33
|
+
overlay.style.inset = "0";
|
|
34
|
+
overlay.style.width = "100%";
|
|
35
|
+
overlay.style.height = "100%";
|
|
36
|
+
overlay.style.pointerEvents = "none";
|
|
37
|
+
overlay.dataset.fancy3dCanvasEngine = "three";
|
|
38
|
+
host.appendChild(overlay);
|
|
39
|
+
const scene = new THREE__namespace.Scene();
|
|
40
|
+
const camera = new THREE__namespace.PerspectiveCamera(50, 1, 0.1, 1e3);
|
|
41
|
+
camera.position.set(0, 0, 8);
|
|
42
|
+
camera.lookAt(0, 0, 0);
|
|
43
|
+
const hemi = new THREE__namespace.HemisphereLight(11781887, 1710638, 1);
|
|
44
|
+
scene.add(hemi);
|
|
45
|
+
const resize = () => {
|
|
46
|
+
const w = host.clientWidth || 1;
|
|
47
|
+
const h = host.clientHeight || 1;
|
|
48
|
+
renderer.setSize(w, h, false);
|
|
49
|
+
camera.aspect = w / h;
|
|
50
|
+
camera.updateProjectionMatrix();
|
|
51
|
+
};
|
|
52
|
+
resize();
|
|
53
|
+
const ro = new ResizeObserver(resize);
|
|
54
|
+
ro.observe(host);
|
|
55
|
+
let raf = 0;
|
|
56
|
+
const loop = () => {
|
|
57
|
+
raf = requestAnimationFrame(loop);
|
|
58
|
+
renderer.render(scene, camera);
|
|
59
|
+
};
|
|
60
|
+
loop();
|
|
61
|
+
function updateViewport(_v) {
|
|
62
|
+
}
|
|
63
|
+
function dispose() {
|
|
64
|
+
cancelAnimationFrame(raf);
|
|
65
|
+
ro.disconnect();
|
|
66
|
+
renderer.dispose();
|
|
67
|
+
if (overlay.parentElement === host) host.removeChild(overlay);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
name: "three",
|
|
71
|
+
root: scene,
|
|
72
|
+
updateViewport,
|
|
73
|
+
dispose
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.threeEngine = threeEngine;
|
|
79
|
+
//# sourceMappingURL=engine.cjs.map
|
|
80
|
+
//# sourceMappingURL=engine.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine.ts"],"names":["THREE"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgBO,IAAM,WAAA,GAA4B;AAAA,EACvC,IAAA,EAAM,OAAA;AAAA,EACN,KAAA,CAAM,MAAmB,SAAA,EAAwC;AAC/D,IAAA,MAAM,QAAA,G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G,CAAA,EAAG,KAAK,CAAA;AAC5B,MAAA,MAAA,CAAO,SAAS,CAAA,GAAI,CAAA;AACpB,MAAA,MAAA,CAAO,sBAAA,EAAuB;AAAA,IAChC,CAAA;AACA,IAAA,MAAA,EAAO;AACP,IAAA,MAAM,EAAA,GAAK,IAAI,cAAA,CAAe,MAAM,CAAA;AACpC,IAAA,EAAA,CAAG,QAAQ,IAAI,CAAA;AAEf,IAAA,IAAI,GAAA,GAAM,CAAA;AACV,IAAA,MAAM,OAAO,MAAM;AACjB,MAAA,GAAA,GAAM,sBAAsB,IAAI,CAAA;AAChC,MAAA,QAAA,CAAS,MAAA,CAAO,OAAO,MAAM,CAAA;AAAA,IAC/B,CAAA;AACA,IAAA,IAAA,EAAK;AAEL,IAAA,SAAS,eAAe,EAAA,EAAmB;AAAA,IAG3C;AAEA,IAAA,SAAS,OAAA,GAAU;AACjB,MAAA,oBAAA,CAAqB,GAAG,CAAA;AACxB,MAAA,EAAA,CAAG,UAAA,EAAW;AACd,MAAA,QAAA,CAAS,OAAA,EAAQ;AACjB,MAAA,IAAI,OAAA,CAAQ,aAAA,KAAkB,IAAA,EAAM,IAAA,CAAK,YAAY,OAAO,CAAA;AAAA,IAC9D;AAEA,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,OAAA;AAAA,MACN,IAAA,EAAM,KAAA;AAAA,MACN,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"engine.cjs","sourcesContent":["/**\n * three.js engine adapter for `@particle-academy/fancy-3d`'s <Canvas>.\n *\n * Mounts a three `WebGLRenderer` + `Scene` + camera into a `<canvas>` overlaid\n * on the Canvas DOM container, then exposes the live `Scene` via\n * `EngineHandle.root` so child components can register meshes alongside the 2D\n * node graph.\n *\n * import { Canvas } from \"@particle-academy/fancy-3d\";\n * import { threeEngine } from \"@particle-academy/fancy-3d-three/engine\";\n *\n * <Canvas engine={threeEngine} style={{ height: 480 }} />\n */\nimport * as THREE from \"three\";\nimport type { CanvasEngine, EngineHandle, ViewportState } from \"@particle-academy/fancy-3d\";\n\nexport const threeEngine: CanvasEngine = {\n name: \"three\",\n mount(host: HTMLElement, _viewport: ViewportState): EngineHandle {\n const renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true, preserveDrawingBuffer: true });\n renderer.setPixelRatio(window.devicePixelRatio || 1);\n const overlay = renderer.domElement;\n overlay.style.position = \"absolute\";\n overlay.style.inset = \"0\";\n overlay.style.width = \"100%\";\n overlay.style.height = \"100%\";\n overlay.style.pointerEvents = \"none\"; // the 2D node graph owns interaction\n overlay.dataset.fancy3dCanvasEngine = \"three\";\n host.appendChild(overlay);\n\n const scene = new THREE.Scene();\n const camera = new THREE.PerspectiveCamera(50, 1, 0.1, 1000);\n camera.position.set(0, 0, 8);\n camera.lookAt(0, 0, 0);\n\n const hemi = new THREE.HemisphereLight(0xb3c6ff, 0x1a1a2e, 1.0);\n scene.add(hemi);\n\n const resize = () => {\n const w = host.clientWidth || 1;\n const h = host.clientHeight || 1;\n renderer.setSize(w, h, false);\n camera.aspect = w / h;\n camera.updateProjectionMatrix();\n };\n resize();\n const ro = new ResizeObserver(resize);\n ro.observe(host);\n\n let raf = 0;\n const loop = () => {\n raf = requestAnimationFrame(loop);\n renderer.render(scene, camera);\n };\n loop();\n\n function updateViewport(_v: ViewportState) {\n // The 3D camera owns its own view; 2D viewport changes are observed but\n // don't move the camera. Consumers can drive the camera off the scene.\n }\n\n function dispose() {\n cancelAnimationFrame(raf);\n ro.disconnect();\n renderer.dispose();\n if (overlay.parentElement === host) host.removeChild(overlay);\n }\n\n return {\n name: \"three\",\n root: scene,\n updateViewport,\n dispose,\n };\n },\n};\n"]}
|
package/dist/engine.d.ts
ADDED
package/dist/engine.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
// src/engine.ts
|
|
4
|
+
var threeEngine = {
|
|
5
|
+
name: "three",
|
|
6
|
+
mount(host, _viewport) {
|
|
7
|
+
const renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true, preserveDrawingBuffer: true });
|
|
8
|
+
renderer.setPixelRatio(window.devicePixelRatio || 1);
|
|
9
|
+
const overlay = renderer.domElement;
|
|
10
|
+
overlay.style.position = "absolute";
|
|
11
|
+
overlay.style.inset = "0";
|
|
12
|
+
overlay.style.width = "100%";
|
|
13
|
+
overlay.style.height = "100%";
|
|
14
|
+
overlay.style.pointerEvents = "none";
|
|
15
|
+
overlay.dataset.fancy3dCanvasEngine = "three";
|
|
16
|
+
host.appendChild(overlay);
|
|
17
|
+
const scene = new THREE.Scene();
|
|
18
|
+
const camera = new THREE.PerspectiveCamera(50, 1, 0.1, 1e3);
|
|
19
|
+
camera.position.set(0, 0, 8);
|
|
20
|
+
camera.lookAt(0, 0, 0);
|
|
21
|
+
const hemi = new THREE.HemisphereLight(11781887, 1710638, 1);
|
|
22
|
+
scene.add(hemi);
|
|
23
|
+
const resize = () => {
|
|
24
|
+
const w = host.clientWidth || 1;
|
|
25
|
+
const h = host.clientHeight || 1;
|
|
26
|
+
renderer.setSize(w, h, false);
|
|
27
|
+
camera.aspect = w / h;
|
|
28
|
+
camera.updateProjectionMatrix();
|
|
29
|
+
};
|
|
30
|
+
resize();
|
|
31
|
+
const ro = new ResizeObserver(resize);
|
|
32
|
+
ro.observe(host);
|
|
33
|
+
let raf = 0;
|
|
34
|
+
const loop = () => {
|
|
35
|
+
raf = requestAnimationFrame(loop);
|
|
36
|
+
renderer.render(scene, camera);
|
|
37
|
+
};
|
|
38
|
+
loop();
|
|
39
|
+
function updateViewport(_v) {
|
|
40
|
+
}
|
|
41
|
+
function dispose() {
|
|
42
|
+
cancelAnimationFrame(raf);
|
|
43
|
+
ro.disconnect();
|
|
44
|
+
renderer.dispose();
|
|
45
|
+
if (overlay.parentElement === host) host.removeChild(overlay);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
name: "three",
|
|
49
|
+
root: scene,
|
|
50
|
+
updateViewport,
|
|
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ACF","file":"engine.js","sourcesContent":["/**\n * three.js engine adapter for `@particle-academy/fancy-3d`'s <Canvas>.\n *\n * Mounts a three `WebGLRenderer` + `Scene` + camera into a `<canvas>` overlaid\n * on the Canvas DOM container, then exposes the live `Scene` via\n * `EngineHandle.root` so child components can register meshes alongside the 2D\n * node graph.\n *\n * import { Canvas } from \"@particle-academy/fancy-3d\";\n * import { threeEngine } from \"@particle-academy/fancy-3d-three/engine\";\n *\n * <Canvas engine={threeEngine} style={{ height: 480 }} />\n */\nimport * as THREE from \"three\";\nimport type { CanvasEngine, EngineHandle, ViewportState } from \"@particle-academy/fancy-3d\";\n\nexport const threeEngine: CanvasEngine = {\n name: \"three\",\n mount(host: HTMLElement, _viewport: ViewportState): EngineHandle {\n const renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true, preserveDrawingBuffer: true });\n renderer.setPixelRatio(window.devicePixelRatio || 1);\n const overlay = renderer.domElement;\n overlay.style.position = \"absolute\";\n overlay.style.inset = \"0\";\n overlay.style.width = \"100%\";\n overlay.style.height = \"100%\";\n overlay.style.pointerEvents = \"none\"; // the 2D node graph owns interaction\n overlay.dataset.fancy3dCanvasEngine = \"three\";\n host.appendChild(overlay);\n\n const scene = new THREE.Scene();\n const camera = new THREE.PerspectiveCamera(50, 1, 0.1, 1000);\n camera.position.set(0, 0, 8);\n camera.lookAt(0, 0, 0);\n\n const hemi = new THREE.HemisphereLight(0xb3c6ff, 0x1a1a2e, 1.0);\n scene.add(hemi);\n\n const resize = () => {\n const w = host.clientWidth || 1;\n const h = host.clientHeight || 1;\n renderer.setSize(w, h, false);\n camera.aspect = w / h;\n camera.updateProjectionMatrix();\n };\n resize();\n const ro = new ResizeObserver(resize);\n ro.observe(host);\n\n let raf = 0;\n const loop = () => {\n raf = requestAnimationFrame(loop);\n renderer.render(scene, camera);\n };\n loop();\n\n function updateViewport(_v: ViewportState) {\n // The 3D camera owns its own view; 2D viewport changes are observed but\n // don't move the camera. Consumers can drive the camera off the scene.\n }\n\n function dispose() {\n cancelAnimationFrame(raf);\n ro.disconnect();\n renderer.dispose();\n if (overlay.parentElement === host) host.removeChild(overlay);\n }\n\n return {\n name: \"three\",\n root: scene,\n updateViewport,\n dispose,\n };\n },\n};\n"]}
|