roamwright 0.2.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.
Files changed (140) hide show
  1. package/CONTRIBUTING.md +3 -1
  2. package/README.md +19 -21
  3. package/geometry/bedding.js +141 -0
  4. package/geometry/builder-cells.js +42 -0
  5. package/geometry/builder-frame.js +47 -0
  6. package/geometry/builder.js +189 -177
  7. package/geometry/cell-mask.js +25 -0
  8. package/geometry/creased-sheet.js +34 -34
  9. package/geometry/ear.js +36 -36
  10. package/geometry/erosion.js +65 -42
  11. package/geometry/face-grid.js +65 -65
  12. package/geometry/foliage.js +47 -0
  13. package/geometry/hair-gathers.js +41 -41
  14. package/geometry/hair-locks.js +41 -41
  15. package/geometry/hair-patch.js +18 -18
  16. package/geometry/hair-shell.js +31 -31
  17. package/geometry/head-profile.js +15 -15
  18. package/geometry/head-shape.js +77 -77
  19. package/geometry/heightfield.js +27 -18
  20. package/geometry/index-parts.js +60 -0
  21. package/geometry/instance-visibility.js +41 -0
  22. package/geometry/instances.js +35 -12
  23. package/geometry/outline-grid.js +7 -7
  24. package/geometry/part-ranges.js +18 -0
  25. package/geometry/path-field.js +63 -33
  26. package/geometry/placement.js +52 -52
  27. package/geometry/point-buckets.js +50 -0
  28. package/geometry/primitives.js +63 -47
  29. package/geometry/sagging-tube.js +27 -27
  30. package/geometry/sampled-surface.js +109 -77
  31. package/geometry/scatter-grid.js +46 -6
  32. package/geometry/sculpt.js +93 -93
  33. package/geometry/shore-grid.js +77 -34
  34. package/geometry/strata-field.js +92 -92
  35. package/geometry/strata-tiles.js +91 -91
  36. package/geometry/stream.js +70 -48
  37. package/geometry/terrain-chunks.js +101 -92
  38. package/geometry/terrain-extension.js +6 -6
  39. package/index.js +5 -0
  40. package/math/cell-edge.js +16 -16
  41. package/math/cell-key.js +6 -0
  42. package/math/circle-clearances.js +19 -0
  43. package/math/cloth-textures.js +6 -6
  44. package/math/cloud-textures.js +20 -20
  45. package/math/color.js +14 -14
  46. package/math/curve.js +22 -22
  47. package/math/mountain-ranges.js +216 -165
  48. package/math/noise.js +101 -49
  49. package/math/particle-noise.js +28 -28
  50. package/math/periodic.js +5 -5
  51. package/math/random.js +24 -15
  52. package/math/rectangles.js +52 -0
  53. package/math/rock-texture.js +7 -7
  54. package/math/scalar.js +5 -5
  55. package/math/surface-textures.js +54 -54
  56. package/motion/arm-reach.js +24 -24
  57. package/motion/ballistic-arc.js +11 -0
  58. package/motion/biped-cycle.js +44 -0
  59. package/motion/biped-leg.js +37 -0
  60. package/motion/biped-stride.js +98 -122
  61. package/motion/contact-transition.js +33 -0
  62. package/motion/crowd-alarms.js +39 -39
  63. package/motion/crowd-routine.js +94 -65
  64. package/motion/daily-clock.js +9 -9
  65. package/motion/deck-surface.js +38 -0
  66. package/motion/ground-lookahead.js +29 -0
  67. package/motion/instance-sight.js +8 -8
  68. package/motion/player.js +36 -28
  69. package/motion/quadruped.js +155 -155
  70. package/motion/spaces.js +32 -32
  71. package/motion/weather.js +73 -24
  72. package/motion/wind.js +32 -13
  73. package/package.json +8 -4
  74. package/rendering/caster-motion.js +5 -5
  75. package/rendering/cell-lod.js +147 -82
  76. package/rendering/cloud-dome.js +28 -28
  77. package/rendering/cloud-field.js +2 -2
  78. package/rendering/compilation-schedule.js +68 -11
  79. package/rendering/contact-shadows.js +2 -2
  80. package/rendering/context.js +12 -0
  81. package/rendering/crowd-skinning.js +13 -13
  82. package/rendering/crust.js +18 -12
  83. package/rendering/daylight.js +3 -3
  84. package/rendering/detail-range.js +28 -0
  85. package/rendering/dispose-meshes.js +18 -0
  86. package/rendering/dof.js +9 -9
  87. package/rendering/eye-adapt.js +14 -14
  88. package/rendering/far-shadow.js +8 -8
  89. package/rendering/flocks.js +78 -78
  90. package/rendering/garment-material.js +17 -17
  91. package/rendering/glow-lines.js +13 -13
  92. package/rendering/hair-strands.js +20 -20
  93. package/rendering/height-probe.js +149 -19
  94. package/rendering/label-layout.js +46 -0
  95. package/rendering/label-range.js +38 -0
  96. package/rendering/light-budget.js +52 -52
  97. package/rendering/light-shafts.js +23 -23
  98. package/rendering/local-lights.js +15 -4
  99. package/rendering/material-lod.js +49 -49
  100. package/rendering/particle-emitters.js +90 -90
  101. package/rendering/particles.js +78 -67
  102. package/rendering/piece-batch.js +91 -26
  103. package/rendering/planar-reflection.js +38 -38
  104. package/rendering/post-shaders.js +17 -13
  105. package/rendering/post.js +71 -71
  106. package/rendering/rain-streaks.js +67 -0
  107. package/rendering/road-surface.js +11 -11
  108. package/rendering/sea-shaders.js +11 -11
  109. package/rendering/shader-warmup.js +29 -16
  110. package/rendering/shadow-alignment.js +4 -4
  111. package/rendering/shadow-depth.js +7 -7
  112. package/rendering/sky-occlusion.js +16 -16
  113. package/rendering/sky.js +16 -6
  114. package/rendering/stage-lights.js +6 -6
  115. package/rendering/static-point-shadow.js +3 -3
  116. package/rendering/still-casters.js +1 -1
  117. package/rendering/strata-material.js +10 -10
  118. package/rendering/stream-flow.js +10 -10
  119. package/rendering/taa.js +26 -26
  120. package/rendering/talus.js +15 -15
  121. package/rendering/terrain-rock.js +7 -7
  122. package/rendering/texture-fills.js +8 -8
  123. package/rendering/textures.js +28 -28
  124. package/rendering/wakes.js +24 -24
  125. package/rendering/water-material.js +36 -23
  126. package/rendering/world-matrices.js +38 -38
  127. package/runtime/diagnostic-log.js +2 -2
  128. package/runtime/first-use.js +33 -28
  129. package/runtime/frame-budget.js +49 -0
  130. package/runtime/frame-pacing.js +33 -0
  131. package/runtime/gpu-timing.js +13 -10
  132. package/runtime/grid-cache.js +1 -1
  133. package/runtime/grid-rows.js +44 -5
  134. package/runtime/hand-over.js +41 -23
  135. package/runtime/pool.js +58 -16
  136. package/runtime/quality-fit.js +1 -1
  137. package/runtime/search.js +22 -22
  138. package/runtime/spatial-audio.js +13 -13
  139. package/runtime/withdrawable-task.js +35 -0
  140. package/runtime/worker.js +7 -0
@@ -13,11 +13,11 @@ function through(rings, k, t) {
13
13
  const last = rings.length - 1,
14
14
  i = Math.min(last - 1, Math.floor(t)),
15
15
  f = t - i,
16
- a = rings[Math.max(0, i - 1)][k],
17
- b = rings[i][k],
18
- c = rings[i + 1][k],
19
- d = rings[Math.min(last, i + 2)][k];
20
- return b + 0.5 * f * (c - a + f * (2 * a - 5 * b + 4 * c - d + f * (3 * (b - c) + d - a)));
16
+ previousValue = rings[Math.max(0, i - 1)][k],
17
+ startValue = rings[i][k],
18
+ endValue = rings[i + 1][k],
19
+ nextValue = rings[Math.min(last, i + 2)][k];
20
+ return startValue + 0.5 * f * (endValue - previousValue + f * (2 * previousValue - 5 * startValue + 4 * endValue - nextValue + f * (3 * (startValue - endValue) + nextValue - previousValue)));
21
21
  }
22
22
 
23
23
  // The ring a rope begins with, above its first: drawn in to a point.
@@ -29,12 +29,12 @@ const shut = ring => [ring[0] + ring[1] * 0.8, ring[1] * SHUT, ring[2] * SHUT, r
29
29
  // y) (its thickness there, of the rings'), hem(a) (how much lower its end hangs there, metres), lean (how far its strands slant:
30
30
  // the way across them goes so much round for each metre down), from (the strand its first side lies at), root (how dark it is
31
31
  // where it begins, if not as dark as hair that is gathered).
32
- function hang(patch, rings, o) {
33
- const open = o.a1 !== undefined;
32
+ function hang(patch, rings, options) {
33
+ const open = options.a1 !== undefined;
34
34
  if (!open) rings = [shut(rings[0]), ...rings];
35
- const { rows, sides, colour } = o,
36
- a0 = o.a0 ?? 0,
37
- a1 = o.a1 ?? TAU,
35
+ const { rows, sides, colour } = options,
36
+ a0 = options.a0 ?? 0,
37
+ a1 = options.a1 ?? TAU,
38
38
  first = patch.points.length / POINT,
39
39
  spans = rings.length - 1,
40
40
  at = (i, j) => first + i * (sides + 1) + j,
@@ -48,13 +48,13 @@ function hang(patch, rings, o) {
48
48
  const v = i / rows,
49
49
  t = v * spans;
50
50
  for (let j = 0; j <= sides; j++) {
51
- const a = a0 + ((a1 - a0) * j) / sides,
52
- y = through(rings, 0, t) - (o.hem ? o.hem(a) * v * v : 0),
53
- k = o.swell ? o.swell(v, a, y) : 1;
51
+ const angle = a0 + ((a1 - a0) * j) / sides,
52
+ y = through(rings, 0, t) - (options.hem ? options.hem(angle) * v * v : 0),
53
+ k = options.swell ? options.swell(v, angle, y) : 1;
54
54
  place.push(
55
- through(rings, 3, t) + Math.cos(a) * through(rings, 1, t) * k,
55
+ through(rings, 3, t) + Math.cos(angle) * through(rings, 1, t) * k,
56
56
  y,
57
- through(rings, 4, t) + Math.sin(a) * through(rings, 2, t) * k,
57
+ through(rings, 4, t) + Math.sin(angle) * through(rings, 2, t) * k,
58
58
  );
59
59
  }
60
60
  }
@@ -66,8 +66,8 @@ function hang(patch, rings, o) {
66
66
  r = (i * (sides + 1) + wrap(j + 1)) * 3,
67
67
  up = (Math.max(0, i - 1) * (sides + 1) + j) * 3,
68
68
  down = (Math.min(rows, i + 1) * (sides + 1) + j) * 3,
69
- p = (i * (sides + 1) + j) * 3,
70
- a = a0 + ((a1 - a0) * j) / sides,
69
+ vertexOffset = (i * (sides + 1) + j) * 3,
70
+ angle = a0 + ((a1 - a0) * j) / sides,
71
71
  v = i / rows,
72
72
  tx = place[r] - place[l],
73
73
  ty = place[r + 1] - place[l + 1],
@@ -79,22 +79,22 @@ function hang(patch, rings, o) {
79
79
  ny = tz * ux - tx * uz,
80
80
  nz = tx * uy - ty * ux;
81
81
  const length = Math.hypot(nx, ny, nz) || 1,
82
- out = nx * Math.cos(a) + nz * Math.sin(a) < 0 ? -1 : 1,
83
- tone = (o.tone ? o.tone(v, a) : 1) * lerp(o.root ?? ROOT_SHADE, 1, sstep(0, 0.35, v));
82
+ out = nx * Math.cos(angle) + nz * Math.sin(angle) < 0 ? -1 : 1,
83
+ tone = (options.tone ? options.tone(v, angle) : 1) * lerp(options.root ?? ROOT_SHADE, 1, sstep(0, 0.35, v));
84
84
  nx *= out / length;
85
85
  ny *= out / length;
86
86
  nz *= out / length;
87
87
  patch.points.push(
88
- place[p],
89
- place[p + 1],
90
- place[p + 2],
88
+ place[vertexOffset],
89
+ place[vertexOffset + 1],
90
+ place[vertexOffset + 2],
91
91
  nx,
92
92
  ny,
93
93
  nz,
94
94
  colour[0] * tone,
95
95
  colour[1] * tone,
96
96
  colour[2] * tone,
97
- (o.from || 0) + (round * j) / sides + (o.lean || 0) * (rings[0][0] - place[p + 1]),
97
+ (options.from || 0) + (round * j) / sides + (options.lean || 0) * (rings[0][0] - place[vertexOffset + 1]),
98
98
  );
99
99
  if (i < rows && j < sides) patch.triangles.push(at(i, j), at(i + 1, j), at(i + 1, j + 1), at(i, j), at(i + 1, j + 1), at(i, j + 1));
100
100
  }
@@ -103,21 +103,21 @@ function hang(patch, rings, o) {
103
103
  // A plait hanging: two halves side by side, their strands slanting in to the line between them, each turn of the plait
104
104
  // standing out on one side and then the other. turn: the height of one turn (metres); side: which way it faces (the angle of
105
105
  // the line between its halves, as a loft counts angles).
106
- function plait(patch, rings, o) {
106
+ function plait(patch, rings, options) {
107
107
  rings = [shut(rings[0]), ...rings];
108
- const turns = Math.max(1, Math.round((rings[0][0] - rings[rings.length - 1][0]) / o.turn)),
108
+ const turns = Math.max(1, Math.round((rings[0][0] - rings[rings.length - 1][0]) / options.turn)),
109
109
  rows = turns * PLAIT_ROWS;
110
110
  for (const half of [-1, 1])
111
111
  hang(patch, rings, {
112
- ...o,
112
+ ...options,
113
113
  rows,
114
- sides: o.sides >> 1,
115
- a0: o.side + (half < 0 ? -Math.PI : 0),
116
- a1: o.side + (half < 0 ? 0 : Math.PI),
114
+ sides: options.sides >> 1,
115
+ a0: options.side + (half < 0 ? -Math.PI : 0),
116
+ a1: options.side + (half < 0 ? 0 : Math.PI),
117
117
  lean: (half * PLAIT_LEAN) / STRANDS.span,
118
- from: (o.from || 0) + half,
119
- swell: (v, a) => 1 + PLAIT_SWELL * half * Math.cos(v * turns * TAU) * Math.sin(Math.abs(a - o.side)) * sstep(0, 0.06, v),
120
- tone: (v, a) => 0.72 + 0.28 * Math.sin(Math.abs(a - o.side)),
118
+ from: (options.from || 0) + half,
119
+ swell: (v, angle) => 1 + PLAIT_SWELL * half * Math.cos(v * turns * TAU) * Math.sin(Math.abs(angle - options.side)) * sstep(0, 0.06, v),
120
+ tone: (v, angle) => 0.72 + 0.28 * Math.sin(Math.abs(angle - options.side)),
121
121
  });
122
122
  }
123
123
 
@@ -129,10 +129,10 @@ function knot(patch, place, at, size, colour, rows, sides) {
129
129
  for (let i = 0; i <= rows; i++)
130
130
  for (let j = 0; j <= sides; j++) {
131
131
  const polar = (i / rows) * Math.PI,
132
- a = (j / sides) * TAU,
133
- nx = Math.sin(polar) * Math.cos(a),
132
+ angle = (j / sides) * TAU,
133
+ nx = Math.sin(polar) * Math.cos(angle),
134
134
  ny = Math.cos(polar),
135
- nz = Math.sin(polar) * Math.sin(a),
135
+ nz = Math.sin(polar) * Math.sin(angle),
136
136
  tone = 0.8 + 0.2 * ny,
137
137
  v = place([at[0] + nx * size[0], at[1] + ny * size[1], at[2] + nz * size[2], nx / size[0], ny / size[1], nz / size[2]]);
138
138
  patch.points.push(
@@ -148,8 +148,8 @@ function knot(patch, place, at, size, colour, rows, sides) {
148
148
  (round * j) / sides + 0.35 * (i / rows),
149
149
  );
150
150
  if (i < rows && j < sides) {
151
- const p = first + i * (sides + 1) + j;
152
- patch.triangles.push(p, p + sides + 1, p + sides + 2, p, p + sides + 2, p + 1);
151
+ const vertexIndex = first + i * (sides + 1) + j;
152
+ patch.triangles.push(vertexIndex, vertexIndex + sides + 1, vertexIndex + sides + 2, vertexIndex, vertexIndex + sides + 2, vertexIndex + 1);
153
153
  }
154
154
  }
155
155
  }
@@ -163,10 +163,10 @@ function nearFallRings(rings, crown) {
163
163
  at = y => {
164
164
  let i = 0;
165
165
  while (i < fallen.length - 2 && y < fallen[i + 1][0]) i++;
166
- const a = fallen[i],
167
- b = fallen[i + 1],
168
- t = Math.min(1, Math.max(0, (y - a[0]) / (b[0] - a[0])));
169
- return [lerp(a[1], b[1], t), lerp(a[2], b[2], t), lerp(a[3], b[3], t)];
166
+ const upperRing = fallen[i],
167
+ lowerRing = fallen[i + 1],
168
+ t = Math.min(1, Math.max(0, (y - upperRing[0]) / (lowerRing[0] - upperRing[0])));
169
+ return [lerp(upperRing[1], lowerRing[1], t), lerp(upperRing[2], lowerRing[2], t), lerp(upperRing[3], lowerRing[3], t)];
170
170
  };
171
171
  return { rings: fallen, at };
172
172
  }
@@ -28,17 +28,17 @@ const _p = new THREE.Vector3(),
28
28
  _dir = new THREE.Vector3();
29
29
 
30
30
  // Moves a point off the neck and the shoulders (o.neck: how far from the neck's axis; o.shoulder: half the shoulders' breadth).
31
- function clearNeck(p, o) {
32
- if (p.y < HAIRLINE && p.z > FACE_EDGE) p.z = FACE_EDGE;
33
- if (p.y >= -0.075) return;
34
- const low = sstep(-0.14, -0.215, p.y),
35
- rx = lerp(o.neck, o.shoulder + 0.035, low),
36
- rz = lerp(o.neck, SHOULDER_DEEP, low),
37
- z = p.z + 0.012,
38
- q = Math.hypot(p.x / rx, z / rz);
31
+ function clearNeck(point, options) {
32
+ if (point.y < HAIRLINE && point.z > FACE_EDGE) point.z = FACE_EDGE;
33
+ if (point.y >= -0.075) return;
34
+ const low = sstep(-0.14, -0.215, point.y),
35
+ rx = lerp(options.neck, options.shoulder + 0.035, low),
36
+ rz = lerp(options.neck, SHOULDER_DEEP, low),
37
+ z = point.z + 0.012,
38
+ q = Math.hypot(point.x / rx, z / rz);
39
39
  if (q < 1) {
40
- p.x /= q;
41
- p.z = z / q - 0.012;
40
+ point.x /= q;
41
+ point.z = z / q - 0.012;
42
42
  }
43
43
  }
44
44
 
@@ -47,22 +47,22 @@ function clearNeck(p, o) {
47
47
  // segs, base, rise and tip (its lift off the mass at the root, how much more by its end, and how far its tip stands up besides,
48
48
  // metres), wave and coil (how far it winds from side to side and how fast), curl (how far it turns at each step, one way),
49
49
  // phase, neck and shoulder.
50
- function layLock(mass, root, o) {
50
+ function layLock(mass, root, options) {
51
51
  const points = [],
52
- step = o.length / o.segs;
52
+ step = options.length / options.segs;
53
53
  _dir.copy(root);
54
- for (let i = 0; i <= o.segs; i++) {
55
- const u = i / o.segs,
56
- lift = o.base + o.rise * u + o.tip * u * u * u;
54
+ for (let i = 0; i <= options.segs; i++) {
55
+ const u = i / options.segs,
56
+ lift = options.base + options.rise * u + options.tip * u * u * u;
57
57
  mass.at(_dir, lift, _p, _n);
58
- clearNeck(_p, o);
58
+ clearNeck(_p, options);
59
59
  points.push([_p.x, _p.y, _p.z, _n.x, _n.y, _n.z, lift]);
60
- if (i === o.segs) break;
61
- o.flow(_dir, _f);
62
- _f.x += o.aside[0];
63
- _f.z += o.aside[1];
60
+ if (i === options.segs) break;
61
+ options.flow(_dir, _f);
62
+ _f.x += options.aside[0];
63
+ _f.z += options.aside[1];
64
64
  _f.addScaledVector(_n, -_f.dot(_n)).normalize();
65
- const turn = (o.wave || 0) * Math.sin(o.phase + i * o.coil) + (o.curl || 0) * (i + 0.5);
65
+ const turn = (options.wave || 0) * Math.sin(options.phase + i * options.coil) + (options.curl || 0) * (i + 0.5);
66
66
  if (turn) _f.applyAxisAngle(_n, turn);
67
67
  mass.at(_dir, 0, _q).addScaledVector(_f, step);
68
68
  mass.skull.under(_q.x, _q.y, _q.z, _dir);
@@ -74,16 +74,16 @@ function layLock(mass, root, o) {
74
74
  // nape, then hanging over the fall of hair down the back. o: round (where round the fall it hangs, as the fall counts angles),
75
75
  // shape(y) (the fall's half-width, half-depth and middle at a height), from (the height at which it leaves the head, as a
76
76
  // share of the head's), end (how low it hangs), combed and segs (its lengths over the head and hanging), lift (metres off the mass), sway and phase (how it wavers as it hangs).
77
- function hangLock(mass, root, o) {
77
+ function hangLock(mass, root, options) {
78
78
  const points = [];
79
- _d.set(Math.cos(o.round), 0, Math.sin(o.round)).multiplyScalar(Math.sqrt(1 - o.from * o.from));
80
- _d.y = o.from;
81
- for (let i = 0; i <= o.combed; i++) {
82
- const lift = 0.001 + o.lift * Math.sin((i / o.combed) * Math.PI * 0.5);
79
+ _d.set(Math.cos(options.round), 0, Math.sin(options.round)).multiplyScalar(Math.sqrt(1 - options.from * options.from));
80
+ _d.y = options.from;
81
+ for (let i = 0; i <= options.combed; i++) {
82
+ const lift = 0.001 + options.lift * Math.sin((i / options.combed) * Math.PI * 0.5);
83
83
  mass.at(
84
84
  _s
85
85
  .copy(root)
86
- .lerp(_d, i / o.combed)
86
+ .lerp(_d, i / options.combed)
87
87
  .normalize(),
88
88
  lift,
89
89
  _p,
@@ -92,14 +92,14 @@ function hangLock(mass, root, o) {
92
92
  points.push([_p.x, _p.y, _p.z, _n.x, _n.y, _n.z, lift]);
93
93
  }
94
94
  const top = _p.y;
95
- for (let j = 1; j <= o.segs; j++) {
96
- const t = j / o.segs,
97
- y = lerp(top, o.end, t),
98
- [rx, rz, cz] = o.shape(y),
99
- a = o.round + o.sway * Math.sin(o.phase + j * 1.3) * t,
95
+ for (let j = 1; j <= options.segs; j++) {
96
+ const t = j / options.segs,
97
+ y = lerp(top, options.end, t),
98
+ [rx, rz, cz] = options.shape(y),
99
+ angle = options.round + options.sway * Math.sin(options.phase + j * 1.3) * t,
100
100
  out = 0.004 + 0.006 * t;
101
- _n.set(Math.cos(a) / rx, 0.6, Math.sin(a) / rz).normalize();
102
- points.push([Math.cos(a) * (rx + out), y, cz + Math.sin(a) * (rz + out), _n.x, _n.y, _n.z, FREE]);
101
+ _n.set(Math.cos(angle) / rx, 0.6, Math.sin(angle) / rz).normalize();
102
+ points.push([Math.cos(angle) * (rx + out), y, cz + Math.sin(angle) * (rz + out), _n.x, _n.y, _n.z, FREE]);
103
103
  }
104
104
  return points;
105
105
  }
@@ -111,18 +111,18 @@ function drawLock(patch, place, mass, points, half, colour, tone, strand) {
111
111
  const last = points.length - 1,
112
112
  first = patch.points.length / POINT;
113
113
  for (let i = 0; i <= last; i++) {
114
- const p = points[i],
115
- a = points[Math.max(0, i - 1)],
116
- b = points[Math.min(last, i + 1)],
114
+ const point = points[i],
115
+ previousPoint = points[Math.max(0, i - 1)],
116
+ nextPoint = points[Math.min(last, i + 1)],
117
117
  u = i / last,
118
118
  wide = half * (0.4 + 0.6 * Math.sin(Math.min(1, u * 3) * Math.PI * 0.5)) * lerp(1, TIP, Math.pow(u, 1.4)),
119
119
  shade = tone * lerp(ROOT_SHADE, TIP_SHADE, u);
120
- _d.set(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
121
- _n.set(p[3], p[4], p[5]);
120
+ _d.set(nextPoint[0] - previousPoint[0], nextPoint[1] - previousPoint[1], nextPoint[2] - previousPoint[2]);
121
+ _n.set(point[3], point[4], point[5]);
122
122
  _s.crossVectors(_d, _n).normalize();
123
123
  for (const k of [-1, 1]) {
124
- _p.set(p[0] + _s.x * wide * k, p[1] + _s.y * wide * k, p[2] + _s.z * wide * k);
125
- if (p[6] !== FREE) mass.at(mass.skull.under(_p.x, _p.y, _p.z, _dir), p[6], _p, _q);
124
+ _p.set(point[0] + _s.x * wide * k, point[1] + _s.y * wide * k, point[2] + _s.z * wide * k);
125
+ if (point[6] !== FREE) mass.at(mass.skull.under(_p.x, _p.y, _p.z, _dir), point[6], _p, _q);
126
126
  else _q.copy(_n);
127
127
  const v = place([
128
128
  _p.x,
@@ -10,29 +10,29 @@ function packHairPatch(points, triangles, emitVertex) {
10
10
  const bands = new Map(), corners = [];
11
11
  let vertexCount = 0;
12
12
  for (let t = 0; t < triangles.length; t += 3) {
13
- const a = triangles[t] * POINT,
14
- b = triangles[t + 1] * POINT,
15
- c = triangles[t + 2] * POINT,
16
- band = Math.floor((points[a + 9] + points[b + 9] + points[c + 9]) / 3 / BAND),
17
- ux = points[b] - points[a],
18
- uy = points[b + 1] - points[a + 1],
19
- uz = points[b + 2] - points[a + 2],
20
- vx = points[c] - points[a],
21
- vy = points[c + 1] - points[a + 1],
22
- vz = points[c + 2] - points[a + 2],
13
+ const firstOffset = triangles[t] * POINT,
14
+ secondOffset = triangles[t + 1] * POINT,
15
+ thirdOffset = triangles[t + 2] * POINT,
16
+ band = Math.floor((points[firstOffset + 9] + points[secondOffset + 9] + points[thirdOffset + 9]) / 3 / BAND),
17
+ ux = points[secondOffset] - points[firstOffset],
18
+ uy = points[secondOffset + 1] - points[firstOffset + 1],
19
+ uz = points[secondOffset + 2] - points[firstOffset + 2],
20
+ vx = points[thirdOffset] - points[firstOffset],
21
+ vy = points[thirdOffset + 1] - points[firstOffset + 1],
22
+ vz = points[thirdOffset + 2] - points[firstOffset + 2],
23
23
  faces =
24
- (uy * vz - uz * vy) * (points[a + 3] + points[b + 3] + points[c + 3]) +
25
- (uz * vx - ux * vz) * (points[a + 4] + points[b + 4] + points[c + 4]) +
26
- (ux * vy - uy * vx) * (points[a + 5] + points[b + 5] + points[c + 5]);
24
+ (uy * vz - uz * vy) * (points[firstOffset + 3] + points[secondOffset + 3] + points[thirdOffset + 3]) +
25
+ (uz * vx - ux * vz) * (points[firstOffset + 4] + points[secondOffset + 4] + points[thirdOffset + 4]) +
26
+ (ux * vy - uy * vx) * (points[firstOffset + 5] + points[secondOffset + 5] + points[thirdOffset + 5]);
27
27
  let put = bands.get(band);
28
28
  if (!put) { put = new Map(); bands.set(band, put); }
29
- for (const p of faces < 0 ? [a, c, b] : [a, b, c]) {
30
- let v = put.get(p);
29
+ for (const pointOffset of faces < 0 ? [firstOffset, thirdOffset, secondOffset] : [firstOffset, secondOffset, thirdOffset]) {
30
+ let v = put.get(pointOffset);
31
31
  if (v === undefined) {
32
32
  v = vertexCount++;
33
- put.set(p, v);
34
- const tag = HAIR_NEAR + Math.min(MOST, Math.max(0, points[p + 9] - band * BAND + MARGIN));
35
- emitVertex(p, tag);
33
+ put.set(pointOffset, v);
34
+ const tag = HAIR_NEAR + Math.min(MOST, Math.max(0, points[pointOffset + 9] - band * BAND + MARGIN));
35
+ emitVertex(pointOffset, tag);
36
36
  }
37
37
  corners.push(v);
38
38
  }
@@ -20,23 +20,23 @@ const _o = new THREE.Vector3(),
20
20
 
21
21
  // The mass of a cut. scale: how far out from the skull its fullest stands (across, up, fore and aft, as shares of the skull);
22
22
  // inHair(x, y, z): how far inside the hairline a direction lies; drop: how far it hangs below the ears; lumps: how deep its
23
- // lumps are (a share of the skull) and lumpy: how many there are round the head; tucked(d): where it lies under a fall of long
23
+ // lumps are (a share of the skull) and lumpy: how many there are round the head; tucked(direction): where it lies under a fall of long
24
24
  // hair and is drawn in to the skull, 0 to 1.
25
- // Returns at(d, lift, out, outward): the point of the mass at a direction from the head's middle, raised off it by lift
26
- // (metres), and the way out there; and full(d): how much of its fullness the mass has at a direction, 0 to 1.
25
+ // Returns at(direction, lift, out, outward): the point of the mass at a direction from the head's middle, raised off it by lift
26
+ // (metres), and the way out there; and full(direction): how much of its fullness the mass has at a direction, 0 to 1.
27
27
  function massOf({ skull, scale, inHair, drop = 0, lumps = 0, lumpy = 5, tucked = null }) {
28
- const full = d => (EDGE + (1 - EDGE) * sstep(-0.01, RISE, inHair(d.x, d.y, d.z))) * (tucked ? 1 - TUCK * tucked(d) : 1),
29
- swell = d =>
28
+ const full = direction => (EDGE + (1 - EDGE) * sstep(-0.01, RISE, inHair(direction.x, direction.y, direction.z))) * (tucked ? 1 - TUCK * tucked(direction) : 1),
29
+ swell = direction =>
30
30
  lumps *
31
- (Math.sin(d.x * lumpy * 2.3 + d.y * lumpy * 1.3) * Math.sin(d.z * lumpy * 2.1 - d.y * lumpy * 1.7) +
32
- 0.6 * Math.sin(d.y * lumpy * 2.9 + d.x * lumpy * 1.1 - d.z * lumpy * 1.9)),
33
- at = (d, lift, out, outward = _n) => {
34
- const k = full(d),
35
- more = lumps ? swell(d) * k : 0;
36
- skull.skull(d, out);
31
+ (Math.sin(direction.x * lumpy * 2.3 + direction.y * lumpy * 1.3) * Math.sin(direction.z * lumpy * 2.1 - direction.y * lumpy * 1.7) +
32
+ 0.6 * Math.sin(direction.y * lumpy * 2.9 + direction.x * lumpy * 1.1 - direction.z * lumpy * 1.9)),
33
+ at = (direction, lift, out, outward = _n) => {
34
+ const k = full(direction),
35
+ more = lumps ? swell(direction) * k : 0;
36
+ skull.skull(direction, out);
37
37
  out.set(
38
38
  out.x * (1 + (scale[0] - 1) * k + more),
39
- out.y * (1 + (scale[1] - 1) * k + more) * (d.y < 0 ? 1 + drop : 1),
39
+ out.y * (1 + (scale[1] - 1) * k + more) * (direction.y < 0 ? 1 + drop : 1),
40
40
  out.z * (1 + (scale[2] - 1) * k + more),
41
41
  );
42
42
  outward.copy(out).sub(MIDDLE).normalize();
@@ -52,7 +52,7 @@ function roundPole(pole) {
52
52
  e1 = new THREE.Vector3(1, 0, 0).addScaledVector(axis, -axis.x).normalize(),
53
53
  e2 = new THREE.Vector3().crossVectors(axis, e1),
54
54
  turn = TURNS * STRANDS.period;
55
- const across = d => (Math.atan2(d.dot(e2), d.dot(e1)) / TAU) * turn;
55
+ const across = direction => (Math.atan2(direction.dot(e2), direction.dot(e1)) / TAU) * turn;
56
56
  across.turn = turn;
57
57
  across.axis = axis;
58
58
  return across;
@@ -65,8 +65,8 @@ function createHairShells(sculptMesh) {
65
65
  return function shellOf(key, mass, across) {
66
66
  let shell = shells.get(key);
67
67
  if (shell) return shell;
68
- const soup = sculptMesh('mass:' + key, DETAIL, (d, o) => mass.at(d, 0, o)),
69
- { P, N, D } = soup,
68
+ const soup = sculptMesh('mass:' + key, DETAIL, (direction, o) => mass.at(direction, 0, o)),
69
+ { P: positions, N: normals, D: directions } = soup,
70
70
  points = [], // x, y, z, the normal, the direction
71
71
  inside = [],
72
72
  known = new Map(),
@@ -79,10 +79,10 @@ function createHairShells(sculptMesh) {
79
79
  // Shared sphere directions have identical positions along the hairline.
80
80
  for (let i = 0; i < soup.n; i++) {
81
81
  const q = i * 3,
82
- at = Math.round(D[q] * 2e4) + ',' + Math.round(D[q + 1] * 2e4) + ',' + Math.round(D[q + 2] * 2e4);
82
+ at = Math.round(directions[q] * 2e4) + ',' + Math.round(directions[q + 1] * 2e4) + ',' + Math.round(directions[q + 2] * 2e4);
83
83
  let v = known.get(at);
84
84
  if (v === undefined) {
85
- v = add(P[q], P[q + 1], P[q + 2], N[q], N[q + 1], N[q + 2], D[q], D[q + 1], D[q + 2], mass.inHair(D[q], D[q + 1], D[q + 2]));
85
+ v = add(positions[q], positions[q + 1], positions[q + 2], normals[q], normals[q + 1], normals[q + 2], directions[q], directions[q + 1], directions[q + 2], mass.inHair(directions[q], directions[q + 1], directions[q + 2]));
86
86
  known.set(at, v);
87
87
  }
88
88
  numbered[i] = v;
@@ -95,23 +95,23 @@ function createHairShells(sculptMesh) {
95
95
  if (v !== undefined) return v;
96
96
  let low = 0,
97
97
  high = 1;
98
- const a = i * 9,
99
- b = j * 9;
98
+ const firstOffset = i * 9,
99
+ secondOffset = j * 9;
100
100
  for (let s = 0; s < SEAM_STEPS; s++) {
101
101
  const t = (low + high) / 2;
102
- _d.set(points[a + 6], points[a + 7], points[a + 8])
103
- .lerp(_e1.set(points[b + 6], points[b + 7], points[b + 8]), t)
102
+ _d.set(points[firstOffset + 6], points[firstOffset + 7], points[firstOffset + 8])
103
+ .lerp(_e1.set(points[secondOffset + 6], points[secondOffset + 7], points[secondOffset + 8]), t)
104
104
  .normalize();
105
105
  if (mass.inHair(_d.x, _d.y, _d.z) > 0) low = t;
106
106
  else high = t;
107
107
  }
108
- _d.set(points[a + 6], points[a + 7], points[a + 8])
109
- .lerp(_e1.set(points[b + 6], points[b + 7], points[b + 8]), low)
108
+ _d.set(points[firstOffset + 6], points[firstOffset + 7], points[firstOffset + 8])
109
+ .lerp(_e1.set(points[secondOffset + 6], points[secondOffset + 7], points[secondOffset + 8]), low)
110
110
  .normalize();
111
111
  mass.at(_d, 0, _o);
112
112
  _e2
113
- .set(points[a + 3], points[a + 4], points[a + 5])
114
- .lerp(_e1.set(points[b + 3], points[b + 4], points[b + 5]), low)
113
+ .set(points[firstOffset + 3], points[firstOffset + 4], points[firstOffset + 5])
114
+ .lerp(_e1.set(points[secondOffset + 3], points[secondOffset + 4], points[secondOffset + 5]), low)
115
115
  .normalize();
116
116
  v = add(_o.x, _o.y, _o.z, _e2.x, _e2.y, _e2.z, _d.x, _d.y, _d.z, 0);
117
117
  crossings.set(side, v);
@@ -134,8 +134,8 @@ function createHairShells(sculptMesh) {
134
134
  for (let t = 0; t < triangles.length; t += 3) {
135
135
  let most = 0;
136
136
  for (let e = 0; e < 3; e++) {
137
- const p = triangles[t + e] * 9;
138
- let q = across(_d.set(points[p + 6], points[p + 7], points[p + 8]));
137
+ const vertexOffset = triangles[t + e] * 9;
138
+ let q = across(_d.set(points[vertexOffset + 6], points[vertexOffset + 7], points[vertexOffset + 8]));
139
139
  if (e) {
140
140
  q += across.turn * Math.round((strands[t] - q) / across.turn);
141
141
  most = Math.max(most, Math.abs(q - strands[t]));
@@ -161,17 +161,17 @@ function placeHairShell(shell, place, colour) {
161
161
  const same = new Map();
162
162
  let count = 0;
163
163
  for (let t = 0; t < triangles.length; t++) {
164
- const p = triangles[t],
165
- key = p * 8192 + Math.round(strands[t] * 1024) + 4096;
164
+ const vertexIndex = triangles[t],
165
+ key = vertexIndex * 8192 + Math.round(strands[t] * 1024) + 4096;
166
166
  let at = same.get(key);
167
167
  if (at === undefined) {
168
168
  at = count++;
169
169
  same.set(key, at);
170
- const q = p * 9,
170
+ const q = vertexIndex * 9,
171
171
  k = at * POINT;
172
172
  for (let i = 0; i < 6; i++) v[i] = points[q + i];
173
173
  place(v);
174
- colour(inside[p], points[q + 6], points[q + 7], points[q + 8], tint);
174
+ colour(inside[vertexIndex], points[q + 6], points[q + 7], points[q + 8], tint);
175
175
  for (let i = 0; i < 6; i++) placed[k + i] = v[i];
176
176
  placed[k + 6] = tint[0];
177
177
  placed[k + 7] = tint[1];
@@ -5,31 +5,31 @@
5
5
  // ════════════════════════════════════════════════════════════════════════
6
6
  // A smooth curve through [at, value] points that never overshoots them.
7
7
  function curve(points) {
8
- const n = points.length,
9
- xs = points.map(p => p[0]),
10
- ys = points.map(p => p[1]),
8
+ const pointCount = points.length,
9
+ coordinates = points.map(p => p[0]),
10
+ values = points.map(p => p[1]),
11
11
  slope = [],
12
12
  tangent = [];
13
- for (let i = 0; i < n - 1; i++) slope.push((ys[i + 1] - ys[i]) / (xs[i + 1] - xs[i]));
14
- for (let i = 0; i < n; i++) {
15
- const a = slope[i - 1],
16
- b = slope[i];
17
- tangent.push(i === 0 ? b : i === n - 1 ? a : a * b <= 0 ? 0 : (2 * a * b) / (a + b));
13
+ for (let i = 0; i < pointCount - 1; i++) slope.push((values[i + 1] - values[i]) / (coordinates[i + 1] - coordinates[i]));
14
+ for (let i = 0; i < pointCount; i++) {
15
+ const previousSlope = slope[i - 1],
16
+ nextSlope = slope[i];
17
+ tangent.push(i === 0 ? nextSlope : i === pointCount - 1 ? previousSlope : previousSlope * nextSlope <= 0 ? 0 : (2 * previousSlope * nextSlope) / (previousSlope + nextSlope));
18
18
  }
19
19
  const exact = x => {
20
- if (x <= xs[0]) return ys[0];
21
- if (x >= xs[n - 1]) return ys[n - 1];
20
+ if (x <= coordinates[0]) return values[0];
21
+ if (x >= coordinates[pointCount - 1]) return values[pointCount - 1];
22
22
  let i = 0;
23
- while (x > xs[i + 1]) i++;
24
- const h = xs[i + 1] - xs[i],
25
- t = (x - xs[i]) / h,
23
+ while (x > coordinates[i + 1]) i++;
24
+ const h = coordinates[i + 1] - coordinates[i],
25
+ t = (x - coordinates[i]) / h,
26
26
  t2 = t * t,
27
27
  t3 = t2 * t;
28
28
  return (
29
- ys[i] * (2 * t3 - 3 * t2 + 1) + tangent[i] * h * (t3 - 2 * t2 + t) + ys[i + 1] * (3 * t2 - 2 * t3) + tangent[i + 1] * h * (t3 - t2)
29
+ values[i] * (2 * t3 - 3 * t2 + 1) + tangent[i] * h * (t3 - 2 * t2 + t) + values[i + 1] * (3 * t2 - 2 * t3) + tangent[i + 1] * h * (t3 - t2)
30
30
  );
31
31
  };
32
- return sampled(exact, xs[0], xs[n - 1]);
32
+ return sampled(exact, coordinates[0], coordinates[pointCount - 1]);
33
33
  }
34
34
  // A function of a length in millimetres, sampled four times a millimetre and read back along the straight line between two
35
35
  // samples: a head asks for its outline many thousand times.