@particle-academy/fancy-3d-babylon 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/README.md +64 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/engine.cjs +59 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +19 -0
- package/dist/engine.d.ts +19 -0
- package/dist/engine.js +52 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.cjs +861 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +323 -0
- package/dist/index.d.ts +323 -0
- package/dist/index.js +836 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +315 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +60 -0
- package/dist/react.d.ts +60 -0
- package/dist/react.js +311 -0
- package/dist/react.js.map +1 -0
- package/package.json +92 -0
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @particle-academy/fancy-3d-babylon
|
|
2
|
+
|
|
3
|
+
Babylon.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, plus the React components that mount onto a Babylon `Scene`: `Stage`, `Monitor`, `Card3D`, `Screen`, primitives, and layout helpers (`placeOnGrid`, `placeOnArc`, `placeOnWall`, `placeOnSphere`, `placeOnPath`).
|
|
6
|
+
|
|
7
|
+
> A Three.js / WebGPU / WebXR engine could ship as a sibling package: `fancy-3d-three`, `fancy-3d-webgpu`, etc. They implement the same `CanvasEngine` interface from the core; they don't depend on this one.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @particle-academy/fancy-3d @particle-academy/fancy-3d-babylon @babylonjs/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You always install three packages together: the core (types + `<Canvas>`), the Babylon adapter (this package), and Babylon itself. None of them pull in the others to keep the core lightweight for non-Babylon consumers.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Mount the Babylon engine on `<Canvas>`
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { Canvas } from "@particle-academy/fancy-3d";
|
|
23
|
+
import { babylonEngine } from "@particle-academy/fancy-3d-babylon/engine";
|
|
24
|
+
|
|
25
|
+
<Canvas engine={babylonEngine} style={{ height: 480 }}>
|
|
26
|
+
{/* 2D children are still allowed — Canvas hosts a DOM overlay
|
|
27
|
+
alongside the WebGL view */}
|
|
28
|
+
</Canvas>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Stage / Monitor / Card3D (React)
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { Stage, Monitor, Card3D } from "@particle-academy/fancy-3d-babylon/react";
|
|
35
|
+
import { Card } from "@particle-academy/react-fancy";
|
|
36
|
+
|
|
37
|
+
<Stage camera={{ position: [0, 2, 5], target: [0, 0, 0] }}>
|
|
38
|
+
<Monitor width={2} height={1.2} position={[0, 1, 0]}>
|
|
39
|
+
<Card>
|
|
40
|
+
<Card.Body>This react-fancy card renders as a live WebGL texture.</Card.Body>
|
|
41
|
+
</Card>
|
|
42
|
+
</Monitor>
|
|
43
|
+
<Card3D position={[2, 0, 0]} rotation={[0, 30, 0]}>
|
|
44
|
+
<h3>Children are plain React</h3>
|
|
45
|
+
</Card3D>
|
|
46
|
+
</Stage>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Layout helpers
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { placeOnGrid, placeOnArc } from "@particle-academy/fancy-3d-babylon";
|
|
53
|
+
|
|
54
|
+
placeOnGrid(node, mesh, bounds, { cols: 4, gapX: 0.2, gapY: 0.2 });
|
|
55
|
+
placeOnArc(node, mesh, bounds, { radius: 3, startAngle: 0, endAngle: Math.PI });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Why a separate package?
|
|
59
|
+
|
|
60
|
+
The core `fancy-3d` is engine-agnostic and lightweight (~80KB). Pulling in Babylon would force every consumer — including ones using only the DOM engine or shipping a custom Three.js adapter — to bundle ~13MB of WebGL runtime they don't use. The split keeps Babylon's cost paid only by Babylon consumers.
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export { __require };
|
|
9
|
+
//# sourceMappingURL=chunk-DGUM43GV.js.map
|
|
10
|
+
//# sourceMappingURL=chunk-DGUM43GV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-DGUM43GV.js"}
|
package/dist/engine.cjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/engine.ts
|
|
11
|
+
var babylonEngine = {
|
|
12
|
+
name: "babylon",
|
|
13
|
+
mount(host, viewport) {
|
|
14
|
+
const BABYLON = __require("@babylonjs/core");
|
|
15
|
+
const overlay = document.createElement("canvas");
|
|
16
|
+
overlay.style.position = "absolute";
|
|
17
|
+
overlay.style.inset = "0";
|
|
18
|
+
overlay.style.width = "100%";
|
|
19
|
+
overlay.style.height = "100%";
|
|
20
|
+
overlay.style.pointerEvents = "none";
|
|
21
|
+
overlay.dataset.fancy3dCanvasEngine = "babylon";
|
|
22
|
+
host.appendChild(overlay);
|
|
23
|
+
const engine = new BABYLON.Engine(overlay, true, { preserveDrawingBuffer: true, stencil: true });
|
|
24
|
+
const scene = new BABYLON.Scene(engine);
|
|
25
|
+
scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
|
|
26
|
+
const camera = new BABYLON.ArcRotateCamera(
|
|
27
|
+
"fancy3d-canvas-camera",
|
|
28
|
+
Math.PI / 2,
|
|
29
|
+
Math.PI / 2.5,
|
|
30
|
+
8,
|
|
31
|
+
BABYLON.Vector3.Zero(),
|
|
32
|
+
scene
|
|
33
|
+
);
|
|
34
|
+
camera.attachControl(overlay, false);
|
|
35
|
+
new BABYLON.HemisphericLight("fancy3d-canvas-light", new BABYLON.Vector3(0, 1, 0), scene);
|
|
36
|
+
const observer = engine.runRenderLoop(() => scene.render());
|
|
37
|
+
function updateViewport(_v) {
|
|
38
|
+
}
|
|
39
|
+
function dispose() {
|
|
40
|
+
try {
|
|
41
|
+
engine.stopRenderLoop(observer);
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
scene.dispose();
|
|
45
|
+
engine.dispose();
|
|
46
|
+
if (overlay.parentElement === host) host.removeChild(overlay);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
name: "babylon",
|
|
50
|
+
root: scene,
|
|
51
|
+
updateViewport,
|
|
52
|
+
dispose
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
exports.babylonEngine = babylonEngine;
|
|
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AQ,IAAA,EAAK;AAAA,MACrB;AAAA,KACF;AACA,IAAA,MAAA,CAAO,aAAA,CAAc,SAAS,KAAK,CAAA;AACnC,IAAA,IAAI,OAAA,CAAQ,gBAAA,CAAiB,sBAAA,EAAwB,IAAI,OAAA,CAAQ,QAAQ,CAAA,EAAG,CAAA,EAAG,CAAC,CAAA,EAAG,KAAK,CAAA;AAExF,IAAA,MAAM,WAAW,MAAA,CAAO,aAAA,CAAc,MAAM,KAAA,CAAM,QAAQ,CAAA;AAE1D,IAAA,SAAS,eAAe,EAAA,EAAmB;AAAA,IAI3C;AAEA,IAAA,SAAS,OAAA,GAAU;AACjB,MAAA,IAAI;AAAE,QAAA,MAAA,CAAO,eAAe,QAAe,CAAA;AAAA,MAAG,CAAA,CAAA,MAAQ;AAAA,MAAC;AACvD,MAAA,KAAA,CAAM,OAAA,EAAQ;AACd,MAAA,MAAA,CAAO,OAAA,EAAQ;AACf,MAAA,IAAI,OAAA,CAAQ,aAAA,KAAkB,IAAA,EAAM,IAAA,CAAK,YAAY,OAAO,CAAA;AAAA,IAC9D;AAEA,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,SAAA;AAAA,MACN,IAAA,EAAM,KAAA;AAAA,MACN,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"engine.cjs","sourcesContent":["/**\n * Babylon engine adapter for `@particle-academy/fancy-3d`'s <Canvas>.\n *\n * Mounts a Babylon `Engine` + `Scene` + camera into a `<canvas>` element\n * overlaid on the Canvas DOM container, then exposes the live `Scene` via\n * `EngineHandle.root` so child components can register meshes alongside the\n * 2D node graph.\n *\n * import { Canvas } from \"@particle-academy/fancy-3d\";\n * import { babylonEngine } from \"@particle-academy/fancy-3d-babylon/engine\";\n *\n * <Canvas engine={babylonEngine} style={{ height: 480 }} />\n */\nimport type { CanvasEngine, EngineHandle, ViewportState } from \"@particle-academy/fancy-3d\";\n\n// Declare a CJS-style `require` so the dts compiler doesn't reject the lazy\n// load below. Browsers don't have `require`, but this whole engine adapter\n// only runs when a host bundler (vite/webpack) replaces the call with its own\n// lazy-module shim, or under node-side SSR where the global exists.\ndeclare const require: (specifier: string) => unknown;\n\nexport const babylonEngine: CanvasEngine = {\n name: \"babylon\",\n mount(host: HTMLElement, viewport: ViewportState): EngineHandle {\n // Lazy require so non-babylon Canvas users don't pay the parse cost.\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const BABYLON: any = require(\"@babylonjs/core\");\n\n const overlay = document.createElement(\"canvas\");\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\";\n overlay.dataset.fancy3dCanvasEngine = \"babylon\";\n host.appendChild(overlay);\n\n const engine = new BABYLON.Engine(overlay, true, { preserveDrawingBuffer: true, stencil: true });\n const scene = new BABYLON.Scene(engine);\n scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);\n\n const camera = new BABYLON.ArcRotateCamera(\n \"fancy3d-canvas-camera\",\n Math.PI / 2,\n Math.PI / 2.5,\n 8,\n BABYLON.Vector3.Zero(),\n scene,\n );\n camera.attachControl(overlay, false);\n new BABYLON.HemisphericLight(\"fancy3d-canvas-light\", new BABYLON.Vector3(0, 1, 0), scene);\n\n const observer = engine.runRenderLoop(() => scene.render());\n\n function updateViewport(_v: ViewportState) {\n // Default: 6DoF camera owns view; 2D viewport changes are observed\n // but don't move the Babylon camera. Consumers can override by\n // attaching their own observers to the scene.\n }\n\n function dispose() {\n try { engine.stopRenderLoop(observer as any); } catch {}\n scene.dispose();\n engine.dispose();\n if (overlay.parentElement === host) host.removeChild(overlay);\n }\n\n return {\n name: \"babylon\",\n root: scene,\n updateViewport,\n dispose,\n };\n },\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CanvasEngine } from '@particle-academy/fancy-3d';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Babylon engine adapter for `@particle-academy/fancy-3d`'s <Canvas>.
|
|
5
|
+
*
|
|
6
|
+
* Mounts a Babylon `Engine` + `Scene` + camera into a `<canvas>` element
|
|
7
|
+
* overlaid on the Canvas DOM container, then exposes the live `Scene` via
|
|
8
|
+
* `EngineHandle.root` so child components can register meshes alongside the
|
|
9
|
+
* 2D node graph.
|
|
10
|
+
*
|
|
11
|
+
* import { Canvas } from "@particle-academy/fancy-3d";
|
|
12
|
+
* import { babylonEngine } from "@particle-academy/fancy-3d-babylon/engine";
|
|
13
|
+
*
|
|
14
|
+
* <Canvas engine={babylonEngine} style={{ height: 480 }} />
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
declare const babylonEngine: CanvasEngine;
|
|
18
|
+
|
|
19
|
+
export { babylonEngine };
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CanvasEngine } from '@particle-academy/fancy-3d';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Babylon engine adapter for `@particle-academy/fancy-3d`'s <Canvas>.
|
|
5
|
+
*
|
|
6
|
+
* Mounts a Babylon `Engine` + `Scene` + camera into a `<canvas>` element
|
|
7
|
+
* overlaid on the Canvas DOM container, then exposes the live `Scene` via
|
|
8
|
+
* `EngineHandle.root` so child components can register meshes alongside the
|
|
9
|
+
* 2D node graph.
|
|
10
|
+
*
|
|
11
|
+
* import { Canvas } from "@particle-academy/fancy-3d";
|
|
12
|
+
* import { babylonEngine } from "@particle-academy/fancy-3d-babylon/engine";
|
|
13
|
+
*
|
|
14
|
+
* <Canvas engine={babylonEngine} style={{ height: 480 }} />
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
declare const babylonEngine: CanvasEngine;
|
|
18
|
+
|
|
19
|
+
export { babylonEngine };
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { __require } from './chunk-DGUM43GV.js';
|
|
2
|
+
|
|
3
|
+
// src/engine.ts
|
|
4
|
+
var babylonEngine = {
|
|
5
|
+
name: "babylon",
|
|
6
|
+
mount(host, viewport) {
|
|
7
|
+
const BABYLON = __require("@babylonjs/core");
|
|
8
|
+
const overlay = document.createElement("canvas");
|
|
9
|
+
overlay.style.position = "absolute";
|
|
10
|
+
overlay.style.inset = "0";
|
|
11
|
+
overlay.style.width = "100%";
|
|
12
|
+
overlay.style.height = "100%";
|
|
13
|
+
overlay.style.pointerEvents = "none";
|
|
14
|
+
overlay.dataset.fancy3dCanvasEngine = "babylon";
|
|
15
|
+
host.appendChild(overlay);
|
|
16
|
+
const engine = new BABYLON.Engine(overlay, true, { preserveDrawingBuffer: true, stencil: true });
|
|
17
|
+
const scene = new BABYLON.Scene(engine);
|
|
18
|
+
scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
|
|
19
|
+
const camera = new BABYLON.ArcRotateCamera(
|
|
20
|
+
"fancy3d-canvas-camera",
|
|
21
|
+
Math.PI / 2,
|
|
22
|
+
Math.PI / 2.5,
|
|
23
|
+
8,
|
|
24
|
+
BABYLON.Vector3.Zero(),
|
|
25
|
+
scene
|
|
26
|
+
);
|
|
27
|
+
camera.attachControl(overlay, false);
|
|
28
|
+
new BABYLON.HemisphericLight("fancy3d-canvas-light", new BABYLON.Vector3(0, 1, 0), scene);
|
|
29
|
+
const observer = engine.runRenderLoop(() => scene.render());
|
|
30
|
+
function updateViewport(_v) {
|
|
31
|
+
}
|
|
32
|
+
function dispose() {
|
|
33
|
+
try {
|
|
34
|
+
engine.stopRenderLoop(observer);
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
scene.dispose();
|
|
38
|
+
engine.dispose();
|
|
39
|
+
if (overlay.parentElement === host) host.removeChild(overlay);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
name: "babylon",
|
|
43
|
+
root: scene,
|
|
44
|
+
updateViewport,
|
|
45
|
+
dispose
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { babylonEngine };
|
|
51
|
+
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A,MACrB;AAAA,KACF;AACA,IAAA,MAAA,CAAO,aAAA,CAAc,SAAS,KAAK,CAAA;AACnC,IAAA,IAAI,OAAA,CAAQ,gBAAA,CAAiB,sBAAA,EAAwB,IAAI,OAAA,CAAQ,QAAQ,CAAA,EAAG,CAAA,EAAG,CAAC,CAAA,EAAG,KAAK,CAAA;AAExF,IAAA,MAAM,WAAW,MAAA,CAAO,aAAA,CAAc,MAAM,KAAA,CAAM,QAAQ,CAAA;AAE1D,IAAA,SAAS,eAAe,EAAA,EAAmB;AAAA,IAI3C;AAEA,IAAA,SAAS,OAAA,GAAU;AACjB,MAAA,IAAI;AAAE,QAAA,MAAA,CAAO,eAAe,QAAe,CAAA;AAAA,MAAG,CAAA,CAAA,MAAQ;AAAA,MAAC;AACvD,MAAA,KAAA,CAAM,OAAA,EAAQ;AACd,MAAA,MAAA,CAAO,OAAA,EAAQ;AACf,MAAA,IAAI,OAAA,CAAQ,aAAA,KAAkB,IAAA,EAAM,IAAA,CAAK,YAAY,OAAO,CAAA;AAAA,IAC9D;AAEA,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,SAAA;AAAA,MACN,IAAA,EAAM,KAAA;AAAA,MACN,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"engine.js","sourcesContent":["/**\n * Babylon engine adapter for `@particle-academy/fancy-3d`'s <Canvas>.\n *\n * Mounts a Babylon `Engine` + `Scene` + camera into a `<canvas>` element\n * overlaid on the Canvas DOM container, then exposes the live `Scene` via\n * `EngineHandle.root` so child components can register meshes alongside the\n * 2D node graph.\n *\n * import { Canvas } from \"@particle-academy/fancy-3d\";\n * import { babylonEngine } from \"@particle-academy/fancy-3d-babylon/engine\";\n *\n * <Canvas engine={babylonEngine} style={{ height: 480 }} />\n */\nimport type { CanvasEngine, EngineHandle, ViewportState } from \"@particle-academy/fancy-3d\";\n\n// Declare a CJS-style `require` so the dts compiler doesn't reject the lazy\n// load below. Browsers don't have `require`, but this whole engine adapter\n// only runs when a host bundler (vite/webpack) replaces the call with its own\n// lazy-module shim, or under node-side SSR where the global exists.\ndeclare const require: (specifier: string) => unknown;\n\nexport const babylonEngine: CanvasEngine = {\n name: \"babylon\",\n mount(host: HTMLElement, viewport: ViewportState): EngineHandle {\n // Lazy require so non-babylon Canvas users don't pay the parse cost.\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const BABYLON: any = require(\"@babylonjs/core\");\n\n const overlay = document.createElement(\"canvas\");\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\";\n overlay.dataset.fancy3dCanvasEngine = \"babylon\";\n host.appendChild(overlay);\n\n const engine = new BABYLON.Engine(overlay, true, { preserveDrawingBuffer: true, stencil: true });\n const scene = new BABYLON.Scene(engine);\n scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);\n\n const camera = new BABYLON.ArcRotateCamera(\n \"fancy3d-canvas-camera\",\n Math.PI / 2,\n Math.PI / 2.5,\n 8,\n BABYLON.Vector3.Zero(),\n scene,\n );\n camera.attachControl(overlay, false);\n new BABYLON.HemisphericLight(\"fancy3d-canvas-light\", new BABYLON.Vector3(0, 1, 0), scene);\n\n const observer = engine.runRenderLoop(() => scene.render());\n\n function updateViewport(_v: ViewportState) {\n // Default: 6DoF camera owns view; 2D viewport changes are observed\n // but don't move the Babylon camera. Consumers can override by\n // attaching their own observers to the scene.\n }\n\n function dispose() {\n try { engine.stopRenderLoop(observer as any); } catch {}\n scene.dispose();\n engine.dispose();\n if (overlay.parentElement === host) host.removeChild(overlay);\n }\n\n return {\n name: \"babylon\",\n root: scene,\n updateViewport,\n dispose,\n };\n },\n};\n"]}
|