phoria2 1.0.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.
- package/README.md +71 -13
- package/dist/bloom.js +1 -1
- package/dist/charts.js +397 -384
- package/dist/charts.js.map +1 -1
- package/dist/core.js +4451 -3568
- package/dist/core.js.map +1 -1
- package/dist/edit.js +67 -67
- package/dist/edit.js.map +1 -1
- package/dist/explain.js +6 -2
- package/dist/explain.js.map +1 -1
- package/dist/gltf.js +211 -166
- package/dist/gltf.js.map +1 -1
- package/dist/motion.js +26 -26
- package/dist/motion.js.map +1 -1
- package/dist/particles.js +49 -49
- package/dist/particles.js.map +1 -1
- package/dist/passes.js +188 -86
- package/dist/passes.js.map +1 -1
- package/dist/phoria2.js +1 -1
- package/dist/picking.js +8 -13
- package/dist/picking.js.map +1 -1
- package/dist/snapshot.js +1 -1
- package/dist/tooltip.js +3 -3
- package/dist/tooltip.js.map +1 -1
- package/dist/types/OrbitControl.d.ts +6 -2
- package/dist/types/Raycaster.d.ts +10 -0
- package/dist/types/View.d.ts +64 -1
- package/dist/types/charts/Chart.d.ts +7 -0
- package/dist/types/explain.d.ts +3 -0
- package/dist/types/frame.d.ts +7 -0
- package/dist/types/geometry/Geometry.d.ts +14 -2
- package/dist/types/keyboard.d.ts +48 -0
- package/dist/types/labels.d.ts +4 -0
- package/dist/types/material/Material.d.ts +125 -0
- package/dist/types/material/Texture.d.ts +37 -5
- package/dist/types/scene/Node.d.ts +19 -14
- package/dist/types/scene/drawables.d.ts +32 -14
- package/dist/types/scene/lights.d.ts +16 -2
- package/dist/types/shadow.d.ts +2 -1
- package/dist/types/types.d.ts +14 -0
- package/dist/types/value/Color.d.ts +0 -4
- package/dist/types/value/Quat.d.ts +4 -2
- package/dist/types/webgl/WebGLRenderer.d.ts +6 -0
- package/dist/types/webgl/passes.d.ts +37 -13
- package/dist/types/webgl/resources.d.ts +24 -2
- package/dist/types/webgl/shaders.d.ts +4 -2
- package/llms-full.txt +153 -15
- package/package.json +4 -1
- package/schema/scene.schema.json +146 -1
- package/src/OrbitControl.js +7 -3
- package/src/Raycaster.js +58 -0
- package/src/View.js +207 -42
- package/src/charts/Chart.js +20 -2
- package/src/explain.js +6 -2
- package/src/frame.js +29 -9
- package/src/geometry/Geometry.js +24 -4
- package/src/gltf/load.js +50 -6
- package/src/keyboard.js +298 -0
- package/src/labels.js +4 -1
- package/src/material/Material.js +104 -19
- package/src/material/Texture.js +116 -11
- package/src/scene/Node.js +20 -9
- package/src/scene/Scene.js +2 -0
- package/src/scene/cameras.js +4 -1
- package/src/scene/drawables.js +48 -12
- package/src/scene/lights.js +40 -6
- package/src/shadow.js +27 -4
- package/src/types.js +6 -0
- package/src/value/Color.js +21 -0
- package/src/value/Quat.js +15 -6
- package/src/watch.js +25 -1
- package/src/webgl/WebGLRenderer.js +51 -12
- package/src/webgl/passes.js +190 -32
- package/src/webgl/picking.js +0 -1
- package/src/webgl/resources.js +89 -8
- package/src/webgl/shaders.js +350 -48
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,
|
|
4
|
-
labels, picking and particles, behind an API small enough to learn in an
|
|
5
|
-
business apps: charts, labelled scenes, diagrams, dashboards
|
|
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
|
|
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.
|
|
60
|
-
"phoria2/charts": "https://cdn.jsdelivr.net/npm/phoria2@1.
|
|
61
|
-
"phoria2/particles": "https://cdn.jsdelivr.net/npm/phoria2@1.
|
|
62
|
-
"phoria2/gltf": "https://cdn.jsdelivr.net/npm/phoria2@1.
|
|
63
|
-
"phoria2/motion": "https://cdn.jsdelivr.net/npm/phoria2@1.
|
|
64
|
-
"phoria2/edit": "https://cdn.jsdelivr.net/npm/phoria2@1.
|
|
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 [
|
|
193
|
-
|
|
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