@particle-academy/fancy-3d 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 +84 -0
- package/dist/babylon.cjs +773 -0
- package/dist/babylon.cjs.map +1 -0
- package/dist/babylon.d.cts +229 -0
- package/dist/babylon.d.ts +229 -0
- package/dist/babylon.js +754 -0
- package/dist/babylon.js.map +1 -0
- package/dist/dom.cjs +225 -0
- package/dist/dom.cjs.map +1 -0
- package/dist/dom.d.cts +16 -0
- package/dist/dom.d.ts +16 -0
- package/dist/dom.js +223 -0
- package/dist/dom.js.map +1 -0
- package/dist/index.cjs +16 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +188 -0
- package/dist/index.d.ts +188 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +311 -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 +307 -0
- package/dist/react.js.map +1 -0
- package/docs/babylon-adapter.md +127 -0
- package/docs/dom-adapter.md +97 -0
- package/docs/primitives.md +168 -0
- package/docs/scene.md +122 -0
- package/docs/screen.md +97 -0
- package/package.json +104 -0
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Scene, Engine } from '@babylonjs/core';
|
|
3
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
4
|
+
|
|
5
|
+
interface StageContextValue {
|
|
6
|
+
engine: Engine;
|
|
7
|
+
scene: Scene;
|
|
8
|
+
/** The HTML <canvas> the engine renders into — its bounding rect anchors overlays. */
|
|
9
|
+
canvas: HTMLCanvasElement;
|
|
10
|
+
/** Subscribe to per-frame ticks. Returns an unsubscribe fn. */
|
|
11
|
+
onFrame(cb: () => void): () => void;
|
|
12
|
+
/** The DOM container that screen overlays mount into. */
|
|
13
|
+
overlayRoot: HTMLDivElement;
|
|
14
|
+
}
|
|
15
|
+
declare function useStage(): StageContextValue;
|
|
16
|
+
interface StageProps {
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
/** Initial camera radius. Defaults to 10. */
|
|
19
|
+
cameraRadius?: number;
|
|
20
|
+
/** Initial camera target. Defaults to (0, 1.5, 0). */
|
|
21
|
+
cameraTarget?: [number, number, number];
|
|
22
|
+
/** Initial camera alpha (horizontal angle). Defaults to π/2. */
|
|
23
|
+
cameraAlpha?: number;
|
|
24
|
+
/** Initial camera beta (vertical angle). Defaults to π/2.4. */
|
|
25
|
+
cameraBeta?: number;
|
|
26
|
+
/** Background clear color. Defaults to a near-black. */
|
|
27
|
+
clearColor?: string;
|
|
28
|
+
/** Disable the default lights / camera if you want to set your own. */
|
|
29
|
+
bare?: boolean;
|
|
30
|
+
/** Callback after the scene is created — set up custom cameras, lights, meshes. */
|
|
31
|
+
onReady?: (scene: Scene) => void;
|
|
32
|
+
className?: string;
|
|
33
|
+
style?: CSSProperties;
|
|
34
|
+
}
|
|
35
|
+
declare function Stage({ children, cameraRadius, cameraTarget, cameraAlpha, cameraBeta, clearColor, bare, onReady, className, style, }: StageProps): react_jsx_runtime.JSX.Element;
|
|
36
|
+
interface ScreenProps {
|
|
37
|
+
children?: ReactNode;
|
|
38
|
+
/** World-space center of the screen. */
|
|
39
|
+
position: [number, number, number];
|
|
40
|
+
/** Mesh dimensions in world units. */
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
/** Y-axis rotation in radians. */
|
|
44
|
+
rotationY?: number;
|
|
45
|
+
/** Bezel color. Defaults to a near-black frame. */
|
|
46
|
+
bezel?: string;
|
|
47
|
+
/** Bezel thickness in world units. Defaults to 0.06. */
|
|
48
|
+
bezelThickness?: number;
|
|
49
|
+
/** Background color visible behind the React content. */
|
|
50
|
+
background?: string;
|
|
51
|
+
/** Design-time pixel width for the children. Defaults to `width * 360`. */
|
|
52
|
+
pixelWidth?: number;
|
|
53
|
+
/** Design-time pixel height for the children. Defaults to `height * 360`. */
|
|
54
|
+
pixelHeight?: number;
|
|
55
|
+
/** Optional name on the Babylon mesh. */
|
|
56
|
+
name?: string;
|
|
57
|
+
}
|
|
58
|
+
declare function Screen({ children, position, width, height, rotationY, bezel, bezelThickness, background, pixelWidth, pixelHeight, name, }: ScreenProps): react_jsx_runtime.JSX.Element;
|
|
59
|
+
|
|
60
|
+
export { Screen, type ScreenProps, Stage, type StageProps, useStage };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { Engine, Scene, Color4, ArcRotateCamera, Vector3, HemisphericLight, Color3, DirectionalLight, MeshBuilder, StandardMaterial, Matrix } from '@babylonjs/core';
|
|
2
|
+
import { createContext, useContext, useRef, useState, useEffect, useLayoutEffect } from 'react';
|
|
3
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
// src/react.tsx
|
|
6
|
+
function adj3(m) {
|
|
7
|
+
return [
|
|
8
|
+
m[4] * m[8] - m[5] * m[7],
|
|
9
|
+
m[2] * m[7] - m[1] * m[8],
|
|
10
|
+
m[1] * m[5] - m[2] * m[4],
|
|
11
|
+
m[5] * m[6] - m[3] * m[8],
|
|
12
|
+
m[0] * m[8] - m[2] * m[6],
|
|
13
|
+
m[2] * m[3] - m[0] * m[5],
|
|
14
|
+
m[3] * m[7] - m[4] * m[6],
|
|
15
|
+
m[1] * m[6] - m[0] * m[7],
|
|
16
|
+
m[0] * m[4] - m[1] * m[3]
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
function multmm(a, b) {
|
|
20
|
+
const c = new Array(9);
|
|
21
|
+
for (let i = 0; i < 3; i++) {
|
|
22
|
+
for (let j = 0; j < 3; j++) {
|
|
23
|
+
let cij = 0;
|
|
24
|
+
for (let k = 0; k < 3; k++) cij += a[3 * i + k] * b[3 * k + j];
|
|
25
|
+
c[3 * i + j] = cij;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return c;
|
|
29
|
+
}
|
|
30
|
+
function multmv(m, v) {
|
|
31
|
+
return [
|
|
32
|
+
m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
|
|
33
|
+
m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
|
|
34
|
+
m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
function basisToPoints(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
38
|
+
const m = [x1, x2, x3, y1, y2, y3, 1, 1, 1];
|
|
39
|
+
const v = multmv(adj3(m), [x4, y4, 1]);
|
|
40
|
+
return multmm(m, [v[0], 0, 0, 0, v[1], 0, 0, 0, v[2]]);
|
|
41
|
+
}
|
|
42
|
+
function quadToQuad(w, h, x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
43
|
+
const s = basisToPoints(0, 0, w, 0, w, h, 0, h);
|
|
44
|
+
const d = basisToPoints(x1, y1, x2, y2, x3, y3, x4, y4);
|
|
45
|
+
const t = multmm(d, adj3(s));
|
|
46
|
+
const n = t[8];
|
|
47
|
+
for (let i = 0; i < 9; i++) t[i] /= n;
|
|
48
|
+
return t;
|
|
49
|
+
}
|
|
50
|
+
function matrix3dString(t) {
|
|
51
|
+
return `matrix3d(${t[0]}, ${t[3]}, 0, ${t[6]}, ${t[1]}, ${t[4]}, 0, ${t[7]}, 0, 0, 1, 0, ${t[2]}, ${t[5]}, 0, ${t[8]})`;
|
|
52
|
+
}
|
|
53
|
+
var StageContext = createContext(null);
|
|
54
|
+
function useStage() {
|
|
55
|
+
const ctx = useContext(StageContext);
|
|
56
|
+
if (!ctx) throw new Error("useStage() must be called inside <Stage>");
|
|
57
|
+
return ctx;
|
|
58
|
+
}
|
|
59
|
+
function Stage({
|
|
60
|
+
children,
|
|
61
|
+
cameraRadius = 10,
|
|
62
|
+
cameraTarget = [0, 1.5, 0],
|
|
63
|
+
cameraAlpha = Math.PI / 2,
|
|
64
|
+
cameraBeta = Math.PI / 2.4,
|
|
65
|
+
clearColor = "#06080f",
|
|
66
|
+
bare = false,
|
|
67
|
+
onReady,
|
|
68
|
+
className,
|
|
69
|
+
style
|
|
70
|
+
}) {
|
|
71
|
+
const containerRef = useRef(null);
|
|
72
|
+
const canvasRef = useRef(null);
|
|
73
|
+
const overlayRef = useRef(null);
|
|
74
|
+
const [stage, setStage] = useState(null);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const canvas = canvasRef.current;
|
|
77
|
+
const overlay = overlayRef.current;
|
|
78
|
+
if (!canvas || !overlay) return;
|
|
79
|
+
const engine = new Engine(canvas, true, { stencil: true, preserveDrawingBuffer: true });
|
|
80
|
+
const scene = new Scene(engine);
|
|
81
|
+
const c = Color4.FromHexString(clearColor);
|
|
82
|
+
scene.clearColor = new Color4(c.r, c.g, c.b, 1);
|
|
83
|
+
if (!bare) {
|
|
84
|
+
const cam = new ArcRotateCamera(
|
|
85
|
+
"fancy3d-cam",
|
|
86
|
+
cameraAlpha,
|
|
87
|
+
cameraBeta,
|
|
88
|
+
cameraRadius,
|
|
89
|
+
new Vector3(...cameraTarget),
|
|
90
|
+
scene
|
|
91
|
+
);
|
|
92
|
+
cam.attachControl(canvas, true);
|
|
93
|
+
cam.lowerRadiusLimit = 1;
|
|
94
|
+
cam.upperRadiusLimit = 80;
|
|
95
|
+
cam.wheelDeltaPercentage = 0.01;
|
|
96
|
+
cam.upperBetaLimit = Math.PI / 2 - 0.05;
|
|
97
|
+
const hemi = new HemisphericLight("fancy3d-hemi", new Vector3(0, 1, 0), scene);
|
|
98
|
+
hemi.intensity = 0.7;
|
|
99
|
+
hemi.diffuse = new Color3(0.7, 0.78, 1);
|
|
100
|
+
hemi.groundColor = new Color3(0.1, 0.1, 0.18);
|
|
101
|
+
const dir = new DirectionalLight("fancy3d-dir", new Vector3(-0.4, -1, -0.6), scene);
|
|
102
|
+
dir.intensity = 0.6;
|
|
103
|
+
}
|
|
104
|
+
onReady?.(scene);
|
|
105
|
+
const frameSubs = /* @__PURE__ */ new Set();
|
|
106
|
+
scene.onBeforeRenderObservable.add(() => {
|
|
107
|
+
frameSubs.forEach((cb) => cb());
|
|
108
|
+
});
|
|
109
|
+
engine.runRenderLoop(() => scene.render());
|
|
110
|
+
const handleResize = () => engine.resize();
|
|
111
|
+
window.addEventListener("resize", handleResize);
|
|
112
|
+
setStage({
|
|
113
|
+
engine,
|
|
114
|
+
scene,
|
|
115
|
+
canvas,
|
|
116
|
+
overlayRoot: overlay,
|
|
117
|
+
onFrame(cb) {
|
|
118
|
+
frameSubs.add(cb);
|
|
119
|
+
return () => frameSubs.delete(cb);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return () => {
|
|
123
|
+
window.removeEventListener("resize", handleResize);
|
|
124
|
+
engine.dispose();
|
|
125
|
+
setStage(null);
|
|
126
|
+
};
|
|
127
|
+
}, []);
|
|
128
|
+
return /* @__PURE__ */ jsxs(
|
|
129
|
+
"div",
|
|
130
|
+
{
|
|
131
|
+
ref: containerRef,
|
|
132
|
+
className,
|
|
133
|
+
style: { position: "relative", overflow: "hidden", ...style },
|
|
134
|
+
"data-fancy-3d-stage": "",
|
|
135
|
+
children: [
|
|
136
|
+
/* @__PURE__ */ jsx(
|
|
137
|
+
"canvas",
|
|
138
|
+
{
|
|
139
|
+
ref: canvasRef,
|
|
140
|
+
style: { display: "block", width: "100%", height: "100%", outline: "none" },
|
|
141
|
+
tabIndex: 0
|
|
142
|
+
}
|
|
143
|
+
),
|
|
144
|
+
/* @__PURE__ */ jsx(
|
|
145
|
+
"div",
|
|
146
|
+
{
|
|
147
|
+
ref: overlayRef,
|
|
148
|
+
style: { position: "absolute", inset: 0, pointerEvents: "none" },
|
|
149
|
+
"data-fancy-3d-overlay-root": ""
|
|
150
|
+
}
|
|
151
|
+
),
|
|
152
|
+
stage && /* @__PURE__ */ jsx(StageContext.Provider, { value: stage, children })
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
function Screen({
|
|
158
|
+
children,
|
|
159
|
+
position,
|
|
160
|
+
width,
|
|
161
|
+
height,
|
|
162
|
+
rotationY = 0,
|
|
163
|
+
bezel = "#0b0f17",
|
|
164
|
+
bezelThickness = 0.06,
|
|
165
|
+
background = "#0b1220",
|
|
166
|
+
pixelWidth,
|
|
167
|
+
pixelHeight,
|
|
168
|
+
name = "screen"
|
|
169
|
+
}) {
|
|
170
|
+
const stage = useStage();
|
|
171
|
+
const meshRef = useRef(null);
|
|
172
|
+
const overlayRef = useRef(null);
|
|
173
|
+
const innerSize = useRef({
|
|
174
|
+
w: pixelWidth ?? Math.max(120, Math.round(width * 360)),
|
|
175
|
+
h: pixelHeight ?? Math.max(80, Math.round(height * 360))
|
|
176
|
+
});
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
const { scene } = stage;
|
|
179
|
+
const bezelMesh = MeshBuilder.CreateBox(`${name}-bezel`, {
|
|
180
|
+
width: width + bezelThickness * 2,
|
|
181
|
+
height: height + bezelThickness * 2,
|
|
182
|
+
depth: bezelThickness
|
|
183
|
+
}, scene);
|
|
184
|
+
bezelMesh.position = new Vector3(position[0], position[1], position[2]);
|
|
185
|
+
bezelMesh.rotation.y = rotationY;
|
|
186
|
+
const bezelMat = new StandardMaterial(`${name}-bezel-mat`, scene);
|
|
187
|
+
bezelMat.diffuseColor = Color3.FromHexString(bezel);
|
|
188
|
+
bezelMat.specularColor = new Color3(0.05, 0.05, 0.05);
|
|
189
|
+
bezelMesh.material = bezelMat;
|
|
190
|
+
const pane = MeshBuilder.CreatePlane(`${name}-pane`, { width, height }, scene);
|
|
191
|
+
pane.position = new Vector3(position[0], position[1], position[2]);
|
|
192
|
+
pane.rotation.y = rotationY;
|
|
193
|
+
const forward = new Vector3(0, 0, -1);
|
|
194
|
+
const rot = Matrix.RotationY(rotationY);
|
|
195
|
+
const offset = Vector3.TransformNormal(forward.scale(bezelThickness / 2 + 1e-3), rot);
|
|
196
|
+
pane.position.addInPlace(offset);
|
|
197
|
+
const paneMat = new StandardMaterial(`${name}-pane-mat`, scene);
|
|
198
|
+
paneMat.diffuseColor = Color3.FromHexString(background);
|
|
199
|
+
paneMat.emissiveColor = Color3.FromHexString(background).scale(0.4);
|
|
200
|
+
pane.material = paneMat;
|
|
201
|
+
pane.metadata = { fancy3d: "screen", screenName: name };
|
|
202
|
+
meshRef.current = pane;
|
|
203
|
+
return () => {
|
|
204
|
+
pane.dispose();
|
|
205
|
+
bezelMesh.dispose();
|
|
206
|
+
meshRef.current = null;
|
|
207
|
+
};
|
|
208
|
+
}, [stage, name, width, height, bezel, bezelThickness, background, position, rotationY]);
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
const unsub = stage.onFrame(() => {
|
|
211
|
+
const mesh = meshRef.current;
|
|
212
|
+
const overlay = overlayRef.current;
|
|
213
|
+
if (!mesh || !overlay) return;
|
|
214
|
+
const cam = stage.scene.activeCamera;
|
|
215
|
+
if (!cam) return;
|
|
216
|
+
const engine = stage.engine;
|
|
217
|
+
const renderW = engine.getRenderWidth();
|
|
218
|
+
const renderH = engine.getRenderHeight();
|
|
219
|
+
const viewport = cam.viewport.toGlobal(renderW, renderH);
|
|
220
|
+
const tm = stage.scene.getTransformMatrix();
|
|
221
|
+
const identity = Matrix.Identity();
|
|
222
|
+
const wm = mesh.getWorldMatrix();
|
|
223
|
+
const halfW = width / 2;
|
|
224
|
+
const halfH = height / 2;
|
|
225
|
+
const localCorners = [
|
|
226
|
+
new Vector3(-halfW, halfH, 0),
|
|
227
|
+
// top-left
|
|
228
|
+
new Vector3(halfW, halfH, 0),
|
|
229
|
+
// top-right
|
|
230
|
+
new Vector3(halfW, -halfH, 0),
|
|
231
|
+
// bottom-right
|
|
232
|
+
new Vector3(-halfW, -halfH, 0)
|
|
233
|
+
// bottom-left
|
|
234
|
+
];
|
|
235
|
+
const worldCorners = localCorners.map((v) => Vector3.TransformCoordinates(v, wm));
|
|
236
|
+
const camPos = cam.globalPosition;
|
|
237
|
+
const right = worldCorners[1].subtract(worldCorners[0]);
|
|
238
|
+
const up = worldCorners[0].subtract(worldCorners[3]);
|
|
239
|
+
const normal = Vector3.Cross(up, right).normalize();
|
|
240
|
+
const center = worldCorners[0].add(worldCorners[2]).scale(0.5);
|
|
241
|
+
const toCam = camPos.subtract(center).normalize();
|
|
242
|
+
const facing = Vector3.Dot(normal, toCam);
|
|
243
|
+
const projected = worldCorners.map((c) => Vector3.Project(c, identity, tm, viewport));
|
|
244
|
+
const inFrustum = projected.every((p) => p.z >= 0 && p.z <= 1);
|
|
245
|
+
const visible = inFrustum && facing > 0.05;
|
|
246
|
+
if (!visible) {
|
|
247
|
+
if (overlay.style.display !== "none") overlay.style.display = "none";
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const dpr = window.devicePixelRatio || 1;
|
|
251
|
+
const w0 = innerSize.current.w;
|
|
252
|
+
const h0 = innerSize.current.h;
|
|
253
|
+
const t = quadToQuad(
|
|
254
|
+
w0,
|
|
255
|
+
h0,
|
|
256
|
+
projected[0].x / dpr,
|
|
257
|
+
projected[0].y / dpr,
|
|
258
|
+
projected[1].x / dpr,
|
|
259
|
+
projected[1].y / dpr,
|
|
260
|
+
projected[2].x / dpr,
|
|
261
|
+
projected[2].y / dpr,
|
|
262
|
+
projected[3].x / dpr,
|
|
263
|
+
projected[3].y / dpr
|
|
264
|
+
);
|
|
265
|
+
if (overlay.style.display !== "block") overlay.style.display = "block";
|
|
266
|
+
overlay.style.transform = matrix3dString(t);
|
|
267
|
+
});
|
|
268
|
+
return unsub;
|
|
269
|
+
}, [stage, width, height]);
|
|
270
|
+
useLayoutEffect(() => {
|
|
271
|
+
const el = overlayRef.current;
|
|
272
|
+
if (!el) return;
|
|
273
|
+
if (el.parentElement !== stage.overlayRoot) {
|
|
274
|
+
stage.overlayRoot.appendChild(el);
|
|
275
|
+
}
|
|
276
|
+
return () => {
|
|
277
|
+
if (el.parentElement === stage.overlayRoot) {
|
|
278
|
+
stage.overlayRoot.removeChild(el);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}, [stage]);
|
|
282
|
+
return /* @__PURE__ */ jsx(
|
|
283
|
+
"div",
|
|
284
|
+
{
|
|
285
|
+
ref: overlayRef,
|
|
286
|
+
"data-fancy-3d-screen": name,
|
|
287
|
+
style: {
|
|
288
|
+
position: "absolute",
|
|
289
|
+
left: 0,
|
|
290
|
+
top: 0,
|
|
291
|
+
width: innerSize.current.w,
|
|
292
|
+
height: innerSize.current.h,
|
|
293
|
+
transformOrigin: "0 0",
|
|
294
|
+
pointerEvents: "auto",
|
|
295
|
+
overflow: "hidden",
|
|
296
|
+
background,
|
|
297
|
+
borderRadius: 4,
|
|
298
|
+
display: "none"
|
|
299
|
+
},
|
|
300
|
+
children
|
|
301
|
+
}
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export { Screen, Stage, useStage };
|
|
306
|
+
//# sourceMappingURL=react.js.map
|
|
307
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx"],"names":["BJScene"],"mappings":";;;;;AAsDA,SAAS,KAAK,CAAA,EAAe;AAC3B,EAAA,OAAO;AAAA,IACL,CAAA,CAAE,CAAC,CAAA,GAAI,CAAA,CAAE,CAAC,IAAI,CAAA,CAAE,CAAC,CAAA,GAAI,CAAA,CAAE,CAAC,CAAA;AAAA,IAAG,CAAA,CAAE,CAAC,CAAA,GAAI,CAAA,CAAE,CAAC,IAAI,CAAA,CAAE,CAAC,CAAA,GAAI,CAAA,CAAE,CAAC,CAAA;AAAA,IAAG,CAAA,CAAE,CAAC,CAAA,GAAI,CAAA,CAAE,CAAC,IAAI,CAAA,CAAE,CAAC,CAAA,GAAI,CAAA,CAAE,CAAC,CAAA;AAAA,IAC9E,CAAA,CAAE,CAAC,CAAA,GAAI,CAAA,CAAE,CAAC,IAAI,CAAA,CAAE,CAAC,CAAA,GAAI,CAAA,CAAE,CAAC,CAAA;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ent":["/**\r\n * `<Stage>` and `<Screen>` — declarative React API for fancy-3d.\r\n *\r\n * <Stage>\r\n * <Screen position={[0, 2, 0]} width={4} height={2.5}>\r\n * <Card>...real react-fancy components...</Card>\r\n * </Screen>\r\n * </Stage>\r\n *\r\n * `<Stage>` owns the Babylon engine + scene + render loop and exposes them\r\n * via context. `<Screen>` builds a bezel mesh, projects its world-space\r\n * corners to screen space each frame, and renders its children into a\r\n * positioned DOM overlay. Children are real React: full interactivity,\r\n * accessibility, and styling — no canvas-rasterized snapshot.\r\n *\r\n * Tradeoffs of mount mode (vs. painted texture):\r\n * - Pro: live, interactive, perfect text rendering.\r\n * - Con: HTML overlay always renders on top of the WebGL canvas; depth\r\n * sorting against other 3D objects is approximate (we hide the overlay\r\n * when the mesh is behind the camera or fully occluded by frustum).\r\n */\r\nimport {\r\n ArcRotateCamera,\r\n Color3,\r\n Color4,\r\n DirectionalLight,\r\n Engine,\r\n HemisphericLight,\r\n Matrix,\r\n Mesh,\r\n MeshBuilder,\r\n Scene as BJScene,\r\n StandardMaterial,\r\n Vector3,\r\n type Camera,\r\n} from \"@babylonjs/core\";\r\nimport {\r\n createContext,\r\n useContext,\r\n useEffect,\r\n useLayoutEffect,\r\n useRef,\r\n useState,\r\n type CSSProperties,\r\n type ReactNode,\r\n} from \"react\";\r\n\r\n/* ------------------------------------------------------------------ */\r\n/* 2D perspective transform — maps a unit rectangle to a 4-point quad */\r\n/* via a 3x3 homography, packed into a CSS matrix3d for transform. */\r\n/* ------------------------------------------------------------------ */\r\n\r\ntype Mat3 = [number, number, number, number, number, number, number, number, number];\r\n\r\nfunction adj3(m: Mat3): Mat3 {\r\n return [\r\n m[4] * m[8] - m[5] * m[7], m[2] * m[7] - m[1] * m[8], m[1] * m[5] - m[2] * m[4],\r\n m[5] * m[6] - m[3] * m[8], m[0] * m[8] - m[2] * m[6], m[2] * m[3] - m[0] * m[5],\r\n m[3] * m[7] - m[4] * m[6], m[1] * m[6] - m[0] * m[7], m[0] * m[4] - m[1] * m[3],\r\n ];\r\n}\r\n\r\nfunction multmm(a: Mat3, b: Mat3): Mat3 {\r\n const c: number[] = new Array(9);\r\n for (let i = 0; i < 3; i++) {\r\n for (let j = 0; j < 3; j++) {\r\n let cij = 0;\r\n for (let k = 0; k < 3; k++) cij += a[3 * i + k] * b[3 * k + j];\r\n c[3 * i + j] = cij;\r\n }\r\n }\r\n return c as Mat3;\r\n}\r\n\r\nfunction multmv(m: Mat3, v: [number, number, number]): [number, number, number] {\r\n return [\r\n m[0] * v[0] + m[1] * v[1] + m[2] * v[2],\r\n m[3] * v[0] + m[4] * v[1] + m[5] * v[2],\r\n m[6] * v[0] + m[7] * v[1] + m[8] * v[2],\r\n ];\r\n}\r\n\r\nfunction basisToPoints(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): Mat3 {\r\n const m: Mat3 = [x1, x2, x3, y1, y2, y3, 1, 1, 1];\r\n const v = multmv(adj3(m), [x4, y4, 1]);\r\n return multmm(m, [v[0], 0, 0, 0, v[1], 0, 0, 0, v[2]]);\r\n}\r\n\r\n/** Compute a homography that maps (0,0)→p1, (w,0)→p2, (w,h)→p3, (0,h)→p4. */\r\nfunction quadToQuad(\r\n w: number, h: number,\r\n x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number\r\n): Mat3 {\r\n const s = basisToPoints(0, 0, w, 0, w, h, 0, h);\r\n const d = basisToPoints(x1, y1, x2, y2, x3, y3, x4, y4);\r\n const t = multmm(d, adj3(s));\r\n // Normalize so t[8] is 1\r\n const n = t[8];\r\n for (let i = 0; i < 9; i++) t[i] /= n;\r\n return t;\r\n}\r\n\r\n/** Pack a 3x3 homography into a CSS matrix3d() string. */\r\nfunction matrix3dString(t: Mat3): string {\r\n return `matrix3d(${t[0]}, ${t[3]}, 0, ${t[6]}, ${t[1]}, ${t[4]}, 0, ${t[7]}, 0, 0, 1, 0, ${t[2]}, ${t[5]}, 0, ${t[8]})`;\r\n}\r\n\r\n/* ------------------------------------------------------------------ */\r\n/* Stage context */\r\n/* ------------------------------------------------------------------ */\r\n\r\ninterface StageContextValue {\r\n engine: Engine;\r\n scene: BJScene;\r\n /** The HTML <canvas> the engine renders into — its bounding rect anchors overlays. */\r\n canvas: HTMLCanvasElement;\r\n /** Subscribe to per-frame ticks. Returns an unsubscribe fn. */\r\n onFrame(cb: () => void): () => void;\r\n /** The DOM container that screen overlays mount into. */\r\n overlayRoot: HTMLDivElement;\r\n}\r\n\r\nconst StageContext = createContext<StageContextValue | null>(null);\r\n\r\nexport function useStage(): StageContextValue {\r\n const ctx = useContext(StageContext);\r\n if (!ctx) throw new Error(\"useStage() must be called inside <Stage>\");\r\n return ctx;\r\n}\r\n\r\n/* ------------------------------------------------------------------ */\r\n/* Stage */\r\n/* ------------------------------------------------------------------ */\r\n\r\nexport interface StageProps {\r\n children?: ReactNode;\r\n /** Initial camera radius. Defaults to 10. */\r\n cameraRadius?: number;\r\n /** Initial camera target. Defaults to (0, 1.5, 0). */\r\n cameraTarget?: [number, number, number];\r\n /** Initial camera alpha (horizontal angle). Defaults to π/2. */\r\n cameraAlpha?: number;\r\n /** Initial camera beta (vertical angle). Defaults to π/2.4. */\r\n cameraBeta?: number;\r\n /** Background clear color. Defaults to a near-black. */\r\n clearColor?: string;\r\n /** Disable the default lights / camera if you want to set your own. */\r\n bare?: boolean;\r\n /** Callback after the scene is created — set up custom cameras, lights, meshes. */\r\n onReady?: (scene: BJScene) => void;\r\n className?: string;\r\n style?: CSSProperties;\r\n}\r\n\r\nexport function Stage({\r\n children,\r\n cameraRadius = 10,\r\n cameraTarget = [0, 1.5, 0],\r\n cameraAlpha = Math.PI / 2,\r\n cameraBeta = Math.PI / 2.4,\r\n clearColor = \"#06080f\",\r\n bare = false,\r\n onReady,\r\n className,\r\n style,\r\n}: StageProps) {\r\n const containerRef = useRef<HTMLDivElement | null>(null);\r\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\r\n const overlayRef = useRef<HTMLDivElement | null>(null);\r\n const [stage, setStage] = useState<StageContextValue | null>(null);\r\n\r\n useEffect(() => {\r\n const canvas = canvasRef.current;\r\n const overlay = overlayRef.current;\r\n if (!canvas || !overlay) return;\r\n\r\n const engine = new Engine(canvas, true, { stencil: true, preserveDrawingBuffer: true });\r\n const scene = new BJScene(engine);\r\n const c = Color4.FromHexString(clearColor);\r\n scene.clearColor = new Color4(c.r, c.g, c.b, 1);\r\n\r\n if (!bare) {\r\n const cam = new ArcRotateCamera(\r\n \"fancy3d-cam\",\r\n cameraAlpha,\r\n cameraBeta,\r\n cameraRadius,\r\n new Vector3(...cameraTarget),\r\n scene\r\n );\r\n cam.attachControl(canvas, true);\r\n cam.lowerRadiusLimit = 1;\r\n cam.upperRadiusLimit = 80;\r\n cam.wheelDeltaPercentage = 0.01;\r\n cam.upperBetaLimit = Math.PI / 2 - 0.05;\r\n\r\n const hemi = new HemisphericLight(\"fancy3d-hemi\", new Vector3(0, 1, 0), scene);\r\n hemi.intensity = 0.7;\r\n hemi.diffuse = new Color3(0.7, 0.78, 1);\r\n hemi.groundColor = new Color3(0.1, 0.1, 0.18);\r\n\r\n const dir = new DirectionalLight(\"fancy3d-dir\", new Vector3(-0.4, -1, -0.6), scene);\r\n dir.intensity = 0.6;\r\n }\r\n\r\n onReady?.(scene);\r\n\r\n const frameSubs = new Set<() => void>();\r\n scene.onBeforeRenderObservable.add(() => {\r\n frameSubs.forEach((cb) => cb());\r\n });\r\n\r\n engine.runRenderLoop(() => scene.render());\r\n const handleResize = () => engine.resize();\r\n window.addEventListener(\"resize\", handleResize);\r\n\r\n setStage({\r\n engine,\r\n scene,\r\n canvas,\r\n overlayRoot: overlay,\r\n onFrame(cb) {\r\n frameSubs.add(cb);\r\n return () => frameSubs.delete(cb);\r\n },\r\n });\r\n\r\n return () => {\r\n window.removeEventListener(\"resize\", handleResize);\r\n engine.dispose();\r\n setStage(null);\r\n };\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, []);\r\n\r\n return (\r\n <div\r\n ref={containerRef}\r\n className={className}\r\n style={{ position: \"relative\", overflow: \"hidden\", ...style }}\r\n data-fancy-3d-stage=\"\"\r\n >\r\n <canvas\r\n ref={canvasRef}\r\n style={{ display: \"block\", width: \"100%\", height: \"100%\", outline: \"none\" }}\r\n tabIndex={0}\r\n />\r\n <div\r\n ref={overlayRef}\r\n style={{ position: \"absolute\", inset: 0, pointerEvents: \"none\" }}\r\n data-fancy-3d-overlay-root=\"\"\r\n />\r\n {stage && <StageContext.Provider value={stage}>{children}</StageContext.Provider>}\r\n </div>\r\n );\r\n}\r\n\r\n/* ------------------------------------------------------------------ */\r\n/* Screen — interactive mount point on a 3D mesh */\r\n/* ------------------------------------------------------------------ */\r\n\r\nexport interface ScreenProps {\r\n children?: ReactNode;\r\n /** World-space center of the screen. */\r\n position: [number, number, number];\r\n /** Mesh dimensions in world units. */\r\n width: number;\r\n height: number;\r\n /** Y-axis rotation in radians. */\r\n rotationY?: number;\r\n /** Bezel color. Defaults to a near-black frame. */\r\n bezel?: string;\r\n /** Bezel thickness in world units. Defaults to 0.06. */\r\n bezelThickness?: number;\r\n /** Background color visible behind the React content. */\r\n background?: string;\r\n /** Design-time pixel width for the children. Defaults to `width * 360`. */\r\n pixelWidth?: number;\r\n /** Design-time pixel height for the children. Defaults to `height * 360`. */\r\n pixelHeight?: number;\r\n /** Optional name on the Babylon mesh. */\r\n name?: string;\r\n}\r\n\r\nexport function Screen({\r\n children,\r\n position,\r\n width,\r\n height,\r\n rotationY = 0,\r\n bezel = \"#0b0f17\",\r\n bezelThickness = 0.06,\r\n background = \"#0b1220\",\r\n pixelWidth,\r\n pixelHeight,\r\n name = \"screen\",\r\n}: ScreenProps) {\r\n const stage = useStage();\r\n const meshRef = useRef<Mesh | null>(null);\r\n const overlayRef = useRef<HTMLDivElement | null>(null);\r\n // Design-time pixel size for the children. The matrix3d transform maps\r\n // this unit rectangle onto the projected mesh quad each frame.\r\n const innerSize = useRef({\r\n w: pixelWidth ?? Math.max(120, Math.round(width * 360)),\r\n h: pixelHeight ?? Math.max(80, Math.round(height * 360)),\r\n });\r\n\r\n // Build the bezel + invisible projection-target plane.\r\n useEffect(() => {\r\n const { scene } = stage;\r\n const bezelMesh = MeshBuilder.CreateBox(`${name}-bezel`, {\r\n width: width + bezelThickness * 2,\r\n height: height + bezelThickness * 2,\r\n depth: bezelThickness,\r\n }, scene);\r\n bezelMesh.position = new Vector3(position[0], position[1], position[2]);\r\n bezelMesh.rotation.y = rotationY;\r\n const bezelMat = new StandardMaterial(`${name}-bezel-mat`, scene);\r\n bezelMat.diffuseColor = Color3.FromHexString(bezel);\r\n bezelMat.specularColor = new Color3(0.05, 0.05, 0.05);\r\n bezelMesh.material = bezelMat;\r\n\r\n // Inner pane the overlay tracks. Its background fills behind the React\r\n // overlay (in case the overlay is briefly mispositioned); the React\r\n // children are stamped on top.\r\n const pane = MeshBuilder.CreatePlane(`${name}-pane`, { width, height }, scene);\r\n pane.position = new Vector3(position[0], position[1], position[2]);\r\n pane.rotation.y = rotationY;\r\n const forward = new Vector3(0, 0, -1);\r\n const rot = Matrix.RotationY(rotationY);\r\n const offset = Vector3.TransformNormal(forward.scale(bezelThickness / 2 + 0.001), rot);\r\n pane.position.addInPlace(offset);\r\n const paneMat = new StandardMaterial(`${name}-pane-mat`, scene);\r\n paneMat.diffuseColor = Color3.FromHexString(background);\r\n paneMat.emissiveColor = Color3.FromHexString(background).scale(0.4);\r\n pane.material = paneMat;\r\n pane.metadata = { fancy3d: \"screen\", screenName: name };\r\n meshRef.current = pane;\r\n\r\n return () => {\r\n pane.dispose();\r\n bezelMesh.dispose();\r\n meshRef.current = null;\r\n };\r\n }, [stage, name, width, height, bezel, bezelThickness, background, position, rotationY]);\r\n\r\n // Each frame: project the four mesh corners and apply the matrix3d\r\n // transform that maps the inner div's local pixel space to the projected\r\n // quad. Imperative — no React re-render per frame.\r\n useEffect(() => {\r\n const unsub = stage.onFrame(() => {\r\n const mesh = meshRef.current;\r\n const overlay = overlayRef.current;\r\n if (!mesh || !overlay) return;\r\n const cam = stage.scene.activeCamera;\r\n if (!cam) return;\r\n const engine = stage.engine;\r\n const renderW = engine.getRenderWidth();\r\n const renderH = engine.getRenderHeight();\r\n const viewport = cam.viewport.toGlobal(renderW, renderH);\r\n const tm = stage.scene.getTransformMatrix();\r\n const identity = Matrix.Identity();\r\n const wm = mesh.getWorldMatrix();\r\n\r\n const halfW = width / 2;\r\n const halfH = height / 2;\r\n // Mesh-local corners ordered: top-left, top-right, bottom-right, bottom-left.\r\n // Babylon's plane: +Y is up in world (when not rotated around X), so\r\n // mesh-local +Y = top.\r\n const localCorners = [\r\n new Vector3(-halfW, halfH, 0), // top-left\r\n new Vector3(halfW, halfH, 0), // top-right\r\n new Vector3(halfW, -halfH, 0), // bottom-right\r\n new Vector3(-halfW, -halfH, 0), // bottom-left\r\n ];\r\n const worldCorners = localCorners.map((v) => Vector3.TransformCoordinates(v, wm));\r\n\r\n // Backface cull — hide overlay when the mesh's front isn't facing camera.\r\n const camPos = cam.globalPosition;\r\n const right = worldCorners[1].subtract(worldCorners[0]);\r\n const up = worldCorners[0].subtract(worldCorners[3]);\r\n const normal = Vector3.Cross(up, right).normalize();\r\n const center = worldCorners[0].add(worldCorners[2]).scale(0.5);\r\n const toCam = camPos.subtract(center).normalize();\r\n const facing = Vector3.Dot(normal, toCam);\r\n\r\n const projected = worldCorners.map((c) => Vector3.Project(c, identity, tm, viewport));\r\n const inFrustum = projected.every((p) => p.z >= 0 && p.z <= 1);\r\n const visible = inFrustum && facing > 0.05;\r\n\r\n if (!visible) {\r\n if (overlay.style.display !== \"none\") overlay.style.display = \"none\";\r\n return;\r\n }\r\n\r\n const dpr = window.devicePixelRatio || 1;\r\n const w0 = innerSize.current.w;\r\n const h0 = innerSize.current.h;\r\n const t = quadToQuad(\r\n w0, h0,\r\n projected[0].x / dpr, projected[0].y / dpr,\r\n projected[1].x / dpr, projected[1].y / dpr,\r\n projected[2].x / dpr, projected[2].y / dpr,\r\n projected[3].x / dpr, projected[3].y / dpr\r\n );\r\n\r\n if (overlay.style.display !== \"block\") overlay.style.display = \"block\";\r\n overlay.style.transform = matrix3dString(t);\r\n });\r\n return unsub;\r\n }, [stage, width, height]);\r\n\r\n // Mount the overlay into the stage's overlay root.\r\n useLayoutEffect(() => {\r\n const el = overlayRef.current;\r\n if (!el) return;\r\n if (el.parentElement !== stage.overlayRoot) {\r\n stage.overlayRoot.appendChild(el);\r\n }\r\n return () => {\r\n if (el.parentElement === stage.overlayRoot) {\r\n stage.overlayRoot.removeChild(el);\r\n }\r\n };\r\n }, [stage]);\r\n\r\n return (\r\n <div\r\n ref={overlayRef}\r\n data-fancy-3d-screen={name}\r\n style={{\r\n position: \"absolute\",\r\n left: 0,\r\n top: 0,\r\n width: innerSize.current.w,\r\n height: innerSize.current.h,\r\n transformOrigin: \"0 0\",\r\n pointerEvents: \"auto\",\r\n overflow: \"hidden\",\r\n background,\r\n borderRadius: 4,\r\n display: \"none\",\r\n }}\r\n >\r\n {children}\r\n </div>\r\n );\r\n}\r\n"]}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Babylon adapter
|
|
2
|
+
|
|
3
|
+
Renders a fancy-3d `Scene` as BabylonJS meshes. Each widget kind paints onto a 2D canvas that's uploaded to a `DynamicTexture` and applied to a plane. Edges become line meshes. Same `Scene` JSON, 3D output.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {
|
|
9
|
+
createBabylonAdapter,
|
|
10
|
+
paintWidget,
|
|
11
|
+
placeOnCylinder,
|
|
12
|
+
sceneBounds,
|
|
13
|
+
TEX_SCALE,
|
|
14
|
+
} from "@particle-academy/fancy-3d/babylon";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Peer dependency:** `@babylonjs/core` (optional — only required when you use this subpath).
|
|
18
|
+
|
|
19
|
+
## Basic Usage
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { Engine, Scene as BJScene, ArcRotateCamera, HemisphericLight, Vector3 } from "@babylonjs/core";
|
|
23
|
+
import { createBabylonAdapter, placeOnCylinder, sceneBounds } from "@particle-academy/fancy-3d/babylon";
|
|
24
|
+
|
|
25
|
+
const engine = new Engine(canvas, true);
|
|
26
|
+
const bj = new BJScene(engine);
|
|
27
|
+
new ArcRotateCamera("cam", Math.PI / 2, Math.PI / 2.2, 11, new Vector3(0, 0, 0), bj).attachControl(canvas, true);
|
|
28
|
+
new HemisphericLight("hemi", new Vector3(0, 1, 0), bj);
|
|
29
|
+
|
|
30
|
+
const adapter = createBabylonAdapter({
|
|
31
|
+
scene3D: bj,
|
|
32
|
+
sizeFor: (spec) => ({ w: 300, h: 200 }),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const bounds = sceneBounds(scene);
|
|
36
|
+
scene.nodes.forEach((node) => {
|
|
37
|
+
const mesh = adapter.render(node.widget, { nodeId: node.id, selected: false });
|
|
38
|
+
placeOnCylinder(node, mesh, bounds, { radius: 6, arc: Math.PI * 0.9 });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
engine.runRenderLoop(() => bj.render());
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
### createBabylonAdapter
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
function createBabylonAdapter(deps: BabylonAdapterDeps): WidgetAdapter<Mesh>;
|
|
50
|
+
|
|
51
|
+
interface BabylonAdapterDeps {
|
|
52
|
+
scene3D: Scene; // your Babylon Scene
|
|
53
|
+
sizeFor(spec: WidgetSpec): { w: number; h: number };
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
| Field | Description |
|
|
58
|
+
|------|-------------|
|
|
59
|
+
| scene3D | The Babylon `Scene` the meshes should be added to |
|
|
60
|
+
| sizeFor | Returns the target pixel size for a widget's texture. The plane mesh is sized world-units = `pixels * (1/180)` |
|
|
61
|
+
|
|
62
|
+
The adapter's `render(spec, ctx)` returns a Babylon `Mesh` whose `metadata.nodeId` matches `ctx.nodeId` — wire `scene.onPointerObservable` to read `pickedMesh.metadata.nodeId` for selection.
|
|
63
|
+
|
|
64
|
+
Selected nodes render a 2px indigo border around the painted texture.
|
|
65
|
+
|
|
66
|
+
### sceneBounds
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
function sceneBounds(scene: Scene): {
|
|
70
|
+
minX: number; maxX: number; minY: number; maxY: number;
|
|
71
|
+
};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Computes the bounding box of all nodes' world-space rectangles. Feed into `placeOnCylinder` (or your own layout function) to map 2D scene coordinates onto a 3D layout.
|
|
75
|
+
|
|
76
|
+
### placeOnCylinder
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
function placeOnCylinder(
|
|
80
|
+
node: SceneNode,
|
|
81
|
+
mesh: Mesh,
|
|
82
|
+
bounds: { minX, maxX, minY, maxY },
|
|
83
|
+
opts?: { radius?: number; arc?: number }
|
|
84
|
+
): void;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Wraps a node's 2D position onto a partial cylinder facing the camera. Default `radius=6`, `arc=π * 0.9` (~160°). DOM `x` becomes angle around the cylinder; DOM `y` becomes vertical position. Sibling layout helpers (`placeOnGrid`, `placeOnArc`, `placeOnPath`) are planned.
|
|
88
|
+
|
|
89
|
+
### paintWidget
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
function paintWidget(
|
|
93
|
+
ctx: CanvasRenderingContext2D,
|
|
94
|
+
spec: WidgetSpec,
|
|
95
|
+
w: number,
|
|
96
|
+
h: number,
|
|
97
|
+
selected: boolean
|
|
98
|
+
): void;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Low-level escape hatch — paints any `WidgetSpec` onto a 2D canvas you supply. Used internally by the adapter and by [`createWidgetTexture`](./primitives.md#createwidgettexture). Call this when you want widget content on a custom mesh shape that primitives don't yet expose.
|
|
102
|
+
|
|
103
|
+
### TEX_SCALE
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const TEX_SCALE: number; // = 2
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Texture super-sampling factor — primitives create textures `TEX_SCALE×` larger than their pixel size and pre-scale the canvas context, producing crisp output on high-DPI displays.
|
|
110
|
+
|
|
111
|
+
## Selection & interaction
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { PointerEventTypes } from "@babylonjs/core";
|
|
115
|
+
|
|
116
|
+
bj.onPointerObservable.add((pi) => {
|
|
117
|
+
if (pi.type !== PointerEventTypes.POINTERPICK) return;
|
|
118
|
+
const id = (pi.pickInfo?.pickedMesh?.metadata as { nodeId?: string })?.nodeId;
|
|
119
|
+
if (id) handleSelect(id);
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Scale or outline the picked mesh on hover for feedback (`mesh.scaling.setAll(1.04)`, `mesh.renderOutline = true`).
|
|
124
|
+
|
|
125
|
+
## V-flip
|
|
126
|
+
|
|
127
|
+
Babylon plane UVs run `V=0` at the bottom; canvas Y runs top-to-bottom. The adapter sets `tex.vScale = -1; tex.vOffset = 1` so painted content reads right-side-up. If you build textures by hand (without `createWidgetTexture` or the primitives), apply this flip yourself.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# DOM adapter
|
|
2
|
+
|
|
3
|
+
Renders a fancy-3d `Scene` to React elements composed from `@particle-academy/react-fancy`. The reference 2D adapter — useful when you want the same scene data to power a flat dashboard alongside its 3D rendering, or as a graceful fallback when WebGL isn't available.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { domAdapter } from "@particle-academy/fancy-3d/dom";
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Peer dependency:** `@particle-academy/react-fancy` (optional — only required when you use this subpath).
|
|
12
|
+
|
|
13
|
+
## Basic Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { Canvas } from "@particle-academy/react-fancy";
|
|
17
|
+
import { domAdapter } from "@particle-academy/fancy-3d/dom";
|
|
18
|
+
import type { Scene } from "@particle-academy/fancy-3d";
|
|
19
|
+
|
|
20
|
+
const scene: Scene = {
|
|
21
|
+
nodes: [
|
|
22
|
+
{ id: "rev", position: { x: 60, y: 60 }, size: { w: 220, h: 110 },
|
|
23
|
+
widget: { kind: "kpi", label: "Revenue", value: "$48k", delta: "+12%", trend: "up" } },
|
|
24
|
+
{ id: "chart", position: { x: 60, y: 200 }, size: { w: 460, h: 220 },
|
|
25
|
+
widget: { kind: "chart", title: "Trend", variant: "area",
|
|
26
|
+
series: [12, 18, 14, 22, 28, 24, 32], color: "#6366f1" } },
|
|
27
|
+
],
|
|
28
|
+
edges: [{ id: "e1", from: "rev", to: "chart", curve: "bezier" }],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function Dashboard() {
|
|
32
|
+
return (
|
|
33
|
+
<Canvas showGrid fitOnMount className="h-[600px] w-full">
|
|
34
|
+
{scene.nodes.map((n) => (
|
|
35
|
+
<Canvas.Node key={n.id} id={n.id} x={n.position.x} y={n.position.y}
|
|
36
|
+
style={{ width: n.size?.w, height: n.size?.h }}>
|
|
37
|
+
{domAdapter.render(n.widget, { nodeId: n.id, selected: false })}
|
|
38
|
+
</Canvas.Node>
|
|
39
|
+
))}
|
|
40
|
+
{scene.edges.map((e) => (
|
|
41
|
+
<Canvas.Edge key={e.id} from={e.from} to={e.to} curve={e.curve} />
|
|
42
|
+
))}
|
|
43
|
+
</Canvas>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
### domAdapter
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const domAdapter: WidgetAdapter<ReactNode>;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Singleton adapter — no construction needed. Call `domAdapter.render(spec, ctx)` to get a React element for any `WidgetSpec`.
|
|
57
|
+
|
|
58
|
+
### AdapterContext
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
interface AdapterContext {
|
|
62
|
+
nodeId: string;
|
|
63
|
+
selected: boolean;
|
|
64
|
+
onSelect?: (id: string) => void;
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Field | Description |
|
|
69
|
+
|------|-------------|
|
|
70
|
+
| nodeId | Forwarded to the rendered element so click handlers know which node was clicked |
|
|
71
|
+
| selected | When `true`, the element gets an indigo ring outline |
|
|
72
|
+
| onSelect | Called on `mousedown` with the `nodeId` — wire selection state in the host |
|
|
73
|
+
|
|
74
|
+
## Widget coverage
|
|
75
|
+
|
|
76
|
+
The DOM adapter handles every kind in [Scene types](./scene.md#widgetspec):
|
|
77
|
+
|
|
78
|
+
| Widget kind | Rendered as |
|
|
79
|
+
|-------------|-------------|
|
|
80
|
+
| kpi | `<Card>` with label + big value + delta |
|
|
81
|
+
| chart | `<Card>` with inline SVG sparkline (line / bar / area) |
|
|
82
|
+
| kanban | `<Card>` with column tracks + card chips |
|
|
83
|
+
| table | `<Card>` with `<table>` rows |
|
|
84
|
+
| profile | `<Profile>` inside `<Card>` |
|
|
85
|
+
| callout | `<Callout>` with tone-mapped color |
|
|
86
|
+
| form | `<Card>` with `<Switch>` and native inputs |
|
|
87
|
+
| action | `<Card>` with `<Action>` buttons |
|
|
88
|
+
| timeline | `<Card>` with `<Timeline events={...}>` |
|
|
89
|
+
| code | `<Card>` with `<pre>` block + language badge |
|
|
90
|
+
| image | `<Card>` wrapping `<img>` |
|
|
91
|
+
| text | `<Card>` with heading + body |
|
|
92
|
+
| demoPage | Card with accent header bar, category chip, path, title, description, CTA |
|
|
93
|
+
| screen | Inner `<canvas>` (when `paint` provided) or static label/image, framed by a styled bezel + power LED |
|
|
94
|
+
|
|
95
|
+
## Adding more kinds
|
|
96
|
+
|
|
97
|
+
Adding a new `WidgetSpec` discriminant requires updates in three places: `scene.ts` (type), `painters.ts` (Babylon paint case), and `dom.tsx` (React render case). Both adapters are kept in lock-step so any consumer can swap engines without losing widgets.
|