roamwright 0.1.1 → 0.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/CONTRIBUTING.md +39 -8
- package/README.md +53 -24
- package/examples/viaduct-camera.js +40 -0
- package/examples/viaduct-landscape.js +81 -0
- package/examples/viaduct.css +75 -0
- package/examples/viaduct.html +47 -0
- package/examples/viaduct.js +332 -0
- package/geometry/creased-sheet.js +127 -0
- package/geometry/ear.js +97 -0
- package/geometry/erosion.js +106 -0
- package/geometry/face-grid.js +143 -0
- package/geometry/garment-tags.js +11 -0
- package/geometry/hair-gathers.js +174 -0
- package/geometry/hair-locks.js +156 -0
- package/geometry/hair-patch.js +42 -0
- package/geometry/hair-shell.js +186 -0
- package/geometry/hair-tags.js +6 -0
- package/geometry/head-profile.js +138 -0
- package/geometry/head-shape.js +499 -0
- package/geometry/heightfield.js +68 -0
- package/geometry/outline-grid.js +46 -0
- package/geometry/path-field.js +65 -0
- package/geometry/sagging-tube.js +58 -0
- package/geometry/sampled-surface.js +101 -0
- package/geometry/scatter-grid.js +32 -0
- package/geometry/sculpt.js +263 -0
- package/geometry/shore-grid.js +67 -0
- package/geometry/strata-field.js +339 -0
- package/geometry/strata-tiles.js +215 -0
- package/geometry/stream.js +94 -0
- package/geometry/terrain-chunks.js +300 -0
- package/geometry/terrain-extension.js +44 -0
- package/math/cell-edge.js +44 -0
- package/math/cloth-textures.js +83 -0
- package/math/cloud-textures.js +112 -0
- package/math/color.js +29 -0
- package/math/mountain-ranges.js +463 -0
- package/math/particle-noise.js +48 -0
- package/math/periodic.js +20 -0
- package/math/rock-texture.js +56 -0
- package/math/surface-textures.js +241 -0
- package/motion/arm-reach.js +74 -0
- package/motion/biped-stride.js +276 -0
- package/motion/crowd-alarms.js +127 -0
- package/motion/crowd-routine.js +183 -0
- package/motion/daily-clock.js +59 -0
- package/motion/instance-sight.js +84 -0
- package/motion/quadruped.js +332 -0
- package/motion/weather.js +59 -0
- package/motion/wind.js +27 -0
- package/package.json +6 -4
- package/rendering/caster-motion.js +79 -0
- package/rendering/cell-lod.js +175 -0
- package/rendering/cloud-dome.js +371 -0
- package/rendering/cloud-field.js +83 -0
- package/rendering/compilation-schedule.js +34 -0
- package/rendering/contact-shadows.js +79 -0
- package/rendering/crowd-skinning.js +133 -0
- package/rendering/crust.js +28 -0
- package/rendering/daylight.js +50 -0
- package/rendering/far-shadow.js +186 -0
- package/rendering/flocks.js +323 -0
- package/rendering/garment-material.js +110 -0
- package/rendering/glow-lines.js +74 -0
- package/rendering/glow-shell.js +90 -0
- package/rendering/hair-strands.js +67 -0
- package/rendering/height-haze.js +129 -0
- package/rendering/height-probe.js +91 -0
- package/rendering/interior-mapping.js +19 -0
- package/rendering/light-budget.js +222 -0
- package/rendering/light-points.js +51 -0
- package/rendering/light-shafts.js +131 -0
- package/rendering/local-lights.js +28 -0
- package/rendering/low-light.js +13 -0
- package/rendering/material-lod.js +110 -0
- package/rendering/particle-emitters.js +223 -0
- package/rendering/particles.js +297 -0
- package/rendering/planar-reflection.js +175 -0
- package/rendering/post-shaders.js +21 -1
- package/rendering/post.js +4 -0
- package/rendering/rain-rings.js +22 -0
- package/rendering/road-surface.js +63 -0
- package/rendering/sea-shaders.js +230 -0
- package/rendering/shader-warmup.js +197 -0
- package/rendering/shadow-alignment.js +28 -0
- package/rendering/shadow-depth.js +129 -0
- package/rendering/sky-occlusion.js +187 -0
- package/rendering/sky.js +169 -0
- package/rendering/stage-lights.js +209 -0
- package/rendering/static-point-shadow.js +119 -0
- package/rendering/strata-material.js +93 -0
- package/rendering/stream-flow.js +36 -0
- package/rendering/surface-light.js +22 -0
- package/rendering/surface-projection.js +69 -0
- package/rendering/talus.js +26 -0
- package/rendering/terrain-rock.js +48 -0
- package/rendering/texture-fills.js +68 -0
- package/rendering/viewport.js +9 -0
- package/rendering/wakes.js +99 -0
- package/rendering/water-material.js +288 -0
- package/runtime/device-quality.js +27 -0
- package/runtime/diagnostic-log.js +80 -0
- package/runtime/events.js +14 -0
- package/runtime/first-use.js +3 -1
- package/runtime/frame-yield.js +14 -0
- package/runtime/grid-cache.js +88 -0
- package/runtime/grid-rows.js +9 -0
- package/runtime/module-preload.js +15 -0
- package/runtime/search.js +69 -0
- package/runtime/spatial-audio.js +57 -0
- package/scripts/serve.py +26 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Bounded diagnostic entries, scoped to a page, visit and storage key. */
|
|
2
|
+
export function createDiagnosticLog({
|
|
3
|
+
storageKey, page = globalThis, capacity = 300, saveDelayMs = 1500,
|
|
4
|
+
idleMs = 5000, textLimit = 600, perSecond = 20, visit = Date.now().toString(36),
|
|
5
|
+
}) {
|
|
6
|
+
let placeOf = () => '';
|
|
7
|
+
function stored() {
|
|
8
|
+
try {
|
|
9
|
+
const list = JSON.parse(page.localStorage.getItem(storageKey));
|
|
10
|
+
return Array.isArray(list) ? list : [];
|
|
11
|
+
} catch {
|
|
12
|
+
return []; // storage refused (a private window) or spoilt: start afresh
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const entries = stored();
|
|
16
|
+
let saving = 0,
|
|
17
|
+
burstAt = 0,
|
|
18
|
+
burst = 0,
|
|
19
|
+
dropped = 0;
|
|
20
|
+
const whenIdle = page.requestIdleCallback ? fn => page.requestIdleCallback(fn, { timeout: idleMs }) : fn => page.setTimeout(fn, 0);
|
|
21
|
+
const saveSoon = () => whenIdle(save);
|
|
22
|
+
function save() {
|
|
23
|
+
saving = 0;
|
|
24
|
+
try {
|
|
25
|
+
page.localStorage.setItem(storageKey, JSON.stringify(entries));
|
|
26
|
+
} catch {
|
|
27
|
+
// storage full or refused: the log lives on in this visit
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function noteLog(kind, text) {
|
|
32
|
+
const second = Math.floor(page.performance.now() / 1000);
|
|
33
|
+
if (second !== burstAt) {
|
|
34
|
+
burstAt = second;
|
|
35
|
+
burst = 0;
|
|
36
|
+
}
|
|
37
|
+
if (++burst > perSecond) {
|
|
38
|
+
dropped++;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (dropped) {
|
|
42
|
+
const left = dropped;
|
|
43
|
+
dropped = 0;
|
|
44
|
+
noteLog('warn', `${left} entries of the page's log left out: more than ${perSecond} came in one second`);
|
|
45
|
+
}
|
|
46
|
+
const words = String(text).slice(0, textLimit),
|
|
47
|
+
last = entries[entries.length - 1];
|
|
48
|
+
if (last && last.visit === visit && last.kind === kind && last.text === words) last.n = (last.n || 1) + 1;
|
|
49
|
+
else {
|
|
50
|
+
const entry = { t: new Date().toISOString(), kind, text: words, at: page.location.pathname + page.location.search, visit };
|
|
51
|
+
if (kind !== 'note') entry.ctx = where();
|
|
52
|
+
entries.push(entry);
|
|
53
|
+
if (entries.length > capacity) entries.splice(0, entries.length - capacity);
|
|
54
|
+
}
|
|
55
|
+
if (!saving) saving = page.setTimeout(saveSoon, saveDelayMs);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function where() {
|
|
59
|
+
try {
|
|
60
|
+
return placeOf();
|
|
61
|
+
} catch {
|
|
62
|
+
return ''; // asked while the modules that know are still loading
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function setLogPlace(say) {
|
|
66
|
+
placeOf = say;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const flushes = [];
|
|
70
|
+
const beforeLogRead = flush => flushes.push(flush);
|
|
71
|
+
function readLog(kind) {
|
|
72
|
+
for (let i = 0; i < flushes.length; i++) flushes[i]();
|
|
73
|
+
return kind ? entries.filter(e => e.kind === kind) : entries.slice();
|
|
74
|
+
}
|
|
75
|
+
function clearLog() {
|
|
76
|
+
entries.length = 0;
|
|
77
|
+
save();
|
|
78
|
+
}
|
|
79
|
+
return { beforeLogRead, clearLog, noteLog, readLog, save, setLogPlace };
|
|
80
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Independent synchronous event channels. Listeners run in registration order.
|
|
2
|
+
export function createEvents() {
|
|
3
|
+
const listeners = new Map();
|
|
4
|
+
function on(name, listener) {
|
|
5
|
+
const list = listeners.get(name);
|
|
6
|
+
if (list) list.push(listener);
|
|
7
|
+
else listeners.set(name, [listener]);
|
|
8
|
+
}
|
|
9
|
+
function emit(name, ...args) {
|
|
10
|
+
const list = listeners.get(name);
|
|
11
|
+
if (list) for (const listener of list) listener(...args);
|
|
12
|
+
}
|
|
13
|
+
return { on, emit };
|
|
14
|
+
}
|
package/runtime/first-use.js
CHANGED
|
@@ -4,17 +4,19 @@
|
|
|
4
4
|
* a timeout drains requests that would otherwise never resolve.
|
|
5
5
|
*/
|
|
6
6
|
export function createFirstUse({ renderer, waitMs = 250, now = () => performance.now() }) {
|
|
7
|
+
const initialized = new WeakSet();
|
|
7
8
|
const waiting = [];
|
|
8
9
|
const asked = [];
|
|
9
10
|
let frameBegan = -Infinity;
|
|
10
11
|
|
|
11
12
|
function useProgram(program) {
|
|
12
|
-
if (!program.program) return;
|
|
13
|
+
if (!program.program || initialized.has(program.program)) return;
|
|
13
14
|
const gl = renderer.getContext();
|
|
14
15
|
const previous = renderer.debug.checkShaderErrors;
|
|
15
16
|
try {
|
|
16
17
|
renderer.debug.checkShaderErrors = previous && !gl.getProgramParameter(program.program, gl.LINK_STATUS);
|
|
17
18
|
program.getUniforms();
|
|
19
|
+
initialized.add(program.program);
|
|
18
20
|
} finally {
|
|
19
21
|
renderer.debug.checkShaderErrors = previous;
|
|
20
22
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// A timer also releases the caller when animation frames are suspended.
|
|
2
|
+
export const nextFrame = (maxWaitMs = 50) =>
|
|
3
|
+
new Promise(resolve => {
|
|
4
|
+
const done = () => {
|
|
5
|
+
clearTimeout(timer);
|
|
6
|
+
cancelAnimationFrame(frame);
|
|
7
|
+
resolve();
|
|
8
|
+
};
|
|
9
|
+
const timer = setTimeout(done, maxWaitMs),
|
|
10
|
+
frame = requestAnimationFrame(done);
|
|
11
|
+
});
|
|
12
|
+
// A promise kept once the next frame has been painted: a task queued from the frame's own callback runs after its paint. What
|
|
13
|
+
// was just put on the page is then on the screen before a long job begins.
|
|
14
|
+
export const painted = (maxWaitMs = 50) => nextFrame(maxWaitMs).then(() => new Promise(resolve => setTimeout(resolve, 0)));
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Persist typed grid arrays in IndexedDB. A synchronous hint lets a consumer
|
|
2
|
+
// start computing immediately on a cold visit. A missing hint is always safe.
|
|
3
|
+
export function createGridCache({ database, store, build, revisions, hintPrefix }) {
|
|
4
|
+
const revisionOf = name => revisions ? Object.hasOwn(revisions, name) && revisions[name] : build;
|
|
5
|
+
const recordKey = (name, revision) => revisions ? [name, revision] : revision + ' ' + name;
|
|
6
|
+
|
|
7
|
+
function obsolete(key, name, revision) {
|
|
8
|
+
if (!revisions) return !String(key).startsWith(build + ' ');
|
|
9
|
+
// Drop legacy build-wide records. With individual revisions, retire only this grid's older copies.
|
|
10
|
+
return !Array.isArray(key) || (key[0] === name && key[1] !== revision);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function open() {
|
|
14
|
+
return new Promise(resolve => {
|
|
15
|
+
try {
|
|
16
|
+
const request = indexedDB.open(database, 1);
|
|
17
|
+
let blocked = false;
|
|
18
|
+
request.onupgradeneeded = () => request.result.createObjectStore(store);
|
|
19
|
+
request.onblocked = () => { blocked = true; resolve(null); };
|
|
20
|
+
request.onerror = () => resolve(null);
|
|
21
|
+
request.onsuccess = () => {
|
|
22
|
+
if (blocked) request.result.close();
|
|
23
|
+
else resolve(request.result);
|
|
24
|
+
};
|
|
25
|
+
} catch {
|
|
26
|
+
resolve(null);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function hasKept(name) {
|
|
32
|
+
try {
|
|
33
|
+
const revision = revisionOf(name);
|
|
34
|
+
return !!revision && localStorage.getItem(hintPrefix + name) === revision;
|
|
35
|
+
} catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function takeKept(name, arrays) {
|
|
41
|
+
const revision = revisionOf(name);
|
|
42
|
+
if (!revision) return false;
|
|
43
|
+
const db = await open();
|
|
44
|
+
if (!db) return false;
|
|
45
|
+
try {
|
|
46
|
+
const kept = await new Promise((resolve, reject) => {
|
|
47
|
+
const request = db.transaction(store).objectStore(store).get(recordKey(name, revision));
|
|
48
|
+
request.onsuccess = () => resolve(request.result);
|
|
49
|
+
request.onerror = () => reject(request.error);
|
|
50
|
+
});
|
|
51
|
+
if (!Array.isArray(kept) || kept.length !== arrays.length ||
|
|
52
|
+
!kept.every((a,i) => ArrayBuffer.isView(a) && a.constructor === arrays[i].constructor && a.length === arrays[i].length)) return false;
|
|
53
|
+
arrays.forEach((array,i) => array.set(kept[i]));
|
|
54
|
+
return true;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
} finally {
|
|
58
|
+
db.close();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function keep(name, arrays) {
|
|
63
|
+
const revision = revisionOf(name);
|
|
64
|
+
if (!revision) return;
|
|
65
|
+
const db = await open();
|
|
66
|
+
if (!db) return;
|
|
67
|
+
try {
|
|
68
|
+
await new Promise((resolve, reject) => {
|
|
69
|
+
const transaction = db.transaction(store, 'readwrite');
|
|
70
|
+
transaction.oncomplete = resolve;
|
|
71
|
+
transaction.onabort = () => reject(transaction.error);
|
|
72
|
+
const records = transaction.objectStore(store);
|
|
73
|
+
const keys = records.getAllKeys();
|
|
74
|
+
keys.onsuccess = () => {
|
|
75
|
+
for (const key of keys.result) if (obsolete(key, name, revision)) records.delete(key);
|
|
76
|
+
};
|
|
77
|
+
records.put(arrays, recordKey(name, revision));
|
|
78
|
+
});
|
|
79
|
+
localStorage.setItem(hintPrefix + name, revision);
|
|
80
|
+
} catch {
|
|
81
|
+
// A refused or full store can be retried on the next visit.
|
|
82
|
+
} finally {
|
|
83
|
+
db.close();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return { hasKept, takeKept, keep };
|
|
88
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
// `rows` rows, with any number of values to a row (a height, three of a normal, four of a cover).
|
|
3
|
+
|
|
4
|
+
// Copy the half-open row interval [j0, j1) from each grid.
|
|
5
|
+
const cutRows = (grids, rows, j0, j1) => grids.map(grid => grid.slice((j0 * grid.length) / rows, (j1 * grid.length) / rows));
|
|
6
|
+
// Puts what cutRows cut back into grids of the same shapes, from row j0 on.
|
|
7
|
+
const pasteRows = (grids, rows, j0, cut) => grids.forEach((grid, i) => grid.set(cut[i], (j0 * grid.length) / rows));
|
|
8
|
+
|
|
9
|
+
export { cutRows, pasteRows };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Preload dependency URLs once per loader, relative to the caller's module. */
|
|
2
|
+
export function createModulePreloader(base, document = globalThis.document) {
|
|
3
|
+
const requested = new Set();
|
|
4
|
+
return files => {
|
|
5
|
+
for (const file of files) {
|
|
6
|
+
const url = new URL(file, base).href;
|
|
7
|
+
if (requested.has(url)) continue;
|
|
8
|
+
const link = document.createElement('link');
|
|
9
|
+
link.rel = 'modulepreload';
|
|
10
|
+
link.href = url;
|
|
11
|
+
document.head.appendChild(link);
|
|
12
|
+
requested.add(url);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Token scoring for searchable place names, titles and descriptions.
|
|
2
|
+
const EXACT = 4,
|
|
3
|
+
START = 3,
|
|
4
|
+
INSIDE = 2, // a query word of INSIDE_LEAST letters or more found inside a word (a fragment inside a longer name)
|
|
5
|
+
INSIDE_LEAST = 3,
|
|
6
|
+
NEAR = 1.6, // a word one slip away; each further slip costs SLIP
|
|
7
|
+
SLIP = 0.5;
|
|
8
|
+
|
|
9
|
+
// A text as the search reads it: its words, lower case, without accents
|
|
10
|
+
const searchWords = text =>
|
|
11
|
+
text
|
|
12
|
+
.normalize('NFD')
|
|
13
|
+
.replace(/\p{M}/gu, '')
|
|
14
|
+
.toLowerCase()
|
|
15
|
+
.split(/[^\p{L}\p{N}]+/u)
|
|
16
|
+
.filter(Boolean);
|
|
17
|
+
|
|
18
|
+
// The slips a word of `n` letters may have and still match: none under four letters, one up to six, two from seven
|
|
19
|
+
const slipsAllowed = n => (n < 4 ? 0 : n < 7 ? 1 : 2);
|
|
20
|
+
|
|
21
|
+
// Edits (a letter changed, added, dropped, or two swapped) between a and b, or most + 1 once it is sure to be more than most
|
|
22
|
+
function slips(a, b, most) {
|
|
23
|
+
if (Math.abs(a.length - b.length) > most) return most + 1;
|
|
24
|
+
let prev2 = null,
|
|
25
|
+
prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
26
|
+
for (let i = 1; i <= a.length; i++) {
|
|
27
|
+
const row = [i];
|
|
28
|
+
let least = i;
|
|
29
|
+
for (let j = 1; j <= b.length; j++) {
|
|
30
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
31
|
+
let d = Math.min(prev[j] + 1, row[j - 1] + 1, prev[j - 1] + cost);
|
|
32
|
+
if (prev2 && i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d = Math.min(d, prev2[j - 2] + 1);
|
|
33
|
+
row.push(d);
|
|
34
|
+
if (d < least) least = d;
|
|
35
|
+
}
|
|
36
|
+
if (least > most) return most + 1;
|
|
37
|
+
prev2 = prev;
|
|
38
|
+
prev = row;
|
|
39
|
+
}
|
|
40
|
+
return prev[b.length];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// How well one query word matches one word of the text: 0 for not at all
|
|
44
|
+
function wordMatch(q, w) {
|
|
45
|
+
if (w === q) return EXACT;
|
|
46
|
+
if (w.startsWith(q)) return START;
|
|
47
|
+
if (q.length >= INSIDE_LEAST && w.includes(q)) return INSIDE;
|
|
48
|
+
const most = slipsAllowed(q.length);
|
|
49
|
+
if (!most) return 0;
|
|
50
|
+
// against the whole word, and against its start as long as the query (a word still being typed)
|
|
51
|
+
const d = Math.min(slips(q, w, most), w.length > q.length ? slips(q, w.slice(0, q.length), most) : most + 1);
|
|
52
|
+
return d <= most ? NEAR - SLIP * (d - 1) : 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// How well a query matches a text given as its title's words and the rest's (from searchWords): 0 when some word of the query
|
|
56
|
+
// matches nothing; else the sum over the query's words of each one's best match, a match in the title counting twice.
|
|
57
|
+
function fuzzyScore(query, titleWords, restWords) {
|
|
58
|
+
let total = 0;
|
|
59
|
+
for (const q of query) {
|
|
60
|
+
let best = 0;
|
|
61
|
+
for (const w of titleWords) best = Math.max(best, 2 * wordMatch(q, w));
|
|
62
|
+
if (best < 2 * EXACT) for (const w of restWords) best = Math.max(best, wordMatch(q, w));
|
|
63
|
+
if (!best) return 0;
|
|
64
|
+
total += best;
|
|
65
|
+
}
|
|
66
|
+
return total;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { fuzzyScore, searchWords };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Noise every bed is cut from, its end blended into its start so it loops unheard: pink (Kellet's filter, as much in each octave,
|
|
2
|
+
// normalised) for the wind, or brown (a leaky sum, with a little white) for water, crowds and rain, at the level they were set to.
|
|
3
|
+
export function createNoiseLoop(c, { pink = false, seconds = 8, crossfade = 0.25, random = Math.random } = {}) {
|
|
4
|
+
const n = Math.floor(c.sampleRate * seconds),
|
|
5
|
+
seam = Math.min(n, Math.floor(c.sampleRate * crossfade)),
|
|
6
|
+
buf = c.createBuffer(1, n, c.sampleRate),
|
|
7
|
+
d = buf.getChannelData(0);
|
|
8
|
+
let b0 = 0,
|
|
9
|
+
b1 = 0,
|
|
10
|
+
b2 = 0,
|
|
11
|
+
peak = 0;
|
|
12
|
+
for (let i = 0; i < n; i++) {
|
|
13
|
+
const w = random() * 2 - 1;
|
|
14
|
+
if (pink) {
|
|
15
|
+
b0 = 0.99765 * b0 + w * 0.099046;
|
|
16
|
+
b1 = 0.963 * b1 + w * 0.2965164;
|
|
17
|
+
b2 = 0.57 * b2 + w * 1.0526913;
|
|
18
|
+
d[i] = b0 + b1 + b2 + w * 0.1848;
|
|
19
|
+
} else {
|
|
20
|
+
b0 = (b0 + 0.03 * w) / 1.03;
|
|
21
|
+
d[i] = b0 * 3.2 + w * 0.05;
|
|
22
|
+
}
|
|
23
|
+
peak = Math.max(peak, Math.abs(d[i]));
|
|
24
|
+
}
|
|
25
|
+
for (let i = 0; i < seam; i++) {
|
|
26
|
+
const k = i / seam;
|
|
27
|
+
d[i] = d[i] * k + d[n - seam + i] * (1 - k);
|
|
28
|
+
}
|
|
29
|
+
if (pink && peak > 0) for (let i = 0; i < n; i++) d[i] *= 0.9 / peak;
|
|
30
|
+
return buf;
|
|
31
|
+
}
|
|
32
|
+
export function createSpatialPanner(c, x, y, z, referenceDistance = 10) {
|
|
33
|
+
const pan = c.createPanner();
|
|
34
|
+
pan.panningModel = 'equalpower';
|
|
35
|
+
pan.distanceModel = 'inverse';
|
|
36
|
+
pan.refDistance = referenceDistance;
|
|
37
|
+
if (pan.positionX) {
|
|
38
|
+
pan.positionX.value = x;
|
|
39
|
+
pan.positionY.value = y;
|
|
40
|
+
pan.positionZ.value = z;
|
|
41
|
+
} else pan.setPosition(x, y, z);
|
|
42
|
+
return pan;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function placeListener(L, matrix) {
|
|
46
|
+
const e = matrix.elements;
|
|
47
|
+
if (!L.positionX) return; // a browser without the listener's parameters hears every sound where it stands
|
|
48
|
+
L.positionX.value = e[12];
|
|
49
|
+
L.positionY.value = e[13];
|
|
50
|
+
L.positionZ.value = e[14];
|
|
51
|
+
L.forwardX.value = -e[8];
|
|
52
|
+
L.forwardY.value = -e[9];
|
|
53
|
+
L.forwardZ.value = -e[10];
|
|
54
|
+
L.upX.value = e[4];
|
|
55
|
+
L.upY.value = e[5];
|
|
56
|
+
L.upZ.value = e[6];
|
|
57
|
+
}
|
package/scripts/serve.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Serve the checkout for the interactive examples and browser fixtures."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ExampleServer(ThreadingHTTPServer):
|
|
8
|
+
# ES modules fan out into parallel requests on a cold browser load.
|
|
9
|
+
request_queue_size = 128
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Handler(SimpleHTTPRequestHandler):
|
|
13
|
+
protocol_version = "HTTP/1.1"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
|
|
18
|
+
with ExampleServer(("127.0.0.1", port), Handler) as server:
|
|
19
|
+
print(f"Serving Roamwright on port {server.server_port}", flush=True)
|
|
20
|
+
examples = f"http://127.0.0.1:{server.server_port}/examples/"
|
|
21
|
+
print(f"Alpine viaduct: {examples}viaduct.html?seed=42", flush=True)
|
|
22
|
+
print(f"Seeded island: {examples}?seed=42", flush=True)
|
|
23
|
+
try:
|
|
24
|
+
server.serve_forever()
|
|
25
|
+
except KeyboardInterrupt:
|
|
26
|
+
pass
|