roamwright 0.1.0 → 0.1.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/README.md +1 -1
- package/geometry/builder.js +11 -14
- package/math/curve.js +3 -4
- package/package.json +1 -1
- package/rendering/post.js +4 -5
- package/rendering/still-casters.js +6 -11
- package/rendering/world-matrices.js +4 -6
- package/runtime/quality-fit.js +5 -9
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Install with npm. It resolves the Three.js peer automatically for a new project.
|
|
|
23
23
|
npm install roamwright
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Version 0.1.
|
|
26
|
+
Version 0.1.1 supports **Three.js 0.187.0** and **0.170.0**. To select a revision explicitly, use `npm install roamwright three@0.187.0`. You can also install the tagged source directly with `npm install github:enestaylan/roamwright#v0.1.1`.
|
|
27
27
|
|
|
28
28
|
Use an ES module bundler, or provide a browser import map as in the example. Supply a canvas with a CSS width and height.
|
|
29
29
|
|
package/geometry/builder.js
CHANGED
|
@@ -9,8 +9,8 @@ import { box, TRS } from './primitives.js';
|
|
|
9
9
|
const _n3 = new THREE.Matrix3(),
|
|
10
10
|
_v = new THREE.Vector3(),
|
|
11
11
|
_m5 = new THREE.Matrix4();
|
|
12
|
-
//
|
|
13
|
-
//
|
|
12
|
+
// Three.js calls this upload callback with the attribute as its receiver. Static
|
|
13
|
+
// geometry can release its CPU copy once the GPU owns the buffer.
|
|
14
14
|
function releaseArray() {
|
|
15
15
|
this.bytes = this.array.byteLength; // what stands on the card, for the reckoning of memory
|
|
16
16
|
this.array = null;
|
|
@@ -71,8 +71,8 @@ function geometryOf(parts, sphere = null) {
|
|
|
71
71
|
if (!sphere && points instanceof Float32Array && points.length) sphere = sphereOf(points);
|
|
72
72
|
if (sphere) g.boundingSphere = new THREE.Sphere(new THREE.Vector3(sphere[0], sphere[1], sphere[2]), sphere[3]);
|
|
73
73
|
else g.computeBoundingSphere();
|
|
74
|
-
//
|
|
75
|
-
//
|
|
74
|
+
// Skinned meshes compute bounds on the CPU. Keep their positions, joint indices
|
|
75
|
+
// and weights available, including when several meshes share the geometry.
|
|
76
76
|
for (const name in g.attributes) if (!(parts.skinIndex && SKIN_BOUNDS.includes(name))) g.attributes[name].onUpload(releaseArray);
|
|
77
77
|
return g;
|
|
78
78
|
}
|
|
@@ -92,10 +92,8 @@ function stillMesh(geometry, material, shadow) {
|
|
|
92
92
|
if (shadow) markStill(m);
|
|
93
93
|
return m;
|
|
94
94
|
}
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
// renderer keeps the binding of a mesh's attributes by geometry and program, so each draw of such a mesh bound every attribute
|
|
98
|
-
// anew and made garbage doing it (hundreds a frame over a land's cover).
|
|
95
|
+
// Share GPU buffers and bounds while giving each instanced mesh a geometry identity
|
|
96
|
+
// of its own. Three.js can then reuse the vertex bindings for each mesh.
|
|
99
97
|
function geometryView(source) {
|
|
100
98
|
if (!source.boundingSphere) source.computeBoundingSphere();
|
|
101
99
|
const view = new THREE.BufferGeometry();
|
|
@@ -104,8 +102,8 @@ function geometryView(source) {
|
|
|
104
102
|
view.boundingSphere = source.boundingSphere.clone();
|
|
105
103
|
return view;
|
|
106
104
|
}
|
|
107
|
-
const ROOM = 768, //
|
|
108
|
-
GROWTH = 2, //
|
|
105
|
+
const ROOM = 768, // initial capacity in scalar components
|
|
106
|
+
GROWTH = 2, // geometric growth keeps the total copying cost linear
|
|
109
107
|
NO_FLOATS = new Float32Array(0),
|
|
110
108
|
NO_NORMAL_BYTES = new Int8Array(0),
|
|
111
109
|
NO_COLOUR_BYTES = new Uint8Array(0);
|
|
@@ -152,8 +150,8 @@ class GB {
|
|
|
152
150
|
this.spent = false; // true once release has let the parts go
|
|
153
151
|
this.wide = false; // true once a colour outside 0..1 or a normal's number outside -1..1 is put in: bytes cannot hold it
|
|
154
152
|
this.skw = null;
|
|
155
|
-
// Set
|
|
156
|
-
//
|
|
153
|
+
// Set pb to [] to record the start of each part. Its six bounding-box components
|
|
154
|
+
// are measured before vertex positions are rounded to floats.
|
|
157
155
|
this.bounds = [];
|
|
158
156
|
}
|
|
159
157
|
// What has been filled so far, for whoever looks at it: positions, normals and colours, three numbers to a vertex.
|
|
@@ -519,8 +517,7 @@ class GB {
|
|
|
519
517
|
build(compact = !this.wide) {
|
|
520
518
|
return geometryOf(this.parts(compact));
|
|
521
519
|
}
|
|
522
|
-
//
|
|
523
|
-
// the function that filled it, as in a town's builder) would otherwise hold tens of megabytes of plain numbers for good.
|
|
520
|
+
// Drop the backing arrays after the geometry has taken ownership of its buffers.
|
|
524
521
|
release() {
|
|
525
522
|
this.positions = this.normals = this.colours = NO_FLOATS;
|
|
526
523
|
this.normalBytes = NO_NORMAL_BYTES;
|
package/math/curve.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// ════════════════════════════════════════════════════════════════════════
|
|
2
2
|
// A smooth curve through a line of [x, z] points: a centripetal Catmull-Rom spline, walked at even steps of its length.
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// using the far end's extension for both ends.
|
|
4
|
+
// Matches Three.js CatmullRomCurve3.getSpacedPoints for open centripetal curves,
|
|
5
|
+
// using scalar arithmetic suitable for workers. The evaluation order and the
|
|
6
|
+
// extrapolation used at the ends of two-point curves match Three.js.
|
|
8
7
|
// ════════════════════════════════════════════════════════════════════════
|
|
9
8
|
const ARC_STEPS = 200, // the pieces the curve's length is measured in
|
|
10
9
|
REPEATED = 1e-4; // points closer than this (to the power the knots are spaced by) count as one
|
package/package.json
CHANGED
package/rendering/post.js
CHANGED
|
@@ -11,7 +11,7 @@ import { AO_FS, BLOOM, BLUR_FS, EASU_FS, FINAL_FS, GRADE, PRESENT_FS, QUAD_VS, R
|
|
|
11
11
|
// shafts are soft, so they are worked out at half size; bloom works at half size and below. None of them writes a full-size copy of the frame.
|
|
12
12
|
// Where a device cannot hold its preset at the picture's size, the world is drawn smaller (post.scale of each side, set by the quality
|
|
13
13
|
// fit) and brought up to the picture's size after the final pass, by an edge-adaptive upscale and a sharpening pass (the method of
|
|
14
|
-
// AMD's FSR 1).
|
|
14
|
+
// AMD's FSR 1). Overlay sprites render at the output resolution (drawnAtFullSize).
|
|
15
15
|
// With temporal anti-aliasing (taa.js) the scene is drawn with the lens moved a little each frame, the final pass keeps a running
|
|
16
16
|
// picture of it, tone-mapped, and a third full-size pass grades that onto the screen.
|
|
17
17
|
const DOF_EASE = 0.08; // how much of depth of field comes in or goes out a frame
|
|
@@ -107,7 +107,7 @@ export function createPostProcessing({
|
|
|
107
107
|
uTime: grade.uTime,
|
|
108
108
|
},
|
|
109
109
|
});
|
|
110
|
-
//
|
|
110
|
+
// Render overlays at output resolution with depth testing against the main scene.
|
|
111
111
|
const overlay = new THREE.Scene();
|
|
112
112
|
// A scene of one quad that covers the screen, for a post-processing pass.
|
|
113
113
|
function fullScreen(material) {
|
|
@@ -480,9 +480,8 @@ export function createPostProcessing({
|
|
|
480
480
|
}
|
|
481
481
|
// The upscale's targets while they exist, for the reckoning of memory.
|
|
482
482
|
const upscaleTargets = () => [upscale.low, upscale.full];
|
|
483
|
-
//
|
|
484
|
-
// over
|
|
485
|
-
// picture's own pass laid it over light: its cover is raised to what it hid there (exact over black, near enough over the rest).
|
|
483
|
+
// Composite a depth-tested sprite at output resolution. Adjust its alpha for
|
|
484
|
+
// blending over encoded colour after the main grading pass.
|
|
486
485
|
function drawnAtFullSize(sprite) {
|
|
487
486
|
const material = sprite.material;
|
|
488
487
|
material.onBeforeCompile = shader => {
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// moves: a shadow cache draws it once into a kept picture, and each later redraw starts from that picture and draws only
|
|
6
|
-
// what moves over it. What stands still carries STILL_LAYER, by which that one draw picks it out. While the picture is drawn over
|
|
7
|
-
// (`still.kept`), a still caster that is in it as it stands leaves itself out (the shadow renderer); one that is
|
|
8
|
-
// not (shown since, a batch whose pieces changed, a mesh that moved) is drawn as ever and the picture is marked to be drawn again.
|
|
9
|
-
// Each adds which it is to `still.sum` in both draws, so that one hidden since is missed by the sum and is noticed too.
|
|
1
|
+
// A point-light shadow has six faces. Cache static casters once, then draw
|
|
2
|
+
// dynamic geometry over that depth on subsequent passes. STILL_LAYER selects
|
|
3
|
+
// the static casters. The revision and membership sum invalidate the cache
|
|
4
|
+
// when a caster moves, changes geometry, appears or disappears.
|
|
10
5
|
const STILL_LAYER = 2,
|
|
11
6
|
STILL_BIT = 1 << STILL_LAYER;
|
|
12
7
|
const still = { kept: false, sum: 0, round: 0 }; // round: which drawing of the kept picture this is
|
|
@@ -17,8 +12,8 @@ const isStill = object => (object.layers.mask & STILL_BIT) !== 0;
|
|
|
17
12
|
// Where a mesh stands, how it is turned (about any axis) and its size, as one number
|
|
18
13
|
const placeOf = e => e[12] * 1.37 + e[13] * 2.11 + e[14] * 0.59 + e[0] * 5.3 + e[1] * 3.3 + e[2] * 4.1 + e[5] * 1.9 + e[6] * 2.7;
|
|
19
14
|
|
|
20
|
-
//
|
|
21
|
-
//
|
|
15
|
+
// Record a caster during cache generation. On subsequent draws, skip it only
|
|
16
|
+
// when its cached revision still matches the caller-supplied transform or batch revision.
|
|
22
17
|
function keptAway(object, as) {
|
|
23
18
|
if (!still.kept) {
|
|
24
19
|
object.keptIn = still.round;
|
|
@@ -4,12 +4,10 @@ import * as THREE from 'three';
|
|
|
4
4
|
// ════════════════════════════════════════════════════════════════════════
|
|
5
5
|
// Where everything stands in the world, worked out once a frame and only for what moved
|
|
6
6
|
// ════════════════════════════════════════════════════════════════════════
|
|
7
|
-
//
|
|
8
|
-
// matrix
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// it is placed in the world again only then, or when it has been put under another parent, or when something above it moved.
|
|
12
|
-
// An object that keeps its matrix itself (matrixAutoUpdate false) and changes it must say so, as Three asks: matrixWorldNeedsUpdate.
|
|
7
|
+
// Update world transforms once before rendering multiple passes. Compose a local
|
|
8
|
+
// matrix when its transform changes, then propagate changes through descendants.
|
|
9
|
+
// Reparenting also invalidates the world transform. For manually managed matrices,
|
|
10
|
+
// set matrixWorldNeedsUpdate after editing the matrix directly.
|
|
13
11
|
|
|
14
12
|
|
|
15
13
|
const plainWalk = THREE.Object3D.prototype.updateMatrixWorld;
|
package/runtime/quality-fit.js
CHANGED
|
@@ -9,14 +9,11 @@ const FRAME_MS = 1000 / 60, // the target: sixty frames a second
|
|
|
9
9
|
VERDICTS = 2, // the verdicts in a row that step the preset down: one heavy view or one hitch does not
|
|
10
10
|
TRIAL_VERDICTS = 3, // and the roomy ones in a row before the next preset up is tried
|
|
11
11
|
CEILING_MS = 180000, // a drawn size that missed the target is not tried again for this long: the miss may have been a passing load
|
|
12
|
-
//
|
|
13
|
-
// often the world still arriving, and a phone must not sit at Low for three minutes for it; a preset that keeps missing
|
|
14
|
-
// is not tried every minute, since each trial makes the houses, the grass and the shaders again
|
|
12
|
+
// Back off repeated preset trials, since reconfiguring a renderer can itself cause slow frames.
|
|
15
13
|
PRESET_CEILINGS_MS = [60000, 180000, 600000],
|
|
16
|
-
SETTLE_MS = 3000, //
|
|
17
|
-
ARRIVAL_SETTLE_MS = 10000, //
|
|
18
|
-
|
|
19
|
-
SCALES = [1, 0.85, 0.75, 0.67];
|
|
14
|
+
SETTLE_MS = 3000, // allow uploads and shader compilation to settle after reconfiguration
|
|
15
|
+
ARRIVAL_SETTLE_MS = 10000, // initial asset uploads may take longer than a preset change
|
|
16
|
+
SCALES = [1, 0.85, 0.75, 0.67]; // render resolution as a fraction of each viewport dimension
|
|
20
17
|
export function createQualityFit({ state, post, cardBlocks, cardDone, store, deviceQuality, applyQuality, setDrawScale, warmShaders, emit, noteLog }) {
|
|
21
18
|
const { keepChoice, keepFit, keepScale, keptChoice, keptFit, keptOnce, keptScale } = store;
|
|
22
19
|
const fit = {
|
|
@@ -62,8 +59,7 @@ export function createQualityFit({ state, post, cardBlocks, cardDone, store, dev
|
|
|
62
59
|
fit.slow = fit.roomy = 0;
|
|
63
60
|
fit.next = performance.now() + SETTLE_MS;
|
|
64
61
|
}
|
|
65
|
-
//
|
|
66
|
-
// card, and frames are slow for a few seconds whatever the preset. Nothing is timed until that has passed.
|
|
62
|
+
// Exclude initial uploads and compilation from steady-state frame timings.
|
|
67
63
|
function settleQuality() {
|
|
68
64
|
rest();
|
|
69
65
|
fit.next = performance.now() + ARRIVAL_SETTLE_MS;
|