roamwright 0.1.1 → 0.4.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.
Files changed (120) hide show
  1. package/CONTRIBUTING.md +39 -8
  2. package/README.md +74 -24
  3. package/examples/viaduct-camera.js +40 -0
  4. package/examples/viaduct-landscape.js +81 -0
  5. package/examples/viaduct.css +75 -0
  6. package/examples/viaduct.html +47 -0
  7. package/examples/viaduct.js +332 -0
  8. package/geometry/creased-sheet.js +127 -0
  9. package/geometry/ear.js +97 -0
  10. package/geometry/erosion.js +106 -0
  11. package/geometry/face-grid.js +143 -0
  12. package/geometry/foliage.js +47 -0
  13. package/geometry/garment-tags.js +11 -0
  14. package/geometry/hair-gathers.js +174 -0
  15. package/geometry/hair-locks.js +156 -0
  16. package/geometry/hair-patch.js +42 -0
  17. package/geometry/hair-shell.js +186 -0
  18. package/geometry/hair-tags.js +6 -0
  19. package/geometry/head-profile.js +138 -0
  20. package/geometry/head-shape.js +499 -0
  21. package/geometry/heightfield.js +68 -0
  22. package/geometry/index-parts.js +60 -0
  23. package/geometry/instance-visibility.js +41 -0
  24. package/geometry/instances.js +23 -0
  25. package/geometry/outline-grid.js +46 -0
  26. package/geometry/part-ranges.js +18 -0
  27. package/geometry/path-field.js +65 -0
  28. package/geometry/sagging-tube.js +58 -0
  29. package/geometry/sampled-surface.js +101 -0
  30. package/geometry/scatter-grid.js +32 -0
  31. package/geometry/sculpt.js +263 -0
  32. package/geometry/shore-grid.js +67 -0
  33. package/geometry/strata-field.js +339 -0
  34. package/geometry/strata-tiles.js +215 -0
  35. package/geometry/stream.js +94 -0
  36. package/geometry/terrain-chunks.js +304 -0
  37. package/geometry/terrain-extension.js +44 -0
  38. package/math/cell-edge.js +44 -0
  39. package/math/cloth-textures.js +83 -0
  40. package/math/cloud-textures.js +112 -0
  41. package/math/color.js +29 -0
  42. package/math/mountain-ranges.js +463 -0
  43. package/math/particle-noise.js +48 -0
  44. package/math/periodic.js +20 -0
  45. package/math/rock-texture.js +56 -0
  46. package/math/surface-textures.js +241 -0
  47. package/motion/arm-reach.js +74 -0
  48. package/motion/biped-stride.js +276 -0
  49. package/motion/crowd-alarms.js +127 -0
  50. package/motion/crowd-routine.js +183 -0
  51. package/motion/daily-clock.js +59 -0
  52. package/motion/ground-lookahead.js +29 -0
  53. package/motion/instance-sight.js +84 -0
  54. package/motion/quadruped.js +332 -0
  55. package/motion/weather.js +59 -0
  56. package/motion/wind.js +27 -0
  57. package/package.json +6 -4
  58. package/rendering/caster-motion.js +79 -0
  59. package/rendering/cell-lod.js +184 -0
  60. package/rendering/cloud-dome.js +371 -0
  61. package/rendering/cloud-field.js +83 -0
  62. package/rendering/compilation-schedule.js +34 -0
  63. package/rendering/contact-shadows.js +79 -0
  64. package/rendering/crowd-skinning.js +133 -0
  65. package/rendering/crust.js +28 -0
  66. package/rendering/daylight.js +50 -0
  67. package/rendering/far-shadow.js +186 -0
  68. package/rendering/flocks.js +323 -0
  69. package/rendering/garment-material.js +110 -0
  70. package/rendering/glow-lines.js +74 -0
  71. package/rendering/glow-shell.js +90 -0
  72. package/rendering/hair-strands.js +67 -0
  73. package/rendering/height-haze.js +129 -0
  74. package/rendering/height-probe.js +91 -0
  75. package/rendering/interior-mapping.js +19 -0
  76. package/rendering/light-budget.js +222 -0
  77. package/rendering/light-points.js +51 -0
  78. package/rendering/light-shafts.js +131 -0
  79. package/rendering/local-lights.js +28 -0
  80. package/rendering/low-light.js +13 -0
  81. package/rendering/material-lod.js +110 -0
  82. package/rendering/particle-emitters.js +223 -0
  83. package/rendering/particles.js +297 -0
  84. package/rendering/piece-batch.js +74 -20
  85. package/rendering/planar-reflection.js +175 -0
  86. package/rendering/post-shaders.js +21 -1
  87. package/rendering/post.js +4 -0
  88. package/rendering/rain-rings.js +22 -0
  89. package/rendering/road-surface.js +63 -0
  90. package/rendering/sea-shaders.js +230 -0
  91. package/rendering/shader-warmup.js +197 -0
  92. package/rendering/shadow-alignment.js +28 -0
  93. package/rendering/shadow-depth.js +129 -0
  94. package/rendering/sky-occlusion.js +187 -0
  95. package/rendering/sky.js +169 -0
  96. package/rendering/stage-lights.js +209 -0
  97. package/rendering/static-point-shadow.js +119 -0
  98. package/rendering/strata-material.js +93 -0
  99. package/rendering/stream-flow.js +36 -0
  100. package/rendering/surface-light.js +22 -0
  101. package/rendering/surface-projection.js +69 -0
  102. package/rendering/talus.js +26 -0
  103. package/rendering/terrain-rock.js +48 -0
  104. package/rendering/texture-fills.js +68 -0
  105. package/rendering/viewport.js +9 -0
  106. package/rendering/wakes.js +99 -0
  107. package/rendering/water-material.js +288 -0
  108. package/runtime/device-quality.js +27 -0
  109. package/runtime/diagnostic-log.js +80 -0
  110. package/runtime/events.js +14 -0
  111. package/runtime/first-use.js +3 -1
  112. package/runtime/frame-budget.js +49 -0
  113. package/runtime/frame-yield.js +14 -0
  114. package/runtime/gpu-timing.js +6 -3
  115. package/runtime/grid-cache.js +88 -0
  116. package/runtime/grid-rows.js +9 -0
  117. package/runtime/module-preload.js +15 -0
  118. package/runtime/search.js +69 -0
  119. package/runtime/spatial-audio.js +57 -0
  120. package/scripts/serve.py +26 -0
@@ -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
+ }
@@ -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