phoria2 1.1.0 → 1.2.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.
Files changed (60) hide show
  1. package/README.md +71 -13
  2. package/dist/bloom.js +4 -4
  3. package/dist/bloom.js.map +1 -1
  4. package/dist/charts.js +358 -345
  5. package/dist/charts.js.map +1 -1
  6. package/dist/core.js +3989 -3600
  7. package/dist/core.js.map +1 -1
  8. package/dist/edit.js +43 -43
  9. package/dist/edit.js.map +1 -1
  10. package/dist/explain.js +5 -1
  11. package/dist/explain.js.map +1 -1
  12. package/dist/gltf.js +96 -96
  13. package/dist/gltf.js.map +1 -1
  14. package/dist/motion.js +3 -3
  15. package/dist/motion.js.map +1 -1
  16. package/dist/particles.js +16 -16
  17. package/dist/particles.js.map +1 -1
  18. package/dist/passes.js +26 -26
  19. package/dist/passes.js.map +1 -1
  20. package/dist/phoria2.js +1 -1
  21. package/dist/picking.js +16 -16
  22. package/dist/picking.js.map +1 -1
  23. package/dist/types/OrbitControl.d.ts +6 -2
  24. package/dist/types/Raycaster.d.ts +10 -0
  25. package/dist/types/View.d.ts +59 -1
  26. package/dist/types/charts/Chart.d.ts +7 -0
  27. package/dist/types/explain.d.ts +3 -0
  28. package/dist/types/frame.d.ts +7 -0
  29. package/dist/types/geometry/Geometry.d.ts +8 -2
  30. package/dist/types/keyboard.d.ts +48 -0
  31. package/dist/types/labels.d.ts +4 -0
  32. package/dist/types/scene/Node.d.ts +19 -14
  33. package/dist/types/scene/drawables.d.ts +32 -14
  34. package/dist/types/scene/lights.d.ts +16 -2
  35. package/dist/types/shadow.d.ts +2 -1
  36. package/dist/types/types.d.ts +14 -0
  37. package/dist/types/value/Color.d.ts +0 -4
  38. package/dist/types/value/Quat.d.ts +4 -2
  39. package/llms-full.txt +58 -9
  40. package/package.json +4 -1
  41. package/schema/scene.schema.json +19 -1
  42. package/src/OrbitControl.js +7 -3
  43. package/src/Raycaster.js +58 -0
  44. package/src/View.js +204 -41
  45. package/src/charts/Chart.js +20 -2
  46. package/src/explain.js +6 -2
  47. package/src/frame.js +29 -9
  48. package/src/geometry/Geometry.js +16 -3
  49. package/src/keyboard.js +298 -0
  50. package/src/labels.js +4 -1
  51. package/src/scene/Node.js +20 -9
  52. package/src/scene/Scene.js +2 -0
  53. package/src/scene/cameras.js +4 -1
  54. package/src/scene/drawables.js +48 -12
  55. package/src/scene/lights.js +40 -6
  56. package/src/shadow.js +27 -4
  57. package/src/types.js +6 -0
  58. package/src/value/Color.js +21 -0
  59. package/src/value/Quat.js +15 -6
  60. package/src/watch.js +6 -1
package/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # phoria2
2
2
 
3
- Small, friendly 3D for the web. A WebGL 2 renderer with PBR materials, instancing, points, lines,
4
- labels, picking and particles, behind an API small enough to learn in an afternoon - aimed at
5
- business apps: charts, labelled scenes, diagrams, dashboards and product viewers.
3
+ Small, friendly 3D for the web. A WebGL 2 renderer with PBR materials, shadows, instancing, points,
4
+ lines, labels, picking, glTF models and particles, behind an API small enough to learn in an
5
+ afternoon - aimed at business apps: charts, labelled scenes, diagrams, dashboards, floor plans and
6
+ product viewers.
6
7
 
7
- - **Small**: about 57 KB gzipped for a lit, interactive scene, and about 116 KB for everything;
8
+ - **Small**: about 70 KB gzipped for a lit, interactive scene, and about 116 KB for everything;
8
9
  charts, particles, glTF, motion and editing are separate imports, and the heavier parts (shadows,
9
10
  HDR environments, GPU picking) load only when used.
11
+ - **Interaction built in**: tooltips, hover highlights, click and drag handlers, and HTML labels
12
+ that hide when they overlap or go behind something - each an option or a line of code, not a
13
+ layer to build.
10
14
  - **Idle when nothing changes**: a view draws only when something in it changed, so a dashboard of
11
15
  many views only updates when needed.
12
16
  - **Any number of views on a page**: browsers allow about 16 WebGL contexts per page, so most
@@ -16,8 +20,18 @@ business apps: charts, labelled scenes, diagrams, dashboards and product viewers
16
20
  - **Tells you what to write**: every option is checked, and a mistake throws an error that names
17
21
  the fix - pass `colour` and you get `Material: use 'color'`. Written to be easy for coding
18
22
  agents too.
23
+ - **Accessible**: `keyboard: true` lets people step through bars, points and parts with the
24
+ arrow keys while a screen reader says what each one is; motion follows the system's
25
+ reduced-motion setting.
26
+ - **Integrates well**: physics, solid modelling and path finding can be added using libraries made
27
+ for them - the gallery shows phoria2 rendering with Rapier, Manifold and recast-navigation.
19
28
  - **No runtime dependencies.** ES modules, with TypeScript types.
20
29
 
30
+ **New to phoria2?** The [getting started tutorial](https://kevs3d.co.uk/phoria2/tutorial.html)
31
+ builds a first 3D scene and then a live dashboard of 3D charts, step by step - each step running
32
+ beside its code, ready to copy as one HTML file. The [demo gallery](https://kevs3d.co.uk/phoria2/)
33
+ shows the rest.
34
+
21
35
  **Using a coding agent?** Point it at [llms-full.txt](https://kevs3d.co.uk/phoria2/llms-full.txt) - the whole API
22
36
  in one page ([llms.txt](https://kevs3d.co.uk/phoria2/llms.txt) is the short index). Both ship in the
23
37
  package too, at `node_modules/phoria2/llms-full.txt`.
@@ -56,12 +70,12 @@ own). Pin the version so a new release can't change your page:
56
70
  <script type="importmap">
57
71
  {
58
72
  "imports": {
59
- "phoria2": "https://cdn.jsdelivr.net/npm/phoria2@1.1.0/dist/phoria2.js",
60
- "phoria2/charts": "https://cdn.jsdelivr.net/npm/phoria2@1.1.0/dist/charts.js",
61
- "phoria2/particles": "https://cdn.jsdelivr.net/npm/phoria2@1.1.0/dist/particles.js",
62
- "phoria2/gltf": "https://cdn.jsdelivr.net/npm/phoria2@1.1.0/dist/gltf.js",
63
- "phoria2/motion": "https://cdn.jsdelivr.net/npm/phoria2@1.1.0/dist/motion.js",
64
- "phoria2/edit": "https://cdn.jsdelivr.net/npm/phoria2@1.1.0/dist/edit.js"
73
+ "phoria2": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/phoria2.js",
74
+ "phoria2/charts": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/charts.js",
75
+ "phoria2/particles": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/particles.js",
76
+ "phoria2/gltf": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/gltf.js",
77
+ "phoria2/motion": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/motion.js",
78
+ "phoria2/edit": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/edit.js"
65
79
  }
66
80
  }
67
81
  </script>
@@ -88,7 +102,21 @@ view.start((dt) => cube.rotateY(0.6 * dt))
88
102
  ```
89
103
 
90
104
  The canvas takes its size from CSS; the view matches its drawing buffer to it and follows resizes.
91
- The camera starts fitted to the scene, and `orbit: true` lets the user turn, pan and zoom it.
105
+ The camera starts fitted to the scene, and `orbit: true` lets the user turn, pan and zoom it. The
106
+ [tutorial](https://kevs3d.co.uk/phoria2/tutorial.html) takes it on from here: materials, shadows,
107
+ labels, hover and click.
108
+
109
+ ## Interaction
110
+
111
+ ```js
112
+ const view = new View({ canvas: '#c', orbit: true, highlight: '#ffffff',
113
+ tooltip: (hit) => ({ title: hit.datum.name, rows: { Sales: hit.datum.sales } }) })
114
+ view.on('click', (hit) => hit && select(hit.datum)) // hit is null for empty space
115
+ chair.onDrag = (drag) => drag.point && chair.position.copy(drag.point)
116
+ ```
117
+
118
+ A hit carries the node, the instance and its row of `data`, so a chart of 10,000 bars is one mesh
119
+ with one handler. Labels are HTML, styled with your CSS.
92
120
 
93
121
  ## Charts
94
122
 
@@ -121,6 +149,34 @@ view.frame(model)
121
149
  model.play() // its first animation
122
150
  ```
123
151
 
152
+ ## With other libraries
153
+
154
+ phoria2 draws; a library built for the job does the rest. Physics engines hand back positions and
155
+ `{ x, y, z, w }` rotations, which instances take as they are:
156
+
157
+ ```js
158
+ // each frame: Rapier moves the bricks, phoria2 draws them - one mesh, one draw call
159
+ world.step()
160
+ bodies.forEach((body, i) => bricks.setInstance(i, { position: body.translation(), quaternion: body.rotation() }))
161
+ ```
162
+
163
+ The gallery's Integrations section has four, each with its source: a brick tower knocked down with
164
+ [Rapier](https://rapier.rs), a tablecloth simulated by Rapier's soft bodies, a block cut and joined with
165
+ [Manifold](https://github.com/elalish/manifold), and people finding their way round an office with
166
+ [recast-navigation](https://github.com/isaac-mason/recast-navigation-js).
167
+
168
+ ## Accessibility *(1.2)*
169
+
170
+ ```js
171
+ const view = new View({ canvas: '#c', keyboard: true })
172
+ ```
173
+
174
+ The canvas joins the page's tab order. The arrow keys step through whatever can be hovered or
175
+ clicked - each bar, point, link or part - showing its highlight and tooltip, and Enter clicks it. A
176
+ screen reader hears each one ("North, Sales: 26. 1 of 48") and a description of the view, which
177
+ charts write for themselves. Glides, auto-rotation and chart transitions follow the system's
178
+ reduced-motion setting (`reducedMotion` to choose).
179
+
124
180
  ## With React
125
181
 
126
182
  React owns the canvas; phoria2 draws on it. Make the view once, dispose of it on unmount, and
@@ -189,8 +245,10 @@ Any browser with WebGL 2: current Chrome, Edge, Firefox and Safari (desktop and
189
245
 
190
246
  ## Examples
191
247
 
192
- The [demo gallery](https://kevs3d.co.uk/phoria2/) shows each feature and a few showcase scenes;
193
- its source is in [`demos/`](https://github.com/kevinroast/phoria2/tree/main/demos).
248
+ The [getting started tutorial](https://kevs3d.co.uk/phoria2/tutorial.html) walks through a first
249
+ scene and a chart dashboard. The [demo gallery](https://kevs3d.co.uk/phoria2/) has charts and
250
+ diagrams, a demo for each feature, showcase scenes and integrations with other libraries; its
251
+ source, and the tutorial's, is in [`demos/`](https://github.com/kevinroast/phoria2/tree/main/demos).
194
252
 
195
253
  ## Licence
196
254
 
package/dist/bloom.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as e, M as t } from "./core.js";
1
+ import { E as e, w as t } from "./core.js";
2
2
  // src/webgl/bloom.js
3
3
  var n = `precision highp float;
4
4
  in vec2 vUv;
@@ -6,7 +6,7 @@ uniform sampler2D uSource;
6
6
  uniform vec2 uTexel;
7
7
  uniform float uThreshold;
8
8
  out vec4 fragColor;
9
- ${e}
9
+ ${t}
10
10
  vec3 tap(vec2 uv) {
11
11
  vec3 c = texture(uSource, uv).rgb;
12
12
  return uThreshold < 0.0 ? c : srgbToLinear(c);
@@ -29,7 +29,7 @@ uniform sampler2D uScene;
29
29
  uniform sampler2D uBloom;
30
30
  uniform float uStrength;
31
31
  out vec4 fragColor;
32
- ${e}
32
+ ${t}
33
33
  void main() {
34
34
  vec4 scene = texture(uScene, vUv);
35
35
  vec3 glow = texture(uBloom, vUv).rgb * uStrength;
@@ -37,7 +37,7 @@ vec3 c = srgbToLinear(scene.rgb) + glow;
37
37
  float a = clamp(scene.a + max(glow.r, max(glow.g, glow.b)), 0.0, 1.0);
38
38
  fragColor = vec4(linearToSrgb(c), a);
39
39
  }
40
- `, a = [t, n], o = [t, r], s = [t, i], c = 6, l = class {
40
+ `, a = [e, n], o = [e, r], s = [e, i], c = 6, l = class {
41
41
  #e = null;
42
42
  #t = !1;
43
43
  constructor(e, t) {
package/dist/bloom.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bloom.js","names":["COMMON","FULLSCREEN_VERTEX","DOWN_FRAGMENT","UP_FRAGMENT","COMPOSITE_FRAGMENT","DOWN","UP","COMPOSITE","LEVELS","Bloom","gl","programs","#target","#float","#free","target","#targetFor","width","height","down","source","sw","sh","level","i","settings","up","weight","levels","from","to","composite","samples","multisampled","color","depth","texture","t","format","w","h","framebuffer","picture","b"],"sources":[],"mappings":""}
1
+ {"version":3,"file":"bloom.js","names":["FULLSCREEN_VERTEX","COMMON","DOWN_FRAGMENT","UP_FRAGMENT","COMPOSITE_FRAGMENT","DOWN","UP","COMPOSITE","LEVELS","Bloom","gl","programs","#target","#float","#free","target","#targetFor","width","height","down","source","sw","sh","level","i","settings","up","weight","levels","from","to","composite","samples","multisampled","color","depth","texture","t","format","w","h","framebuffer","picture","b"],"sources":[],"mappings":""}