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
package/geometry/hair-gathers.js
CHANGED
|
@@ -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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
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,
|
|
33
|
-
const open =
|
|
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 } =
|
|
36
|
-
a0 =
|
|
37
|
-
a1 =
|
|
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
|
|
52
|
-
y = through(rings, 0, t) - (
|
|
53
|
-
k =
|
|
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(
|
|
55
|
+
through(rings, 3, t) + Math.cos(angle) * through(rings, 1, t) * k,
|
|
56
56
|
y,
|
|
57
|
-
through(rings, 4, t) + Math.sin(
|
|
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
|
-
|
|
70
|
-
|
|
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(
|
|
83
|
-
tone = (
|
|
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[
|
|
89
|
-
place[
|
|
90
|
-
place[
|
|
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
|
-
(
|
|
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,
|
|
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]) /
|
|
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
|
-
...
|
|
112
|
+
...options,
|
|
113
113
|
rows,
|
|
114
|
-
sides:
|
|
115
|
-
a0:
|
|
116
|
-
a1:
|
|
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: (
|
|
119
|
-
swell: (v,
|
|
120
|
-
tone: (v,
|
|
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
|
-
|
|
133
|
-
nx = Math.sin(polar) * Math.cos(
|
|
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(
|
|
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
|
|
152
|
-
patch.triangles.push(
|
|
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
|
|
167
|
-
|
|
168
|
-
t = Math.min(1, Math.max(0, (y -
|
|
169
|
-
return [lerp(
|
|
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
|
}
|
package/geometry/hair-locks.js
CHANGED
|
@@ -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(
|
|
32
|
-
if (
|
|
33
|
-
if (
|
|
34
|
-
const low = sstep(-0.14, -0.215,
|
|
35
|
-
rx = lerp(
|
|
36
|
-
rz = lerp(
|
|
37
|
-
z =
|
|
38
|
-
q = Math.hypot(
|
|
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
|
-
|
|
41
|
-
|
|
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,
|
|
50
|
+
function layLock(mass, root, options) {
|
|
51
51
|
const points = [],
|
|
52
|
-
step =
|
|
52
|
+
step = options.length / options.segs;
|
|
53
53
|
_dir.copy(root);
|
|
54
|
-
for (let i = 0; i <=
|
|
55
|
-
const u = i /
|
|
56
|
-
lift =
|
|
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,
|
|
58
|
+
clearNeck(_p, options);
|
|
59
59
|
points.push([_p.x, _p.y, _p.z, _n.x, _n.y, _n.z, lift]);
|
|
60
|
-
if (i ===
|
|
61
|
-
|
|
62
|
-
_f.x +=
|
|
63
|
-
_f.z +=
|
|
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 = (
|
|
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,
|
|
77
|
+
function hangLock(mass, root, options) {
|
|
78
78
|
const points = [];
|
|
79
|
-
_d.set(Math.cos(
|
|
80
|
-
_d.y =
|
|
81
|
-
for (let i = 0; i <=
|
|
82
|
-
const lift = 0.001 +
|
|
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 /
|
|
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 <=
|
|
96
|
-
const t = j /
|
|
97
|
-
y = lerp(top,
|
|
98
|
-
[rx, rz, cz] =
|
|
99
|
-
|
|
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(
|
|
102
|
-
points.push([Math.cos(
|
|
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
|
|
115
|
-
|
|
116
|
-
|
|
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(
|
|
121
|
-
_n.set(
|
|
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(
|
|
125
|
-
if (
|
|
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,
|
package/geometry/hair-patch.js
CHANGED
|
@@ -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
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
band = Math.floor((points[
|
|
17
|
-
ux = points[
|
|
18
|
-
uy = points[
|
|
19
|
-
uz = points[
|
|
20
|
-
vx = points[
|
|
21
|
-
vy = points[
|
|
22
|
-
vz = points[
|
|
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[
|
|
25
|
-
(uz * vx - ux * vz) * (points[
|
|
26
|
-
(ux * vy - uy * vx) * (points[
|
|
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
|
|
30
|
-
let v = put.get(
|
|
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(
|
|
34
|
-
const tag = HAIR_NEAR + Math.min(MOST, Math.max(0, points[
|
|
35
|
-
emitVertex(
|
|
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
|
}
|
package/geometry/hair-shell.js
CHANGED
|
@@ -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(
|
|
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(
|
|
26
|
-
// (metres), and the way out there; and full(
|
|
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 =
|
|
29
|
-
swell =
|
|
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(
|
|
32
|
-
0.6 * Math.sin(
|
|
33
|
-
at = (
|
|
34
|
-
const k = full(
|
|
35
|
-
more = lumps ? swell(
|
|
36
|
-
skull.skull(
|
|
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) * (
|
|
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 =
|
|
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, (
|
|
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(
|
|
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(
|
|
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
|
|
99
|
-
|
|
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[
|
|
103
|
-
.lerp(_e1.set(points[
|
|
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[
|
|
109
|
-
.lerp(_e1.set(points[
|
|
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[
|
|
114
|
-
.lerp(_e1.set(points[
|
|
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
|
|
138
|
-
let q = across(_d.set(points[
|
|
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
|
|
165
|
-
key =
|
|
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 =
|
|
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[
|
|
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];
|
package/geometry/head-profile.js
CHANGED
|
@@ -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
|
|
9
|
-
|
|
10
|
-
|
|
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 <
|
|
14
|
-
for (let i = 0; i <
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
tangent.push(i === 0 ?
|
|
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 <=
|
|
21
|
-
if (x >=
|
|
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 >
|
|
24
|
-
const h =
|
|
25
|
-
t = (x -
|
|
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
|
-
|
|
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,
|
|
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.
|