phoria2 1.0.0-rc.2 → 1.0.0-rc.4
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 +28 -3
- package/dist/bloom.js +123 -0
- package/dist/bloom.js.map +1 -0
- package/dist/charts.js +494 -483
- package/dist/charts.js.map +1 -1
- package/dist/core.js +3528 -2220
- package/dist/core.js.map +1 -1
- package/dist/edit.js +280 -0
- package/dist/edit.js.map +1 -0
- package/dist/explain.js +2 -2
- package/dist/explain.js.map +1 -1
- package/dist/gltf.js +122 -122
- package/dist/gltf.js.map +1 -1
- package/dist/motion.js +172 -0
- package/dist/motion.js.map +1 -0
- package/dist/particles.js +49 -45
- package/dist/particles.js.map +1 -1
- package/dist/passes.js +205 -51
- package/dist/passes.js.map +1 -1
- package/dist/phoria2.js +1 -1
- package/dist/picking.js +60 -53
- package/dist/picking.js.map +1 -1
- package/dist/snapshot.js +27 -14
- package/dist/snapshot.js.map +1 -1
- package/dist/tooltip.js +3 -3
- package/dist/tooltip.js.map +1 -1
- package/dist/types/OrbitControl.d.ts +17 -0
- package/dist/types/Raycaster.d.ts +4 -0
- package/dist/types/View.d.ts +74 -2
- package/dist/types/charts/spec.d.ts +32 -0
- package/dist/types/clip.d.ts +66 -0
- package/dist/types/edit/History.d.ts +78 -0
- package/dist/types/edit/TransformHandle.d.ts +113 -0
- package/dist/types/edit/index.d.ts +10 -0
- package/dist/types/fog.d.ts +57 -0
- package/dist/types/frame.d.ts +140 -3
- package/dist/types/geometry/Curve.d.ts +174 -0
- package/dist/types/geometry/Geometry.d.ts +8 -0
- package/dist/types/geometry/generators.d.ts +82 -2
- package/dist/types/geometry/outline.d.ts +192 -0
- package/dist/types/geometry/triangulate.d.ts +13 -0
- package/dist/types/gltf/Animation.d.ts +1 -1
- package/dist/types/index.d.ts +9 -1
- package/dist/types/labelLayout.d.ts +44 -1
- package/dist/types/labels.d.ts +11 -0
- package/dist/types/material/Material.d.ts +18 -0
- package/dist/types/material/Texture.d.ts +7 -0
- package/dist/types/motion/Timeline.d.ts +95 -0
- package/dist/types/motion/ease.d.ts +4 -0
- package/dist/types/motion/follow.d.ts +77 -0
- package/dist/types/motion/index.d.ts +15 -0
- package/dist/types/particles/Body.d.ts +6 -14
- package/dist/types/particles/Emitter.d.ts +0 -1
- package/dist/types/registry.d.ts +8 -1
- package/dist/types/scene/Node.d.ts +141 -7
- package/dist/types/scene/Scene.d.ts +15 -1
- package/dist/types/scene/drawables.d.ts +27 -2
- package/dist/types/scene/lights.d.ts +4 -1
- package/dist/types/shadow.d.ts +15 -0
- package/dist/types/snapshot.d.ts +4 -1
- package/dist/types/validate.d.ts +9 -0
- package/dist/types/value/Ray.d.ts +8 -0
- package/dist/types/value/Vec3.d.ts +2 -0
- package/dist/types/webgl/WebGLRenderer.d.ts +45 -0
- package/dist/types/webgl/bloom.d.ts +69 -0
- package/dist/types/webgl/context.d.ts +9 -0
- package/dist/types/webgl/passes.d.ts +39 -1
- package/dist/types/webgl/shaders.d.ts +7 -3
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -27,6 +27,29 @@ Or straight from a CDN, with no build step:
|
|
|
27
27
|
</script>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
To use more than the core - charts, particles, glTF, motion or editing - map each import to the package's own
|
|
31
|
+
files, so they share one copy of the core (the CDN's ready-made `+esm` builds each bundle their
|
|
32
|
+
own). Pin the version so a new release can't change your page:
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<script type="importmap">
|
|
36
|
+
{
|
|
37
|
+
"imports": {
|
|
38
|
+
"phoria2": "https://cdn.jsdelivr.net/npm/phoria2@1.0.0-rc.4/dist/phoria2.js",
|
|
39
|
+
"phoria2/charts": "https://cdn.jsdelivr.net/npm/phoria2@1.0.0-rc.4/dist/charts.js",
|
|
40
|
+
"phoria2/particles": "https://cdn.jsdelivr.net/npm/phoria2@1.0.0-rc.4/dist/particles.js",
|
|
41
|
+
"phoria2/gltf": "https://cdn.jsdelivr.net/npm/phoria2@1.0.0-rc.4/dist/gltf.js",
|
|
42
|
+
"phoria2/motion": "https://cdn.jsdelivr.net/npm/phoria2@1.0.0-rc.4/dist/motion.js",
|
|
43
|
+
"phoria2/edit": "https://cdn.jsdelivr.net/npm/phoria2@1.0.0-rc.4/dist/edit.js"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
<script type="module">
|
|
48
|
+
import { View } from 'phoria2'
|
|
49
|
+
import { chart } from 'phoria2/charts'
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
30
53
|
## A first scene
|
|
31
54
|
|
|
32
55
|
```html
|
|
@@ -112,10 +135,12 @@ A full example, with a chart that follows its data, is in
|
|
|
112
135
|
|
|
113
136
|
| Import | |
|
|
114
137
|
|---|---|
|
|
115
|
-
| `phoria2` | the view, scene graph, cameras, lights, materials, geometry, textures, picking, labels, `create()` from JSON |
|
|
138
|
+
| `phoria2` | the view, scene graph, cameras, lights, materials, geometry, curves, textures, picking, labels, bloom, `create()` from JSON |
|
|
116
139
|
| `phoria2/charts` | `chart()` - charts from a spec of mark, data and channels, and the scales they use |
|
|
117
140
|
| `phoria2/particles` | `Emitter` and `Body` |
|
|
118
141
|
| `phoria2/gltf` | `loadGLTF()` - glTF 2.0 models with their materials and animations |
|
|
142
|
+
| `phoria2/motion` | `Timeline` - named steps played in order, `follow()` along a curve, `reveal()` a path as it's travelled - for explainers and guided tours |
|
|
143
|
+
| `phoria2/edit` | `TransformHandle` - a move and turn handle with grid and angle snapping - and `History` for undo, for planners and layout editors |
|
|
119
144
|
|
|
120
145
|
## Browsers
|
|
121
146
|
|
|
@@ -123,8 +148,8 @@ Any browser with WebGL 2: current Chrome, Edge, Firefox and Safari (desktop and
|
|
|
123
148
|
|
|
124
149
|
## Examples
|
|
125
150
|
|
|
126
|
-
The demo gallery shows each feature and a few showcase scenes;
|
|
127
|
-
[`demos/`](https://github.com/kevinroast/phoria2/tree/main/demos).
|
|
151
|
+
The [demo gallery](https://kevs3d.co.uk/phoria2/) shows each feature and a few showcase scenes;
|
|
152
|
+
its source is in [`demos/`](https://github.com/kevinroast/phoria2/tree/main/demos).
|
|
128
153
|
|
|
129
154
|
## Licence
|
|
130
155
|
|
package/dist/bloom.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { F as e, N as t } from "./core.js";
|
|
2
|
+
// src/webgl/bloom.js
|
|
3
|
+
var n = `precision highp float;
|
|
4
|
+
in vec2 vUv;
|
|
5
|
+
uniform sampler2D uSource;
|
|
6
|
+
uniform vec2 uTexel;
|
|
7
|
+
uniform float uThreshold;
|
|
8
|
+
out vec4 fragColor;
|
|
9
|
+
${t}
|
|
10
|
+
vec3 tap(vec2 uv) {
|
|
11
|
+
vec3 c = texture(uSource, uv).rgb;
|
|
12
|
+
return uThreshold < 0.0 ? c : srgbToLinear(c);
|
|
13
|
+
}
|
|
14
|
+
void main() {
|
|
15
|
+
vec3 c = (tap(vUv + uTexel * vec2(-1.0, -1.0)) + tap(vUv + uTexel * vec2(1.0, -1.0)) +
|
|
16
|
+
tap(vUv + uTexel * vec2(-1.0, 1.0)) + tap(vUv + uTexel * vec2(1.0, 1.0))) * 0.25;
|
|
17
|
+
if (uThreshold >= 0.0) {
|
|
18
|
+
float bright = max(c.r, max(c.g, c.b));
|
|
19
|
+
float knee = uThreshold * 0.5 + 1e-4;
|
|
20
|
+
float soft = clamp(bright - uThreshold + knee, 0.0, 2.0 * knee);
|
|
21
|
+
soft = soft * soft / (4.0 * knee);
|
|
22
|
+
c *= max(soft, bright - uThreshold) / max(bright, 1e-4);
|
|
23
|
+
}
|
|
24
|
+
fragColor = vec4(c, 1.0);
|
|
25
|
+
}
|
|
26
|
+
`, r = "precision highp float;\nin vec2 vUv;\nuniform sampler2D uSource;\nuniform vec2 uTexel;\nuniform float uWeight;\nout vec4 fragColor;\nvoid main() {\nvec3 c = texture(uSource, vUv).rgb * 4.0;\nc += (texture(uSource, vUv + uTexel * vec2(-1.0, 0.0)).rgb + texture(uSource, vUv + uTexel * vec2(1.0, 0.0)).rgb +\ntexture(uSource, vUv + uTexel * vec2(0.0, -1.0)).rgb + texture(uSource, vUv + uTexel * vec2(0.0, 1.0)).rgb) * 2.0;\nc += texture(uSource, vUv + uTexel * vec2(-1.0, -1.0)).rgb + texture(uSource, vUv + uTexel * vec2(1.0, -1.0)).rgb +\ntexture(uSource, vUv + uTexel * vec2(-1.0, 1.0)).rgb + texture(uSource, vUv + uTexel * vec2(1.0, 1.0)).rgb;\nfragColor = vec4(c / 16.0 * uWeight, 1.0);\n}\n", i = `precision highp float;
|
|
27
|
+
in vec2 vUv;
|
|
28
|
+
uniform sampler2D uScene;
|
|
29
|
+
uniform sampler2D uBloom;
|
|
30
|
+
uniform float uStrength;
|
|
31
|
+
out vec4 fragColor;
|
|
32
|
+
${t}
|
|
33
|
+
void main() {
|
|
34
|
+
vec4 scene = texture(uScene, vUv);
|
|
35
|
+
vec3 glow = texture(uBloom, vUv).rgb * uStrength;
|
|
36
|
+
vec3 c = srgbToLinear(scene.rgb) + glow;
|
|
37
|
+
float a = clamp(scene.a + max(glow.r, max(glow.g, glow.b)), 0.0, 1.0);
|
|
38
|
+
fragColor = vec4(linearToSrgb(c), a);
|
|
39
|
+
}
|
|
40
|
+
`, a = [e, n], o = [e, r], s = [e, i], c = 6, l = class {
|
|
41
|
+
#e = null;
|
|
42
|
+
#t = null;
|
|
43
|
+
#n = !1;
|
|
44
|
+
constructor(e, t) {
|
|
45
|
+
this.gl = e, this.programs = t, this.reset();
|
|
46
|
+
}
|
|
47
|
+
reset() {
|
|
48
|
+
this.#e = null, this.#t = null, this.#n = !!this.gl.getExtension("EXT_color_buffer_float");
|
|
49
|
+
}
|
|
50
|
+
dispose() {
|
|
51
|
+
this.#i(), this.#e = null;
|
|
52
|
+
}
|
|
53
|
+
begin(e, t) {
|
|
54
|
+
let n = this.gl, r = this.#r(e, t);
|
|
55
|
+
n.bindFramebuffer(n.FRAMEBUFFER, r.multisampled), n.viewport(0, 0, e, t);
|
|
56
|
+
}
|
|
57
|
+
end(e) {
|
|
58
|
+
let t = this.gl, n = this.#e, { width: r, height: i, levels: c } = n;
|
|
59
|
+
t.bindFramebuffer(t.READ_FRAMEBUFFER, n.multisampled), t.bindFramebuffer(t.DRAW_FRAMEBUFFER, n.resolved), t.blitFramebuffer(0, 0, r, i, 0, 0, r, i, t.COLOR_BUFFER_BIT, t.NEAREST), t.bindFramebuffer(t.READ_FRAMEBUFFER, null), t.bindFramebuffer(t.DRAW_FRAMEBUFFER, null), t.disable(t.DEPTH_TEST), t.disable(t.CULL_FACE), t.disable(t.BLEND), t.depthMask(!1), t.bindVertexArray(this.#a());
|
|
60
|
+
let l = this.programs.ready("bloom-down", [], a);
|
|
61
|
+
t.useProgram(l.program);
|
|
62
|
+
let u = n.picture, d = r, f = i;
|
|
63
|
+
c.forEach((n, r) => {
|
|
64
|
+
t.bindFramebuffer(t.FRAMEBUFFER, n.framebuffer), t.viewport(0, 0, n.width, n.height), l.set("uSource", u), l.set("uTexel", [1 / d, 1 / f]), l.set("uThreshold", r === 0 ? Math.max(0, e.threshold) : -1), t.drawArrays(t.TRIANGLES, 0, 3), u = n.texture, d = n.width, f = n.height;
|
|
65
|
+
});
|
|
66
|
+
let p = this.programs.ready("bloom-up", [], o);
|
|
67
|
+
t.useProgram(p.program), t.enable(t.BLEND), t.blendFunc(t.ONE, t.ONE);
|
|
68
|
+
let m = Math.min(1, Math.max(0, e.radius));
|
|
69
|
+
for (let e = c.length - 1; e > 0; e--) {
|
|
70
|
+
let n = c[e], r = c[e - 1];
|
|
71
|
+
t.bindFramebuffer(t.FRAMEBUFFER, r.framebuffer), t.viewport(0, 0, r.width, r.height), p.set("uSource", n.texture), p.set("uTexel", [1 / n.width, 1 / n.height]), p.set("uWeight", m), t.drawArrays(t.TRIANGLES, 0, 3);
|
|
72
|
+
}
|
|
73
|
+
t.disable(t.BLEND), t.bindFramebuffer(t.FRAMEBUFFER, null), t.viewport(0, 0, r, i);
|
|
74
|
+
let h = this.programs.ready("bloom-composite", [], s);
|
|
75
|
+
t.useProgram(h.program), h.set("uScene", n.picture), h.set("uBloom", c[0].texture), h.set("uStrength", Math.max(0, e.strength)), t.drawArrays(t.TRIANGLES, 0, 3), t.depthMask(!0), t.enable(t.DEPTH_TEST), t.bindVertexArray(null);
|
|
76
|
+
}
|
|
77
|
+
#r(e, t) {
|
|
78
|
+
if (this.#e && this.#e.width === e && this.#e.height === t) return this.#e;
|
|
79
|
+
this.#i();
|
|
80
|
+
let n = this.gl, r = Math.min(4, n.getParameter(n.MAX_SAMPLES)), i = n.createFramebuffer();
|
|
81
|
+
n.bindFramebuffer(n.FRAMEBUFFER, i);
|
|
82
|
+
let a = n.createRenderbuffer();
|
|
83
|
+
n.bindRenderbuffer(n.RENDERBUFFER, a), n.renderbufferStorageMultisample(n.RENDERBUFFER, r, n.RGBA8, e, t), n.framebufferRenderbuffer(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.RENDERBUFFER, a);
|
|
84
|
+
let o = n.createRenderbuffer();
|
|
85
|
+
n.bindRenderbuffer(n.RENDERBUFFER, o), n.renderbufferStorageMultisample(n.RENDERBUFFER, r, n.DEPTH24_STENCIL8, e, t), n.framebufferRenderbuffer(n.FRAMEBUFFER, n.DEPTH_STENCIL_ATTACHMENT, n.RENDERBUFFER, o);
|
|
86
|
+
let s = (e, t, r) => {
|
|
87
|
+
let i = n.createTexture();
|
|
88
|
+
n.activeTexture(n.TEXTURE15), n.bindTexture(n.TEXTURE_2D, i), n.texStorage2D(n.TEXTURE_2D, 1, r, e, t), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE);
|
|
89
|
+
let a = n.createFramebuffer();
|
|
90
|
+
return n.bindFramebuffer(n.FRAMEBUFFER, a), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, i, 0), {
|
|
91
|
+
texture: i,
|
|
92
|
+
framebuffer: a,
|
|
93
|
+
width: e,
|
|
94
|
+
height: t
|
|
95
|
+
};
|
|
96
|
+
}, l = s(e, t, n.RGBA8), u = [], d = e, f = t;
|
|
97
|
+
for (let e = 0; e < c && (d = Math.max(1, d >> 1), f = Math.max(1, f >> 1), !(e > 1 && Math.min(d, f) < 8)); e++) u.push(s(d, f, this.#n ? n.RGBA16F : n.RGBA8));
|
|
98
|
+
return n.bindFramebuffer(n.FRAMEBUFFER, null), n.bindRenderbuffer(n.RENDERBUFFER, null), this.#e = {
|
|
99
|
+
width: e,
|
|
100
|
+
height: t,
|
|
101
|
+
multisampled: i,
|
|
102
|
+
buffers: [a, o],
|
|
103
|
+
resolved: l.framebuffer,
|
|
104
|
+
picture: l.texture,
|
|
105
|
+
levels: u
|
|
106
|
+
}, this.#e;
|
|
107
|
+
}
|
|
108
|
+
#i() {
|
|
109
|
+
let e = this.#e;
|
|
110
|
+
if (!e) return;
|
|
111
|
+
let t = this.gl;
|
|
112
|
+
t.deleteFramebuffer(e.multisampled);
|
|
113
|
+
for (let n of e.buffers) t.deleteRenderbuffer(n);
|
|
114
|
+
t.deleteFramebuffer(e.resolved), t.deleteTexture(e.picture);
|
|
115
|
+
for (let n of e.levels) t.deleteFramebuffer(n.framebuffer), t.deleteTexture(n.texture);
|
|
116
|
+
}
|
|
117
|
+
#a() {
|
|
118
|
+
return this.#t ||= this.gl.createVertexArray(), this.#t;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
export { l as Bloom };
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=bloom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bloom.js","names":["FULLSCREEN_VERTEX","COMMON","DOWN_FRAGMENT","UP_FRAGMENT","COMPOSITE_FRAGMENT","DOWN","UP","COMPOSITE","LEVELS","Bloom","gl","programs","#target","#empty","#float","#free","target","#targetFor","width","height","#emptyArray","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":""}
|