phoria2 0.0.0-stage → 1.0.0-rc.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/LICENSE +21 -0
- package/README.md +131 -2
- package/dist/charts.js +1787 -0
- package/dist/charts.js.map +1 -0
- package/dist/core.js +5382 -0
- package/dist/core.js.map +1 -0
- package/dist/explain.js +52 -0
- package/dist/explain.js.map +1 -0
- package/dist/gltf.js +470 -0
- package/dist/gltf.js.map +1 -0
- package/dist/hdr.js +51 -0
- package/dist/hdr.js.map +1 -0
- package/dist/particles.js +297 -0
- package/dist/particles.js.map +1 -0
- package/dist/passes.js +218 -0
- package/dist/passes.js.map +1 -0
- package/dist/phoria2.js +1 -0
- package/dist/picking.js +170 -0
- package/dist/picking.js.map +1 -0
- package/dist/snapshot.js +22 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/tooltip.js +55 -0
- package/dist/tooltip.js.map +1 -0
- package/dist/types/OrbitControl.d.ts +119 -0
- package/dist/types/Raycaster.d.ts +74 -0
- package/dist/types/View.d.ts +254 -0
- package/dist/types/charts/Chart.d.ts +55 -0
- package/dist/types/charts/axes.d.ts +29 -0
- package/dist/types/charts/index.d.ts +10 -0
- package/dist/types/charts/legend.d.ts +15 -0
- package/dist/types/charts/marks.d.ts +74 -0
- package/dist/types/charts/network.d.ts +9 -0
- package/dist/types/charts/scales.d.ts +107 -0
- package/dist/types/charts/spec.d.ts +62 -0
- package/dist/types/charts/style.d.ts +1 -0
- package/dist/types/describe.d.ts +27 -0
- package/dist/types/explain.d.ts +38 -0
- package/dist/types/frame.d.ts +277 -0
- package/dist/types/geometry/Geometry.d.ts +91 -0
- package/dist/types/geometry/fromPolygons.d.ts +52 -0
- package/dist/types/geometry/generators.d.ts +192 -0
- package/dist/types/gltf/Animation.d.ts +51 -0
- package/dist/types/gltf/index.d.ts +6 -0
- package/dist/types/gltf/load.d.ts +54 -0
- package/dist/types/hdr.d.ts +8 -0
- package/dist/types/index.d.ts +48 -0
- package/dist/types/irradiance.d.ts +10 -0
- package/dist/types/labelLayout.d.ts +60 -0
- package/dist/types/labels.d.ts +50 -0
- package/dist/types/material/Material.d.ts +208 -0
- package/dist/types/material/Texture.d.ts +87 -0
- package/dist/types/math/mat3.d.ts +8 -0
- package/dist/types/math/mat4.d.ts +39 -0
- package/dist/types/math/quat.d.ts +18 -0
- package/dist/types/math/vec2.d.ts +10 -0
- package/dist/types/math/vec3.d.ts +34 -0
- package/dist/types/math/vec4.d.ts +10 -0
- package/dist/types/math.d.ts +8 -0
- package/dist/types/particles/Body.d.ts +46 -0
- package/dist/types/particles/Emitter.d.ts +145 -0
- package/dist/types/particles/index.d.ts +10 -0
- package/dist/types/presets.d.ts +44 -0
- package/dist/types/registry.d.ts +10 -0
- package/dist/types/resolve.d.ts +17 -0
- package/dist/types/scene/Node.d.ts +236 -0
- package/dist/types/scene/Scene.d.ts +75 -0
- package/dist/types/scene/cameras.d.ts +78 -0
- package/dist/types/scene/drawables.d.ts +290 -0
- package/dist/types/scene/lights.d.ts +151 -0
- package/dist/types/shadow.d.ts +30 -0
- package/dist/types/snapshot.d.ts +29 -0
- package/dist/types/tooltip.d.ts +17 -0
- package/dist/types/types.d.ts +21 -0
- package/dist/types/validate.d.ts +44 -0
- package/dist/types/value/Box3.d.ts +34 -0
- package/dist/types/value/Color.d.ts +71 -0
- package/dist/types/value/Euler.d.ts +35 -0
- package/dist/types/value/Mat4.d.ts +30 -0
- package/dist/types/value/Quat.d.ts +74 -0
- package/dist/types/value/Ray.d.ts +43 -0
- package/dist/types/value/Vec3.d.ts +88 -0
- package/dist/types/value/cssColors.d.ts +2 -0
- package/dist/types/watch.d.ts +14 -0
- package/dist/types/webgl/WebGLRenderer.d.ts +117 -0
- package/dist/types/webgl/context.d.ts +67 -0
- package/dist/types/webgl/passes.d.ts +66 -0
- package/dist/types/webgl/picking.d.ts +52 -0
- package/dist/types/webgl/programs.d.ts +68 -0
- package/dist/types/webgl/resources.d.ts +86 -0
- package/dist/types/webgl/shaders.d.ts +28 -0
- package/package.json +74 -4
- package/schema/chart.schema.json +186 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-2026 Kevin Roast
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,132 @@
|
|
|
1
|
-
#
|
|
1
|
+
# phoria2
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
6
|
+
|
|
7
|
+
- **Small**: about 46 KB gzipped for a lit, interactive scene; charts, particles and glTF are
|
|
8
|
+
separate imports, and the heavier parts (shadows, HDR environments, GPU picking) load only when used.
|
|
9
|
+
- **Idle when nothing changes**: a view draws only when something in it changed, so a dashboard of
|
|
10
|
+
many views only updates when needed.
|
|
11
|
+
- **Tells you what to write**: every option is checked, and a mistake throws an error that names
|
|
12
|
+
the fix - pass `colour` and you get `Material: use 'color'`. Written to be easy for coding
|
|
13
|
+
agents too.
|
|
14
|
+
- **No runtime dependencies.** ES modules, with TypeScript types.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install phoria2
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or straight from a CDN, with no build step:
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<script type="module">
|
|
26
|
+
import { View, Mesh, box } from 'https://cdn.jsdelivr.net/npm/phoria2/+esm'
|
|
27
|
+
</script>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## A first scene
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<canvas id="c" style="width: 100%; height: 100vh; display: block"></canvas>
|
|
34
|
+
<script type="module" src="./main.js"></script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import { View, Mesh, box, DirectionalLight } from 'phoria2'
|
|
39
|
+
|
|
40
|
+
const view = new View({ canvas: '#c', orbit: true, background: '#1c1c20' })
|
|
41
|
+
const cube = view.scene.add(new Mesh({ geometry: box(2), material: { color: 'orange' } }))
|
|
42
|
+
view.scene.add(new DirectionalLight({ direction: [-1, -2, -1] }))
|
|
43
|
+
view.start((dt) => cube.rotateY(0.6 * dt))
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The canvas takes its size from CSS; the view matches its drawing buffer to it and follows resizes.
|
|
47
|
+
The camera starts fitted to the scene, and `orbit: true` lets the user turn, pan and zoom it.
|
|
48
|
+
|
|
49
|
+
## Charts
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import { View } from 'phoria2'
|
|
53
|
+
import { chart } from 'phoria2/charts'
|
|
54
|
+
|
|
55
|
+
const view = new View({ canvas: '#c', orbit: true })
|
|
56
|
+
view.scene.add(chart({
|
|
57
|
+
mark: 'bar',
|
|
58
|
+
data: rows, // [{ month: 'Jan', region: 'North', sales: 41 }, ...]
|
|
59
|
+
x: 'month', z: 'region', y: 'sales',
|
|
60
|
+
color: 'region',
|
|
61
|
+
tooltip: true,
|
|
62
|
+
}))
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Marks: `bar`, `point`, `line`, `area`, `surface` and `network`, with axes, legends, labels, tooltips
|
|
66
|
+
and animated updates (`chart.update(newRows)`). A JSON schema for specs ships as
|
|
67
|
+
`phoria2/charts/schema.json`.
|
|
68
|
+
|
|
69
|
+
## Models
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
import { loadGLTF } from 'phoria2/gltf'
|
|
73
|
+
|
|
74
|
+
const model = await loadGLTF('models/chair.glb') // .glb or .gltf
|
|
75
|
+
view.scene.add(model)
|
|
76
|
+
view.frame(model)
|
|
77
|
+
model.play() // its first animation
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## With React
|
|
81
|
+
|
|
82
|
+
React owns the canvas; phoria2 draws on it. Make the view once, dispose of it on unmount, and
|
|
83
|
+
change the scene in place when props change:
|
|
84
|
+
|
|
85
|
+
```jsx
|
|
86
|
+
import { useEffect, useRef } from 'react'
|
|
87
|
+
import { View, Mesh, box } from 'phoria2'
|
|
88
|
+
|
|
89
|
+
export function SpinningBox({ color }) {
|
|
90
|
+
const canvas = useRef(null)
|
|
91
|
+
const mesh = useRef(null)
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
const view = new View({ canvas: canvas.current, orbit: true })
|
|
95
|
+
mesh.current = view.scene.add(new Mesh({ geometry: box(2) }))
|
|
96
|
+
view.start((dt) => mesh.current.rotateY(0.6 * dt))
|
|
97
|
+
return () => view.dispose()
|
|
98
|
+
}, [])
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
mesh.current.material.color.set(color)
|
|
102
|
+
}, [color])
|
|
103
|
+
|
|
104
|
+
return <canvas ref={canvas} style={{ width: '100%', height: 320 }} />
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
A full example, with a chart that follows its data, is in
|
|
109
|
+
[`examples/react`](https://github.com/kevinroast/phoria2/tree/main/examples/react).
|
|
110
|
+
|
|
111
|
+
## What's in the package
|
|
112
|
+
|
|
113
|
+
| Import | |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `phoria2` | the view, scene graph, cameras, lights, materials, geometry, textures, picking, labels, `create()` from JSON |
|
|
116
|
+
| `phoria2/charts` | `chart()` - charts from a spec of mark, data and channels, and the scales they use |
|
|
117
|
+
| `phoria2/particles` | `Emitter` and `Body` |
|
|
118
|
+
| `phoria2/gltf` | `loadGLTF()` - glTF 2.0 models with their materials and animations |
|
|
119
|
+
|
|
120
|
+
## Browsers
|
|
121
|
+
|
|
122
|
+
Any browser with WebGL 2: current Chrome, Edge, Firefox and Safari (desktop and iOS 15+).
|
|
123
|
+
|
|
124
|
+
## Examples
|
|
125
|
+
|
|
126
|
+
The demo gallery shows each feature and a few showcase scenes; its source is in
|
|
127
|
+
[`demos/`](https://github.com/kevinroast/phoria2/tree/main/demos).
|
|
128
|
+
|
|
129
|
+
## Licence
|
|
130
|
+
|
|
131
|
+
MIT - see [LICENSE](LICENSE). phoria2 is a rewrite of phoria, a 2013 library that drew 3D on the
|
|
132
|
+
canvas 2D context.
|