@particle-academy/fancy-3d 0.1.0 → 0.1.2

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/docs/screen.md CHANGED
@@ -1,97 +1,97 @@
1
- # Screen widget
2
-
3
- A 3D-native widget shaped like a hardware display: bezel frame, power LED, brightness, and an inner surface that hosts label text, an image, or arbitrary 2D content via a `paint(ctx)` callback. Use it whenever you want a "monitor" or "device screen" inside a 3D scene.
4
-
5
- ## Why it lives in fancy-3d
6
-
7
- `Screen` only makes sense in spatial UIs — it has no meaning in a flat 2D dashboard. That's why it's a fancy-3d widget kind, not a `react-fancy` component. Both the DOM adapter and the Babylon adapter render it; the DOM adapter shows it as a styled card with an inner canvas, the Babylon adapter paints it onto a `DynamicTexture`.
8
-
9
- ## ScreenSpec
10
-
11
- ```ts
12
- interface ScreenSpec {
13
- kind: "screen";
14
- content:
15
- | { type: "label"; title: string; subtitle?: string }
16
- | { type: "image"; src: string; alt?: string }
17
- | { type: "paint"; paint: (ctx: CanvasRenderingContext2D, w: number, h: number) => void };
18
- bezel?: string; // CSS hex; default "#0b0f17"
19
- bezelThickness?: number; // px; default 14
20
- on?: boolean; // default true
21
- background?: string; // CSS hex; default "#020617"
22
- brightness?: number; // 0..1; default 1 when on, 0.06 when off
23
- }
24
- ```
25
-
26
- | Field | Description |
27
- |------|-------------|
28
- | content.label | Big centered title with optional subtitle — easiest case |
29
- | content.image | Image source + alt text (Babylon currently shows alt text as a placeholder; supply a `paint` if you need real image rendering on a mesh) |
30
- | content.paint | Freeform 2D — draw charts, animation frames, text, anything |
31
- | bezel | Frame color around the screen |
32
- | bezelThickness | How thick the frame is in canvas pixels |
33
- | on | Toggles the power LED color and the brightness ramp |
34
- | background | Inner screen background when `paint` doesn't fill the canvas |
35
- | brightness | Multiplied via `globalAlpha` on the inner content — useful for "screen powered down" looks |
36
-
37
- ## Usage
38
-
39
- ### As a Scene widget (DOM or Babylon)
40
-
41
- ```ts
42
- const display: SceneNode = {
43
- id: "monitor",
44
- position: { x: 0, y: 0 },
45
- size: { w: 320, h: 200 },
46
- widget: {
47
- kind: "screen",
48
- content: { type: "label", title: "OK", subtitle: "All systems healthy" },
49
- bezel: "#1f2937",
50
- on: true,
51
- },
52
- };
53
- ```
54
-
55
- The DOM adapter renders this as a `<div>` with bezel styling around an inner canvas. The Babylon adapter paints it onto a plane mesh with the bezel + power LED + glass-reflection sheen as part of the texture.
56
-
57
- ### Live drawing with `paint`
58
-
59
- ```ts
60
- const liveScreen: ScreenSpec = {
61
- kind: "screen",
62
- content: {
63
- type: "paint",
64
- paint: (ctx, w, h) => {
65
- ctx.fillStyle = "#0ea5e9";
66
- ctx.font = `bold ${h * 0.2}px ui-monospace, monospace`;
67
- ctx.textAlign = "center";
68
- ctx.fillText(new Date().toLocaleTimeString(), w / 2, h / 2);
69
- },
70
- },
71
- };
72
- ```
73
-
74
- The DOM adapter calls `paint` once on mount and again whenever the `content` reference changes. To animate, wrap the spec in `useMemo` keyed on a tick or change the spec reference each frame.
75
-
76
- ### Mounted on a primitive
77
-
78
- `Screen` is a widget kind, so it works as the `surface` of any primitive:
79
-
80
- ```ts
81
- import { createBillboard } from "@particle-academy/fancy-3d/babylon";
82
-
83
- const tv = createBillboard({
84
- scene,
85
- width: 4, height: 2.5,
86
- surface: { type: "widget", widget: liveScreen },
87
- });
88
- ```
89
-
90
- ## Power LED
91
-
92
- A small dot in the bottom-right corner of the bezel:
93
-
94
- - `on: true` → emerald LED, full brightness
95
- - `on: false` → slate LED, dimmed inner content (`brightness ≈ 0.06`)
96
-
97
- Override `brightness` directly to fade between states for "powering on" animations.
1
+ # Screen widget
2
+
3
+ A 3D-native widget shaped like a hardware display: bezel frame, power LED, brightness, and an inner surface that hosts label text, an image, or arbitrary 2D content via a `paint(ctx)` callback. Use it whenever you want a "monitor" or "device screen" inside a 3D scene.
4
+
5
+ ## Why it lives in fancy-3d
6
+
7
+ `Screen` only makes sense in spatial UIs — it has no meaning in a flat 2D dashboard. That's why it's a fancy-3d widget kind, not a `react-fancy` component. Both the DOM adapter and the Babylon adapter render it; the DOM adapter shows it as a styled card with an inner canvas, the Babylon adapter paints it onto a `DynamicTexture`.
8
+
9
+ ## ScreenSpec
10
+
11
+ ```ts
12
+ interface ScreenSpec {
13
+ kind: "screen";
14
+ content:
15
+ | { type: "label"; title: string; subtitle?: string }
16
+ | { type: "image"; src: string; alt?: string }
17
+ | { type: "paint"; paint: (ctx: CanvasRenderingContext2D, w: number, h: number) => void };
18
+ bezel?: string; // CSS hex; default "#0b0f17"
19
+ bezelThickness?: number; // px; default 14
20
+ on?: boolean; // default true
21
+ background?: string; // CSS hex; default "#020617"
22
+ brightness?: number; // 0..1; default 1 when on, 0.06 when off
23
+ }
24
+ ```
25
+
26
+ | Field | Description |
27
+ |------|-------------|
28
+ | content.label | Big centered title with optional subtitle — easiest case |
29
+ | content.image | Image source + alt text (Babylon currently shows alt text as a placeholder; supply a `paint` if you need real image rendering on a mesh) |
30
+ | content.paint | Freeform 2D — draw charts, animation frames, text, anything |
31
+ | bezel | Frame color around the screen |
32
+ | bezelThickness | How thick the frame is in canvas pixels |
33
+ | on | Toggles the power LED color and the brightness ramp |
34
+ | background | Inner screen background when `paint` doesn't fill the canvas |
35
+ | brightness | Multiplied via `globalAlpha` on the inner content — useful for "screen powered down" looks |
36
+
37
+ ## Usage
38
+
39
+ ### As a Scene widget (DOM or Babylon)
40
+
41
+ ```ts
42
+ const display: SceneNode = {
43
+ id: "monitor",
44
+ position: { x: 0, y: 0 },
45
+ size: { w: 320, h: 200 },
46
+ widget: {
47
+ kind: "screen",
48
+ content: { type: "label", title: "OK", subtitle: "All systems healthy" },
49
+ bezel: "#1f2937",
50
+ on: true,
51
+ },
52
+ };
53
+ ```
54
+
55
+ The DOM adapter renders this as a `<div>` with bezel styling around an inner canvas. The Babylon adapter paints it onto a plane mesh with the bezel + power LED + glass-reflection sheen as part of the texture.
56
+
57
+ ### Live drawing with `paint`
58
+
59
+ ```ts
60
+ const liveScreen: ScreenSpec = {
61
+ kind: "screen",
62
+ content: {
63
+ type: "paint",
64
+ paint: (ctx, w, h) => {
65
+ ctx.fillStyle = "#0ea5e9";
66
+ ctx.font = `bold ${h * 0.2}px ui-monospace, monospace`;
67
+ ctx.textAlign = "center";
68
+ ctx.fillText(new Date().toLocaleTimeString(), w / 2, h / 2);
69
+ },
70
+ },
71
+ };
72
+ ```
73
+
74
+ The DOM adapter calls `paint` once on mount and again whenever the `content` reference changes. To animate, wrap the spec in `useMemo` keyed on a tick or change the spec reference each frame.
75
+
76
+ ### Mounted on a primitive
77
+
78
+ `Screen` is a widget kind, so it works as the `surface` of any primitive:
79
+
80
+ ```ts
81
+ import { createBillboard } from "@particle-academy/fancy-3d/babylon";
82
+
83
+ const tv = createBillboard({
84
+ scene,
85
+ width: 4, height: 2.5,
86
+ surface: { type: "widget", widget: liveScreen },
87
+ });
88
+ ```
89
+
90
+ ## Power LED
91
+
92
+ A small dot in the bottom-right corner of the bezel:
93
+
94
+ - `on: true` → emerald LED, full brightness
95
+ - `on: false` → slate LED, dimmed inner content (`brightness ≈ 0.06`)
96
+
97
+ Override `brightness` directly to fade between states for "powering on" animations.
package/package.json CHANGED
@@ -1,104 +1,105 @@
1
- {
2
- "name": "@particle-academy/fancy-3d",
3
- "version": "0.1.0",
4
- "description": "Bring Particle Academy's fancy components into 3D — engine-agnostic scene types, a BabylonJS adapter, and 3D-native components like Screen.",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/Particle-Academy/fancy-3d.git"
8
- },
9
- "homepage": "https://github.com/Particle-Academy/fancy-3d#readme",
10
- "bugs": "https://github.com/Particle-Academy/fancy-3d/issues",
11
- "type": "module",
12
- "main": "./dist/index.cjs",
13
- "module": "./dist/index.js",
14
- "types": "./dist/index.d.ts",
15
- "exports": {
16
- ".": {
17
- "import": {
18
- "types": "./dist/index.d.ts",
19
- "default": "./dist/index.js"
20
- },
21
- "require": {
22
- "types": "./dist/index.d.cts",
23
- "default": "./dist/index.cjs"
24
- }
25
- },
26
- "./babylon": {
27
- "import": {
28
- "types": "./dist/babylon.d.ts",
29
- "default": "./dist/babylon.js"
30
- },
31
- "require": {
32
- "types": "./dist/babylon.d.cts",
33
- "default": "./dist/babylon.cjs"
34
- }
35
- },
36
- "./dom": {
37
- "import": {
38
- "types": "./dist/dom.d.ts",
39
- "default": "./dist/dom.js"
40
- },
41
- "require": {
42
- "types": "./dist/dom.d.cts",
43
- "default": "./dist/dom.cjs"
44
- }
45
- },
46
- "./react": {
47
- "import": {
48
- "types": "./dist/react.d.ts",
49
- "default": "./dist/react.js"
50
- },
51
- "require": {
52
- "types": "./dist/react.d.cts",
53
- "default": "./dist/react.cjs"
54
- }
55
- }
56
- },
57
- "files": [
58
- "dist",
59
- "docs",
60
- "README.md"
61
- ],
62
- "scripts": {
63
- "build": "tsup",
64
- "dev": "tsup --watch",
65
- "lint": "tsc --noEmit",
66
- "clean": "rm -rf dist",
67
- "prepublishOnly": "tsup"
68
- },
69
- "keywords": [
70
- "react",
71
- "3d",
72
- "babylonjs",
73
- "scene",
74
- "ui",
75
- "spatial"
76
- ],
77
- "peerDependencies": {
78
- "@babylonjs/core": "^7.0.0 || ^8.0.0 || ^9.0.0",
79
- "@particle-academy/react-fancy": "*",
80
- "react": "^18.0.0 || ^19.0.0",
81
- "react-dom": "^18.0.0 || ^19.0.0"
82
- },
83
- "peerDependenciesMeta": {
84
- "@babylonjs/core": {
85
- "optional": true
86
- },
87
- "@particle-academy/react-fancy": {
88
- "optional": true
89
- }
90
- },
91
- "devDependencies": {
92
- "@babylonjs/core": "^9.0.0",
93
- "@types/react": "^19.0.0",
94
- "@types/react-dom": "^19.0.0",
95
- "react": "^19.0.0",
96
- "react-dom": "^19.0.0",
97
- "tsup": "^8.5.0",
98
- "typescript": "^5.8.0"
99
- },
100
- "publishConfig": {
101
- "access": "public"
102
- },
103
- "license": "MIT"
104
- }
1
+ {
2
+ "name": "@particle-academy/fancy-3d",
3
+ "version": "0.1.2",
4
+ "description": "Bring Particle Academy's fancy components into 3D — engine-agnostic scene types, a BabylonJS adapter, and 3D-native components like Screen.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Particle-Academy/fancy-3d.git"
8
+ },
9
+ "homepage": "https://github.com/Particle-Academy/fancy-3d#readme",
10
+ "bugs": "https://github.com/Particle-Academy/fancy-3d/issues",
11
+ "type": "module",
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "import": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "require": {
22
+ "types": "./dist/index.d.cts",
23
+ "default": "./dist/index.cjs"
24
+ }
25
+ },
26
+ "./babylon": {
27
+ "import": {
28
+ "types": "./dist/babylon.d.ts",
29
+ "default": "./dist/babylon.js"
30
+ },
31
+ "require": {
32
+ "types": "./dist/babylon.d.cts",
33
+ "default": "./dist/babylon.cjs"
34
+ }
35
+ },
36
+ "./dom": {
37
+ "import": {
38
+ "types": "./dist/dom.d.ts",
39
+ "default": "./dist/dom.js"
40
+ },
41
+ "require": {
42
+ "types": "./dist/dom.d.cts",
43
+ "default": "./dist/dom.cjs"
44
+ }
45
+ },
46
+ "./react": {
47
+ "import": {
48
+ "types": "./dist/react.d.ts",
49
+ "default": "./dist/react.js"
50
+ },
51
+ "require": {
52
+ "types": "./dist/react.d.cts",
53
+ "default": "./dist/react.cjs"
54
+ }
55
+ }
56
+ },
57
+ "files": [
58
+ "dist",
59
+ "docs",
60
+ "README.md"
61
+ ],
62
+ "scripts": {
63
+ "build": "tsup",
64
+ "dev": "tsup --watch",
65
+ "lint": "tsc --noEmit",
66
+ "clean": "rm -rf dist",
67
+ "prepublishOnly": "tsup"
68
+ },
69
+ "keywords": [
70
+ "react",
71
+ "3d",
72
+ "babylonjs",
73
+ "scene",
74
+ "ui",
75
+ "spatial"
76
+ ],
77
+ "peerDependencies": {
78
+ "@babylonjs/core": "^7.0.0 || ^8.0.0 || ^9.0.0",
79
+ "@particle-academy/react-fancy": "*",
80
+ "react": "^18.0.0 || ^19.0.0",
81
+ "react-dom": "^18.0.0 || ^19.0.0"
82
+ },
83
+ "peerDependenciesMeta": {
84
+ "@babylonjs/core": {
85
+ "optional": true
86
+ },
87
+ "@particle-academy/react-fancy": {
88
+ "optional": true
89
+ }
90
+ },
91
+ "devDependencies": {
92
+ "@babylonjs/core": "^9.0.0",
93
+ "@particle-academy/react-fancy": "^2.9.0",
94
+ "@types/react": "^19.0.0",
95
+ "@types/react-dom": "^19.0.0",
96
+ "react": "^19.0.0",
97
+ "react-dom": "^19.0.0",
98
+ "tsup": "^8.5.0",
99
+ "typescript": "^5.8.0"
100
+ },
101
+ "publishConfig": {
102
+ "access": "public"
103
+ },
104
+ "license": "MIT"
105
+ }