@adatechnology/game-animals-three 0.4.22 → 0.4.23

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.
@@ -51,15 +51,40 @@ var GameAnimalsThree = (() => {
51
51
  var DEFERRED_QUEUE_ID = {
52
52
  DESTRUCTION_EVENTS: "destruction.events",
53
53
  BREACH_PAINT: "floorplan.breach-paint",
54
+ BREACH_CUT: "floorplan.breach-cut",
54
55
  AUDIO_VOICES: "audio.voices",
55
- VEHICLE_CREASE: "vehicles.crease"
56
+ VEHICLE_CREASE: "vehicles.crease",
57
+ AUDIO_OCCLUSION: "audio.occlusion",
58
+ FLUID_FILM: "fluids.film",
59
+ VEHICLE_LOD_BATCH: "vehicles.lod-batch",
60
+ SETTLED_BATCH: "destruction.settled-batch",
61
+ STATIC_BATCH: "render.static-batch",
62
+ ANIMALS_STATIC_BATCH: "animals.static-batch",
63
+ CHARACTERS_STATIC_BATCH: "characters.static-batch",
64
+ HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
65
+ DESTRUCTION_PREFIT: "destruction.prefit"
56
66
  };
57
67
  var DEFERRED_PRIORITY = {
58
68
  [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
59
- [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
69
+ // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
70
+ [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
71
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
60
72
  [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
61
- [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
73
+ [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
74
+ [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
75
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
76
+ [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
77
+ [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
78
+ [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
79
+ [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
80
+ [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
81
+ [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
82
+ [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
62
83
  };
84
+ var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
85
+ function drainDetached(queue, budgetMs, clock = () => performance.now()) {
86
+ return queue.run(clock() + budgetMs, clock);
87
+ }
63
88
  var KIT_ORIGIN_KEY = "kitOrigin";
64
89
  function markKitOrigin(object2, origin) {
65
90
  const node = object2;
@@ -104,8 +129,24 @@ var GameAnimalsThree = (() => {
104
129
  var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing2) => `land_${surface}_${landing2}`));
105
130
  var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
106
131
  var SWING_LEAD_SECONDS = { punch: 0.07, kick: 0.09, shove: 0, blade: 0.05, blunt: 0.1, chop: 0.11 };
132
+ var WORKER_KIND_ID = {
133
+ GROUND_TILES: "destruction.ground-tiles",
134
+ CROWD_PHYSICS: "crowd.physics",
135
+ PIECE_BOXES: "destruction.piece-boxes",
136
+ STATIC_COLLIDERS: "destruction.static-colliders",
137
+ SHAPES_GENERATE: "shapes.generate",
138
+ WORLD_REGION: "world.region"
139
+ };
140
+ var WORKER_KIND_DEFAULTS = {
141
+ [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
142
+ [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
143
+ [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
144
+ [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
145
+ [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
146
+ [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
147
+ };
107
148
 
108
- // ../game-audio/dist/chunk-ZFNHDQRV.js
149
+ // ../game-audio/dist/chunk-ZE4VVIU3.js
109
150
  var DISTANCE_CURVES = {
110
151
  /** The game's `sfx`: `vol / (1 + d² × 0.004)`, cutoff `/ (1 + d × 0.01)`, silent below 0.01 (jogo L62091–62092, L62101). */
111
152
  game_sfx: { model: "inverse_square", k: 4e-3, cutoffK: 0.01, minGain: 0.01 },
@@ -1729,7 +1770,7 @@ var GameAnimalsThree = (() => {
1729
1770
  for (const side of [-1, 1]) addMesh(THREE, k.head, new THREE.ConeGeometry(0.025, 0.13, 8), tools.material(13616808), side * 0.12, k.hd.r * 1.05, k.hd.r * 0.05, 0, 0, side * -0.9);
1730
1771
  };
1731
1772
  var horse = ({ THREE, rig, tools }, k) => {
1732
- for (let index = 0; index < 9; index++) addMesh(THREE, k.neck, new THREE.BoxGeometry(0.035, 0.16, 0.08), k.dark, 0, 0.06 + index * 0.065, -0.12 + index * 4e-3, -0.25, 0, 0);
1773
+ for (let index = 0; index < 9; index++) addMesh(THREE, k.neck, new THREE.BoxGeometry(0.035 + index % 3 * 4e-3, 0.16, 0.08), k.dark, 0, 0.06 + index * 0.065, -0.12 + index * 4e-3, -0.25, 0, 0);
1733
1774
  addMesh(THREE, k.head, new THREE.BoxGeometry(0.03, 0.12, 0.06), k.dark, 0, k.hd.r * 1.05, k.hd.r * 0.3, 0.6, 0, 0);
1734
1775
  const last = rig.tail[rig.tail.length - 1];
1735
1776
  tools.ball(last, 0.08, k.dark, 0, -0.42, 0, 0.7, 4.5, 0.7);
@@ -1820,7 +1861,7 @@ var GameAnimalsThree = (() => {
1820
1861
  }
1821
1862
  };
1822
1863
 
1823
- // ../game-shapes/dist/chunk-FZQTELDQ.js
1864
+ // ../game-shapes/dist/chunk-E3X7UDDV.js
1824
1865
  function canonicalJson(value) {
1825
1866
  if (value === null) return "null";
1826
1867
  if (typeof value === "number") return Object.is(value, -0) ? "-0" : Number.isFinite(value) ? String(value) : JSON.stringify(String(value));
@@ -3210,6 +3251,11 @@ var GameAnimalsThree = (() => {
3210
3251
  custom: { fields: { generator: str, params: () => null }, required: ["generator"] }
3211
3252
  };
3212
3253
 
3254
+ // ../game-shapes/dist/index.js
3255
+ var SAME_COLOUR = 1 / 512;
3256
+ var SAME_FACING = 1 - 1e-6;
3257
+ var PARALLEL = Math.cos(2 * Math.PI / 180);
3258
+
3213
3259
  // ../game-shapes-three/dist/index.js
3214
3260
  var UV_BEFORE_NORMAL = /* @__PURE__ */ new Set(["LatheGeometry", "ExtrudeGeometry"]);
3215
3261
  var INDEX_FIRST = /* @__PURE__ */ new Set(["BoxGeometry", "CylinderGeometry", "ConeGeometry", "SphereGeometry", "PlaneGeometry", "CircleGeometry", "RingGeometry", "LatheGeometry", "TorusGeometry"]);
@@ -4191,6 +4237,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4191
4237
  const radius = 0.012 + 0.03 * Math.sin(Math.min(1, t * 1.15) * Math.PI) * (t < 0.1 ? 0.75 + t * 2.5 : 1) + (t < 0.05 ? 0.012 : 0);
4192
4238
  const material = index % 4 === 1 || index % 4 === 2 ? secondary : primary;
4193
4239
  const group = new THREE.Group();
4240
+ group.position.z = -index * SEGMENT_LENGTH;
4194
4241
  rig.trunk.add(group);
4195
4242
  const sphere2 = tools.ball(group, radius, material, 0, radius, 0, 1, 0.78, 1.5);
4196
4243
  sphere2.userData.joint = index % 3 === 0 ? 1 : 0;
@@ -4267,6 +4314,54 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4267
4314
  var EFFECT_STEP_SECONDS = 1 / 50;
4268
4315
  var BATCHED_LAYER = 30;
4269
4316
  var MATRIX_EPSILON = 1e-6;
4317
+ function createStaticBatchQueue({ id = DEFERRED_QUEUE_ID.STATIC_BATCH } = {}) {
4318
+ const members = [];
4319
+ let cursor = 0;
4320
+ let attached = false;
4321
+ const deferred = {
4322
+ id,
4323
+ pending() {
4324
+ let units = 0;
4325
+ for (const work of members) units += work.pendingUnits();
4326
+ return units;
4327
+ },
4328
+ run(deadline, clock) {
4329
+ let ran = 0;
4330
+ let skipped = 0;
4331
+ while (members.length > 0 && skipped < members.length) {
4332
+ if (ran > 0 && clock() >= deadline) break;
4333
+ const work = members[cursor % members.length];
4334
+ cursor = (cursor + 1) % members.length;
4335
+ if (work.pendingUnits() > 0) {
4336
+ work.runUnit();
4337
+ ran++;
4338
+ skipped = 0;
4339
+ } else skipped++;
4340
+ }
4341
+ return ran;
4342
+ },
4343
+ flush() {
4344
+ for (const work of [...members]) work.finishAll();
4345
+ },
4346
+ attach() {
4347
+ attached = true;
4348
+ },
4349
+ detach() {
4350
+ attached = false;
4351
+ }
4352
+ };
4353
+ return {
4354
+ deferredQueue: () => deferred,
4355
+ isAttached: () => attached,
4356
+ join(work) {
4357
+ members.push(work);
4358
+ return () => {
4359
+ const at = members.indexOf(work);
4360
+ if (at >= 0) members.splice(at, 1);
4361
+ };
4362
+ }
4363
+ };
4364
+ }
4270
4365
  var ATTRIBUTES = ["position", "normal", "uv", "color"];
4271
4366
  var isShown = (object2, root) => {
4272
4367
  for (let node = object2; node; node = node.parent) {
@@ -4281,43 +4376,91 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4281
4376
  const geometry = mesh2.geometry;
4282
4377
  return geometry.attributes.position !== void 0 && Object.keys(geometry.morphAttributes).length === 0;
4283
4378
  };
4284
- var signatureOf = (mesh2, materialKey2) => {
4379
+ var signatureOf = (mesh2, materialKey2, shadowOnly) => {
4380
+ if (shadowOnly) return shadowSideKey(mesh2.material);
4285
4381
  const { attributes } = mesh2.geometry;
4286
4382
  const present = ATTRIBUTES.filter((name) => attributes[name] !== void 0).map((name) => `${name}${attributes[name].itemSize}`);
4287
4383
  return `${materialKey2(mesh2.material)}|${present.join(",")}|${mesh2.castShadow ? 1 : 0}${mesh2.receiveShadow ? 1 : 0}`;
4288
4384
  };
4289
4385
  var uuidOf = (material) => material.uuid;
4290
- var sameMatrix = (a, b) => a.elements.every((value, index) => Math.abs(value - b.elements[index]) < MATRIX_EPSILON);
4386
+ var castsPlainShadow = (mesh2) => {
4387
+ const material = mesh2.material;
4388
+ const custom = mesh2;
4389
+ if (!mesh2.castShadow || !material.visible || custom.customDepthMaterial || custom.customDistanceMaterial) return false;
4390
+ if (material.wireframe === true || (material.clippingPlanes?.length ?? 0) > 0) return false;
4391
+ if (material.displacementMap && material.displacementScale !== 0) return false;
4392
+ return !(material.alphaTest > 0 && (material.map || material.alphaMap));
4393
+ };
4394
+ var shadowSideKey = (material) => `${material.side}|${material.shadowSide ?? ""}`;
4395
+ var sameMatrix = (a, b) => {
4396
+ const left = a.elements;
4397
+ const right = b.elements;
4398
+ for (let at = 0; at < 16; at++) if (Math.abs(left[at] - right[at]) >= MATRIX_EPSILON) return false;
4399
+ return true;
4400
+ };
4291
4401
  function createStaticBatcher(THREE, root, options = {}) {
4292
4402
  const include = options.include ?? (() => true);
4293
- const follow = options.followMeshes === true;
4403
+ const shadowOnly = options.shadowOnly === true;
4404
+ const follow = options.followMeshes === true && !shadowOnly;
4294
4405
  root.updateMatrixWorld(true);
4295
4406
  const inverse = new THREE.Matrix4().copy(root.matrixWorld).invert();
4407
+ const materialKey2 = options.materialKey ?? uuidOf;
4296
4408
  const groups = /* @__PURE__ */ new Map();
4297
4409
  root.traverse((object2) => {
4298
4410
  const mesh2 = object2;
4299
- if (!mesh2.isMesh || !isShown(mesh2, root) || !isBatchable(mesh2) || !include(mesh2)) return;
4300
- const key = signatureOf(mesh2, options.materialKey ?? uuidOf);
4301
- groups.set(key, [...groups.get(key) ?? [], mesh2]);
4411
+ if (!mesh2.isMesh || !isShown(mesh2, root) || !isBatchable(mesh2) || shadowOnly && !castsPlainShadow(mesh2) || !include(mesh2)) return;
4412
+ const key = signatureOf(mesh2, materialKey2, shadowOnly);
4413
+ const waiting = groups.get(key);
4414
+ if (waiting) waiting.push(mesh2);
4415
+ else groups.set(key, [mesh2]);
4302
4416
  });
4303
4417
  const group = new THREE.Group();
4304
4418
  group.name = "static-batches";
4305
4419
  const sources = [];
4306
- const pending = [...groups.values()].filter((meshes) => meshes.length >= 2);
4307
- const mergeSome = (deadline) => {
4308
- while (pending.length > 0) {
4309
- const meshes = pending.shift();
4310
- if (meshes.every((mesh2) => isShown(mesh2, root))) sources.push(...mergeGroup(THREE, { meshes, inverse: new THREE.Matrix4().copy(root.matrixWorld).invert(), group, follow, onBatch: options.onBatch }));
4311
- if (performance.now() >= deadline) return;
4420
+ const maxVertices = options.maxVertices ?? (shadowOnly ? 65535 : Number.POSITIVE_INFINITY);
4421
+ const chunks = (meshes) => {
4422
+ const out = [[]];
4423
+ let vertices = 0;
4424
+ for (const mesh2 of meshes) {
4425
+ const count = mesh2.geometry.attributes.position.count;
4426
+ if (vertices + count > maxVertices && out[out.length - 1].length > 0) {
4427
+ out.push([]);
4428
+ vertices = 0;
4429
+ }
4430
+ ;
4431
+ out[out.length - 1].push(mesh2);
4432
+ vertices += count;
4312
4433
  }
4434
+ return out;
4435
+ };
4436
+ const pending = [...groups.entries()].flatMap(([key, meshes]) => chunks(meshes).map((chunk) => [key, chunk])).filter(([, meshes]) => meshes.length >= 2);
4437
+ const groupedMasks = /* @__PURE__ */ new Map();
4438
+ for (const [, meshes] of pending) for (const mesh2 of meshes) groupedMasks.set(mesh2, mesh2.layers.mask);
4439
+ const isUnchanged = (mesh2, key) => isShown(mesh2, root) && include(mesh2) && isBatchable(mesh2) && (!shadowOnly || castsPlainShadow(mesh2)) && mesh2.layers.mask === groupedMasks.get(mesh2) && signatureOf(mesh2, materialKey2, shadowOnly) === key;
4440
+ const mergeNext = () => {
4441
+ const [key, meshes] = pending.shift();
4442
+ const still = meshes.filter((mesh2) => isUnchanged(mesh2, key));
4443
+ for (const mesh2 of meshes) groupedMasks.delete(mesh2);
4444
+ if (still.length < 2) return;
4445
+ inverse.copy(root.matrixWorld).invert();
4446
+ for (const source of mergeGroup(THREE, { meshes: still, inverse, group, follow, shadowOnly, onBatch: options.onBatch })) sources.push(source);
4313
4447
  };
4314
- if (options.budgetMs === void 0) mergeSome(Number.POSITIVE_INFINITY);
4448
+ const queue = options.queue ?? createStaticBatchQueue();
4449
+ const leaveQueue = queue.join({
4450
+ pendingUnits: () => pending.length,
4451
+ runUnit: mergeNext,
4452
+ finishAll() {
4453
+ while (pending.length > 0) mergeNext();
4454
+ }
4455
+ });
4456
+ if (options.budgetMs === void 0 && options.queue === void 0) while (pending.length > 0) mergeNext();
4315
4457
  root.add(group);
4316
4458
  const scratch = new THREE.Matrix4();
4317
4459
  let released = 0;
4318
4460
  const release = (source) => {
4319
4461
  source.released = true;
4320
- source.mesh.layers.mask = source.mask;
4462
+ if (shadowOnly) source.mesh.castShadow = source.castShadow;
4463
+ else source.mesh.layers.mask = source.mask;
4321
4464
  const { index } = source.batch;
4322
4465
  const first = index.array[source.start];
4323
4466
  for (let at = source.start; at < source.start + source.count; at++) index.array[at] = first;
@@ -4337,7 +4480,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4337
4480
  return {
4338
4481
  group,
4339
4482
  update() {
4340
- if (pending.length > 0) mergeSome(performance.now() + (options.budgetMs ?? Number.POSITIVE_INFINITY));
4483
+ if (pending.length > 0 && !queue.isAttached()) drainDetached(queue.deferredQueue(), options.budgetMs ?? Number.POSITIVE_INFINITY);
4341
4484
  const before = released;
4342
4485
  inverse.copy(root.matrixWorld).invert();
4343
4486
  for (const source of sources) if (!source.released && hasChanged(source)) release(source);
@@ -4345,31 +4488,41 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4345
4488
  },
4346
4489
  stats: () => ({ batches: group.children.length, batched: sources.filter((source) => !source.released).length, released }),
4347
4490
  dispose() {
4348
- for (const source of sources) if (!source.released) source.mesh.layers.mask = source.mask;
4491
+ for (const source of sources) {
4492
+ if (source.released) continue;
4493
+ if (shadowOnly) source.mesh.castShadow = source.castShadow;
4494
+ else source.mesh.layers.mask = source.mask;
4495
+ }
4496
+ leaveQueue();
4497
+ pending.length = 0;
4498
+ groupedMasks.clear();
4349
4499
  group.removeFromParent();
4350
4500
  for (const child of group.children) {
4351
4501
  ;
4352
4502
  child.geometry.dispose();
4503
+ if (shadowOnly) child.material.dispose();
4353
4504
  child.skeleton?.dispose();
4354
4505
  }
4355
4506
  }
4356
4507
  };
4357
4508
  }
4358
- function copyAttribute(name, attribute, target, offset, matrix, normalMatrix2) {
4509
+ var isPlain = (attribute) => !attribute.isInterleavedBufferAttribute && !attribute.normalized;
4510
+ function copyAttribute(name, attribute, target, offset, matrix) {
4359
4511
  const size = attribute.itemSize;
4512
+ const count = attribute.count;
4360
4513
  const source = attribute.array;
4361
- const flat = !attribute.isInterleavedBufferAttribute && source.length === attribute.count * size;
4514
+ const plain = isPlain(attribute);
4362
4515
  if (name !== "position" && name !== "normal") {
4363
- if (flat) target.set(source, offset * size);
4364
- else for (let at = 0; at < attribute.count; at++) for (let k = 0; k < size; k++) target[(offset + at) * size + k] = attribute.getComponent(at, k);
4516
+ if (!attribute.isInterleavedBufferAttribute && source.length === count * size) target.set(source, offset * size);
4517
+ else for (let at = 0; at < count; at++) for (let k = 0; k < size; k++) target[(offset + at) * size + k] = attribute.getComponent(at, k);
4365
4518
  return;
4366
4519
  }
4367
- const e = (name === "position" ? matrix : normalMatrix2).elements;
4520
+ const e = matrix.elements;
4368
4521
  const isNormal = name === "normal";
4369
- for (let at = 0; at < attribute.count; at++) {
4370
- const x = attribute.getX(at);
4371
- const y = attribute.getY(at);
4372
- const z = attribute.getZ(at);
4522
+ for (let at = 0; at < count; at++) {
4523
+ const x = plain ? source[at * size] : attribute.getX(at);
4524
+ const y = plain ? source[at * size + 1] : attribute.getY(at);
4525
+ const z = plain ? source[at * size + 2] : attribute.getZ(at);
4373
4526
  const out = (offset + at) * 3;
4374
4527
  if (isNormal) {
4375
4528
  const nx = e[0] * x + e[3] * y + e[6] * z;
@@ -4405,11 +4558,23 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4405
4558
  mesh2.frustumCulled = false;
4406
4559
  return mesh2;
4407
4560
  }
4408
- function mergeGroup(THREE, { meshes, inverse: rootInverse, group, follow, onBatch }) {
4561
+ function shadowBatch(THREE, merged, like) {
4562
+ const material = new THREE.MeshBasicMaterial({ colorWrite: false, depthWrite: false, side: like.side });
4563
+ material.shadowSide = like.shadowSide;
4564
+ material.name = "shadow-batch";
4565
+ const mesh2 = new THREE.Mesh(merged, material);
4566
+ merged.setDrawRange(0, -1);
4567
+ mesh2.onBeforeShadow = () => merged.setDrawRange(0, Number.POSITIVE_INFINITY);
4568
+ mesh2.onAfterShadow = () => merged.setDrawRange(0, -1);
4569
+ mesh2.castShadow = true;
4570
+ mesh2.receiveShadow = false;
4571
+ return mesh2;
4572
+ }
4573
+ function mergeGroup(THREE, { meshes, inverse: rootInverse, group, follow, shadowOnly, onBatch }) {
4409
4574
  const identity = new THREE.Matrix4();
4410
4575
  const inverse = follow ? identity : rootInverse;
4411
4576
  const first = meshes[0];
4412
- const names = ATTRIBUTES.filter((name) => first.geometry.attributes[name] !== void 0);
4577
+ const names = shadowOnly ? ["position"] : ATTRIBUTES.filter((name) => first.geometry.attributes[name] !== void 0);
4413
4578
  const pieces = meshes.map((mesh22) => {
4414
4579
  const local = new THREE.Matrix4().multiplyMatrices(inverse, mesh22.matrixWorld);
4415
4580
  const vertices = mesh22.geometry.attributes.position.count;
@@ -4419,14 +4584,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4419
4584
  const totalVertices = pieces.reduce((sum, piece) => sum + piece.vertices, 0);
4420
4585
  const totalIndices = pieces.reduce((sum, piece) => sum + piece.indexCount, 0);
4421
4586
  const merged = new THREE.BufferGeometry();
4422
- const normalMatrix2 = new THREE.Matrix3();
4587
+ const normalMatrices = names.includes("normal") ? pieces.map((piece) => new THREE.Matrix3().getNormalMatrix(follow ? identity : piece.local)) : [];
4423
4588
  for (const name of names) {
4424
4589
  const size = first.geometry.attributes[name].itemSize;
4425
4590
  const array = new Float32Array(totalVertices * size);
4426
4591
  let offset = 0;
4427
- for (const piece of pieces) {
4428
- const matrix = follow ? identity : piece.local;
4429
- copyAttribute(name, piece.mesh.geometry.attributes[name], array, offset, matrix, normalMatrix2.getNormalMatrix(matrix));
4592
+ for (const [at, piece] of pieces.entries()) {
4593
+ const matrix = name === "normal" ? normalMatrices[at] : follow ? identity : piece.local;
4594
+ copyAttribute(name, piece.mesh.geometry.attributes[name], array, offset, matrix);
4430
4595
  offset += piece.vertices;
4431
4596
  }
4432
4597
  merged.setAttribute(name, new THREE.BufferAttribute(array, size));
@@ -4434,10 +4599,12 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4434
4599
  const indexArray2 = totalVertices > 65535 ? new Uint32Array(totalIndices) : new Uint16Array(totalIndices);
4435
4600
  const indexAttribute = new THREE.BufferAttribute(indexArray2, 1);
4436
4601
  merged.setIndex(indexAttribute);
4437
- const mesh2 = follow ? skinnedBatch(THREE, merged, first.material, meshes) : new THREE.Mesh(merged, first.material);
4438
- mesh2.name = `batch:${first.material.name || first.material.type}`;
4439
- mesh2.castShadow = first.castShadow;
4440
- mesh2.receiveShadow = first.receiveShadow;
4602
+ const mesh2 = shadowOnly ? shadowBatch(THREE, merged, first.material) : follow ? skinnedBatch(THREE, merged, first.material, meshes) : new THREE.Mesh(merged, first.material);
4603
+ mesh2.name = shadowOnly ? `shadow-batch:${shadowSideKey(first.material)}` : `batch:${first.material.name || first.material.type}`;
4604
+ if (!shadowOnly) {
4605
+ mesh2.castShadow = first.castShadow;
4606
+ mesh2.receiveShadow = first.receiveShadow;
4607
+ }
4441
4608
  mesh2.raycast = () => void 0;
4442
4609
  merged.computeBoundingBox();
4443
4610
  merged.computeBoundingSphere();
@@ -4449,8 +4616,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4449
4616
  let indexOffset = 0;
4450
4617
  for (const piece of pieces) {
4451
4618
  const index = piece.mesh.geometry.index;
4452
- if (index) for (let at = 0; at < piece.indexCount; at++) indexArray2[indexOffset + at] = index.getX(at) + vertexOffset;
4453
- else for (let at = 0; at < piece.indexCount; at++) indexArray2[indexOffset + at] = at + vertexOffset;
4619
+ if (index) {
4620
+ const indices = index.array;
4621
+ for (let at = 0; at < piece.indexCount; at++) indexArray2[indexOffset + at] = indices[at] + vertexOffset;
4622
+ } else for (let at = 0; at < piece.indexCount; at++) indexArray2[indexOffset + at] = at + vertexOffset;
4454
4623
  sources.push({
4455
4624
  mesh: piece.mesh,
4456
4625
  geometry: piece.mesh.geometry,
@@ -4459,12 +4628,14 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4459
4628
  local: piece.local,
4460
4629
  world: piece.mesh.matrixWorld.clone(),
4461
4630
  mask: piece.mesh.layers.mask,
4631
+ castShadow: piece.mesh.castShadow,
4462
4632
  batch,
4463
4633
  start: indexOffset,
4464
4634
  count: piece.indexCount,
4465
4635
  released: false
4466
4636
  });
4467
- piece.mesh.layers.set(BATCHED_LAYER);
4637
+ if (shadowOnly) piece.mesh.castShadow = false;
4638
+ else piece.mesh.layers.set(BATCHED_LAYER);
4468
4639
  vertexOffset += piece.vertices;
4469
4640
  indexOffset += piece.indexCount;
4470
4641
  }
@@ -4596,7 +4767,6 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4596
4767
  var SKIN_COUNT2 = 40;
4597
4768
  var SKIN_FIELD = { x0: -18, z0: -10, columns: 8, gap: 4.5 };
4598
4769
  var DEFAULT_TIME_SCALE = 60;
4599
- var BATCH_BUDGET_MS = 1;
4600
4770
  function createAnimalsTestModule(options = {}) {
4601
4771
  const locale = options.locale ?? "pt-BR";
4602
4772
  const text = TEXT[locale] ?? TEXT["pt-BR"];
@@ -4613,6 +4783,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4613
4783
  let skins = [];
4614
4784
  let rings = [];
4615
4785
  const placed = /* @__PURE__ */ new Map();
4786
+ const batchQueue = createStaticBatchQueue({ id: DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH });
4616
4787
  const random = () => 0.5;
4617
4788
  const drawSeed = options.seed ?? 7;
4618
4789
  const bitten = () => ({ turned: [...placed.values()].filter((p) => p.counted === "turned").length, dead: [...placed.values()].filter((p) => p.counted === "dead").length });
@@ -4627,7 +4798,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4627
4798
  rebuildOutbreak();
4628
4799
  const batch = (entry) => {
4629
4800
  entry.batcher?.dispose();
4630
- if (three) entry.batcher = createStaticBatcher(three, entry.rig.root, { followMeshes: true, budgetMs: BATCH_BUDGET_MS });
4801
+ if (three) entry.batcher = createStaticBatcher(three, entry.rig.root, { followMeshes: true, queue: batchQueue, budgetMs: 1 });
4631
4802
  };
4632
4803
  const look = (entry, state) => {
4633
4804
  animals?.setVisualState(entry.rig, state);
@@ -4856,9 +5027,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
4856
5027
  sound = lent.audio && options.sound !== false ? createAnimalSound(lent.audio, options.sound ?? {}) : null;
4857
5028
  const stopChange = lent.bench?.onChange(onChange);
4858
5029
  const stopFrame = lent.onFrame(frame);
5030
+ const stopBatches = lent.defer?.(batchQueue.deferredQueue(), DEFERRED_PRIORITY[DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]);
4859
5031
  return () => {
4860
5032
  stopChange?.();
4861
5033
  stopFrame();
5034
+ stopBatches?.();
4862
5035
  clearRings();
4863
5036
  clearSkins();
4864
5037
  sound?.dispose();