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.
- package/CONTRIBUTING.md +3 -1
- package/README.md +19 -21
- 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 +47 -0
- 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 +60 -0
- package/geometry/instance-visibility.js +41 -0
- package/geometry/instances.js +35 -12
- package/geometry/outline-grid.js +7 -7
- package/geometry/part-ranges.js +18 -0
- 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 +101 -92
- 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 +29 -0
- 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 +8 -4
- package/rendering/caster-motion.js +5 -5
- package/rendering/cell-lod.js +147 -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 +91 -26
- 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-budget.js +49 -0
- package/runtime/frame-pacing.js +33 -0
- package/runtime/gpu-timing.js +13 -10
- 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/head-shape.js
CHANGED
|
@@ -22,7 +22,7 @@ const MM = 0.001,
|
|
|
22
22
|
SCAR_SHADE = 0.14, // how much a millimetre of a scar's seam darkens the skin in it (a crease holds shadow)
|
|
23
23
|
WOUND_DEEP = 4.5, // millimetres a fresh wound's torn flesh lies below the skin round it,
|
|
24
24
|
WOUND_SWELL = 2.2, // and how far the bruised skin at its edges swells;
|
|
25
|
-
HEALED_DEEP = 2.4, // once healed (
|
|
25
|
+
HEALED_DEEP = 2.4, // once healed (faceFeatures.healed), how far the scar lies sunk where the flesh was torn, and how high its edges and
|
|
26
26
|
HEALED_RIDGE = 0.9, // the cords of scar tissue across it stand
|
|
27
27
|
// Where a wound has torn the nose away, the opening into the skull's nose left in its place: a pear-shaped hollow down the
|
|
28
28
|
// middle of the face (from the top of its rows to its foot, millimetres up the face), its half width at the foot, how deep it
|
|
@@ -35,19 +35,19 @@ const MM = 0.001,
|
|
|
35
35
|
// worked out: a head asks for these some hundred thousand times.
|
|
36
36
|
const FAR = 3.2;
|
|
37
37
|
function bump(v, at, wide) {
|
|
38
|
-
const
|
|
39
|
-
return
|
|
38
|
+
const scaledOffset = (v - at) / wide;
|
|
39
|
+
return scaledOffset > FAR || scaledOffset < -FAR ? 0 : Math.exp(-scaledOffset * scaledOffset);
|
|
40
40
|
}
|
|
41
41
|
function blob(x, y, ax, ay, wx, wy) {
|
|
42
42
|
const dx = (x - ax) / wx,
|
|
43
43
|
dy = (y - ay) / wy,
|
|
44
|
-
|
|
45
|
-
return
|
|
44
|
+
distanceSquared = dx * dx + dy * dy;
|
|
45
|
+
return distanceSquared > FAR * FAR ? 0 : Math.exp(-distanceSquared);
|
|
46
46
|
}
|
|
47
47
|
// The larger of two heights, rounded where they meet.
|
|
48
|
-
function smoothMax(
|
|
49
|
-
const h = clamp(0.5 + (
|
|
50
|
-
return lerp(
|
|
48
|
+
function smoothMax(firstValue, secondValue, blendWidth) {
|
|
49
|
+
const h = clamp(0.5 + (firstValue - secondValue) / (2 * blendWidth), 0, 1);
|
|
50
|
+
return lerp(secondValue, firstValue, h) + blendWidth * h * (1 - h);
|
|
51
51
|
}
|
|
52
52
|
// How far a point lies from the line a-b, to which side of it (positive to the outside of the face), and how far along.
|
|
53
53
|
function fromLine(x, y, ax, ay, bx, by, out) {
|
|
@@ -62,27 +62,27 @@ function fromLine(x, y, ax, ay, bx, by, out) {
|
|
|
62
62
|
const _slice = { x: 0, z: 0 },
|
|
63
63
|
_line = [0, 0];
|
|
64
64
|
|
|
65
|
-
// The surface of a head
|
|
65
|
+
// The surface of a head with the given features, as a function of a direction from its middle: sampleHead(direction, outPoint, channels). Channels: lips,
|
|
66
66
|
// shade, warmth (cheeks, nose), where a beard grows on cheeks and jaw, brow, where a moustache grows, the chin's tuft, a scar. A fine head has open lids and a mouth that can open (its grid lays rows
|
|
67
67
|
// along their edges); a plain one, for the far mesh and for coarse sculpts, has them closed and painted.
|
|
68
68
|
function headFn(features = {}, fine = false) {
|
|
69
|
-
const
|
|
70
|
-
const age =
|
|
71
|
-
fat =
|
|
72
|
-
dead =
|
|
73
|
-
jawWide = (
|
|
74
|
-
chinWide = ((
|
|
75
|
-
slope =
|
|
76
|
-
lips =
|
|
77
|
-
noseLong =
|
|
78
|
-
noseWide =
|
|
69
|
+
const faceFeatures = { jaw: 0.5, lips: 1, cheek: 1, mouthW: 1, brow: 1, socket: 1, hollow: 0, chin: 1, nose: 1, bridge: 0, ...features };
|
|
70
|
+
const age = faceFeatures.age || 0,
|
|
71
|
+
fat = faceFeatures.fat || 0,
|
|
72
|
+
dead = faceFeatures.dead || 0,
|
|
73
|
+
jawWide = (faceFeatures.jaw - 0.5) * 0.17,
|
|
74
|
+
chinWide = ((faceFeatures.chinW ?? 1) - 1) * 0.5,
|
|
75
|
+
slope = faceFeatures.slope ?? 1,
|
|
76
|
+
lips = faceFeatures.lips,
|
|
77
|
+
noseLong = faceFeatures.noseL ?? 1,
|
|
78
|
+
noseWide = faceFeatures.noseW ?? 1;
|
|
79
79
|
const width = sampled(
|
|
80
80
|
y =>
|
|
81
81
|
WIDTH(y) *
|
|
82
82
|
(1 +
|
|
83
83
|
jawWide * bump(y, -84, 26) +
|
|
84
84
|
chinWide * sstep(-88, -108, y) +
|
|
85
|
-
(
|
|
85
|
+
(faceFeatures.cheek - 1) * 0.05 * bump(y, -18, 16) +
|
|
86
86
|
fat * 0.1 * bump(y, -62, 36)),
|
|
87
87
|
-HALF,
|
|
88
88
|
HALF,
|
|
@@ -100,7 +100,7 @@ function headFn(features = {}, fine = false) {
|
|
|
100
100
|
// the outline of the bare skull and jaw at a height, at an angle round from the front
|
|
101
101
|
// (a grid asks for one height many times running, so the slice last asked for is kept)
|
|
102
102
|
const kept = { y: NaN, square: 2, wide: 0, fore: 0, aft: 0, mid: 0 };
|
|
103
|
-
const slice = (y, angle,
|
|
103
|
+
const slice = (y, angle, output) => {
|
|
104
104
|
if (y !== kept.y) {
|
|
105
105
|
const k = closing(y);
|
|
106
106
|
kept.y = y;
|
|
@@ -112,24 +112,24 @@ function headFn(features = {}, fine = false) {
|
|
|
112
112
|
}
|
|
113
113
|
const n = kept.square,
|
|
114
114
|
s = Math.sin(angle),
|
|
115
|
-
|
|
116
|
-
q = Math.pow(Math.pow(Math.abs(s), n) + Math.pow(Math.abs(
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
cosAngle = Math.cos(angle),
|
|
116
|
+
q = Math.pow(Math.pow(Math.abs(s), n) + Math.pow(Math.abs(cosAngle), n), -1 / n);
|
|
117
|
+
output.x = kept.wide * s * q;
|
|
118
|
+
output.z = kept.mid + (cosAngle > 0 ? kept.fore : kept.aft) * cosAngle * q;
|
|
119
119
|
};
|
|
120
120
|
|
|
121
121
|
// the eyes: where each ball sits, and the edges of its lids from the inner corner (0) to the outer (1)
|
|
122
|
-
const eyeX = 31.5 * (
|
|
122
|
+
const eyeX = 31.5 * (faceFeatures.eyeGap ?? 1),
|
|
123
123
|
eyeY = -1,
|
|
124
124
|
ballR = 12.2,
|
|
125
125
|
lidR = ballR + 1.3,
|
|
126
126
|
innerX = eyeX - 14.5,
|
|
127
127
|
outerX = eyeX + 14,
|
|
128
|
-
one = !!
|
|
129
|
-
opening = one ? 0 : (
|
|
130
|
-
tilt =
|
|
128
|
+
one = !!faceFeatures.oneEye, // the two eyes healed over, and one in the middle of the brow
|
|
129
|
+
opening = one ? 0 : (faceFeatures.eye ?? 1),
|
|
130
|
+
tilt = faceFeatures.tilt ?? 0;
|
|
131
131
|
slice(eyeY, Math.asin(eyeX / width(eyeY)) * 0.93, _slice);
|
|
132
|
-
const eyeZ = _slice.z - 14.4 - (
|
|
132
|
+
const eyeZ = _slice.z - 14.4 - (faceFeatures.deep ?? 0);
|
|
133
133
|
slice(ONE_EYE.y, 0, _slice);
|
|
134
134
|
const oneZ = _slice.z + ONE_EYE.out - ONE_EYE.r, // where the middle of the one eye's ball is
|
|
135
135
|
oneLid = ONE_EYE.r + 1.3;
|
|
@@ -137,16 +137,16 @@ function headFn(features = {}, fine = false) {
|
|
|
137
137
|
upperLid = t => corner(t) + 5.4 * opening * Math.pow(4 * Math.pow(t, 0.85) * (1 - Math.pow(t, 0.85)), 0.72),
|
|
138
138
|
lowerLid = t => corner(t) - 3.9 * opening * Math.pow(4 * Math.pow(t, 1.15) * (1 - Math.pow(t, 1.15)), 0.8);
|
|
139
139
|
// a row of the grid is bent so that the two lid rows run along the lids' edges; away from the eye it lies level
|
|
140
|
-
const lidEdges = (ax,
|
|
140
|
+
const lidEdges = (ax, output) => {
|
|
141
141
|
const t = (ax - innerX) / (outerX - innerX);
|
|
142
142
|
if (t > 0 && t < 1) {
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
output[0] = upperLid(t);
|
|
144
|
+
output[1] = lowerLid(t);
|
|
145
145
|
} else {
|
|
146
146
|
const c = corner(clamp(t, 0, 1)),
|
|
147
147
|
e = sstep(0, 7, t < 0 ? innerX - ax : ax - outerX);
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
output[0] = c + (LID_TOP - c) * e;
|
|
149
|
+
output[1] = c + (LID_LOW - c) * e;
|
|
150
150
|
}
|
|
151
151
|
return t;
|
|
152
152
|
};
|
|
@@ -158,11 +158,11 @@ function headFn(features = {}, fine = false) {
|
|
|
158
158
|
: low - ((LID_LOW - row) * (low - LID_BELOW)) / (LID_LOW - LID_BELOW);
|
|
159
159
|
|
|
160
160
|
// An old scar at a point of the face (millimetres; x to the person's left), as how far the skin is sunk there and how pale it
|
|
161
|
-
// is:
|
|
161
|
+
// is: faceFeatures.scar is the seam's two ends, its width (millimetres) and how far its middle bows down from the straight, like a smile.
|
|
162
162
|
// A wider one is deeper and paler.
|
|
163
163
|
const _scar = [0, 0],
|
|
164
164
|
scarAt = (x, y) => {
|
|
165
|
-
const [ax0, ay0, bx, by, wide = SCAR_WIDE, bow = 0] =
|
|
165
|
+
const [ax0, ay0, bx, by, wide = SCAR_WIDE, bow = 0] = faceFeatures.scar,
|
|
166
166
|
k = Math.sqrt(wide / SCAR_WIDE);
|
|
167
167
|
fromLine(x, y, ax0, ay0, bx, by, _line);
|
|
168
168
|
const t = _line[1],
|
|
@@ -172,19 +172,19 @@ function headFn(features = {}, fine = false) {
|
|
|
172
172
|
_scar[1] = k * ends * bump(d, 0, wide);
|
|
173
173
|
return _scar;
|
|
174
174
|
};
|
|
175
|
-
// A fresh wound (
|
|
175
|
+
// A fresh wound (faceFeatures.wound: as a scar, its two ends, width and bow): a broad band of torn flesh, sunk and ragged, the skin
|
|
176
176
|
// swollen along its edges; as how deep it lies at a point and how much of it there is (0 to 1). Healed, the band has closed
|
|
177
177
|
// into a scar: shallower, the swelling gone, its edges and cords of scar tissue across it standing proud.
|
|
178
178
|
const _wound = [0, 0],
|
|
179
179
|
woundAt = (x, y) => {
|
|
180
|
-
const [ax0, ay0, bx, by, wide, bow = 0] =
|
|
180
|
+
const [ax0, ay0, bx, by, wide, bow = 0] = faceFeatures.wound;
|
|
181
181
|
fromLine(x, y, ax0, ay0, bx, by, _line);
|
|
182
182
|
const t = _line[1],
|
|
183
183
|
ragged = 0.22 * wide * (Math.sin(t * 23 + x * 0.31) * 0.6 + Math.sin(t * 41 - y * 0.27) * 0.4),
|
|
184
184
|
d = Math.abs(_line[0] + bow * 4 * t * (1 - t)) - ragged,
|
|
185
185
|
ends = sstep(-0.06, 0.08, t) * sstep(1.06, 0.92, t),
|
|
186
186
|
torn = ends * sstep(wide, wide * 0.7, d);
|
|
187
|
-
_wound[0] =
|
|
187
|
+
_wound[0] = faceFeatures.healed
|
|
188
188
|
? torn * HEALED_DEEP * (0.75 + 0.25 * Math.sin(x * 0.9) * Math.sin(y * 1.1)) -
|
|
189
189
|
HEALED_RIDGE * (ends * bump(d, wide * 0.85, wide * 0.18) + torn * Math.max(0, Math.sin(t * 29 + x * 0.2)) ** 3)
|
|
190
190
|
: torn * WOUND_DEEP * (0.8 + 0.2 * Math.sin(x * 0.9) * Math.sin(y * 1.1)) - ends * WOUND_SWELL * bump(d, wide * 1.15, wide * 0.4);
|
|
@@ -192,33 +192,33 @@ function headFn(features = {}, fine = false) {
|
|
|
192
192
|
return _wound;
|
|
193
193
|
};
|
|
194
194
|
// an eye the wound crosses is burst and swollen shut
|
|
195
|
-
const woundShut =
|
|
195
|
+
const woundShut = faceFeatures.wound ? [woundAt(-eyeX, eyeY)[1], woundAt(eyeX, eyeY)[1]] : null;
|
|
196
196
|
// a wound across the middle of the nose takes all of it below the bone, tip and wings, not only the band it crosses
|
|
197
|
-
const noseLost =
|
|
198
|
-
const mouthX = 24.5 *
|
|
197
|
+
const noseLost = faceFeatures.wound ? Math.max(woundAt(0, -12)[1], woundAt(0, -22)[1], woundAt(0, -32)[1]) : 0;
|
|
198
|
+
const mouthX = 24.5 * faceFeatures.mouthW,
|
|
199
199
|
browLine = ax => 19 + 5 * Math.sin(Math.PI * clamp(ax / 56, 0, 1)) - 2.5 * sstep(40, 60, ax),
|
|
200
|
-
foldDeep = (0.55 + 1.5 * age + fat) * (
|
|
200
|
+
foldDeep = (0.55 + 1.5 * age + fat) * (faceFeatures.fold ?? 1),
|
|
201
201
|
alaX = 11.8 * noseWide;
|
|
202
202
|
// the soft forms of the face without the nose, lids and lips: brow ridge, sockets, cheekbones, the muzzle of the mouth, chin
|
|
203
203
|
const soft = (ax, y) => {
|
|
204
204
|
const line = browLine(ax),
|
|
205
|
-
ridge = (1 + 2.8 * bump(ax, 17, 14)) *
|
|
206
|
-
socket =
|
|
205
|
+
ridge = (1 + 2.8 * bump(ax, 17, 14)) * faceFeatures.brow * sstep(64, 42, ax) * (y > line ? bump(y, line, 8) : bump(y, line, 4.2)),
|
|
206
|
+
socket = faceFeatures.socket * (4 * blob(ax, y, 30, 5, 17, 11) + 2.6 * blob(ax, y, 17.5, 1, 7, 9));
|
|
207
207
|
return (
|
|
208
208
|
ridge -
|
|
209
209
|
socket +
|
|
210
|
-
2.6 *
|
|
210
|
+
2.6 * faceFeatures.cheek * blob(ax, y, 46, -16, 14, 11) -
|
|
211
211
|
(0.5 + 1.2 * age) * blob(ax, y, 26, -15, 9, 5) -
|
|
212
|
-
(3 *
|
|
212
|
+
(3 * faceFeatures.hollow + 2 * age) * blob(ax, y, 43, -55, 13, 16) +
|
|
213
213
|
3.4 * blob(ax, y, 0, -63, 26, 19) +
|
|
214
214
|
3 * fat * blob(ax, y, 38, -52, 18, 22) +
|
|
215
215
|
2.2 * (age + fat) * blob(ax, y, 36, -91, 10, 9) -
|
|
216
216
|
3 * blob(ax, y, 0, -83.5, 17, 4.6) +
|
|
217
|
-
3.6 *
|
|
217
|
+
3.6 * faceFeatures.chin * blob(ax, y, 0, -100, 15 * (faceFeatures.chinW ?? 1), 10)
|
|
218
218
|
);
|
|
219
219
|
};
|
|
220
220
|
|
|
221
|
-
const point = (row, angle,
|
|
221
|
+
const point = (row, angle, output, ch) => {
|
|
222
222
|
slice(row, angle, _slice);
|
|
223
223
|
const side = _slice.x < 0 ? -1 : 1,
|
|
224
224
|
cosA = Math.cos(angle),
|
|
@@ -249,7 +249,7 @@ function headFn(features = {}, fine = false) {
|
|
|
249
249
|
if (face > 0) {
|
|
250
250
|
out = soft(ax, y);
|
|
251
251
|
shade -=
|
|
252
|
-
0.15 * clamp((
|
|
252
|
+
0.15 * clamp((faceFeatures.socket * blob(ax, y, 30, 5, 17, 11)) / 1.2, 0, 1) +
|
|
253
253
|
0.1 * bump(y, browLine(ax) - 8, 4.5) * sstep(50, 36, ax) * sstep(6, 14, ax);
|
|
254
254
|
if (age > 0) {
|
|
255
255
|
// the lines of age: furrows across the brow (an aged head's grid has rows for them), the frown between the brows,
|
|
@@ -267,18 +267,18 @@ function headFn(features = {}, fine = false) {
|
|
|
267
267
|
out -= age * (0.5 * furrow + 0.7 * frown + 0.3 * fan);
|
|
268
268
|
shade -= age * (0.17 * furrow + 0.16 * frown + 0.12 * fan);
|
|
269
269
|
}
|
|
270
|
-
if (
|
|
270
|
+
if (faceFeatures.scar) {
|
|
271
271
|
// an old wound the skin has closed over: a pale band with a sunken seam down its middle, puckered a little either side
|
|
272
272
|
const [deep, pale] = scarAt(side * ax, y);
|
|
273
273
|
scar = pale;
|
|
274
274
|
out -= deep;
|
|
275
275
|
shade -= SCAR_SHADE * Math.max(0, deep);
|
|
276
276
|
}
|
|
277
|
-
if (
|
|
277
|
+
if (faceFeatures.wound) {
|
|
278
278
|
const [deep, torn] = woundAt(side * ax, y);
|
|
279
279
|
raw = torn;
|
|
280
280
|
out -= deep;
|
|
281
|
-
shade -= (
|
|
281
|
+
shade -= (faceFeatures.healed ? 0.12 : 0.3) * torn * (0.6 + 0.4 * Math.sin(ax * 0.7 + y * 0.9)); // the torn flesh holds shadow in its pits
|
|
282
282
|
}
|
|
283
283
|
// the lids over the ball of the eye, with the fold above the upper one and, with age, the bag under the lower
|
|
284
284
|
const ex = ax - eyeX,
|
|
@@ -327,13 +327,13 @@ function headFn(features = {}, fine = false) {
|
|
|
327
327
|
// the nose: a ridge down the middle of the face to a rounded tip, wings beside it and the nostrils beneath
|
|
328
328
|
const noseY = 12 + (y - 12) / noseLong;
|
|
329
329
|
if (noseY < 17 && noseY > -52) {
|
|
330
|
-
const reach = NOSE_OUT(noseY) * (1 + (
|
|
330
|
+
const reach = NOSE_OUT(noseY) * (1 + (faceFeatures.nose - 1) * sstep(8, -6, noseY)) + 2.2 * faceFeatures.bridge * bump(noseY, -8, 11),
|
|
331
331
|
t = ax / (NOSE_WIDE(noseY) * (1 + (noseWide - 1) * sstep(-5, -35, noseY))),
|
|
332
332
|
tip = bump(noseY, -36, 7);
|
|
333
333
|
const torn = 1 - Math.max(0.85 * raw, noseLost * sstep(-6, -16, noseY)); // what a wound has torn away of the nose
|
|
334
334
|
if (t < 1) out += reach * lerp(1 - sstep(0.22, 1, t), Math.pow(1 - t * t, 0.75), 0.75 * tip) * torn;
|
|
335
335
|
const wr = ((ax - alaX) / (6.4 * noseWide)) ** 2 + ((noseY + 41.5) / 6.4) ** 2;
|
|
336
|
-
if (wr < 1) out = smoothMax(out, soft(ax, y) + 7.2 *
|
|
336
|
+
if (wr < 1) out = smoothMax(out, soft(ax, y) + 7.2 * faceFeatures.nose * Math.pow(1 - wr, 0.7) * torn, 1.2);
|
|
337
337
|
const nostril = ((ax - 6.6 * noseWide) / (4.2 * noseWide)) ** 2 + ((noseY + 45.4) / 2.2) ** 2;
|
|
338
338
|
if (nostril < 1.6) {
|
|
339
339
|
out -= (fine ? 2.6 : 0.6) * sstep(1.6, 0.4, nostril);
|
|
@@ -345,8 +345,8 @@ function headFn(features = {}, fine = false) {
|
|
|
345
345
|
const { top, foot, wide } = NOSE_HOLE,
|
|
346
346
|
half = wide * (0.35 + 0.65 * sstep(top, foot + 6, noseY)) * noseWide,
|
|
347
347
|
hole = noseLost * sstep(top + 2, top - 4, noseY) * sstep(foot - 2, foot + 3, noseY) * sstep(1, 0.55, ax / half);
|
|
348
|
-
out -= hole * (
|
|
349
|
-
shade *= 1 - hole * (
|
|
348
|
+
out -= hole * (faceFeatures.healed ? NOSE_HOLE.healedDeep : NOSE_HOLE.deep);
|
|
349
|
+
shade *= 1 - hole * (faceFeatures.healed ? NOSE_HOLE.healedDark : NOSE_HOLE.dark);
|
|
350
350
|
raw = Math.max(raw, hole); // coloured as the wound round it is, raw or scarred
|
|
351
351
|
}
|
|
352
352
|
warm += 0.5 * tip * bump(ax, 0, 13);
|
|
@@ -418,17 +418,17 @@ function headFn(features = {}, fine = false) {
|
|
|
418
418
|
flank =
|
|
419
419
|
1 +
|
|
420
420
|
(-2.8 * (1 + 0.8 * age) * bump(y, 22, 17) * bump(turn, 1.05, 0.33) +
|
|
421
|
-
1.6 *
|
|
422
|
-
(0.6 + 1.2 *
|
|
421
|
+
1.6 * faceFeatures.cheek * bump(y, -14, 8) * bump(turn, 1.2, 0.35) +
|
|
422
|
+
(0.6 + 1.2 * faceFeatures.jaw) * bump(y, -62, 18) * bump(turn, 1.25, 0.3)) /
|
|
423
423
|
75;
|
|
424
424
|
if (y < -84) {
|
|
425
425
|
shade -= 0.2 * sstep(0.25, -0.35, cosA) * sstep(-84, -98, y); // under the jaw
|
|
426
426
|
if (!dead) beard = Math.max(beard, sstep(-84, -93, y));
|
|
427
427
|
}
|
|
428
428
|
const mid = MIDDLE(y);
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
429
|
+
output.x = side * ax * flank * MM;
|
|
430
|
+
output.y = y * MM;
|
|
431
|
+
output.z = (mid + (_slice.z - mid) * flank + out) * MM;
|
|
432
432
|
if (ch) {
|
|
433
433
|
ch[0] = lip;
|
|
434
434
|
ch[1] = Math.max(0.04, shade);
|
|
@@ -441,16 +441,16 @@ function headFn(features = {}, fine = false) {
|
|
|
441
441
|
}
|
|
442
442
|
};
|
|
443
443
|
|
|
444
|
-
const
|
|
445
|
-
|
|
444
|
+
const sampleHead = (d, output, ch) => point(d.y * HALF, Math.atan2(d.x, d.z), output, ch);
|
|
445
|
+
sampleHead.point = point; // by a row of the grid (millimetres up from the middle) and an angle round from the front
|
|
446
446
|
// the bare skull at a direction, for what sits over it (hair, hoods, helmets)
|
|
447
|
-
|
|
447
|
+
sampleHead.skull = (d, output) => {
|
|
448
448
|
const y = d.y * HALF;
|
|
449
449
|
slice(y, Math.atan2(d.x, d.z), _slice);
|
|
450
|
-
|
|
450
|
+
output.set(_slice.x * MM, y * MM, _slice.z * MM);
|
|
451
451
|
};
|
|
452
452
|
// how far out from the bare skull a point lies (metres from the head's middle): 1 on its surface, less within
|
|
453
|
-
|
|
453
|
+
sampleHead.reach = (px, py, pz) => {
|
|
454
454
|
const up = py / MM,
|
|
455
455
|
y = clamp(up, -HALF, HALF),
|
|
456
456
|
n = SQUARE(y),
|
|
@@ -461,10 +461,10 @@ function headFn(features = {}, fine = false) {
|
|
|
461
461
|
return across;
|
|
462
462
|
};
|
|
463
463
|
// the direction at which the bare skull lies under a point (metres from the head's middle), on the line from the middle
|
|
464
|
-
// through it: what
|
|
465
|
-
|
|
464
|
+
// through it: what sampleHead.skull turns into a point again. Hair that lies over the skull finds its place by it.
|
|
465
|
+
sampleHead.under = (px, py, pz, d) => {
|
|
466
466
|
for (let i = 0; i < UNDER_STEPS; i++) {
|
|
467
|
-
const k =
|
|
467
|
+
const k = sampleHead.reach(px, py, pz);
|
|
468
468
|
px /= k;
|
|
469
469
|
py /= k;
|
|
470
470
|
pz /= k;
|
|
@@ -477,7 +477,7 @@ function headFn(features = {}, fine = false) {
|
|
|
477
477
|
};
|
|
478
478
|
const upAt = t => Math.asin(clamp((upperLid(t) - eyeY) / lidR, -0.95, 0.95)),
|
|
479
479
|
lowAt = t => Math.asin(clamp((lowerLid(t) - eyeY) / lidR, -0.95, 0.95));
|
|
480
|
-
|
|
480
|
+
sampleHead.eye = {
|
|
481
481
|
x: eyeX * MM,
|
|
482
482
|
y: eyeY * MM,
|
|
483
483
|
z: eyeZ * MM,
|
|
@@ -489,11 +489,11 @@ function headFn(features = {}, fine = false) {
|
|
|
489
489
|
t > 0 && t < 1 ? clamp((upAt(t) - lowAt(t) + 0.06 * Math.sqrt(Math.sin(Math.PI * t))) / (upAt(0.45) - lowAt(0.45) + 0.06), 0, 1) : 0, // the share of it at each point along the lid
|
|
490
490
|
upper: t => upperLid(t) * MM,
|
|
491
491
|
};
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
return
|
|
492
|
+
sampleHead.mouth = { x: mouthX * MM, y: SEAM * MM };
|
|
493
|
+
sampleHead.one = one ? { y: ONE_EYE.y * MM, z: oneZ * MM, r: ONE_EYE.r * MM, wide: ONE_EYE.wide * MM } : null; // the one eye's ball, if so
|
|
494
|
+
sampleHead.browLine = x => browLine(x / MM) * MM;
|
|
495
|
+
sampleHead.scar = (x, y) => (faceFeatures.scar ? scarAt(x / MM, y / MM)[1] : 0); // how much of a scar there is at a point (metres)
|
|
496
|
+
return sampleHead;
|
|
497
497
|
}
|
|
498
498
|
|
|
499
499
|
export { FURROWS, LID_ABOVE, LID_BELOW, LID_LOW, LID_TOP, SEAM, headFn };
|
package/geometry/heightfield.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Sample and refine regular terrain grids in local X/Z coordinates. Heights follow the triangles used to render the surface.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Interpolate height on the same triangle that the renderer draws.
|
|
8
|
+
* @param {import('three').PlaneGeometry} geometry - Regular X/Z grid whose first vertex has the smallest X and Z.
|
|
9
|
+
* @param {(x: number, z: number) => number} [outside] - Fallback height beyond the grid.
|
|
10
|
+
* @returns {(x: number, z: number) => (number | undefined)} A sampler in local geometry coordinates. Outside the grid it returns the fallback height, or undefined.
|
|
11
|
+
*/
|
|
3
12
|
export function heightfieldSampler(geometry, outside) {
|
|
4
13
|
const { widthSegments: columns, heightSegments: rows } = geometry.parameters;
|
|
5
14
|
const positions = geometry.getAttribute('position');
|
|
@@ -9,21 +18,21 @@ export function heightfieldSampler(geometry, outside) {
|
|
|
9
18
|
const depth = positions.getZ(rows * (columns + 1)) - z0;
|
|
10
19
|
if (!(width > 0 && depth > 0)) throw new RangeError('Expected a regular heightfield in the X/Z plane');
|
|
11
20
|
return (x, z) => {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
const col = Math.min(Math.floor(
|
|
16
|
-
const row = Math.min(Math.floor(
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
return
|
|
21
|
+
const gridX = (x - x0) / width * columns;
|
|
22
|
+
const gridZ = (z - z0) / depth * rows;
|
|
23
|
+
if (gridX < 0 || gridZ < 0 || gridX > columns || gridZ > rows) return outside?.(x, z);
|
|
24
|
+
const col = Math.min(Math.floor(gridX), columns - 1);
|
|
25
|
+
const row = Math.min(Math.floor(gridZ), rows - 1);
|
|
26
|
+
const columnFraction = gridX - col, rowFraction = gridZ - row;
|
|
27
|
+
const cornerIndex = row * (columns + 1) + col;
|
|
28
|
+
const farLeft = positions.getY(cornerIndex + columns + 1);
|
|
29
|
+
const nearRight = positions.getY(cornerIndex + 1);
|
|
30
|
+
if (columnFraction + rowFraction <= 1) {
|
|
31
|
+
const nearLeft = positions.getY(cornerIndex);
|
|
32
|
+
return nearLeft + (nearRight - nearLeft) * columnFraction + (farLeft - nearLeft) * rowFraction;
|
|
24
33
|
}
|
|
25
|
-
const
|
|
26
|
-
return
|
|
34
|
+
const farRight = positions.getY(cornerIndex + columns + 2);
|
|
35
|
+
return farRight + (farLeft - farRight) * (1 - columnFraction) + (nearRight - farRight) * (1 - rowFraction);
|
|
27
36
|
};
|
|
28
37
|
}
|
|
29
38
|
|
|
@@ -59,8 +68,8 @@ export function refineHeightfield(base, { x, z, cells, subdivisions, height, cre
|
|
|
59
68
|
});
|
|
60
69
|
const sample = heightfieldSampler(patch, coarse);
|
|
61
70
|
// Keep the base vertex and index layout for other disjoint patches and external attributes.
|
|
62
|
-
for (let
|
|
63
|
-
const start = (
|
|
71
|
+
for (let patchRow = row; patchRow < row + cells; patchRow++) {
|
|
72
|
+
const start = (patchRow * columns + col) * 6;
|
|
64
73
|
base.index.array.fill(0, start, start + cells * 6);
|
|
65
74
|
}
|
|
66
75
|
base.index.needsUpdate = true;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Weld identical vertex records without rounding or changing triangle order. Comparing the
|
|
2
|
+
// stored bytes preserves seams, signed zero and normalized attributes exactly.
|
|
3
|
+
export function indexParts(parts) {
|
|
4
|
+
const count = parts.position.length / 3;
|
|
5
|
+
if (!count || parts.index) return parts;
|
|
6
|
+
const attributes = Object.entries(parts).map(([name, data]) => {
|
|
7
|
+
const strideBytes = data.byteLength / count;
|
|
8
|
+
const words = !(strideBytes % 4 || data.byteOffset % 4);
|
|
9
|
+
const View = words ? Uint32Array : Uint8Array;
|
|
10
|
+
return {
|
|
11
|
+
name,
|
|
12
|
+
data,
|
|
13
|
+
stride: strideBytes / View.BYTES_PER_ELEMENT,
|
|
14
|
+
source: new View(data.buffer, data.byteOffset, data.byteLength / View.BYTES_PER_ELEMENT),
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
const buckets = new Uint32Array(2 ** Math.ceil(Math.log2(count)));
|
|
18
|
+
const links = new Uint32Array(count);
|
|
19
|
+
const originals = new Uint32Array(count);
|
|
20
|
+
const index = count <= 65535 ? new Uint16Array(count) : new Uint32Array(count);
|
|
21
|
+
let used = 0;
|
|
22
|
+
for (let vertex = 0; vertex < count; vertex++) {
|
|
23
|
+
// Hash the complete record so coincident positions along seams, or a tight cluster
|
|
24
|
+
// of tiny features, do not all form one long chain.
|
|
25
|
+
let hash = 2166136261;
|
|
26
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
27
|
+
const { source, stride } = attributes[i];
|
|
28
|
+
const offset = vertex * stride;
|
|
29
|
+
for (let j = 0; j < stride; j++) hash = Math.imul(hash ^ source[offset + j], 16777619);
|
|
30
|
+
}
|
|
31
|
+
const bucket = (hash ^ (hash >>> 16)) & (buckets.length - 1);
|
|
32
|
+
let link = buckets[bucket];
|
|
33
|
+
while (link && !sameVertex(attributes, originals[link - 1], vertex)) link = links[link - 1];
|
|
34
|
+
if (!link) {
|
|
35
|
+
originals[used] = vertex;
|
|
36
|
+
links[used] = buckets[bucket];
|
|
37
|
+
link = buckets[bucket] = ++used;
|
|
38
|
+
}
|
|
39
|
+
index[vertex] = link - 1;
|
|
40
|
+
}
|
|
41
|
+
const packed = { index };
|
|
42
|
+
for (const { name, data, stride, source } of attributes) {
|
|
43
|
+
const out = new data.constructor(used * (data.length / count));
|
|
44
|
+
const dest = new source.constructor(out.buffer);
|
|
45
|
+
for (let i = 0; i < used; i++) {
|
|
46
|
+
const from = originals[i] * stride;
|
|
47
|
+
for (let j = 0; j < stride; j++) dest[i * stride + j] = source[from + j];
|
|
48
|
+
}
|
|
49
|
+
packed[name] = out;
|
|
50
|
+
}
|
|
51
|
+
return packed;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function sameVertex(attributes, firstVertex, secondVertex) {
|
|
55
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
56
|
+
const { source, stride } = attributes[i];
|
|
57
|
+
for (let j = 0; j < stride; j++) if (source[firstVertex * stride + j] !== source[secondVertex * stride + j]) return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// For opaque, independently owned instance attributes. Logical ids remain stable while
|
|
2
|
+
// visible records occupy the front of the arrays. The original full bounds stay valid.
|
|
3
|
+
export function createInstanceVisibility(mesh) {
|
|
4
|
+
const slots = Uint32Array.from({ length: mesh.count }, (_, i) => i);
|
|
5
|
+
const logicalIds = slots.slice();
|
|
6
|
+
const attributes = [mesh.instanceMatrix];
|
|
7
|
+
if (mesh.instanceColor) attributes.push(mesh.instanceColor);
|
|
8
|
+
if (!mesh.boundingSphere) mesh.computeBoundingSphere();
|
|
9
|
+
return function show(id, visible) {
|
|
10
|
+
if (!Number.isInteger(id) || id < 0 || id >= logicalIds.length) throw new RangeError('Unknown instance id');
|
|
11
|
+
const from = slots[id];
|
|
12
|
+
if (from < mesh.count === visible) return;
|
|
13
|
+
const to = visible ? mesh.count++ : --mesh.count;
|
|
14
|
+
if (from === to) return;
|
|
15
|
+
const other = logicalIds[to];
|
|
16
|
+
logicalIds[from] = other;
|
|
17
|
+
slots[other] = from;
|
|
18
|
+
logicalIds[to] = id;
|
|
19
|
+
slots[id] = to;
|
|
20
|
+
for (const attribute of attributes) {
|
|
21
|
+
const { array, itemSize } = attribute;
|
|
22
|
+
const sourceOffset = from * itemSize,
|
|
23
|
+
destinationOffset = to * itemSize;
|
|
24
|
+
for (let i = 0; i < itemSize; i++) {
|
|
25
|
+
const value = array[sourceOffset + i];
|
|
26
|
+
array[sourceOffset + i] = array[destinationOffset + i];
|
|
27
|
+
array[destinationOffset + i] = value;
|
|
28
|
+
}
|
|
29
|
+
// Include the hidden slot: it can become visible by growing count without another swap.
|
|
30
|
+
const start = Math.min(sourceOffset, destinationOffset),
|
|
31
|
+
end = Math.max(sourceOffset, destinationOffset) + itemSize;
|
|
32
|
+
const range = attribute.updateRanges[0];
|
|
33
|
+
if (range) {
|
|
34
|
+
const limit = Math.max(end, range.start + range.count);
|
|
35
|
+
range.start = Math.min(start, range.start);
|
|
36
|
+
range.count = limit - range.start;
|
|
37
|
+
} else attribute.addUpdateRange(start, end - start);
|
|
38
|
+
attribute.needsUpdate = true;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
package/geometry/instances.js
CHANGED
|
@@ -7,14 +7,14 @@ import { markStill } from '../rendering/still-casters.js';
|
|
|
7
7
|
// (instanceArrays, putInstance), and the instanced meshes the page draws from them (instancedMesh, instancedTwin).
|
|
8
8
|
// ════════════════════════════════════════════════════════════════════════
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
const instanceArrays =
|
|
12
|
-
//
|
|
13
|
-
function putInstance(arrays,
|
|
14
|
-
matrix.toArray(arrays.matrices,
|
|
15
|
-
arrays.colours[
|
|
16
|
-
arrays.colours[
|
|
17
|
-
arrays.colours[
|
|
10
|
+
// Allocate space for one matrix and one linear RGB colour per instance.
|
|
11
|
+
const instanceArrays = instanceCount => ({ matrices: new Float32Array(instanceCount * 16), colours: new Float32Array(instanceCount * 3) });
|
|
12
|
+
// Write the transform and linear RGB colour at instanceIndex in Three.js buffer order.
|
|
13
|
+
function putInstance(arrays, instanceIndex, matrix, red, green, blue) {
|
|
14
|
+
matrix.toArray(arrays.matrices, instanceIndex * 16);
|
|
15
|
+
arrays.colours[instanceIndex * 3] = red;
|
|
16
|
+
arrays.colours[instanceIndex * 3 + 1] = green;
|
|
17
|
+
arrays.colours[instanceIndex * 3 + 2] = blue;
|
|
18
18
|
}
|
|
19
19
|
// An instanced mesh of `geometry` drawn at the copies of `arrays`. It is made empty and then given them, so that it does not
|
|
20
20
|
// first write a matrix of its own for every copy only to have it replaced.
|
|
@@ -46,15 +46,15 @@ class Copies {
|
|
|
46
46
|
this.matrices = [];
|
|
47
47
|
this.colours = [];
|
|
48
48
|
}
|
|
49
|
-
add(shape,
|
|
49
|
+
add(shape, color, transform) {
|
|
50
50
|
if (shape !== this.shape) throw new Error('Copies hold one shape');
|
|
51
|
-
const
|
|
52
|
-
this.matrices.push(...
|
|
51
|
+
const elements = transform.elements;
|
|
52
|
+
this.matrices.push(...elements);
|
|
53
53
|
const at = this.matrices.length - 4; // the translation, moved to the builder's origin
|
|
54
54
|
this.matrices[at] += this.ox;
|
|
55
55
|
this.matrices[at + 1] += this.oy;
|
|
56
56
|
this.matrices[at + 2] += this.oz;
|
|
57
|
-
this.colours.push(
|
|
57
|
+
this.colours.push(color[0], color[1], color[2]);
|
|
58
58
|
}
|
|
59
59
|
// The instanced mesh of the copies under `parent`, standing still, casting a shadow unless told not to; the lists are let go.
|
|
60
60
|
mesh(material, parent, shadow = true) {
|
|
@@ -74,3 +74,26 @@ class Copies {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
export { Copies, instanceArrays, instancedMesh, instancedTwin, putInstance };
|
|
77
|
+
|
|
78
|
+
// Partition static world-space transforms and their colors into independently cullable
|
|
79
|
+
// cells. A single cell keeps its original arrays; order within every cell is stable.
|
|
80
|
+
export function partitionInstances(arrays, cellSize) {
|
|
81
|
+
if (!(cellSize > 0)) throw new RangeError('Expected a positive cell size');
|
|
82
|
+
const { matrices, colours } = arrays;
|
|
83
|
+
const cells = new Map();
|
|
84
|
+
for (let i = 0; i < matrices.length / 16; i++) {
|
|
85
|
+
const cellKey = Math.floor(matrices[i*16+12] / cellSize) + ',' + Math.floor(matrices[i*16+14] / cellSize);
|
|
86
|
+
let ids = cells.get(cellKey);
|
|
87
|
+
if (!ids) cells.set(cellKey, ids = []);
|
|
88
|
+
ids.push(i);
|
|
89
|
+
}
|
|
90
|
+
if (cells.size < 2) return matrices.length ? [arrays] : [];
|
|
91
|
+
return Array.from(cells.values(), ids => {
|
|
92
|
+
const cell = instanceArrays(ids.length);
|
|
93
|
+
ids.forEach((id, i) => {
|
|
94
|
+
cell.matrices.set(matrices.subarray(id*16,id*16+16), i*16);
|
|
95
|
+
cell.colours.set(colours.subarray(id*3,id*3+3), i*3);
|
|
96
|
+
});
|
|
97
|
+
return cell;
|
|
98
|
+
});
|
|
99
|
+
}
|
package/geometry/outline-grid.js
CHANGED
|
@@ -29,13 +29,13 @@ function polyGrid(poly, cell, pad) {
|
|
|
29
29
|
// The signed distance anywhere, read from a grid of polyGrid's; beyond the box, the distance to the box.
|
|
30
30
|
function gridField({ x0, z0, x1, z1, nx, nz, cell, pad, g }) {
|
|
31
31
|
return (x, z) => {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
const i = Math.min(nx - 2,
|
|
36
|
-
j = Math.min(nz - 2,
|
|
37
|
-
u =
|
|
38
|
-
v =
|
|
32
|
+
const gridX = (x - x0) / cell,
|
|
33
|
+
gridZ = (z - z0) / cell;
|
|
34
|
+
if (gridX < 0 || gridZ < 0 || gridX > nx - 1 || gridZ > nz - 1) return pad + Math.hypot(Math.max(x0 - x, 0, x - x1), Math.max(z0 - z, 0, z - z1));
|
|
35
|
+
const i = Math.min(nx - 2, gridX | 0),
|
|
36
|
+
j = Math.min(nz - 2, gridZ | 0),
|
|
37
|
+
u = gridX - i,
|
|
38
|
+
v = gridZ - j,
|
|
39
39
|
k = j * nx + i;
|
|
40
40
|
return (g[k] * (1 - u) + g[k + 1] * u) * (1 - v) + (g[k + nx] * (1 - u) + g[k + nx + 1] * u) * v;
|
|
41
41
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Concatenate matching attribute records in order. Each [parts, from, to] range uses
|
|
2
|
+
// offsets in the three-component position array. Other attribute strides are inferred.
|
|
3
|
+
export function joinParts(pieces) {
|
|
4
|
+
if (!pieces.length) return {};
|
|
5
|
+
const vertices = pieces.reduce((sum, [, from, to]) => sum + (to - from) / 3, 0),
|
|
6
|
+
[sample] = pieces.find(([parts]) => parts.position.length) ?? pieces[0],
|
|
7
|
+
joined = {};
|
|
8
|
+
for (const name in sample) {
|
|
9
|
+
const size = vertices && sample[name].length / (sample.position.length / 3),
|
|
10
|
+
array = (joined[name] = new sample[name].constructor(vertices * size));
|
|
11
|
+
let writeOffset = 0;
|
|
12
|
+
for (const [parts, from, to] of pieces) {
|
|
13
|
+
array.set(parts[name].subarray((from / 3) * size, (to / 3) * size), writeOffset);
|
|
14
|
+
writeOffset += ((to - from) / 3) * size;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return joined;
|
|
18
|
+
}
|