phoria2 1.1.0 → 1.3.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 (81) hide show
  1. package/README.md +70 -13
  2. package/dist/bloom.js +4 -4
  3. package/dist/bloom.js.map +1 -1
  4. package/dist/charts.js +538 -508
  5. package/dist/charts.js.map +1 -1
  6. package/dist/core.js +4270 -3652
  7. package/dist/core.js.map +1 -1
  8. package/dist/edit.js +65 -65
  9. package/dist/edit.js.map +1 -1
  10. package/dist/explain.js +6 -2
  11. package/dist/explain.js.map +1 -1
  12. package/dist/gltf.js +116 -116
  13. package/dist/gltf.js.map +1 -1
  14. package/dist/keyboard.js +188 -0
  15. package/dist/keyboard.js.map +1 -0
  16. package/dist/motion.js +35 -35
  17. package/dist/motion.js.map +1 -1
  18. package/dist/particles.js +188 -115
  19. package/dist/particles.js.map +1 -1
  20. package/dist/passes.js +29 -29
  21. package/dist/passes.js.map +1 -1
  22. package/dist/phoria2.js +1 -1
  23. package/dist/picking.js +32 -16
  24. package/dist/picking.js.map +1 -1
  25. package/dist/snapshot.js +1 -1
  26. package/dist/tooltip.js +1 -1
  27. package/dist/types/OrbitControl.d.ts +6 -2
  28. package/dist/types/Raycaster.d.ts +10 -0
  29. package/dist/types/View.d.ts +70 -1
  30. package/dist/types/area.d.ts +18 -0
  31. package/dist/types/charts/Chart.d.ts +7 -0
  32. package/dist/types/explain.d.ts +3 -0
  33. package/dist/types/frame.d.ts +7 -0
  34. package/dist/types/geometry/Geometry.d.ts +24 -2
  35. package/dist/types/index.d.ts +2 -0
  36. package/dist/types/keyboard.d.ts +48 -0
  37. package/dist/types/labels.d.ts +4 -0
  38. package/dist/types/material/Material.d.ts +15 -0
  39. package/dist/types/material/Texture.d.ts +18 -2
  40. package/dist/types/particles/Emitter.d.ts +39 -2
  41. package/dist/types/scene/Node.d.ts +19 -14
  42. package/dist/types/scene/drawables.d.ts +54 -15
  43. package/dist/types/scene/lights.d.ts +16 -2
  44. package/dist/types/shadow.d.ts +2 -1
  45. package/dist/types/types.d.ts +14 -0
  46. package/dist/types/value/Color.d.ts +0 -4
  47. package/dist/types/value/Quat.d.ts +4 -2
  48. package/dist/types/webgl/resources.d.ts +12 -2
  49. package/dist/types/webgl/shaders.d.ts +7 -2
  50. package/llms-full.txt +106 -10
  51. package/package.json +4 -1
  52. package/schema/scene.schema.json +67 -1
  53. package/src/OrbitControl.js +7 -3
  54. package/src/Raycaster.js +58 -0
  55. package/src/View.js +220 -41
  56. package/src/area.js +131 -0
  57. package/src/charts/Chart.js +20 -2
  58. package/src/charts/marks.js +29 -2
  59. package/src/explain.js +6 -2
  60. package/src/frame.js +29 -9
  61. package/src/geometry/Geometry.js +32 -4
  62. package/src/index.js +1 -0
  63. package/src/keyboard.js +298 -0
  64. package/src/labels.js +4 -1
  65. package/src/material/Material.js +9 -2
  66. package/src/material/Texture.js +55 -2
  67. package/src/particles/Emitter.js +121 -10
  68. package/src/scene/Node.js +20 -9
  69. package/src/scene/Scene.js +2 -0
  70. package/src/scene/cameras.js +4 -1
  71. package/src/scene/drawables.js +115 -15
  72. package/src/scene/lights.js +40 -6
  73. package/src/shadow.js +27 -4
  74. package/src/types.js +6 -0
  75. package/src/value/Color.js +21 -0
  76. package/src/value/Quat.js +15 -6
  77. package/src/watch.js +14 -2
  78. package/src/webgl/WebGLRenderer.js +36 -5
  79. package/src/webgl/picking.js +22 -1
  80. package/src/webgl/resources.js +168 -14
  81. package/src/webgl/shaders.js +110 -11
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. The [demo gallery](https://kevs3d.co.uk/phoria2/).
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,17 @@ 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.
33
+
21
34
  **Using a coding agent?** Point it at [llms-full.txt](https://kevs3d.co.uk/phoria2/llms-full.txt) - the whole API
22
35
  in one page ([llms.txt](https://kevs3d.co.uk/phoria2/llms.txt) is the short index). Both ship in the
23
36
  package too, at `node_modules/phoria2/llms-full.txt`.
@@ -56,12 +69,12 @@ own). Pin the version so a new release can't change your page:
56
69
  <script type="importmap">
57
70
  {
58
71
  "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"
72
+ "phoria2": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/phoria2.js",
73
+ "phoria2/charts": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/charts.js",
74
+ "phoria2/particles": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/particles.js",
75
+ "phoria2/gltf": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/gltf.js",
76
+ "phoria2/motion": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/motion.js",
77
+ "phoria2/edit": "https://cdn.jsdelivr.net/npm/phoria2@1.2.0/dist/edit.js"
65
78
  }
66
79
  }
67
80
  </script>
@@ -88,7 +101,21 @@ view.start((dt) => cube.rotateY(0.6 * dt))
88
101
  ```
89
102
 
90
103
  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.
104
+ The camera starts fitted to the scene, and `orbit: true` lets the user turn, pan and zoom it. The
105
+ [tutorial](https://kevs3d.co.uk/phoria2/tutorial.html) takes it on from here: materials, shadows,
106
+ labels, hover and click.
107
+
108
+ ## Interaction
109
+
110
+ ```js
111
+ const view = new View({ canvas: '#c', orbit: true, highlight: '#ffffff',
112
+ tooltip: (hit) => ({ title: hit.datum.name, rows: { Sales: hit.datum.sales } }) })
113
+ view.on('click', (hit) => hit && select(hit.datum)) // hit is null for empty space
114
+ chair.onDrag = (drag) => drag.point && chair.position.copy(drag.point)
115
+ ```
116
+
117
+ A hit carries the node, the instance and its row of `data`, so a chart of 10,000 bars is one mesh
118
+ with one handler. Labels are HTML, styled with your CSS.
92
119
 
93
120
  ## Charts
94
121
 
@@ -121,6 +148,34 @@ view.frame(model)
121
148
  model.play() // its first animation
122
149
  ```
123
150
 
151
+ ## With other libraries
152
+
153
+ phoria2 draws; a library built for the job does the rest. Physics engines hand back positions and
154
+ `{ x, y, z, w }` rotations, which instances take as they are:
155
+
156
+ ```js
157
+ // each frame: Rapier moves the bricks, phoria2 draws them - one mesh, one draw call
158
+ world.step()
159
+ bodies.forEach((body, i) => bricks.setInstance(i, { position: body.translation(), quaternion: body.rotation() }))
160
+ ```
161
+
162
+ The gallery's Integrations section has four, each with its source: a brick tower knocked down with
163
+ [Rapier](https://rapier.rs), a tablecloth simulated by Rapier's soft bodies, a block cut and joined with
164
+ [Manifold](https://github.com/elalish/manifold), and people finding their way round an office with
165
+ [recast-navigation](https://github.com/isaac-mason/recast-navigation-js).
166
+
167
+ ## Accessibility *(1.2)*
168
+
169
+ ```js
170
+ const view = new View({ canvas: '#c', keyboard: true })
171
+ ```
172
+
173
+ The canvas joins the page's tab order. The arrow keys step through whatever can be hovered or
174
+ clicked - each bar, point, link or part - showing its highlight and tooltip, and Enter clicks it. A
175
+ screen reader hears each one ("North, Sales: 26. 1 of 48") and a description of the view, which
176
+ charts write for themselves. Glides, auto-rotation and chart transitions follow the system's
177
+ reduced-motion setting (`reducedMotion` to choose).
178
+
124
179
  ## With React
125
180
 
126
181
  React owns the canvas; phoria2 draws on it. Make the view once, dispose of it on unmount, and
@@ -189,8 +244,10 @@ Any browser with WebGL 2: current Chrome, Edge, Firefox and Safari (desktop and
189
244
 
190
245
  ## Examples
191
246
 
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).
247
+ The [getting started tutorial](https://kevs3d.co.uk/phoria2/tutorial.html) walks through a first
248
+ scene and a chart dashboard. The [demo gallery](https://kevs3d.co.uk/phoria2/) has charts and
249
+ diagrams, a demo for each feature, showcase scenes and integrations with other libraries; its
250
+ source, and the tutorial's, is in [`demos/`](https://github.com/kevinroast/phoria2/tree/main/demos).
194
251
 
195
252
  ## Licence
196
253
 
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":""}