roamwright 0.59.0 → 0.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,12 +24,12 @@ function hair(b, A, p, coat, q) {
24
24
  tube(
25
25
  b,
26
26
  [
27
- [1.0, zF + 0.02, 0, 0, 0, 0],
28
- [1.0, zF + 0.05, 0.012, 0.02, 0.02, 0],
29
- [A.neck[0] + 0.135 * nt + 0.012, A.neck[1] - 0.075 * nt, 0.016, 0.022, 0.03, 1],
30
- [mid[0] + 0.1 * nt, mid[1] - 0.088 * nt, 0.016, 0.022, 0.03, 2],
31
- [A.poll[0] + 0.045, A.poll[1] - 0.055, 0.014, 0.018, 0.03, 2.8],
32
- [A.poll[0] + 0.045, A.poll[1] - 0.01, 0, 0, 0, 3],
27
+ [0.94, zF + 0.02, 0, 0, 0, 0],
28
+ [0.96, zF + 0.055, 0.009, 0.012, 0.014, 0],
29
+ [A.neck[0] + 0.135 * nt + 0.008, Math.max(zF + 0.095, A.neck[1] - 0.055 * nt), 0.014, 0.018, 0.026, 1],
30
+ [mid[0] + 0.1 * nt, mid[1] - 0.088 * nt, 0.015, 0.02, 0.028, 2],
31
+ [A.poll[0] + 0.042, A.poll[1] - 0.055, 0.013, 0.016, 0.026, 2.8],
32
+ [A.poll[0] + 0.042, A.poll[1] - 0.01, 0, 0, 0, 3],
33
33
  ],
34
34
  {
35
35
  chain: [BONE.chest, BONE.neck, BONE.neck2, BONE.head],
@@ -113,8 +113,8 @@ function mane(b, A, p, lock, side, q) {
113
113
  mid = [(A.neck[0] + A.poll[0]) / 2, (A.neck[1] + A.poll[1]) / 2],
114
114
  // the crest: [y, z, bone along the chest, neck, neck2, head], with the neck's half-width and its half-depth below the crest there
115
115
  crest = [
116
- [1.0, zF + 0.05, 0, 0.11 * p.girth, 0.2],
117
- [A.neck[0] + 0.135 * nt + 0.012, A.neck[1] - 0.075 * nt, 1, 0.1 * nt, 0.17 * nt],
116
+ [0.985, zF + 0.045, 0, 0.105 * p.girth, 0.19],
117
+ [A.neck[0] + 0.135 * nt + 0.012, Math.max(zF + 0.095, A.neck[1] - 0.055 * nt), 1, 0.1 * nt, 0.17 * nt],
118
118
  [mid[0] + 0.1 * nt, mid[1] - 0.088 * nt, 2, 0.074 * nt, 0.13 * nt],
119
119
  [A.poll[0] + 0.045, A.poll[1] - 0.055, 2.8, 0.052 * nt, 0.09 * nt],
120
120
  ],
@@ -0,0 +1,79 @@
1
+ // ════════════════════════════════════════════════════════════════════════
2
+ // A nose leather: the bare, wet pad at the tip of a short-muzzled beast's nose (a cat's, a fox's, a bear's), a rounded
3
+ // triangle broadest at its top and pointed down, swelling out of the muzzle it sits on. Laid over the muzzle's surface from
4
+ // vertex colours and one tag, so it needs no socket, and a worker can build it.
5
+ // ════════════════════════════════════════════════════════════════════════
6
+
7
+ /**
8
+ * Lays a nose leather on a muzzle.
9
+ * @param {import('./builder.js').GB} gb The builder, which keeps tags.
10
+ * @param {object} o In the lengths of the head it is laid on.
11
+ * @param {number[]} o.at The middle of its foot, on the muzzle's surface.
12
+ * @param {number[]} o.face The unit direction the muzzle's front faces.
13
+ * @param {number[]} o.up A unit direction across it: the head's own up.
14
+ * @param {number} o.wide Its half-width at the top.
15
+ * @param {number} o.high Its half-height (to its point below the middle).
16
+ * @param {number} o.depth How far it swells out of the muzzle.
17
+ * @param {number[]} o.colour Linear [r, g, b].
18
+ * @param {number} o.tag The tag of bare, wet skin.
19
+ * @param {number} o.bone The bone every point follows.
20
+ * @param {number} o.segments The points of its rim.
21
+ */
22
+ function noseLeather(gb, { at, face, up, wide, high, depth, colour, tag, bone, segments: n }) {
23
+ const rx = up[1] * face[2] - up[2] * face[1],
24
+ ry = up[2] * face[0] - up[0] * face[2],
25
+ rz = up[0] * face[1] - up[1] * face[0],
26
+ rl = Math.hypot(rx, ry, rz) || 1,
27
+ ux = rx / rl,
28
+ uy = ry / rl,
29
+ uz = rz / rl,
30
+ REACH = 1.22; // the outline's furthest points, as a share of a circle's: the three corners of the triangle
31
+ // the outline at the angle phi: a circle swelled towards three corners, one below and two above, so the leather is a rounded
32
+ // triangle pointed down
33
+ const outline = phi => 1 + 0.22 * Math.cos(3 * (phi + Math.PI / 2)),
34
+ point = (phi, f, lift, out) => {
35
+ const r = outline(phi) * f,
36
+ u = wide * r * Math.cos(phi),
37
+ v = high * r * Math.sin(phi),
38
+ d = depth * (1 - (r / REACH) ** 2) + lift;
39
+ out[0] = at[0] + ux * u + up[0] * v + face[0] * d;
40
+ out[1] = at[1] + uy * u + up[1] * v + face[1] * d;
41
+ out[2] = at[2] + uz * u + up[2] * v + face[2] * d;
42
+ const nx = face[0] / depth + (ux * u) / (wide * wide),
43
+ ny = face[1] / depth + (uy * u) / (wide * wide) + (up[1] * v) / (high * high),
44
+ nz = face[2] / depth + (uz * u) / (wide * wide) + (up[2] * v) / (high * high),
45
+ l = Math.hypot(nx, ny, nz) || 1;
46
+ out[3] = nx / l;
47
+ out[4] = ny / l;
48
+ out[5] = nz / l;
49
+ return out;
50
+ },
51
+ P = [0, 0, 0, 0, 0, 0],
52
+ Q = [0, 0, 0, 0, 0, 0],
53
+ R = [0, 0, 0, 0, 0, 0],
54
+ S = [0, 0, 0, 0, 0, 0],
55
+ put = p => gb.raw(p[0], p[1], p[2], p[3], p[4], p[5], colour[0], colour[1], colour[2], bone, bone, 1),
56
+ // the eye's way round (right, up) has its outward normal along `face`, so a ring wound counter-clockwise faces out
57
+ tri = (a, b, c) => {
58
+ put(a);
59
+ put(b);
60
+ put(c);
61
+ };
62
+ gb.tv = tag;
63
+ for (let j = 0; j < n; j++) {
64
+ const a = (j / n) * Math.PI * 2,
65
+ b = ((j + 1) / n) * Math.PI * 2;
66
+ // the rim's strip, from the ring sunk into the muzzle to the outline...
67
+ point(a, 1.1, -depth * 0.25, P);
68
+ point(b, 1.1, -depth * 0.25, Q);
69
+ point(a, 1, 0, R);
70
+ point(b, 1, 0, S);
71
+ tri(P, R, S);
72
+ tri(P, S, Q);
73
+ // ...and the dome, a fan from its centre
74
+ point(0, 0, 0, P);
75
+ tri(P, R, S);
76
+ }
77
+ }
78
+
79
+ export { noseLeather };
@@ -50,11 +50,13 @@ function lock(gb, p, d, n, len, wide, root, end, b1, b2, w, tip = -1) {
50
50
  }
51
51
  }
52
52
 
53
- // A skin lofted through stations along a path. A station is [y, z, half-width, rise, fall, bone, squareness, lean]: the section
54
- // stands across the path, `rise` on the side that is up when the path runs forward (the front, when it runs down a leg) and
53
+ // A skin lofted through stations along a path. A station is [y, z, half-width, rise, fall, bone, squareness, lean, level]: the
54
+ // section stands across the path, `rise` on the side that is up when the path runs forward (the front, when it runs down a leg) and
55
55
  // `fall` on the other; `bone` is a place along o.chain (1.5: halfway between its second and third bones); squareness 2 is an
56
- // ellipse, more is boxier; lean moves the station outwards (inwards when negative) from the path's own side. The stations are
57
- // joined by a spline, o.sub rings to a span, o.around points to a ring.
56
+ // ellipse, more is boxier; lean moves the station outwards (inwards when negative) from the path's own side. A thigh is better
57
+ // described by its edges at each height than by sections across its bone, so a station may lie `level` (0 to 1): level, the
58
+ // section lies across the body's upright plane at the station's height, `rise` towards the nose and `fall` towards the tail
59
+ // (geometry/animal-haunch.js). The stations are joined by a spline, o.sub rings to a span, o.around points to a ring.
58
60
  // o.x, o.side the path's place to the side, and -1 to mirror the section for a left limb
59
61
  // o.coat(col, x, y, z, nx, ny, nz, a, v) fills col with the colour and the tag (how smooth) at a point
60
62
  // o.warp(p, q, a, v) moves the point p[q..q+2] before the normals are found (a socket, a muscle, a toe)
@@ -78,7 +80,8 @@ function tube(gb, S, o) {
78
80
  N = _n,
79
81
  R = _c,
80
82
  X = _x;
81
- const at = (k, i, t) => spline(S[Math.max(0, i - 1)][k], S[i][k], S[Math.min(n - 1, i + 1)][k], S[Math.min(n - 1, i + 2)][k], t);
83
+ const at = (k, i, t) =>
84
+ spline(S[Math.max(0, i - 1)][k] ?? 0, S[i][k] ?? 0, S[Math.min(n - 1, i + 1)][k] ?? 0, S[Math.min(n - 1, i + 2)][k] ?? 0, t);
82
85
  for (let r = 0; r < rings; r++) {
83
86
  const i = Math.min(n - 2, (r / sub) | 0),
84
87
  t = r / sub - i,
@@ -87,6 +90,7 @@ function tube(gb, S, o) {
87
90
  w = Math.max(0, at(2, i, t)),
88
91
  u = Math.max(0, at(3, i, t)),
89
92
  d = Math.max(0, at(4, i, t)),
93
+ level = Math.min(1, Math.max(0, at(8, i, t))), // how far this ring lies level instead of across the path
90
94
  e = 2 / ((S[i][6] ?? 2) + ((S[i + 1][6] ?? 2) - (S[i][6] ?? 2)) * t),
91
95
  xc = x0 + side * ((S[i][7] ?? 0) + ((S[i + 1][7] ?? 0) - (S[i][7] ?? 0)) * t);
92
96
  let ty = at(0, i, t + 0.02) - at(0, i, t - 0.02),
@@ -108,8 +112,8 @@ function tube(gb, S, o) {
108
112
  sy = Math.sign(s) * Math.abs(s) ** e * (s > 0 ? u : d),
109
113
  q = (r * seg + j) * 3;
110
114
  P[q] = xc + side * cx * w;
111
- P[q + 1] = y + tz * sy;
112
- P[q + 2] = z - ty * sy;
115
+ P[q + 1] = y + tz * sy * (1 - level);
116
+ P[q + 2] = z + sy * (level - ty * (1 - level));
113
117
  if (o.warp) o.warp(P, q, a, r / (rings - 1));
114
118
  }
115
119
  }
package/index.js CHANGED
@@ -8,6 +8,15 @@
8
8
 
9
9
  // ── Context, math & core geometry ────────────────────────────────────────
10
10
  export { RENDER_LAYERS, createRenderContext } from './rendering/context.js';
11
+ export {
12
+ UNSIGNED_HDR_SENTINEL,
13
+ createMatchedRenderTarget,
14
+ createMatchingRenderTarget,
15
+ describeRenderTargetFormat,
16
+ isUnsignedFloatInternalFormat,
17
+ } from './rendering/target-format.js';
18
+ export { createPipelineWarmup } from './rendering/warm-pipelines.js';
19
+ export { createNextTask } from './runtime/next-task.js';
11
20
  export { createDaylightSky, createSkyPanorama, createSkyTexture } from './rendering/daylight-sky.js';
12
21
  export { bindKeyboardOrbit, createOrbitCamera } from './rendering/orbit-camera.js';
13
22
  export { createDayCycle, luminanceOf } from './rendering/day-cycle.js';
@@ -131,8 +140,10 @@ export { rigHorse } from './rendering/animal-horse-figure.js';
131
140
  export { buildCattle } from './rendering/animal-cattle-figure.js';
132
141
  export { buildCamel } from './rendering/animal-camel-figure.js';
133
142
  export { buildCanine } from './rendering/animal-canine-figure.js';
143
+ export { catBodies, catRig } from './geometry/animal-cat-body.js';
134
144
  export { horsePose } from './motion/animal-bearing.js';
135
145
  export { caninePose } from './motion/animal-canine-bearing.js';
146
+ export { catPose } from './motion/animal-cat-bearing.js';
136
147
  export { herdArrays } from './motion/animal-herd-cast.js';
137
148
  export { createFlierShapes, createSwarm, FLY_WINGS } from './rendering/flier-swarm.js';
138
149
  export { FLY_LOOK, flyShape } from './geometry/flier-shapes.js';
@@ -94,10 +94,10 @@ function horsePose(H, dt, t, speed, a = null, ground = null) {
94
94
  leg.w = 0;
95
95
  if (k === lazy && S[REST] > 0.01) {
96
96
  leg.w = S[REST];
97
- leg.y = 0.012 * Q.leg;
98
- leg.z = L.fz + 0.06 * Q.leg;
99
- leg.a3 = 0.32;
100
- leg.a4 = 0.75;
97
+ leg.y = 0.008 * Q.leg;
98
+ leg.z = L.fz + 0.015 * Q.leg;
99
+ leg.a3 = 0.06;
100
+ leg.a4 = 0.45;
101
101
  }
102
102
  if (S[DOWN] > 0.01) {
103
103
  leg.w = S[DOWN];
@@ -1,4 +1,5 @@
1
1
  import { clamp, sstep, TAU } from '../math/scalar.js';
2
+ import { catPose } from './animal-cat-bearing.js';
2
3
  import { BONE, LEGS, stepRig } from './quadruped.js';
3
4
 
4
5
  // ════════════════════════════════════════════════════════════════════════
@@ -59,6 +60,7 @@ function gazeYaw(a, F) {
59
60
  * @returns {number} How far its group should rise: nothing, since the body rises on its own legs.
60
61
  */
61
62
  function caninePose(a, dt, t, blow, ground = null, watch = a.lookAt) {
63
+ if (a.rig?.isCat) return catPose(a, dt, t, blow, ground, watch);
62
64
  const Q = a.rig,
63
65
  B = Q.bones,
64
66
  joints = Q.joints,
@@ -121,8 +123,8 @@ function caninePose(a, dt, t, blow, ground = null, watch = a.lookAt) {
121
123
  len = L.len[0] + L.len[1] + L.len[2],
122
124
  odd = k % 2 ? 1 : -1;
123
125
  leg.w = 0;
124
- // sitting and lying, the hocks are on the ground with the paws ahead of them; lying, so are the forearms
125
- if (hind) hold(leg, Math.max(sit, lie), 0, pz + 0.3 * h + odd * 0.02 * h, -1.25, 0);
126
+ // sitting, the hocks rest on the ground just behind the hips with the paws tucked ahead of them; lying, paws stretch further forward
127
+ if (hind) hold(leg, Math.max(sit, lie), 0, pz + (0.3 - 0.18 * sit) * h + odd * 0.02 * h, -1.2, 0);
126
128
  else hold(leg, lie, 0, pz + 0.52 * h + odd * 0.03 * h, -1.3, 0);
127
129
  // a spring: the forelegs thrown forward, the hind legs trailing
128
130
  if (hind) hold(leg, reach, py - 0.5 * len, pz - 0.82 * len, 0.5, 0.9);
@@ -0,0 +1,157 @@
1
+ import { clamp, sstep, TAU } from '../math/scalar.js';
2
+ import { BONE, LEGS, stepRig } from './quadruped.js';
3
+
4
+ // ════════════════════════════════════════════════════════════════════════
5
+ // A house cat's bearing on top of its light feline gait (motion/quadruped.js): a head carried level and turned to what it
6
+ // watches, independent flicking ears, a sleek prowl crouch, a neat sit with the tail round the feet and a curled rest, and a
7
+ // tail as long as the body that is raised with a gentle hook when the cat stands, low in a curve when it walks and twitching
8
+ // at its tip on the prowl. Zero per-frame allocations.
9
+ // ════════════════════════════════════════════════════════════════════════
10
+ const CROUCH = 0,
11
+ SIT = 1,
12
+ LIE = 2,
13
+ LIMP = 3,
14
+ NECK_X = 4,
15
+ NECK_Y = 5,
16
+ EARS = 6,
17
+ CHANNELS = 7,
18
+ SIT_BACK = 0.68,
19
+ _want = new Float32Array(CHANNELS),
20
+ _manner = { dy: 0, dz: 0, pitch: 0, hips: 0, chest: 0, legs: [0, 1, 2, 3].map(() => ({ y: 0, z: 0, a3: 0, a4: 0, w: 0 })) },
21
+ _frame = { x: 0, y: 0, z: 0, yaw: 0, s: 1, ground: null };
22
+
23
+ function hold(leg, w, y, z, a3, a4) {
24
+ if (w <= 0) return;
25
+ const k = w / (leg.w + w);
26
+ leg.y += (y - leg.y) * k;
27
+ leg.z += (z - leg.z) * k;
28
+ leg.a3 += (a3 - leg.a3) * k;
29
+ leg.a4 += (a4 - leg.a4) * k;
30
+ leg.w = Math.min(1, leg.w + w);
31
+ }
32
+
33
+ function gazeYaw(a, F) {
34
+ if (!F) return null;
35
+ const dx = F.x - a.x,
36
+ dz = F.z - a.z;
37
+ if (dx * dx + dz * dz < 1.5) return null;
38
+ let dy = Math.atan2(dx, dz) - a.yaw;
39
+ dy -= Math.round(dy / TAU) * TAU;
40
+ return Math.abs(dy) < 1.9 ? clamp(dy, -1, 1) : null;
41
+ }
42
+
43
+ /**
44
+ * Poses a house cat for this frame on top of its light feline gait: upright swaying tail, alert head, crouched prowl, neat sit
45
+ * and curled rest.
46
+ * @param {object} a The cat actor (`rig` from `catRig`, `group`, `x`, `y`, `z`, `yaw`, `seed`, `pose`, `fixY`, `lookAt`).
47
+ * @param {number} dt Seconds since the last frame.
48
+ * @param {number} t Seconds of the clock.
49
+ * @param {{ w: number, cr: number } | null} [blow=null] Optional crouch/spring cue.
50
+ * @param {((x: number, z: number) => number) | null} [ground=null] Ground height sampler, or null for flat floor.
51
+ * @param {{ x: number, z: number } | null} [watch=a.lookAt] Optional target the cat watches.
52
+ * @returns {number} Always 0 (the cat rises on its own legs).
53
+ */
54
+ function catPose(a, dt, t, blow = null, ground = null, watch = a.lookAt) {
55
+ const Q = a.rig,
56
+ B = Q.bones,
57
+ joints = Q.joints,
58
+ h = Q.leg,
59
+ S = a.hs && a.hs.length >= CHANNELS ? a.hs : (a.hs = new Float32Array(CHANNELS)),
60
+ W = _want,
61
+ M = _manner,
62
+ pose = a.pose,
63
+ dead = pose === 'dead',
64
+ prowl = pose === 'prowl' || pose === 'guard' || pose === 'strike',
65
+ fx = blow ? blow.w : 0,
66
+ run = sstep(0.95, 1.8, Q.u || 0),
67
+ brisk = sstep(0.05, 0.55, Q.u || 0);
68
+ W[CROUCH] = Math.max(prowl ? 0.42 : pose === 'cower' ? 0.55 : 0, blow ? (blow.cr || 0) * fx : 0);
69
+ W[SIT] = pose === 'sit' ? 1 : 0;
70
+ W[LIE] = pose === 'kneel' ? 1 : 0;
71
+ W[LIMP] = dead ? 1 : 0;
72
+ const look = dead || brisk > 0.5 ? null : gazeYaw(a, watch),
73
+ idle = Math.sin(t * 0.31 + a.seed * 27) * 0.28 * (1 - brisk);
74
+ W[NECK_Y] = look === null ? idle : idle * 0.25 + look * 0.75;
75
+ W[NECK_X] = dead ? 0.45 : 0.16 * run + 0.3 * W[CROUCH] + (pose === 'cower' ? 0.25 : 0);
76
+ W[EARS] = dead ? 0.35 : pose === 'cower' ? 0.85 : prowl ? 0.35 : 0;
77
+ const quick = Math.min(1, dt * (blow ? 16 : 5));
78
+ for (let i = 0; i < CHANNELS; i++) S[i] += (W[i] - S[i]) * quick;
79
+
80
+ const sit = S[SIT],
81
+ lie = S[LIE],
82
+ limp = S[LIMP],
83
+ tip = -SIT_BACK * sit,
84
+ sy = joints[LEGS[0]][1] - joints[0][1],
85
+ sz = joints[LEGS[0]][2] - joints[0][2],
86
+ floor = joints[LEGS[0] + 1][1] - 0.08 * h;
87
+ M.pitch = tip + 0.08 * S[CROUCH] * (1 - limp);
88
+ M.dy = -0.24 * h * S[CROUCH] - floor * lie - (sy * Math.cos(tip) - sz * Math.sin(tip) - sy) - (a.cur ? a.cur[6] : 0);
89
+ M.dz = -(sy * Math.sin(tip) + sz * Math.cos(tip) - sz);
90
+ M.chest = 0.06 * sit - 0.06 * S[CROUCH];
91
+ M.hips = -0.05 * sit;
92
+ const rootY = joints[0][1] + M.dy,
93
+ rootZ = joints[0][2] + M.dz;
94
+ for (let k = 0; k < 4; k++) {
95
+ const leg = M.legs[k],
96
+ hind = k > 1,
97
+ L = Q.legs[k],
98
+ oy = joints[L.bone][1] - joints[0][1],
99
+ oz = joints[L.bone][2] - joints[0][2],
100
+ py = rootY + oy * Math.cos(M.pitch) - oz * Math.sin(M.pitch),
101
+ pz = rootZ + oy * Math.sin(M.pitch) + oz * Math.cos(M.pitch),
102
+ len = L.len[0] + L.len[1] + L.len[2],
103
+ odd = k % 2 ? 1 : -1;
104
+ leg.w = 0;
105
+ if (hind) hold(leg, Math.max(sit, lie), 0, pz + 0.28 * h + odd * 0.02 * h, -1.2, 0);
106
+ else hold(leg, lie, 0, pz + 0.42 * h + odd * 0.025 * h, -1.25, 0);
107
+ if (hind) hold(leg, limp, py - 0.8 * len, pz - (0.22 + odd * 0.1) * len, 0.25, 0.5);
108
+ else hold(leg, limp, py - 0.78 * len, pz + (0.26 + odd * 0.12) * len, 0.2, 0.55);
109
+ }
110
+ const F = _frame,
111
+ free = a.fixY === null || a.fixY === undefined;
112
+ F.x = a.x;
113
+ F.y = a.y;
114
+ F.z = a.z;
115
+ F.yaw = a.yaw;
116
+ F.s = a.group.scale.y;
117
+ F.ground = free && !dead ? ground : null;
118
+ stepRig(Q, F, dt, M);
119
+
120
+ // Poised feline head: smooth, steady carry with minimal walk bob and a closed mouth at rest.
121
+ const level = -(Q.pitch + B[BONE.chest].rotation.x) * 0.85,
122
+ nx = S[NECK_X],
123
+ ny = S[NECK_Y],
124
+ nod = 0.018 * brisk * (1 - run) * Math.sin(Q.ph * TAU * 2);
125
+ B[BONE.neck].rotation.set(level * 0.55 + nx * 0.55 + nod, ny * 0.35, 0);
126
+ B[BONE.neck2].rotation.set(level * 0.45 + nx * 0.45, ny * 0.35, 0);
127
+ B[BONE.head].rotation.set(-nx * 0.5 - nod * 0.5 + 0.2 * limp, ny * 0.42, ny * 0.08 + (Q.breed?.tilt || 0));
128
+ B[BONE.jaw].rotation.x = 0;
129
+
130
+ // Alert upright ears with occasional subtle flicks.
131
+ const twitch = sstep(0.95, 1, Math.sin(t * 0.85 + a.seed * 37)) * Math.sin(t * 26) * 0.16;
132
+ B[BONE.earL].rotation.set(-0.55 * S[EARS] + twitch, 0, 0.2 * S[EARS]);
133
+ B[BONE.earR].rotation.set(-0.55 * S[EARS], 0, -0.2 * S[EARS]);
134
+
135
+ // The tail, as long as the body, at rest streaming back with a slight droop. Standing still it is raised with a gentle hook at
136
+ // the tip and a slow sway; walking, it is low in a curve with the tip lifted; prowling, low with its tip twitching; at a run it
137
+ // streams behind; sitting, it comes down and curls round the feet; lying, it curls beside the body.
138
+ const beat = t * (1.2 + 1.6 * brisk) + a.seed * 19,
139
+ rest = Math.max(sit, lie),
140
+ limpTail = limp,
141
+ crouch = S[CROUCH],
142
+ lift = Math.max(0, (1 - brisk * 0.75) * (1 - run) * (1 - rest) * (1 - limpTail) * (1 - crouch * 2)),
143
+ curlSide = rest * 0.72,
144
+ sway = (0.1 + 0.08 * brisk) * (1 - limpTail) * (1 - rest * 0.6) * Math.sin(beat),
145
+ tipTwitch = 0.25 * crouch * Math.max(0, Math.sin(beat * 3.1));
146
+ const walk = brisk * (1 - run) * (1 - rest); // walking: the tail hangs back and down, its tip lifted a little
147
+ B[BONE.tail].rotation.set(0.75 * lift - 0.35 * crouch - 0.25 * walk - 1.0 * rest + 0.05 * run, curlSide + sway * 0.5, 0);
148
+ B[BONE.tail + 1].rotation.set(0.6 * lift - 0.1 * crouch - 0.15 * walk - 0.3 * rest - 0.1 * run, curlSide * 0.8 + sway, 0);
149
+ B[BONE.tail + 2].rotation.set(
150
+ -0.7 * lift + 0.35 * (1 - lift) * (1 - rest) + 0.25 * walk + 0.5 * crouch + 0.3 * run + tipTwitch,
151
+ curlSide * 0.6 + sway * 1.3,
152
+ 0,
153
+ );
154
+ return 0;
155
+ }
156
+
157
+ export { catPose };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roamwright",
3
- "version": "0.59.0",
3
+ "version": "0.61.0",
4
4
  "description": "A procedural worldbuilding engine built on top of Three.js. Generate landscapes with rivers and changing weather, animate crowds, and explore on foot or in flight.",
5
5
  "keywords": [
6
6
  "threejs",
@@ -14,6 +14,8 @@ import * as THREE from 'three';
14
14
  * - `unmirrored` (`1`): objects visible to the main camera but excluded from planar reflections unless enabled.
15
15
  * - `stillCasters` (`2`): static shadow casters cached by `createStaticPointShadow` and `still-casters.js`.
16
16
  * - `heightProbe` (`3`): temporary layer used during offscreen `createHeightProbe` depth measurements.
17
+ * - `warmDraw` (`29`): lent, for the length of one draw, to an object and the scene's lights by the pipeline warm-up
18
+ * (`warm-pipelines.js`), so the view draws that object alone with the programs of the whole scene's light.
17
19
  * - `reflectionMask` (`30`): water-visibility stencil mask drawn only by the planar reflection camera.
18
20
  */
19
21
  export const RENDER_LAYERS = Object.freeze({
@@ -21,6 +23,7 @@ export const RENDER_LAYERS = Object.freeze({
21
23
  unmirrored: 1,
22
24
  stillCasters: 2,
23
25
  heightProbe: 3,
26
+ warmDraw: 29,
24
27
  reflectionMask: 30,
25
28
  });
26
29
 
@@ -59,6 +62,12 @@ export function createRenderContext(
59
62
  renderer.shadowMap.enabled = true;
60
63
  renderer.shadowMap.type = THREE.PCFShadowMap;
61
64
  renderer.info.autoReset = false;
65
+ // Prime Three's lazy synchronous WebGL queries while the GPU process is idle, so the first textured or batched draw
66
+ // does not stall on a round trip behind queued shader links. Use `has` so unsupported extensions are cached silently.
67
+ renderer.capabilities.getMaxAnisotropy();
68
+ renderer.extensions.has('WEBGL_multi_draw');
69
+ renderer.extensions.has('KHR_parallel_shader_compile');
70
+ renderer.extensions.has('EXT_texture_norm16');
62
71
  const scene = new THREE.Scene();
63
72
  const camera = new THREE.PerspectiveCamera(fov, 1, near, far);
64
73
  camera.rotation.order = rotationOrder;
@@ -13,7 +13,9 @@ import { RENDER_LAYERS } from './context.js';
13
13
  * `hysteresis` (score ratio needed to switch reflection owner), `fadeDistance` (`[near, far]` metres),
14
14
  * `altitudeFade` (`[near, far]` metres above water), `maxCellDistance` (metres), `levelSpan` (metres of vertical water-level tolerance),
15
15
  * `lowInlandDistance` (`[near, far]` metres inland), `lowInlandClearance` (`[high, low]` metres above ground),
16
- * `maskLayer` / `extraLayer` (Three.js layer indices), and `smear` (vertical NDC reflection padding).
16
+ * `maskLayer` / `extraLayer` (Three.js layer indices), `smear` (vertical NDC reflection padding),
17
+ * and `matchTarget` (optional reference render target, format descriptor, or getter whose colour
18
+ * and depth attachment format the reflection target mirrors to avoid duplicate GPU pipeline builds).
17
19
  */
18
20
  export const DEFAULT_PLANAR_REFLECTION_OPTIONS = Object.freeze({
19
21
  fxScene: null,
@@ -35,6 +37,7 @@ export const DEFAULT_PLANAR_REFLECTION_OPTIONS = Object.freeze({
35
37
  hideMaterials: null,
36
38
  bendAt: null,
37
39
  smear: 0.16,
40
+ matchTarget: null,
38
41
  });
39
42
 
40
43
  /**
@@ -13,6 +13,7 @@ import {
13
13
  resolveWaterBody,
14
14
  smoothStep,
15
15
  } from './planar-reflection-options.js';
16
+ import { createMatchedRenderTarget } from './target-format.js';
16
17
 
17
18
  const WAVE_X = 0.1; // horizontal NDC padding around visible water cells for wave-bent lookups
18
19
  const WAVE_Y = 0.16; // vertical NDC padding around visible water cells for wave-bent lookups
@@ -21,7 +22,6 @@ const SAMPLE_NDC_LIMIT = 1.08; // frustum margin when testing water coverage sam
21
22
  const MIN_CAMERA_CLEARANCE = 0.25; // minimum camera height above a water plane in metres
22
23
  const LOS_CLEARANCE = 0.35; // terrain clearance margin in metres along camera-to-water sightlines
23
24
  const LOS_FRACTIONS = [0.18, 0.34, 0.5, 0.66, 0.82];
24
- const NOTHING = new THREE.Color(-1, -1, -1); // sentinel outside the scissored water region
25
25
  const MASK_CELLS_MOST = 4096; // visible water cells the mask can hold; with more in view the whole part is drawn as before
26
26
  const MASK_FIRST = -1e9; // the mask's place in the drawing order: before everything else
27
27
  const TILES_X = 64, // the mask as a coarse grid over the part, for asking whether a rectangle touches it
@@ -81,6 +81,7 @@ export function createPlanarReflection(options) {
81
81
  };
82
82
 
83
83
  const bodies = [];
84
+ const matchedRT = createMatchedRenderTarget(opts.matchTarget);
84
85
  const savedColor = new THREE.Color();
85
86
  const corner = [new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()];
86
87
  const forward = new THREE.Vector3();
@@ -669,14 +670,13 @@ export function createPlanarReflection(options) {
669
670
  if (uniforms.uRefl) uniforms.uRefl.value = null;
670
671
  return;
671
672
  }
672
- if (unseen && M.rt && frame % hiddenInterval) {
673
+ if (matchedRT.sync()) {
674
+ M.rt = matchedRT.target;
675
+ sizeMirror();
676
+ } else if (unseen && frame % hiddenInterval) {
673
677
  uniforms.uRefl.value = M.rt.texture;
674
678
  return;
675
679
  }
676
- if (!M.rt) {
677
- M.rt = new THREE.WebGLRenderTarget(4, 4, { type: THREE.HalfFloatType, depthBuffer: true });
678
- sizeMirror();
679
- }
680
680
 
681
681
  const reflectionCamera = M.cam,
682
682
  o = M.o.set(0, waterLevel, 0);
@@ -739,7 +739,7 @@ export function createPlanarReflection(options) {
739
739
  M.rt.scissorTest = false;
740
740
  M.rt.viewport.set(0, 0, M.rt.width, M.rt.height);
741
741
  renderer.setRenderTarget(M.rt);
742
- renderer.setClearColor(NOTHING, 1);
742
+ renderer.setClearColor(matchedRT.sentinelColor, 1);
743
743
  renderer.clear();
744
744
  renderer.setClearColor(savedColor, clearAlpha);
745
745
  if (!whole && fitToPart(reflectionCamera.projectionMatrix, M.rt)) {
@@ -860,7 +860,7 @@ export function createPlanarReflection(options) {
860
860
  scene.remove(mask.mesh);
861
861
  mask.mesh.geometry.dispose();
862
862
  mask.mesh.material.dispose();
863
- mirror.rt?.dispose();
863
+ matchedRT.dispose();
864
864
  mirror.rt = mirror.cells = null;
865
865
  mirror.on = false;
866
866
  }