@adatechnology/game-vehicles-three 0.10.0 → 0.11.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.
- package/README.md +17 -0
- package/dist/{chunk-5T52WAQS.js → chunk-GAPMLLDL.js} +224 -5
- package/dist/chunk-GAPMLLDL.js.map +1 -0
- package/dist/chunk-UHLZ23KF.js +565 -0
- package/dist/chunk-UHLZ23KF.js.map +1 -0
- package/dist/index.d.ts +173 -10
- package/dist/index.global.js +1424 -62
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +482 -3
- package/dist/index.js.map +1 -1
- package/dist/testing.js +2 -1
- package/dist/worker-kinds-Dnbh9_c9.d.ts +51 -0
- package/dist/worker-kinds.d.ts +2 -0
- package/dist/worker-kinds.js +9 -0
- package/dist/worker-kinds.js.map +1 -0
- package/package.json +20 -12
- package/dist/chunk-5T52WAQS.js.map +0 -1
package/README.md
CHANGED
|
@@ -19,6 +19,13 @@ car.triangles // 19286 · car.drawCalls // 6 · car.damageables // metal, glass,
|
|
|
19
19
|
- The colour comes from `color` or from `seed` through the palette of the vehicle's group (`colorFromSeed`).
|
|
20
20
|
- Tested against the team's page on three r160 (triangles, draw calls, size, per-class vertices, damageable boxes) and against `DIMS` for the 69 vehicles.
|
|
21
21
|
|
|
22
|
+
## Collision hulls
|
|
23
|
+
|
|
24
|
+
`createVehicleColliders(THREE, vehicle, frame, { hulls: true, maxHulls })` gives the engine the convex hulls of a vehicle (`hulls()`) next to the boxes of `pieces()`. The division of a car into hulls is the same for every car of a model, so it is made once per model:
|
|
25
|
+
|
|
26
|
+
- `planCache: createHullPlanCache()` shares the hulls of the intact cars of a model (key: the vehicle key, its seed key and its build state, or `planKey`); the second car of a model is given the same hull objects in under 2 ms. A dented car neither gives nor takes. `cache.dispose()` lets everything go.
|
|
27
|
+
- `workers` (a `WorkerCoordinator` of `@adatechnology/game-workers`) sends the division of the first car of a model to the `vehicles.hull-plan` kind (`@adatechnology/game-vehicles-three/worker-kinds`, three-free; list `hullPlanKind` in the worker file's `installWorkerHost` and `warm([hullPlanKind])` at load). Until it is back `hulls()` answers an empty list and `isHullPending()` is true: the car keeps the boxes of `pieces()`. The call after the answer installs the plan, so call `hulls()` in the fixed step. Without `workers` the division is made in the call, with the same bytes.
|
|
28
|
+
|
|
22
29
|
## Test area
|
|
23
30
|
|
|
24
31
|
`createVehiclesTestModule({ locale, document?, three?, vehicles?, effects? })` is a `TestableModule` for the shared test room (`room.loadModule`, or `loadVehiclesTestModule(room)`, which learns the room's three.js to compute the door, hood and trunk clips). It lays the eight vehicles of the Frota test, each with its own `DestructibleImpl`, and brings 13 scenarios: the eleven of the team's test page, literal (`vehicles_9mm_windshield`, `vehicles_shotgun_door`, `vehicles_ram_front`, `vehicles_engine_fire`, `vehicles_fuel_tank`, `vehicles_unbolt_wheel`, `vehicles_tear_bumper`, `vehicles_break_mirror`, `vehicles_kill_battery`, `vehicles_rollover`, `vehicles_melt`; the page ids are in `PAGE_SCENARIO_ALIASES`), plus `vehicles_drive_arcade` and `vehicles_drive_semi` for `@adatechnology/game-vehicles-driving`.
|
|
@@ -28,3 +35,13 @@ The bench sets the quality (full or light mode), the paint by seed and palette,
|
|
|
28
35
|
## Rain under the roof
|
|
29
36
|
|
|
30
37
|
`createVehicleRainCovers()` keeps the host's rain (`ModuleHost.rainCover`) told what each vehicle in the scene roofs over: `track(id, destructible, frame)`, then `sync(host.rainCover, dt)` every frame and `clear()` when the module leaves (the vehicles test area does it). The cover comes from `createVehicleRainCover` of `game-vehicles`: the cabin box and roof of a car, the body of a bus or truck; an open pickup bed, bikes, boats, planes, helicopters and the tractor roof nothing. A torn-off roof, a broken windshield or pane and a through-hole of 30 cm or more are openings; a moving car only turns its rectangle (the damage state is read every 0.4 s) and the version the far curtain caches grows every metre or so.
|
|
38
|
+
|
|
39
|
+
## Crash parts on the physics engine (`createCrashParts`, spec 008 T6.9)
|
|
40
|
+
|
|
41
|
+
`createCrashParts({ THREE, world, vehicle, frame, colliders, mass, onPartLost? })` builds a mutable compound of the car's hulls (`colliders.hulls()`, each child tagged with the id of its part) and keeps it in step with the drawing. `shape()` gives the chassis shape; `bind(chassis)` sets the kit's mass, inertia and centre of mass and listens to the contacts; call `step()` after every physics step.
|
|
42
|
+
|
|
43
|
+
- A part that comes off (`vehicle.disassemble`, or a blow) leaves the compound and becomes a body with its own hulls, mass (`PartDef.mass`), box inertia and the velocity of its point on the chassis; the chassis gives up that mass (`massOf(chassis) + parts = the kit's mass`). Nothing is flung (`flying` stays empty), and the part is not born inside anything (pushed out of fixed geometry, at most 3 times).
|
|
44
|
+
- Level-2 damage: each step the strongest contact row of every hull tag becomes a `crashVehicle` (point, direction, approach speed, both masses, width of the part's box, `source` = part id).
|
|
45
|
+
- At rest (chassis under 0.05 m/s for 30 steps) the hulls of what was dented are made again and the changed ones go to the engine with `setChildShape`. A hull that touches something may only move inward, and outward by 2 mm at most (`holdWithin`), until the contact ends.
|
|
46
|
+
- `stats()` reports `released`, `pushedOut`, `settles`, `remade`, `held`, `unplaced`, `blows`, `events`, `hitParts` and `children`; `dispose()` removes every part body. Wheels and lamps without a hull use the drawn box; the interior is spec 009.
|
|
47
|
+
- The hull cache by model (`createHullPlanCache`) and the worker kind `vehicles.hull-plan` are described above; a dented car leaves the cache.
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hullOf,
|
|
3
|
+
hullPlanKind,
|
|
4
|
+
leavesOf,
|
|
5
|
+
newHullPlan,
|
|
6
|
+
planHulls,
|
|
7
|
+
unitsOf
|
|
8
|
+
} from "./chunk-UHLZ23KF.js";
|
|
9
|
+
|
|
1
10
|
// src/test-area/module.ts
|
|
2
11
|
import { DEFERRED_PRIORITY, DEFERRED_QUEUE_ID as DEFERRED_QUEUE_ID2, footprintBlocker } from "@adatechnology/game-contracts";
|
|
3
12
|
import { discardObject3D } from "@adatechnology/game-shapes-three";
|
|
@@ -467,11 +476,14 @@ var colliderOf = (id, key, soup) => {
|
|
|
467
476
|
// src/colliders.ts
|
|
468
477
|
var SHELL_ROLES = /* @__PURE__ */ new Set(["panel", "fender", "roof", "frame", "glass", "pillar", "door", "lid", "hood", "bumper"]);
|
|
469
478
|
var GONE = /* @__PURE__ */ new Set(["broken", "melted", "ashes"]);
|
|
479
|
+
var SOLID_ROLES = /* @__PURE__ */ new Set(["light", "mirror", "engine", "radiator", "fuel_tank", "oil_pan", "battery", "alternator", "gearbox", "steering", "hitch"]);
|
|
480
|
+
var WHEEL_ROLES = /* @__PURE__ */ new Set(["rim", "tyre", "brakes", "shocks"]);
|
|
470
481
|
var MIN_AREA = 1e-9;
|
|
471
482
|
var CHUNK = 0.8;
|
|
472
483
|
var CELL_BIAS2 = 512;
|
|
473
484
|
var CELL_SPAN2 = 1024;
|
|
474
485
|
var PART_SPAN = 2 ** 30;
|
|
486
|
+
var JOB_NUMBERS_PER_CALL = 2e5;
|
|
475
487
|
var DEFAULT_BUDGET = Infinity;
|
|
476
488
|
var isDrawn = (mesh, stop) => {
|
|
477
489
|
if (!mesh.isMesh || !mesh.geometry || mesh.userData.ghost || mesh.userData.helper) return false;
|
|
@@ -499,6 +511,18 @@ var isNotDrawn = (positions, [a, b, c]) => {
|
|
|
499
511
|
const area = Math.hypot(uy * wz - uz * wy, uz * wx - ux * wz, ux * wy - uy * wx);
|
|
500
512
|
return !(area > MIN_AREA);
|
|
501
513
|
};
|
|
514
|
+
var float64Of = (numbers) => {
|
|
515
|
+
const out = new Float64Array(numbers.length);
|
|
516
|
+
for (let i = 0; i < out.length; i++) out[i] = numbers[i];
|
|
517
|
+
return out;
|
|
518
|
+
};
|
|
519
|
+
var uint32Of = (numbers) => {
|
|
520
|
+
const out = new Uint32Array(numbers.length);
|
|
521
|
+
for (let i = 0; i < out.length; i++) out[i] = numbers[i];
|
|
522
|
+
return out;
|
|
523
|
+
};
|
|
524
|
+
var pieceOfJob = (key, piece) => ({ key, vertices: float64Of(piece.soup.vertices), indices: uint32Of(piece.soup.indices) });
|
|
525
|
+
var signatureOfSolid = (members) => members.map((piece) => `${piece.key}.${piece.version}`).join(",");
|
|
502
526
|
var sameMatrix = (a, b) => {
|
|
503
527
|
for (let i = 0; i < 16; i++) if (a[i] !== b[i]) return false;
|
|
504
528
|
return true;
|
|
@@ -508,6 +532,8 @@ var createVehicleColliders = (THREE, vehicle, frame, options = {}) => {
|
|
|
508
532
|
const pieces = /* @__PURE__ */ new Map();
|
|
509
533
|
const partIndex = new Map(vehicle.model.parts.map((part, index) => [part.id, index]));
|
|
510
534
|
const isShown2 = new Map(vehicle.model.parts.map((part) => [part.id, part.visual]));
|
|
535
|
+
const isSolid = new Map(vehicle.model.parts.map((part) => [part.id, SOLID_ROLES.has(part.role)]));
|
|
536
|
+
const isWheel = new Map(vehicle.model.parts.map((part) => [part.id, WHEEL_ROLES.has(part.role)]));
|
|
511
537
|
const shell = vehicle.model.parts.filter((part) => SHELL_ROLES.has(part.role));
|
|
512
538
|
const toFrame = new THREE.Matrix4();
|
|
513
539
|
const toVehicle = new THREE.Matrix4();
|
|
@@ -515,6 +541,15 @@ var createVehicleColliders = (THREE, vehicle, frame, options = {}) => {
|
|
|
515
541
|
const placed = new THREE.Vector3();
|
|
516
542
|
const matrix = new THREE.Matrix4();
|
|
517
543
|
let pending = false;
|
|
544
|
+
let shown = [];
|
|
545
|
+
let hullSources = /* @__PURE__ */ new Map();
|
|
546
|
+
let plan = newHullPlan();
|
|
547
|
+
let isDivided = false;
|
|
548
|
+
let hullGroups = /* @__PURE__ */ new Map();
|
|
549
|
+
let shared;
|
|
550
|
+
let flight;
|
|
551
|
+
let isDamaged = false;
|
|
552
|
+
let building;
|
|
518
553
|
const release = (entry) => {
|
|
519
554
|
for (const key of entry.chunks.keys()) {
|
|
520
555
|
const piece = pieces.get(key);
|
|
@@ -561,7 +596,7 @@ var createVehicleColliders = (THREE, vehicle, frame, options = {}) => {
|
|
|
561
596
|
let piece = pieces.get(key);
|
|
562
597
|
if (!piece) {
|
|
563
598
|
const part = vehicle.model.parts[Math.floor(key / PART_SPAN)].id;
|
|
564
|
-
pieces.set(key, piece = { key, part, entries: /* @__PURE__ */ new Set(), dirty: true, collider: null });
|
|
599
|
+
pieces.set(key, piece = { key, part, entries: /* @__PURE__ */ new Set(), dirty: true, collider: null, soup: null, version: 0, hulls: [], hullVersion: -1 });
|
|
565
600
|
}
|
|
566
601
|
piece.entries.add(entry);
|
|
567
602
|
piece.dirty = true;
|
|
@@ -575,6 +610,7 @@ var createVehicleColliders = (THREE, vehicle, frame, options = {}) => {
|
|
|
575
610
|
const changed = new Uint8Array(array.length / 3);
|
|
576
611
|
for (let i = 0; i < array.length; i++) {
|
|
577
612
|
if (array[i] === entry.snapshot[i]) continue;
|
|
613
|
+
isDamaged = true;
|
|
578
614
|
changed[Math.floor(i / 3)] = 1;
|
|
579
615
|
entry.snapshot[i] = array[i];
|
|
580
616
|
}
|
|
@@ -624,6 +660,8 @@ var createVehicleColliders = (THREE, vehicle, frame, options = {}) => {
|
|
|
624
660
|
}
|
|
625
661
|
}
|
|
626
662
|
piece.collider = colliderOf(piece.part, `${piece.part}#${piece.key % PART_SPAN}`, soup);
|
|
663
|
+
piece.soup = options.hulls ? soup : null;
|
|
664
|
+
piece.version++;
|
|
627
665
|
piece.dirty = false;
|
|
628
666
|
};
|
|
629
667
|
const make = () => {
|
|
@@ -635,7 +673,9 @@ var createVehicleColliders = (THREE, vehicle, frame, options = {}) => {
|
|
|
635
673
|
const state = new Map(vehicle.state().parts.map((part) => [part.id, part]));
|
|
636
674
|
const isGone = (id) => {
|
|
637
675
|
const part = state.get(id);
|
|
638
|
-
|
|
676
|
+
const isOff = part !== void 0 && (GONE.has(part.status) || part.group !== 0);
|
|
677
|
+
if (isOff) isDamaged = true;
|
|
678
|
+
return isOff;
|
|
639
679
|
};
|
|
640
680
|
const budget = { left: options.budget ?? DEFAULT_BUDGET };
|
|
641
681
|
pending = false;
|
|
@@ -662,6 +702,7 @@ var createVehicleColliders = (THREE, vehicle, frame, options = {}) => {
|
|
|
662
702
|
}
|
|
663
703
|
for (const [mesh, owner] of live) read(mesh, owner, budget);
|
|
664
704
|
const out = [];
|
|
705
|
+
shown = [];
|
|
665
706
|
for (const [key, piece] of pieces) {
|
|
666
707
|
if (piece.entries.size === 0) {
|
|
667
708
|
pieces.delete(key);
|
|
@@ -671,13 +712,190 @@ var createVehicleColliders = (THREE, vehicle, frame, options = {}) => {
|
|
|
671
712
|
if (budget.left <= 0) pending = true;
|
|
672
713
|
else rebuild(piece, budget);
|
|
673
714
|
}
|
|
674
|
-
if (piece.collider && !(isGone(piece.part) && isShown2.get(piece.part)))
|
|
715
|
+
if (piece.collider && !(isGone(piece.part) && isShown2.get(piece.part))) {
|
|
716
|
+
out.push(piece.collider);
|
|
717
|
+
shown.push(piece);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return out;
|
|
721
|
+
};
|
|
722
|
+
const nameOf = (piece) => `${piece.part}#${piece.key % PART_SPAN}`;
|
|
723
|
+
const hullsOfPiece = (piece) => {
|
|
724
|
+
if (piece.hullVersion === piece.version) return piece.hulls;
|
|
725
|
+
const made = [];
|
|
726
|
+
for (const unit of unitsOf(nameOf(piece), piece.soup, plan.taken.get(nameOf(piece)))) {
|
|
727
|
+
for (const leaf of leavesOf(unit.key, unit.soup, plan.cuts.get(unit.key) ?? null)) {
|
|
728
|
+
const points = hullOf(leaf.soup);
|
|
729
|
+
if (points) made.push({ hull: { id: piece.part, key: leaf.key, points: new Float32Array(points) }, drawn: leaf.soup.vertices });
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
piece.hulls = made;
|
|
733
|
+
piece.hullVersion = piece.version;
|
|
734
|
+
return piece.hulls;
|
|
735
|
+
};
|
|
736
|
+
const jobOf = (thin, solids) => ({
|
|
737
|
+
pieces: thin.map((piece) => pieceOfJob(nameOf(piece), piece)),
|
|
738
|
+
solids: [...solids].flatMap(([part, members]) => members.map((piece) => pieceOfJob(part, piece))),
|
|
739
|
+
maxHulls: (options.maxHulls ?? Infinity) - solids.size
|
|
740
|
+
});
|
|
741
|
+
const signatureOf = (thin, solids) => `${options.maxHulls ?? Infinity}|${thin.map((piece) => `${nameOf(piece)}:${piece.soup.vertices.length}`).join(",")}|${[...solids].map(([part, members]) => `${part}:${members.map((piece) => `${piece.key}.${piece.soup.vertices.length}`).join("+")}`).join(",")}`;
|
|
742
|
+
const modelKeyOf = () => {
|
|
743
|
+
if (options.planKey) return options.planKey;
|
|
744
|
+
const context = vehicle.vehicle;
|
|
745
|
+
return context.key === void 0 ? void 0 : `${context.key}|${context.seedKey ?? context.key}|${context.state ?? ""}`;
|
|
746
|
+
};
|
|
747
|
+
const install = (result, thin, solids, signature, modelKey) => {
|
|
748
|
+
const owners = new Map(thin.map((piece) => [nameOf(piece), piece]));
|
|
749
|
+
const made = /* @__PURE__ */ new Map();
|
|
750
|
+
for (const leaf of result.leaves) {
|
|
751
|
+
const name = leaf.unit.split("~")[0];
|
|
752
|
+
const owner = owners.get(name);
|
|
753
|
+
if (!owner) continue;
|
|
754
|
+
const list = made.get(name) ?? [];
|
|
755
|
+
list.push({ hull: { id: owner.part, key: leaf.path ? `${leaf.unit}:${leaf.path}` : leaf.unit, points: leaf.points }, drawn: leaf.vertices });
|
|
756
|
+
made.set(name, list);
|
|
757
|
+
}
|
|
758
|
+
plan = { cuts: new Map(result.cuts), taken: new Map(result.taken.map(([unit, numbers]) => [unit, new Set(numbers)])) };
|
|
759
|
+
for (const piece of thin) {
|
|
760
|
+
piece.hulls = made.get(nameOf(piece)) ?? [];
|
|
761
|
+
piece.hullVersion = piece.version;
|
|
762
|
+
}
|
|
763
|
+
for (const solid of result.solids) {
|
|
764
|
+
const members = solids.get(solid.key);
|
|
765
|
+
if (members) hullGroups.set(solid.key, { signature: signatureOfSolid(members), hulls: solid.points.length > 0 ? [{ id: solid.key, key: solid.key, points: solid.points }] : [] });
|
|
766
|
+
}
|
|
767
|
+
isDivided = true;
|
|
768
|
+
if (modelKey && options.planCache && !isDamaged) {
|
|
769
|
+
shared = { signature, plan, pieces: made, solids: new Map(hullGroups) };
|
|
770
|
+
options.planCache.set(modelKey, shared);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
const adopt = (from, thin) => {
|
|
774
|
+
plan = from.plan;
|
|
775
|
+
for (const piece of thin) {
|
|
776
|
+
piece.hulls = from.pieces.get(nameOf(piece)) ?? [];
|
|
777
|
+
piece.hullVersion = piece.version;
|
|
778
|
+
}
|
|
779
|
+
hullGroups = new Map(from.solids);
|
|
780
|
+
shared = from;
|
|
781
|
+
isDivided = true;
|
|
782
|
+
options.planCache.noteReused();
|
|
783
|
+
};
|
|
784
|
+
const divide = (thin, solids) => {
|
|
785
|
+
const signature = signatureOf(thin, solids);
|
|
786
|
+
const modelKey = modelKeyOf();
|
|
787
|
+
const cache = options.planCache;
|
|
788
|
+
if (!flight) {
|
|
789
|
+
const known2 = !isDamaged && modelKey && cache ? cache.get(modelKey) : void 0;
|
|
790
|
+
if (known2 && known2.signature === signature) {
|
|
791
|
+
adopt(known2, thin);
|
|
792
|
+
building = void 0;
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
if (!options.workers) {
|
|
796
|
+
cache?.noteDivided();
|
|
797
|
+
install(planHulls(jobOf(thin, solids)), thin, solids, signature, modelKey);
|
|
798
|
+
return true;
|
|
799
|
+
}
|
|
800
|
+
const going = !isDamaged && modelKey ? cache?.flight(modelKey) : void 0;
|
|
801
|
+
const isGoing = going !== void 0 && going.signature === signature;
|
|
802
|
+
if (!isGoing && !hasJobBuilt(thin, solids, signature)) return false;
|
|
803
|
+
const promise = isGoing ? going.promise : options.workers.run(hullPlanKind, { pieces: building.pieces, solids: building.solids, maxHulls: (options.maxHulls ?? Infinity) - solids.size });
|
|
804
|
+
if (!isGoing) {
|
|
805
|
+
cache?.noteDivided();
|
|
806
|
+
if (modelKey && !isDamaged) cache?.setFlight(modelKey, { signature, promise });
|
|
807
|
+
}
|
|
808
|
+
building = void 0;
|
|
809
|
+
const mine = { signature, job: () => jobOf(thin, solids), failed: false };
|
|
810
|
+
flight = mine;
|
|
811
|
+
promise.then((result) => {
|
|
812
|
+
mine.result = result;
|
|
813
|
+
}, () => {
|
|
814
|
+
mine.failed = true;
|
|
815
|
+
}).finally(() => {
|
|
816
|
+
if (modelKey && cache?.flight(modelKey)?.promise === promise) cache.clearFlight(modelKey);
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
if (!flight.result && !flight.failed) return false;
|
|
820
|
+
const arrived = flight;
|
|
821
|
+
flight = void 0;
|
|
822
|
+
if (arrived.signature !== signature) return divide(thin, solids);
|
|
823
|
+
const known = !isDamaged && modelKey && cache ? cache.get(modelKey) : void 0;
|
|
824
|
+
if (arrived.failed && known && known.signature === signature) adopt(known, thin);
|
|
825
|
+
else install(arrived.result ?? planHulls(arrived.job()), thin, solids, signature, modelKey);
|
|
826
|
+
return true;
|
|
827
|
+
};
|
|
828
|
+
const hasJobBuilt = (thin, solids, signature) => {
|
|
829
|
+
if (!building || building.signature !== signature) building = { signature, pieces: [], solids: [] };
|
|
830
|
+
const solidPieces = [...solids].flatMap(([part, members]) => members.map((piece) => [part, piece]));
|
|
831
|
+
let room = JOB_NUMBERS_PER_CALL;
|
|
832
|
+
while (building.pieces.length < thin.length && room > 0) {
|
|
833
|
+
const piece = thin[building.pieces.length];
|
|
834
|
+
building.pieces.push(pieceOfJob(nameOf(piece), piece));
|
|
835
|
+
room -= piece.soup.vertices.length + piece.soup.indices.length;
|
|
836
|
+
}
|
|
837
|
+
while (building.pieces.length === thin.length && building.solids.length < solidPieces.length && room > 0) {
|
|
838
|
+
const [part, piece] = solidPieces[building.solids.length];
|
|
839
|
+
building.solids.push(pieceOfJob(part, piece));
|
|
840
|
+
room -= piece.soup.vertices.length + piece.soup.indices.length;
|
|
841
|
+
}
|
|
842
|
+
return building.pieces.length === thin.length && building.solids.length === solidPieces.length;
|
|
843
|
+
};
|
|
844
|
+
const hullOfSolid = (part, members) => {
|
|
845
|
+
const signature = signatureOfSolid(members);
|
|
846
|
+
let made = hullGroups.get(part);
|
|
847
|
+
if (!made || made.signature !== signature) {
|
|
848
|
+
const vertices = [];
|
|
849
|
+
const indices = [];
|
|
850
|
+
for (const piece of members) {
|
|
851
|
+
const offset = vertices.length / 3;
|
|
852
|
+
for (const v of piece.soup.vertices) vertices.push(v);
|
|
853
|
+
for (const i of piece.soup.indices) indices.push(i + offset);
|
|
854
|
+
}
|
|
855
|
+
const points = hullOf({ vertices, indices });
|
|
856
|
+
made = { signature, hulls: points ? [{ id: part, key: part, points: new Float32Array(points) }] : [] };
|
|
857
|
+
hullGroups.set(part, made);
|
|
858
|
+
}
|
|
859
|
+
return made.hulls;
|
|
860
|
+
};
|
|
861
|
+
const hulls = () => {
|
|
862
|
+
if (!options.hulls) throw new Error("createVehicleColliders: hulls() needs options.hulls");
|
|
863
|
+
make();
|
|
864
|
+
hullSources = /* @__PURE__ */ new Map();
|
|
865
|
+
const out = [];
|
|
866
|
+
const solids = /* @__PURE__ */ new Map();
|
|
867
|
+
const thin = [];
|
|
868
|
+
for (const piece of shown) {
|
|
869
|
+
if (!piece.soup || isWheel.get(piece.part)) continue;
|
|
870
|
+
if (!isSolid.get(piece.part)) {
|
|
871
|
+
thin.push(piece);
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
const list = solids.get(piece.part);
|
|
875
|
+
if (list) list.push(piece);
|
|
876
|
+
else solids.set(piece.part, [piece]);
|
|
877
|
+
}
|
|
878
|
+
if (!isDivided && !pending && !divide(thin, solids)) return out;
|
|
879
|
+
for (const piece of thin) {
|
|
880
|
+
for (const { hull, drawn } of hullsOfPiece(piece)) {
|
|
881
|
+
out.push(hull);
|
|
882
|
+
hullSources.set(hull, [drawn]);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
for (const id of hullGroups.keys()) if (!solids.has(id)) hullGroups.delete(id);
|
|
886
|
+
for (const [part, members] of solids) {
|
|
887
|
+
for (const hull of hullOfSolid(part, members)) {
|
|
888
|
+
out.push(hull);
|
|
889
|
+
hullSources.set(hull, members.map((piece) => piece.soup.vertices));
|
|
890
|
+
}
|
|
675
891
|
}
|
|
676
892
|
return out;
|
|
677
893
|
};
|
|
678
|
-
|
|
894
|
+
const drawnPointsOf = (hull) => (hullSources.get(hull) ?? []).flatMap((vertices) => Array.from(vertices));
|
|
895
|
+
return { pieces: make, isPending: () => pending, hulls, isHullPending: () => flight !== void 0 || building !== void 0, drawnPointsOf };
|
|
679
896
|
};
|
|
680
897
|
var vehicleColliders = (THREE, vehicle, frame) => createVehicleColliders(THREE, vehicle, frame).pieces();
|
|
898
|
+
var vehicleHulls = (THREE, vehicle, frame) => createVehicleColliders(THREE, vehicle, frame, { hulls: true }).hulls();
|
|
681
899
|
|
|
682
900
|
// src/vehicle-lod.ts
|
|
683
901
|
import { DEFERRED_QUEUE_ID, markKitOrigin as markKitOrigin2 } from "@adatechnology/game-contracts";
|
|
@@ -4461,6 +4679,7 @@ export {
|
|
|
4461
4679
|
createVehicleSound,
|
|
4462
4680
|
createVehicleColliders,
|
|
4463
4681
|
vehicleColliders,
|
|
4682
|
+
vehicleHulls,
|
|
4464
4683
|
VEHICLE_LOD_DISTANCE,
|
|
4465
4684
|
createVehicleLodQueue,
|
|
4466
4685
|
createVehicleLod,
|
|
@@ -4488,4 +4707,4 @@ export {
|
|
|
4488
4707
|
createProvingModule,
|
|
4489
4708
|
loadProvingModule
|
|
4490
4709
|
};
|
|
4491
|
-
//# sourceMappingURL=chunk-
|
|
4710
|
+
//# sourceMappingURL=chunk-GAPMLLDL.js.map
|