roamwright 0.4.0 → 0.20.1
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/CONTRIBUTING.md +3 -1
- package/README.md +11 -34
- package/geometry/bedding.js +141 -0
- package/geometry/builder-cells.js +42 -0
- package/geometry/builder-frame.js +47 -0
- package/geometry/builder.js +189 -177
- package/geometry/cell-mask.js +25 -0
- package/geometry/creased-sheet.js +34 -34
- package/geometry/ear.js +36 -36
- package/geometry/erosion.js +65 -42
- package/geometry/face-grid.js +65 -65
- package/geometry/foliage.js +10 -10
- package/geometry/hair-gathers.js +41 -41
- package/geometry/hair-locks.js +41 -41
- package/geometry/hair-patch.js +18 -18
- package/geometry/hair-shell.js +31 -31
- package/geometry/head-profile.js +15 -15
- package/geometry/head-shape.js +77 -77
- package/geometry/heightfield.js +27 -18
- package/geometry/index-parts.js +2 -2
- package/geometry/instance-visibility.js +12 -12
- package/geometry/instances.js +15 -15
- package/geometry/outline-grid.js +7 -7
- package/geometry/part-ranges.js +3 -3
- package/geometry/path-field.js +63 -33
- package/geometry/placement.js +52 -52
- package/geometry/point-buckets.js +50 -0
- package/geometry/primitives.js +63 -47
- package/geometry/sagging-tube.js +27 -27
- package/geometry/sampled-surface.js +109 -77
- package/geometry/scatter-grid.js +46 -6
- package/geometry/sculpt.js +93 -93
- package/geometry/shore-grid.js +77 -34
- package/geometry/strata-field.js +92 -92
- package/geometry/strata-tiles.js +91 -91
- package/geometry/stream.js +70 -48
- package/geometry/terrain-chunks.js +87 -82
- package/geometry/terrain-extension.js +6 -6
- package/index.js +5 -0
- package/math/cell-edge.js +16 -16
- package/math/cell-key.js +6 -0
- package/math/circle-clearances.js +19 -0
- package/math/cloth-textures.js +6 -6
- package/math/cloud-textures.js +20 -20
- package/math/color.js +14 -14
- package/math/curve.js +22 -22
- package/math/mountain-ranges.js +216 -165
- package/math/noise.js +101 -49
- package/math/particle-noise.js +28 -28
- package/math/periodic.js +5 -5
- package/math/random.js +24 -15
- package/math/rectangles.js +52 -0
- package/math/rock-texture.js +7 -7
- package/math/scalar.js +5 -5
- package/math/surface-textures.js +54 -54
- package/motion/arm-reach.js +24 -24
- package/motion/ballistic-arc.js +11 -0
- package/motion/biped-cycle.js +44 -0
- package/motion/biped-leg.js +37 -0
- package/motion/biped-stride.js +98 -122
- package/motion/contact-transition.js +33 -0
- package/motion/crowd-alarms.js +39 -39
- package/motion/crowd-routine.js +94 -65
- package/motion/daily-clock.js +9 -9
- package/motion/deck-surface.js +38 -0
- package/motion/ground-lookahead.js +5 -5
- package/motion/instance-sight.js +8 -8
- package/motion/player.js +36 -28
- package/motion/quadruped.js +155 -155
- package/motion/spaces.js +32 -32
- package/motion/weather.js +73 -24
- package/motion/wind.js +32 -13
- package/package.json +7 -3
- package/rendering/caster-motion.js +5 -5
- package/rendering/cell-lod.js +138 -82
- package/rendering/cloud-dome.js +28 -28
- package/rendering/cloud-field.js +2 -2
- package/rendering/compilation-schedule.js +68 -11
- package/rendering/contact-shadows.js +2 -2
- package/rendering/context.js +12 -0
- package/rendering/crowd-skinning.js +13 -13
- package/rendering/crust.js +18 -12
- package/rendering/daylight.js +3 -3
- package/rendering/detail-range.js +28 -0
- package/rendering/dispose-meshes.js +18 -0
- package/rendering/dof.js +9 -9
- package/rendering/eye-adapt.js +14 -14
- package/rendering/far-shadow.js +8 -8
- package/rendering/flocks.js +78 -78
- package/rendering/garment-material.js +17 -17
- package/rendering/glow-lines.js +13 -13
- package/rendering/hair-strands.js +20 -20
- package/rendering/height-probe.js +149 -19
- package/rendering/label-layout.js +46 -0
- package/rendering/label-range.js +38 -0
- package/rendering/light-budget.js +52 -52
- package/rendering/light-shafts.js +23 -23
- package/rendering/local-lights.js +15 -4
- package/rendering/material-lod.js +49 -49
- package/rendering/particle-emitters.js +90 -90
- package/rendering/particles.js +78 -67
- package/rendering/piece-batch.js +17 -6
- package/rendering/planar-reflection.js +38 -38
- package/rendering/post-shaders.js +17 -13
- package/rendering/post.js +71 -71
- package/rendering/rain-streaks.js +67 -0
- package/rendering/road-surface.js +11 -11
- package/rendering/sea-shaders.js +11 -11
- package/rendering/shader-warmup.js +29 -16
- package/rendering/shadow-alignment.js +4 -4
- package/rendering/shadow-depth.js +7 -7
- package/rendering/sky-occlusion.js +16 -16
- package/rendering/sky.js +16 -6
- package/rendering/stage-lights.js +6 -6
- package/rendering/static-point-shadow.js +3 -3
- package/rendering/still-casters.js +1 -1
- package/rendering/strata-material.js +10 -10
- package/rendering/stream-flow.js +10 -10
- package/rendering/taa.js +26 -26
- package/rendering/talus.js +15 -15
- package/rendering/terrain-rock.js +7 -7
- package/rendering/texture-fills.js +8 -8
- package/rendering/textures.js +28 -28
- package/rendering/wakes.js +24 -24
- package/rendering/water-material.js +36 -23
- package/rendering/world-matrices.js +38 -38
- package/runtime/diagnostic-log.js +2 -2
- package/runtime/first-use.js +33 -28
- package/runtime/frame-pacing.js +33 -0
- package/runtime/gpu-timing.js +7 -7
- package/runtime/grid-cache.js +1 -1
- package/runtime/grid-rows.js +44 -5
- package/runtime/hand-over.js +41 -23
- package/runtime/pool.js +58 -16
- package/runtime/quality-fit.js +1 -1
- package/runtime/search.js +22 -22
- package/runtime/spatial-audio.js +13 -13
- package/runtime/withdrawable-task.js +35 -0
- package/runtime/worker.js +7 -0
|
@@ -12,12 +12,12 @@ export function createTextureFills({ definitions, fillPixels, request, available
|
|
|
12
12
|
const fillCost = name => definitions[name].cost ?? 1;
|
|
13
13
|
// An empty texture of a fill by name, repeating unless clamped, in sRGB unless it holds data, as `pixelTexture` makes one, and what
|
|
14
14
|
// puts pixels in it. A fill with a `depth` is a block: a texture in three dimensions.
|
|
15
|
-
function emptyTexture(name,
|
|
15
|
+
function emptyTexture(name, options) {
|
|
16
16
|
const { size, depth } = definitions[name],
|
|
17
17
|
texture = depth ? new THREE.Data3DTexture(null, size, size, depth) : new THREE.DataTexture(null, size, size);
|
|
18
|
-
texture.wrapS = texture.wrapT = texture.wrapR =
|
|
19
|
-
texture.colorSpace =
|
|
20
|
-
texture.anisotropy =
|
|
18
|
+
texture.wrapS = texture.wrapT = texture.wrapR = options.clamp ? THREE.ClampToEdgeWrapping : THREE.RepeatWrapping;
|
|
19
|
+
texture.colorSpace = options.data ? THREE.NoColorSpace : THREE.SRGBColorSpace;
|
|
20
|
+
texture.anisotropy = options.aniso || 4;
|
|
21
21
|
texture.magFilter = THREE.LinearFilter;
|
|
22
22
|
texture.minFilter = THREE.LinearMipmapLinearFilter;
|
|
23
23
|
texture.generateMipmaps = true;
|
|
@@ -29,8 +29,8 @@ export function createTextureFills({ definitions, fillPixels, request, available
|
|
|
29
29
|
return { texture, fill };
|
|
30
30
|
}
|
|
31
31
|
// The texture of a fill by name.
|
|
32
|
-
function filledTexture(name,
|
|
33
|
-
const { texture, fill } = emptyTexture(name,
|
|
32
|
+
function filledTexture(name, options = {}) {
|
|
33
|
+
const { texture, fill } = emptyTexture(name, options),
|
|
34
34
|
ask = () => pending.push(request(name, fillCost(name)).then(fill, () => fill(fillPixels(name))));
|
|
35
35
|
if (!available() || started) fill(fillPixels(name));
|
|
36
36
|
else if (asking) ask();
|
|
@@ -51,8 +51,8 @@ export function createTextureFills({ definitions, fillPixels, request, available
|
|
|
51
51
|
|
|
52
52
|
// A texture asked for in the world, by something built ahead of need, that is not drawn before `filled()`: filled on the pool's
|
|
53
53
|
// workers, or here by `fillNow()` if it is wanted before they answer.
|
|
54
|
-
function filledLater(name,
|
|
55
|
-
const { texture, fill } = emptyTexture(name,
|
|
54
|
+
function filledLater(name, options = {}) {
|
|
55
|
+
const { texture, fill } = emptyTexture(name, options);
|
|
56
56
|
let done = false;
|
|
57
57
|
const fillOnce = pixels => {
|
|
58
58
|
if (done) return;
|
package/rendering/textures.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// Create a canvas of the requested width and height. samplePixel(u, v, out) writes RGBA bytes at each pixel centre. A light's texture is
|
|
4
4
|
// made this way, never by a canvas's own gradient: WebKit (an iPhone's engine) dithers a gradient a little in each channel
|
|
5
5
|
// apart, which a night's exposure turns into red and green specks over a lantern's pool or a window's patch of light.
|
|
6
|
-
function pixelCanvas(
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
function pixelCanvas(width, height, samplePixel) {
|
|
7
|
+
const canvas = document.createElement('canvas');
|
|
8
|
+
canvas.width = width;
|
|
9
|
+
canvas.height = height;
|
|
10
|
+
const context = canvas.getContext('2d'),
|
|
11
|
+
imageData = context.createImageData(width, height),
|
|
12
|
+
pixels = imageData.data,
|
|
13
13
|
out = [0, 0, 0, 255];
|
|
14
|
-
for (let y = 0,
|
|
15
|
-
for (let x = 0; x <
|
|
14
|
+
for (let y = 0, pixelOffset = 0; y < height; y++)
|
|
15
|
+
for (let x = 0; x < width; x++, pixelOffset += 4) {
|
|
16
16
|
out[3] = 255;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
samplePixel((x + 0.5) / width, (y + 0.5) / height, out);
|
|
18
|
+
pixels[pixelOffset] = out[0];
|
|
19
|
+
pixels[pixelOffset + 1] = out[1];
|
|
20
|
+
pixels[pixelOffset + 2] = out[2];
|
|
21
|
+
pixels[pixelOffset + 3] = out[3];
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
return
|
|
23
|
+
context.putImageData(imageData, 0, 0);
|
|
24
|
+
return canvas;
|
|
25
25
|
}
|
|
26
|
-
// A square texture built by pixelCanvas, with
|
|
27
|
-
function pixelTexture(size,
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
return canvasTexture(
|
|
26
|
+
// A square texture built by pixelCanvas, with options.draw(context, size) drawing over it.
|
|
27
|
+
function pixelTexture(size, samplePixel, options = {}) {
|
|
28
|
+
const canvas = pixelCanvas(size, size, samplePixel);
|
|
29
|
+
if (options.draw) options.draw(canvas.getContext('2d'), size);
|
|
30
|
+
return canvasTexture(canvas, options);
|
|
31
31
|
}
|
|
32
32
|
// The value at t of a falloff given by stops [[t, value], ...] in rising t, straight between them and held beyond the ends, as
|
|
33
33
|
// a canvas gradient's stops are.
|
|
@@ -43,12 +43,12 @@ function falloffAt(stops, t) {
|
|
|
43
43
|
return stops[stops.length - 1][1];
|
|
44
44
|
}
|
|
45
45
|
// A texture from a canvas: repeating unless clamped, in sRGB unless it holds data.
|
|
46
|
-
function canvasTexture(
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return
|
|
46
|
+
function canvasTexture(canvas, options = {}) {
|
|
47
|
+
const texture = new THREE.CanvasTexture(canvas);
|
|
48
|
+
texture.wrapS = texture.wrapT = options.clamp ? THREE.ClampToEdgeWrapping : THREE.RepeatWrapping;
|
|
49
|
+
texture.colorSpace = options.data ? THREE.NoColorSpace : THREE.SRGBColorSpace;
|
|
50
|
+
texture.anisotropy = options.aniso || 4;
|
|
51
|
+
return texture;
|
|
52
52
|
}
|
|
53
53
|
// A map of numbers that is written once need not stay in memory once it is on the graphics card: its array is let go there.
|
|
54
54
|
// Regenerate the texture after a graphics context loss when using this option.
|
package/rendering/wakes.js
CHANGED
|
@@ -8,41 +8,41 @@ export function createWakes({ slots = 6, minSpeed = 0.25, reach = 450, ease = 4
|
|
|
8
8
|
};
|
|
9
9
|
const hulls = []; // { obj, length, beam, x, z, vx, vz, known, d2 }
|
|
10
10
|
|
|
11
|
-
// Follows the hull carried by
|
|
12
|
-
function followWake(
|
|
13
|
-
const hull = { obj, length, beam, x: 0, z: 0, vx: 0, vz: 0, known: false, d2: Infinity };
|
|
11
|
+
// Follows the hull carried by the object (her middle at its origin), `length` and `beam` metres, for as long as the page lives.
|
|
12
|
+
function followWake(object, length, beam = length * 0.3) {
|
|
13
|
+
const hull = { obj: object, length, beam, x: 0, z: 0, vx: 0, vz: 0, known: false, d2: Infinity };
|
|
14
14
|
hulls.push(hull);
|
|
15
15
|
return () => {
|
|
16
16
|
const i = hulls.indexOf(hull);
|
|
17
17
|
if (i >= 0) hulls.splice(i, 1);
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
// Whether
|
|
21
|
-
function shown(
|
|
22
|
-
let
|
|
23
|
-
for (;
|
|
24
|
-
return
|
|
20
|
+
// Whether the object is in the scene and nothing holding it is hidden.
|
|
21
|
+
function shown(object) {
|
|
22
|
+
let ancestor = object;
|
|
23
|
+
for (; ancestor.parent; ancestor = ancestor.parent) if (!ancestor.visible) return false;
|
|
24
|
+
return ancestor.isScene === true;
|
|
25
25
|
}
|
|
26
26
|
// Each frame: how fast each hull is moving, measured from where her frame was last drawn; the nearest under way fill the slots.
|
|
27
|
-
function updateWakes(
|
|
27
|
+
function updateWakes(deltaSeconds, eye) {
|
|
28
28
|
for (let i = 0; i < hulls.length; i++) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!shown(
|
|
33
|
-
|
|
29
|
+
const hull = hulls[i],
|
|
30
|
+
worldElements = hull.obj.matrixWorld.elements;
|
|
31
|
+
hull.d2 = Infinity;
|
|
32
|
+
if (!shown(hull.obj)) {
|
|
33
|
+
hull.known = false;
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
|
-
if (
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} else
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const d2 = (
|
|
45
|
-
if (d2 < reach * reach &&
|
|
36
|
+
if (hull.known && deltaSeconds > 0) {
|
|
37
|
+
const speedBlend = Math.min(1, deltaSeconds * ease);
|
|
38
|
+
hull.vx += ((worldElements[12] - hull.x) / deltaSeconds - hull.vx) * speedBlend;
|
|
39
|
+
hull.vz += ((worldElements[14] - hull.z) / deltaSeconds - hull.vz) * speedBlend;
|
|
40
|
+
} else hull.vx = hull.vz = 0;
|
|
41
|
+
hull.x = worldElements[12];
|
|
42
|
+
hull.z = worldElements[14];
|
|
43
|
+
hull.known = true;
|
|
44
|
+
const d2 = (hull.x - eye.x) ** 2 + (hull.z - eye.z) ** 2;
|
|
45
|
+
if (d2 < reach * reach && hull.vx * hull.vx + hull.vz * hull.vz > minSpeed * minSpeed) hull.d2 = d2;
|
|
46
46
|
}
|
|
47
47
|
const at = wakeUniforms.uWake.value,
|
|
48
48
|
size = wakeUniforms.uWakeS.value;
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shader materials and vertex attributes for open water and flowing streams.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import * as THREE from 'three';
|
|
2
7
|
import { FOAM_GLSL, SEA_BODY, SEA_OPACITY, SEA_WAVES } from './sea-shaders.js';
|
|
3
8
|
import { RAIN_GLSL, RAIN_PARS } from './rain-rings.js';
|
|
4
9
|
import { STREAM_FLOW_GLSL } from './stream-flow.js';
|
|
5
10
|
import { DEEP, FAR } from '../geometry/stream.js';
|
|
6
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Create the open-water material (`waterMat`) and the ribbon material for rivers (`streamMat`).
|
|
14
|
+
* Supply the depth-map transform, still-water elevation, sea parameters and wake shader inputs.
|
|
15
|
+
* The optional cloud shader supplies a shadow factor at a world-space X/Z position.
|
|
16
|
+
*/
|
|
7
17
|
export function createWaterMaterials({ depthRect, level, seaParameters, wakes, cloudShader = 'float cloudShade(vec2 p) { return 1.0; }', cloudUniforms = {} }) {
|
|
8
18
|
const { WAKE_GLSL, WAKE_PARS, wakeUniforms } = wakes;
|
|
9
19
|
const waterMat = new THREE.ShaderMaterial({
|
|
@@ -60,7 +70,9 @@ export function createWaterMaterials({ depthRect, level, seaParameters, wakes, c
|
|
|
60
70
|
#ifdef SEA
|
|
61
71
|
${seaParameters}
|
|
62
72
|
#endif
|
|
63
|
-
vec2 wv(vec2
|
|
73
|
+
vec2 wv(vec2 waterPosition, vec2 waveDirection, float frequency, float angularSpeed, float amplitude){
|
|
74
|
+
return waveDirection * (frequency * amplitude * cos(dot(waveDirection, waterPosition) * frequency + uTime * angularSpeed));
|
|
75
|
+
}
|
|
64
76
|
vec2 ripple(vec2 offset, vec2 stretch, float range, float phase) {
|
|
65
77
|
vec2 q = offset * stretch;
|
|
66
78
|
float d = length(q), amp = smoothstep(0.04, 0.45, d) * (1.0 - smoothstep(0.4, range, d));
|
|
@@ -210,24 +222,25 @@ export function createWaterMaterials({ depthRect, level, seaParameters, wakes, c
|
|
|
210
222
|
}
|
|
211
223
|
// Preserve the live lighting, clock and wake uniforms when specializing a water material.
|
|
212
224
|
function waterVariant(material) {
|
|
213
|
-
const
|
|
214
|
-
Object.assign(
|
|
215
|
-
Object.assign(
|
|
216
|
-
return
|
|
225
|
+
const variant = material.clone();
|
|
226
|
+
Object.assign(variant.defaultAttributeValues, material.defaultAttributeValues);
|
|
227
|
+
Object.assign(variant.uniforms, material.uniforms);
|
|
228
|
+
return variant;
|
|
217
229
|
}
|
|
218
230
|
|
|
231
|
+
/** Create a variant with its own linear RGB tint. Lighting, wave and wake uniforms stay linked to the original. */
|
|
219
232
|
export function tintedWater(material, tint) {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
return
|
|
233
|
+
const variant = waterVariant(material);
|
|
234
|
+
variant.uniforms.uTint = { value: new THREE.Color(...tint) };
|
|
235
|
+
return variant;
|
|
223
236
|
}
|
|
224
237
|
|
|
225
238
|
// Speeds are metres per second on level and steep reaches, respectively.
|
|
226
239
|
export function rippledStream(material, { speed, rapidSpeed = speed }) {
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return
|
|
240
|
+
const variant = waterVariant(material);
|
|
241
|
+
variant.defines = { ...variant.defines, STREAM_RIFFLES: '' };
|
|
242
|
+
variant.uniforms.uStreamSpeed = { value: new THREE.Vector2(speed, rapidSpeed) };
|
|
243
|
+
return variant;
|
|
231
244
|
}
|
|
232
245
|
// A sheet of open water has no current, banks or spring of its own.
|
|
233
246
|
function stillByDefault(material) {
|
|
@@ -269,19 +282,19 @@ const SHARED = [
|
|
|
269
282
|
];
|
|
270
283
|
export function landWater(waterMat, depth, rect, level, sea = null) {
|
|
271
284
|
const make = (hasDepth, own) => {
|
|
272
|
-
const
|
|
273
|
-
for (const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
285
|
+
const variant = waterMat.clone();
|
|
286
|
+
for (const uniformName of SHARED) if (waterMat.uniforms[uniformName]) variant.uniforms[uniformName] = waterMat.uniforms[uniformName];
|
|
287
|
+
variant.uniforms.uDepth = { value: depth };
|
|
288
|
+
variant.uniforms.uDepthR.value.copy(rect);
|
|
289
|
+
variant.uniforms.uLevel.value = level;
|
|
290
|
+
variant.uniforms.uHasDepth.value = hasDepth;
|
|
291
|
+
variant.uniforms.uRefl = { value: null };
|
|
279
292
|
if (own) {
|
|
280
|
-
Object.assign(
|
|
281
|
-
|
|
293
|
+
Object.assign(variant.uniforms, own);
|
|
294
|
+
variant.defines = { SEA: '' };
|
|
282
295
|
}
|
|
283
|
-
stillByDefault(
|
|
284
|
-
return
|
|
296
|
+
stillByDefault(variant);
|
|
297
|
+
return variant;
|
|
285
298
|
};
|
|
286
299
|
return { open: make(1, sea), stream: make(0) };
|
|
287
300
|
}
|
|
@@ -13,57 +13,57 @@ import * as THREE from 'three';
|
|
|
13
13
|
const plainWalk = THREE.Object3D.prototype.updateMatrixWorld;
|
|
14
14
|
|
|
15
15
|
// Has the object been moved, turned or scaled since it was last asked? (The first time it has.)
|
|
16
|
-
function moved(
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let
|
|
21
|
-
if (
|
|
16
|
+
function moved(object) {
|
|
17
|
+
const position = object.position,
|
|
18
|
+
rotation = object.quaternion,
|
|
19
|
+
scale = object.scale;
|
|
20
|
+
let lastTransform = object.placedAt;
|
|
21
|
+
if (lastTransform === undefined) lastTransform = object.placedAt = new Float64Array(10).fill(NaN);
|
|
22
22
|
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
lastTransform[0] === position.x &&
|
|
24
|
+
lastTransform[1] === position.y &&
|
|
25
|
+
lastTransform[2] === position.z &&
|
|
26
|
+
lastTransform[3] === rotation.x &&
|
|
27
|
+
lastTransform[4] === rotation.y &&
|
|
28
|
+
lastTransform[5] === rotation.z &&
|
|
29
|
+
lastTransform[6] === rotation.w &&
|
|
30
|
+
lastTransform[7] === scale.x &&
|
|
31
|
+
lastTransform[8] === scale.y &&
|
|
32
|
+
lastTransform[9] === scale.z
|
|
33
33
|
)
|
|
34
34
|
return false;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
lastTransform[0] = position.x;
|
|
36
|
+
lastTransform[1] = position.y;
|
|
37
|
+
lastTransform[2] = position.z;
|
|
38
|
+
lastTransform[3] = rotation.x;
|
|
39
|
+
lastTransform[4] = rotation.y;
|
|
40
|
+
lastTransform[5] = rotation.z;
|
|
41
|
+
lastTransform[6] = rotation.w;
|
|
42
|
+
lastTransform[7] = scale.x;
|
|
43
|
+
lastTransform[8] = scale.y;
|
|
44
|
+
lastTransform[9] = scale.z;
|
|
45
45
|
return true;
|
|
46
46
|
}
|
|
47
47
|
// Three's own walk (Object3D.updateMatrixWorld), but for the test of what moved
|
|
48
|
-
function place(
|
|
49
|
-
if (
|
|
50
|
-
|
|
48
|
+
function place(object, force) {
|
|
49
|
+
if (object.updateMatrixWorld !== plainWalk) {
|
|
50
|
+
object.updateMatrixWorld(force); // a kind with work of its own to do (a camera, a skinned mesh): Three's walk from here down
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
|
-
if (
|
|
54
|
-
if (
|
|
55
|
-
|
|
53
|
+
if (object.matrixAutoUpdate && moved(object)) object.updateMatrix();
|
|
54
|
+
if (object.placedUnder !== object.parent) {
|
|
55
|
+
object.placedUnder = object.parent;
|
|
56
56
|
force = true;
|
|
57
57
|
}
|
|
58
|
-
if (
|
|
59
|
-
if (
|
|
60
|
-
if (
|
|
61
|
-
else
|
|
58
|
+
if (object.matrixWorldNeedsUpdate || force) {
|
|
59
|
+
if (object.matrixWorldAutoUpdate) {
|
|
60
|
+
if (object.parent === null) object.matrixWorld.copy(object.matrix);
|
|
61
|
+
else object.matrixWorld.multiplyMatrices(object.parent.matrixWorld, object.matrix);
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
object.matrixWorldNeedsUpdate = false;
|
|
64
64
|
force = true;
|
|
65
65
|
}
|
|
66
|
-
const children =
|
|
66
|
+
const children = object.children;
|
|
67
67
|
for (let i = 0; i < children.length; i++) place(children[i], force);
|
|
68
68
|
}
|
|
69
69
|
// Called once a frame, before anything is drawn
|
|
@@ -17,7 +17,7 @@ export function createDiagnosticLog({
|
|
|
17
17
|
burstAt = 0,
|
|
18
18
|
burst = 0,
|
|
19
19
|
dropped = 0;
|
|
20
|
-
const whenIdle = page.requestIdleCallback ?
|
|
20
|
+
const whenIdle = page.requestIdleCallback ? callback => page.requestIdleCallback(callback, { timeout: idleMs }) : callback => page.setTimeout(callback, 0);
|
|
21
21
|
const saveSoon = () => whenIdle(save);
|
|
22
22
|
function save() {
|
|
23
23
|
saving = 0;
|
|
@@ -70,7 +70,7 @@ export function createDiagnosticLog({
|
|
|
70
70
|
const beforeLogRead = flush => flushes.push(flush);
|
|
71
71
|
function readLog(kind) {
|
|
72
72
|
for (let i = 0; i < flushes.length; i++) flushes[i]();
|
|
73
|
-
return kind ? entries.filter(
|
|
73
|
+
return kind ? entries.filter(entry => entry.kind === kind) : entries.slice();
|
|
74
74
|
}
|
|
75
75
|
function clearLog() {
|
|
76
76
|
entries.length = 0;
|
package/runtime/first-use.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
export function createFirstUse({ renderer, waitMs = 250, now = () => performance.now() }) {
|
|
7
7
|
const initialized = new WeakSet();
|
|
8
8
|
const waiting = [];
|
|
9
|
-
const asked = [];
|
|
10
9
|
let frameBegan = -Infinity;
|
|
11
10
|
|
|
12
11
|
function useProgram(program) {
|
|
@@ -21,42 +20,48 @@ export function createFirstUse({ renderer, waitMs = 250, now = () => performance
|
|
|
21
20
|
renderer.debug.checkShaderErrors = previous;
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
const [programs, resolve] = asked[i];
|
|
27
|
-
if (programs.some(p => waiting.includes(p))) continue;
|
|
28
|
-
asked.splice(i, 1);
|
|
29
|
-
resolve();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function putToUse(programs) {
|
|
23
|
+
function putToUse(programs, signal) {
|
|
24
|
+
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
33
25
|
if (!programs.length) return Promise.resolve();
|
|
34
26
|
if (now() - frameBegan > waitMs) {
|
|
35
27
|
programs.forEach(useProgram);
|
|
36
28
|
return Promise.resolve();
|
|
37
29
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const request = { remaining: programs.length, finish, fail };
|
|
32
|
+
const timer = setTimeout(drainRequest, waitMs * (programs.length + 1));
|
|
33
|
+
for (const program of programs) waiting.push({ program, request });
|
|
34
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
35
|
+
function finish() {
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
signal?.removeEventListener('abort', abort);
|
|
38
|
+
resolve();
|
|
39
|
+
}
|
|
40
|
+
function fail(error) {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
signal?.removeEventListener('abort', abort);
|
|
43
|
+
for (let i = waiting.length - 1; i >= 0; i--)
|
|
44
|
+
if (waiting[i].request === request) waiting.splice(i, 1);
|
|
45
|
+
reject(error);
|
|
46
|
+
}
|
|
47
|
+
function abort() { fail(signal.reason); }
|
|
48
|
+
function drainRequest() {
|
|
49
|
+
for (let i = 0; i < waiting.length;) {
|
|
50
|
+
if (waiting[i].request === request) useOne(waiting.splice(i, 1)[0]);
|
|
51
|
+
else i++;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
53
54
|
});
|
|
54
55
|
}
|
|
56
|
+
function useOne({ program, request }) {
|
|
57
|
+
try {
|
|
58
|
+
useProgram(program);
|
|
59
|
+
if (--request.remaining === 0) request.finish();
|
|
60
|
+
} catch (error) { request.fail(error); }
|
|
61
|
+
}
|
|
55
62
|
function useAtFrameStart() {
|
|
56
63
|
frameBegan = now();
|
|
57
|
-
if (
|
|
58
|
-
useProgram(waiting.shift());
|
|
59
|
-
settle();
|
|
64
|
+
if (waiting.length) useOne(waiting.shift());
|
|
60
65
|
}
|
|
61
66
|
return { putToUse, useAtFrameStart, useProgram };
|
|
62
67
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Track consecutive slow windows using displayed frame intervals in milliseconds.
|
|
3
|
+
* For each frame call `sample(frameMs)`. After the requested number of slow
|
|
4
|
+
* windows, `onSlow(averageFps, elapsedMs)` fires once. A healthy window rearms
|
|
5
|
+
* the monitor. Call `reset()` when pausing or changing views.
|
|
6
|
+
*/
|
|
7
|
+
export function createFramePacingMonitor({ minimumFps, windowMs = 1000, windows = 3, onSlow }) {
|
|
8
|
+
if (!(Number.isFinite(minimumFps) && minimumFps > 0 && Number.isFinite(windowMs) && windowMs > 0 &&
|
|
9
|
+
Number.isInteger(windows) && windows > 0 && typeof onSlow === 'function')) throw new RangeError('Invalid frame pacing options');
|
|
10
|
+
let elapsed = 0, frames = 0, misses = 0, slowFrames = 0, slowMs = 0;
|
|
11
|
+
|
|
12
|
+
function reset() {
|
|
13
|
+
elapsed = frames = misses = slowFrames = slowMs = 0;
|
|
14
|
+
}
|
|
15
|
+
function sample(frameMs) {
|
|
16
|
+
if (!(Number.isFinite(frameMs) && frameMs > 0)) return;
|
|
17
|
+
elapsed += frameMs;
|
|
18
|
+
frames++;
|
|
19
|
+
if (elapsed < windowMs) return;
|
|
20
|
+
if (frames * 1000 >= minimumFps * elapsed) {
|
|
21
|
+
reset();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (misses < windows) {
|
|
25
|
+
slowFrames += frames;
|
|
26
|
+
slowMs += elapsed;
|
|
27
|
+
misses++;
|
|
28
|
+
if (misses === windows) onSlow(slowFrames * 1000 / slowMs, slowMs);
|
|
29
|
+
}
|
|
30
|
+
elapsed = frames = 0;
|
|
31
|
+
}
|
|
32
|
+
return { sample, reset };
|
|
33
|
+
}
|
package/runtime/gpu-timing.js
CHANGED
|
@@ -53,24 +53,24 @@ export function createGpuTiming(renderer) {
|
|
|
53
53
|
// when no measurement can begin (no such query here, or the last one has not been answered yet); cardWork() gives the last
|
|
54
54
|
// answer in milliseconds, or null if there has been none.
|
|
55
55
|
let timer; // the extension, once asked for (null where there is none)
|
|
56
|
-
let
|
|
56
|
+
let pendingQuery = null, // the query waiting for its answer
|
|
57
57
|
work = null;
|
|
58
58
|
function timeCard() {
|
|
59
59
|
const gl = renderer.getContext();
|
|
60
60
|
if (timer === undefined) timer = gl.getExtension('EXT_disjoint_timer_query_webgl2');
|
|
61
61
|
if (!timer) return null;
|
|
62
|
-
if (
|
|
63
|
-
if (!gl.getQueryParameter(
|
|
64
|
-
if (!gl.getParameter(timer.GPU_DISJOINT_EXT)) work = gl.getQueryParameter(
|
|
65
|
-
gl.deleteQuery(
|
|
66
|
-
|
|
62
|
+
if (pendingQuery) {
|
|
63
|
+
if (!gl.getQueryParameter(pendingQuery, gl.QUERY_RESULT_AVAILABLE)) return null;
|
|
64
|
+
if (!gl.getParameter(timer.GPU_DISJOINT_EXT)) work = gl.getQueryParameter(pendingQuery, gl.QUERY_RESULT) / NANOSECONDS_IN_MS;
|
|
65
|
+
gl.deleteQuery(pendingQuery);
|
|
66
|
+
pendingQuery = null;
|
|
67
67
|
}
|
|
68
68
|
const query = gl.createQuery();
|
|
69
69
|
if (!query) return null;
|
|
70
70
|
gl.beginQuery(timer.TIME_ELAPSED_EXT, query);
|
|
71
71
|
return () => {
|
|
72
72
|
gl.endQuery(timer.TIME_ELAPSED_EXT);
|
|
73
|
-
|
|
73
|
+
pendingQuery = query;
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
const cardWork = () => work;
|
package/runtime/grid-cache.js
CHANGED
|
@@ -49,7 +49,7 @@ export function createGridCache({ database, store, build, revisions, hintPrefix
|
|
|
49
49
|
request.onerror = () => reject(request.error);
|
|
50
50
|
});
|
|
51
51
|
if (!Array.isArray(kept) || kept.length !== arrays.length ||
|
|
52
|
-
!kept.every((
|
|
52
|
+
!kept.every((cachedArray,i) => ArrayBuffer.isView(cachedArray) && cachedArray.constructor === arrays[i].constructor && cachedArray.length === arrays[i].length)) return false;
|
|
53
53
|
arrays.forEach((array,i) => array.set(kept[i]));
|
|
54
54
|
return true;
|
|
55
55
|
} catch {
|
package/runtime/grid-rows.js
CHANGED
|
@@ -1,9 +1,48 @@
|
|
|
1
1
|
// Rows of baked grids, cut out to be sent from a worker and put back in their place on the page. A grid is a typed array of
|
|
2
2
|
// `rows` rows, with any number of values to a row (a height, three of a normal, four of a cover).
|
|
3
3
|
|
|
4
|
-
// Copy the half-open row interval [
|
|
5
|
-
const cutRows = (grids, rows,
|
|
6
|
-
// Puts what cutRows cut back into grids of the same shapes,
|
|
7
|
-
const pasteRows = (grids, rows,
|
|
4
|
+
// Copy the half-open row interval [startRow, endRow) from each grid.
|
|
5
|
+
const cutRows = (grids, rows, startRow, endRow) => grids.map(grid => grid.slice((startRow * grid.length) / rows, (endRow * grid.length) / rows));
|
|
6
|
+
// Puts what cutRows cut back into grids of the same shapes, starting at startRow.
|
|
7
|
+
const pasteRows = (grids, rows, startRow, bandData) => grids.forEach((grid, i) => grid.set(bandData[i], (startRow * grid.length) / rows));
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
function checkBandSize(size) {
|
|
10
|
+
if (!Number.isSafeInteger(size) || size <= 0) throw new RangeError('Band size must be a positive integer');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Bake a grid locally with one yield after each synchronous band, including the tail.
|
|
14
|
+
async function bakeRowBands(rows, bandSize, bake, yieldTurn) {
|
|
15
|
+
checkBandSize(bandSize);
|
|
16
|
+
if (!Number.isSafeInteger(rows) || rows < 0) throw new RangeError('Invalid row count');
|
|
17
|
+
for (let from = 0; from < rows; from += bandSize) {
|
|
18
|
+
bake(from, Math.min(rows, from + bandSize));
|
|
19
|
+
await yieldTurn();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Fill the half-open interval [from, to) in typed destination grids of equal row count.
|
|
25
|
+
* request(start, end) returns one cutRows result or a promise for it. Requests are
|
|
26
|
+
* submitted synchronously in row order. Completed cuts are installed and released
|
|
27
|
+
* immediately. Rejection waits for all outstanding writes before returning ownership.
|
|
28
|
+
*/
|
|
29
|
+
async function fillRowBands(grids, rows, bandSize, request, from = 0, to = rows) {
|
|
30
|
+
checkBandSize(bandSize);
|
|
31
|
+
if (!Number.isSafeInteger(rows) || !Number.isSafeInteger(from) || !Number.isSafeInteger(to) ||
|
|
32
|
+
from < 0 || to < from || to > rows) throw new RangeError('Invalid row interval');
|
|
33
|
+
const pending = [];
|
|
34
|
+
async function fill(start, end) {
|
|
35
|
+
const bandData = await request(start, end);
|
|
36
|
+
pasteRows(grids, rows, start, bandData);
|
|
37
|
+
}
|
|
38
|
+
for (let start = from; start < to; start += bandSize)
|
|
39
|
+
pending.push(fill(start, Math.min(start + bandSize, to)));
|
|
40
|
+
try {
|
|
41
|
+
await Promise.all(pending);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
await Promise.allSettled(pending);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { bakeRowBands, cutRows, fillRowBands, pasteRows };
|