@adatechnology/game-destruction-three 1.2.0 → 1.3.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/dist/index.d.ts +50 -1
- package/dist/index.global.js +136 -17
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +124 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -331,6 +331,48 @@ interface JitWarmUpReport {
|
|
|
331
331
|
*/
|
|
332
332
|
declare const warmUpDestructionJit: (THREE: ThreeNamespace, makeRenderer: (options: RendererOptions) => DestructionRenderer, options?: JitWarmUpOptions) => JitWarmUpReport | undefined;
|
|
333
333
|
|
|
334
|
+
/**
|
|
335
|
+
* The rules of the kit that move a piece by themselves (not a shot, a blast or a contact of the engine): each write they make in a piece's velocity goes through
|
|
336
|
+
* `KitEnergyLedger.begin`/`end` with its name, so what each one gave is measured and counted (spec 021).
|
|
337
|
+
*/
|
|
338
|
+
declare const KIT_RULE: {
|
|
339
|
+
/** A piece that lost a leg and is balanced on the line between the ones left is started down over it (`renderer.ts`). */
|
|
340
|
+
readonly GO_OVER_IF_BALANCED: "goOverIfBalanced";
|
|
341
|
+
/** What stood on ground that went (a hole under a foot) is started down over the gap (`renderer.ts`). */
|
|
342
|
+
readonly CHECK_UNDERMINED: "checkUndermined";
|
|
343
|
+
/** Furniture made a piece balanced on an edge of its feet is started over it (`EDGE_NUDGE`, `renderer.ts`). */
|
|
344
|
+
readonly LOOSEN_IF_FOOTLESS: "loosenIfFootless";
|
|
345
|
+
/** A piece of the engine balanced on a narrow support is turned about its edge (`engine-pieces.ts`). */
|
|
346
|
+
readonly TOPPLE: "topple";
|
|
347
|
+
};
|
|
348
|
+
type KitRule = (typeof KIT_RULE)[keyof typeof KIT_RULE];
|
|
349
|
+
/**
|
|
350
|
+
* The resolution of the ruler, as energy height (m): below it a piece is at rest when a rule pushes it (what the rules give from there on is one episode), and a give within it of
|
|
351
|
+
* the fall is no energy made. The 1 mm of spec 008's ruler (`C1_ALLOWANCE`): the push that keeps a lying top balanced gives some thousandths of it.
|
|
352
|
+
*/
|
|
353
|
+
declare const KIT_ENERGY_RESOLUTION = 0.001;
|
|
354
|
+
/** One rule gave a piece more energy in one episode than the piece's own fall would (J). */
|
|
355
|
+
type KitEnergyOver = {
|
|
356
|
+
readonly rule: KitRule;
|
|
357
|
+
readonly objectId: string;
|
|
358
|
+
/** Kinetic energy the rule gave the piece since it was last at rest (J). */
|
|
359
|
+
readonly given: number;
|
|
360
|
+
/** Energy the piece's own weight can release from where it was (J, `fallEnergyOf`): the most a rule that only starts a fall may give. */
|
|
361
|
+
readonly fall: number;
|
|
362
|
+
};
|
|
363
|
+
/** What one rule did, over the life of the ledger. */
|
|
364
|
+
type KitRuleTally = {
|
|
365
|
+
readonly rule: KitRule;
|
|
366
|
+
/** Writes it made. */
|
|
367
|
+
readonly pushes: number;
|
|
368
|
+
/** Episodes in which it gave more than the piece's own fall. */
|
|
369
|
+
readonly overs: number;
|
|
370
|
+
/** Its largest give against the fall of the piece and the ruler's resolution (given / (fall + m g `KIT_ENERGY_RESOLUTION`); 0 before any push; over 1 is energy made). */
|
|
371
|
+
readonly worstShare: number;
|
|
372
|
+
/** The episode of that largest share. */
|
|
373
|
+
readonly worst: KitEnergyOver | null;
|
|
374
|
+
};
|
|
375
|
+
|
|
334
376
|
/**
|
|
335
377
|
* Public types of @adatechnology/game-destruction-three.
|
|
336
378
|
*
|
|
@@ -541,6 +583,11 @@ interface RendererOptions {
|
|
|
541
583
|
* own load path and are not checked.
|
|
542
584
|
*/
|
|
543
585
|
onBrokenChecked?: (objectId: string, released: boolean) => void;
|
|
586
|
+
/**
|
|
587
|
+
* A rule of the kit that moves a piece by itself (starting the fall of what lost a leg or its ground, the push over an edge: `KIT_RULE`) gave a piece more kinetic energy since it
|
|
588
|
+
* was last at rest than the piece's own fall would release: energy the kit made, which is a bug of that rule. Nothing is cut; the host logs it. `DestructionRenderer.kitEnergy` counts them.
|
|
589
|
+
*/
|
|
590
|
+
onKitEnergy?: (over: KitEnergyOver) => void;
|
|
544
591
|
/**
|
|
545
592
|
* Called when a sound should play; the host maps keys to audio (e.g. `impact_metal`, `shatter_glass`, `ignite`, `explode`). `burn_loop` is sent when a part starts to burn and `burn_end` when it burns out or is put out.
|
|
546
593
|
* An impact or a break also sends `detail.keys`, the keys to try before `key`, most specific first (`impact_concrete_ballistic`, `impact_concrete`, `impact_masonry_ballistic`, `impact_masonry`).
|
|
@@ -702,6 +749,8 @@ interface DestructionRenderer {
|
|
|
702
749
|
setHostSolids(id: string, source: (() => readonly HostSolid[]) | null): void;
|
|
703
750
|
/** Push a piece (throws, blasts). */
|
|
704
751
|
impulse(objectId: string, impulse: Vec3, point?: Vec3): void;
|
|
752
|
+
/** What each rule of the kit that moves a piece by itself (`KIT_RULE`) gave the pieces it pushed, against their own fall (see `onKitEnergy`). */
|
|
753
|
+
kitEnergy(): KitRuleTally[];
|
|
705
754
|
/** Integrate fragments, pieces and particles; apply pending visual changes. Call once per frame after `world.update`. */
|
|
706
755
|
update(dt: number): void;
|
|
707
756
|
/** With `interpolate`: the awake pieces and fragments drawn `alpha` (0 to 1) of the way from the pose before the last step to the step's. Call in the present phase; 1 draws the step's pose. */
|
|
@@ -1249,4 +1298,4 @@ declare function blastFireSampleBank(manifest: SfxManifest, options?: BlastFireS
|
|
|
1249
1298
|
/** Every particle kind the renderer can emit (the game's sprite kinds, see `@adatechnology/game-vfx`). */
|
|
1250
1299
|
type ParticleKind = SpriteKind;
|
|
1251
1300
|
|
|
1252
|
-
export { BIG_BLAST_RADIUS, BLAST_DEBRIS_DEFAULTS, BLAST_FALLOFF, BLAST_FAR_DISTANCE, BLAST_FAR_FALLOFF, BLAST_FIRE_SAMPLES, BLAST_KINDS, BLAST_KIND_OF, BLAST_RAYS_PER_FRAME, BLAST_SOUNDS, BLAST_SOUND_OF, BLAST_WAVE_PARTS_PER_FRAME, BURN_LOOP, type BindOptions, type BlastDebrisOptions, type BlastFireSampleBankOptions, type BlastFireSampleDefaults, type BlastKind, type BlastPacer, type BlastPacerOptions, type BlastWake, DEFAULT_CRACKLES, DEFAULT_FIRE, DEFAULT_INDOOR_CONFINEMENT, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, DESTRUCTION_VOICE_GROUPS, DRAG_SOUNDS, type DebrisCostOptions, type DebrisCostSample, type DeferredQueueRegistration, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EVENT_APPLY_WEIGHT, EVENT_CLASS, EXPLOSION_BOOM, type EventClass, type ExplodeOptions, type ExplosionWorkOptions, FIRE_FADE_SECONDS, FIRE_FALLOFF, FIRE_LOOP, FIRE_SOUNDS, type FarDebrisAction, type FarDebrisOptions, type FragmentLifeRule, GRENADE_PIN_PULL, GROUND_WORKER_FRAMES, type GroundPatchRead, type GroundTileJob, type GroundTileResult, type GroundWorkerPort, IMPACT_BURST_GROUP, IMPACT_FAMILY_TAGS, IMPACT_SOUNDS, IMPACT_SOUND_KEYS, type ImpactFamily, type ImpactKeys, type JitWarmUpOptions, type JitWarmUpReport, type LooseBody, type LoosenCause, MIN_PIECE_MASS_KG, type MakePieceOptions, type Mesh, type MeshRange, type Object3D, type PacedBlast, type PartHint, type ParticleKind, PhysicsOptionError, type Piece, type PiecePhysics, type Quality, ROCKET_MOTOR_LOOP, type RendererOptions, type ResolvedBlastDebris, SCENE_SOUNDS, SETTLED_BATCH_DEFAULTS, SETTLED_BATCH_ORIGIN, SMOKE_HISS_LOOP, STRUCTURAL_UNITS_PER_FRAME, SUGGESTED_MAX_AWAKE_FRAGMENTS, SUGGESTED_MAX_AWAKE_PIECES, type SettledBatchOptions, type SettledBatchStats, type SolidBox, type SoundDetail, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type StaticPartJob, type ThreeNamespace, WORK_UNIT_DEFAULTS, type WorkUnitCosts, bandLength, blastFireSampleBank, blastSoundIds, breakSoundKeys, computeGroundTile, createBlastPacer, createCoordinatorGroundPort, createDestructionRenderer, createDestructionSound, createInlineGroundPort, createMainThreadGroundPort, createWorkerGroundPort, dragSoundKey, eventApplyWeight, groundTilesKind, heatColor, impactFamily, impactKey, impactSoundIds, impactSoundKeys, installGroundWorker, measureStaticPart, readGroundBand, readGroundPatch, resolveBlastDebris, resolveWorkUnitCosts, ricochetSoundKeys, shotKey, specFromObject3D, splitWorkUnits, staticCollidersKind, warmUpDestructionJit };
|
|
1301
|
+
export { BIG_BLAST_RADIUS, BLAST_DEBRIS_DEFAULTS, BLAST_FALLOFF, BLAST_FAR_DISTANCE, BLAST_FAR_FALLOFF, BLAST_FIRE_SAMPLES, BLAST_KINDS, BLAST_KIND_OF, BLAST_RAYS_PER_FRAME, BLAST_SOUNDS, BLAST_SOUND_OF, BLAST_WAVE_PARTS_PER_FRAME, BURN_LOOP, type BindOptions, type BlastDebrisOptions, type BlastFireSampleBankOptions, type BlastFireSampleDefaults, type BlastKind, type BlastPacer, type BlastPacerOptions, type BlastWake, DEFAULT_CRACKLES, DEFAULT_FIRE, DEFAULT_INDOOR_CONFINEMENT, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, DESTRUCTION_VOICE_GROUPS, DRAG_SOUNDS, type DebrisCostOptions, type DebrisCostSample, type DeferredQueueRegistration, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EVENT_APPLY_WEIGHT, EVENT_CLASS, EXPLOSION_BOOM, type EventClass, type ExplodeOptions, type ExplosionWorkOptions, FIRE_FADE_SECONDS, FIRE_FALLOFF, FIRE_LOOP, FIRE_SOUNDS, type FarDebrisAction, type FarDebrisOptions, type FragmentLifeRule, GRENADE_PIN_PULL, GROUND_WORKER_FRAMES, type GroundPatchRead, type GroundTileJob, type GroundTileResult, type GroundWorkerPort, IMPACT_BURST_GROUP, IMPACT_FAMILY_TAGS, IMPACT_SOUNDS, IMPACT_SOUND_KEYS, type ImpactFamily, type ImpactKeys, type JitWarmUpOptions, type JitWarmUpReport, KIT_ENERGY_RESOLUTION, KIT_RULE, type KitEnergyOver, type KitRule, type KitRuleTally, type LooseBody, type LoosenCause, MIN_PIECE_MASS_KG, type MakePieceOptions, type Mesh, type MeshRange, type Object3D, type PacedBlast, type PartHint, type ParticleKind, PhysicsOptionError, type Piece, type PiecePhysics, type Quality, ROCKET_MOTOR_LOOP, type RendererOptions, type ResolvedBlastDebris, SCENE_SOUNDS, SETTLED_BATCH_DEFAULTS, SETTLED_BATCH_ORIGIN, SMOKE_HISS_LOOP, STRUCTURAL_UNITS_PER_FRAME, SUGGESTED_MAX_AWAKE_FRAGMENTS, SUGGESTED_MAX_AWAKE_PIECES, type SettledBatchOptions, type SettledBatchStats, type SolidBox, type SoundDetail, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type StaticPartJob, type ThreeNamespace, WORK_UNIT_DEFAULTS, type WorkUnitCosts, bandLength, blastFireSampleBank, blastSoundIds, breakSoundKeys, computeGroundTile, createBlastPacer, createCoordinatorGroundPort, createDestructionRenderer, createDestructionSound, createInlineGroundPort, createMainThreadGroundPort, createWorkerGroundPort, dragSoundKey, eventApplyWeight, groundTilesKind, heatColor, impactFamily, impactKey, impactSoundIds, impactSoundKeys, installGroundWorker, measureStaticPart, readGroundBand, readGroundPatch, resolveBlastDebris, resolveWorkUnitCosts, ricochetSoundKeys, shotKey, specFromObject3D, splitWorkUnits, staticCollidersKind, warmUpDestructionJit };
|
package/dist/index.global.js
CHANGED
|
@@ -57,6 +57,8 @@ var GameDestructionThree = (() => {
|
|
|
57
57
|
IMPACT_FAMILY_TAGS: () => IMPACT_FAMILY_TAGS,
|
|
58
58
|
IMPACT_SOUNDS: () => IMPACT_SOUNDS,
|
|
59
59
|
IMPACT_SOUND_KEYS: () => IMPACT_SOUND_KEYS,
|
|
60
|
+
KIT_ENERGY_RESOLUTION: () => KIT_ENERGY_RESOLUTION,
|
|
61
|
+
KIT_RULE: () => KIT_RULE,
|
|
60
62
|
MIN_PIECE_MASS_KG: () => MIN_PIECE_MASS_KG,
|
|
61
63
|
PhysicsOptionError: () => PhysicsOptionError,
|
|
62
64
|
ROCKET_MOTOR_LOOP: () => ROCKET_MOTOR_LOOP,
|
|
@@ -14389,6 +14391,97 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14389
14391
|
});
|
|
14390
14392
|
};
|
|
14391
14393
|
|
|
14394
|
+
// src/kit-energy.ts
|
|
14395
|
+
var KIT_RULE = {
|
|
14396
|
+
/** A piece that lost a leg and is balanced on the line between the ones left is started down over it (`renderer.ts`). */
|
|
14397
|
+
GO_OVER_IF_BALANCED: "goOverIfBalanced",
|
|
14398
|
+
/** What stood on ground that went (a hole under a foot) is started down over the gap (`renderer.ts`). */
|
|
14399
|
+
CHECK_UNDERMINED: "checkUndermined",
|
|
14400
|
+
/** Furniture made a piece balanced on an edge of its feet is started over it (`EDGE_NUDGE`, `renderer.ts`). */
|
|
14401
|
+
LOOSEN_IF_FOOTLESS: "loosenIfFootless",
|
|
14402
|
+
/** A piece of the engine balanced on a narrow support is turned about its edge (`engine-pieces.ts`). */
|
|
14403
|
+
TOPPLE: "topple"
|
|
14404
|
+
};
|
|
14405
|
+
var RULES = Object.values(KIT_RULE);
|
|
14406
|
+
var GRAVITY3 = 9.81;
|
|
14407
|
+
var KIT_ENERGY_RESOLUTION = 1e-3;
|
|
14408
|
+
var REST_HEIGHT = KIT_ENERGY_RESOLUTION;
|
|
14409
|
+
var kineticEnergyOf = (body) => {
|
|
14410
|
+
const [vx2, vy2, vz2] = body.velocity;
|
|
14411
|
+
const [wx, wy, wz] = body.angularVelocity;
|
|
14412
|
+
const { x, y, z, w } = body.root.quaternion;
|
|
14413
|
+
const lx = (1 - 2 * (y * y + z * z)) * wx + 2 * (x * y + z * w) * wy + 2 * (x * z - y * w) * wz;
|
|
14414
|
+
const ly = 2 * (x * y - z * w) * wx + (1 - 2 * (x * x + z * z)) * wy + 2 * (y * z + x * w) * wz;
|
|
14415
|
+
const lz = 2 * (x * z + y * w) * wx + 2 * (y * z - x * w) * wy + (1 - 2 * (x * x + y * y)) * wz;
|
|
14416
|
+
const [hx, hy, hz2] = body.halfExtents;
|
|
14417
|
+
const m = body.mass;
|
|
14418
|
+
let ix = m * (hy * hy + hz2 * hz2) / 3;
|
|
14419
|
+
let iy = m * (hx * hx + hz2 * hz2) / 3;
|
|
14420
|
+
let iz = m * (hx * hx + hy * hy) / 3;
|
|
14421
|
+
const round2 = body.round;
|
|
14422
|
+
if (round2) {
|
|
14423
|
+
const about = round2.inertia * m * round2.radius * round2.radius;
|
|
14424
|
+
if (round2.kind === "sphere") ix = iy = iz = about;
|
|
14425
|
+
else if (round2.axis === 0) ix = about;
|
|
14426
|
+
else if (round2.axis === 1) iy = about;
|
|
14427
|
+
else iz = about;
|
|
14428
|
+
}
|
|
14429
|
+
return 0.5 * m * (vx2 * vx2 + vy2 * vy2 + vz2 * vz2) + 0.5 * (ix * lx * lx + iy * ly * ly + iz * lz * lz);
|
|
14430
|
+
};
|
|
14431
|
+
var fallEnergyOf = (body) => {
|
|
14432
|
+
const { x, y, z, w } = body.root.quaternion;
|
|
14433
|
+
const [hx, hy, hz2] = body.halfExtents;
|
|
14434
|
+
const [cx, cy, cz] = body.massCentre ?? [0, 0, 0];
|
|
14435
|
+
const rx = 2 * (x * y + z * w);
|
|
14436
|
+
const ry = 1 - 2 * (x * x + z * z);
|
|
14437
|
+
const rz = 2 * (y * z - x * w);
|
|
14438
|
+
const over2 = hx * Math.abs(rx) + hy * Math.abs(ry) + hz2 * Math.abs(rz) + rx * cx + ry * cy + rz * cz;
|
|
14439
|
+
const lowest = Math.min(hx - Math.abs(cx), hy - Math.abs(cy), hz2 - Math.abs(cz));
|
|
14440
|
+
return body.mass * GRAVITY3 * Math.max(0, over2 - lowest);
|
|
14441
|
+
};
|
|
14442
|
+
var KitEnergyLedger = class {
|
|
14443
|
+
constructor(onOver) {
|
|
14444
|
+
__publicField(this, "onOver", onOver);
|
|
14445
|
+
__publicField(this, "before", 0);
|
|
14446
|
+
__publicField(this, "tallies", new Map(RULES.map((rule) => [rule, { pushes: 0, overs: 0, worstShare: 0, worst: null }])));
|
|
14447
|
+
__publicField(this, "episodes", /* @__PURE__ */ new WeakMap());
|
|
14448
|
+
}
|
|
14449
|
+
begin(body) {
|
|
14450
|
+
this.before = kineticEnergyOf(body);
|
|
14451
|
+
if (this.before > body.mass * GRAVITY3 * REST_HEIGHT) return;
|
|
14452
|
+
const episode = this.episodes.get(body);
|
|
14453
|
+
if (!episode) {
|
|
14454
|
+
this.episodes.set(body, { given: new Float64Array(RULES.length), over: new Uint8Array(RULES.length), fall: fallEnergyOf(body) });
|
|
14455
|
+
return;
|
|
14456
|
+
}
|
|
14457
|
+
episode.given.fill(0);
|
|
14458
|
+
episode.over.fill(0);
|
|
14459
|
+
episode.fall = fallEnergyOf(body);
|
|
14460
|
+
}
|
|
14461
|
+
end(rule, body) {
|
|
14462
|
+
const tally = this.tallies.get(rule);
|
|
14463
|
+
tally.pushes++;
|
|
14464
|
+
const episode = this.episodes.get(body);
|
|
14465
|
+
const open = episode ?? { given: new Float64Array(RULES.length), over: new Uint8Array(RULES.length), fall: fallEnergyOf(body) };
|
|
14466
|
+
if (!episode) this.episodes.set(body, open);
|
|
14467
|
+
const index = RULES.indexOf(rule);
|
|
14468
|
+
const given = open.given[index] + kineticEnergyOf(body) - this.before;
|
|
14469
|
+
open.given[index] = given;
|
|
14470
|
+
const share = given <= 0 ? 0 : given / (open.fall + body.mass * GRAVITY3 * KIT_ENERGY_RESOLUTION);
|
|
14471
|
+
if (share > tally.worstShare) {
|
|
14472
|
+
tally.worstShare = share;
|
|
14473
|
+
tally.worst = { rule, objectId: body.objectId, given, fall: open.fall };
|
|
14474
|
+
}
|
|
14475
|
+
if (share <= 1 || open.over[index]) return;
|
|
14476
|
+
open.over[index] = 1;
|
|
14477
|
+
tally.overs++;
|
|
14478
|
+
this.onOver?.({ rule, objectId: body.objectId, given, fall: open.fall });
|
|
14479
|
+
}
|
|
14480
|
+
tally() {
|
|
14481
|
+
return RULES.map((rule) => ({ rule, ...this.tallies.get(rule) }));
|
|
14482
|
+
}
|
|
14483
|
+
};
|
|
14484
|
+
|
|
14392
14485
|
// src/engine-ground-heights.ts
|
|
14393
14486
|
var changedHeights = (before, after2, size) => {
|
|
14394
14487
|
let minX = size;
|
|
@@ -15712,20 +15805,25 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15712
15805
|
if (wx <= wz) {
|
|
15713
15806
|
const edge = dirX > 0 ? x1 : x0;
|
|
15714
15807
|
const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN, this.turningOf(b, 2)) * dt : 0;
|
|
15808
|
+
if (dw === 0) return;
|
|
15715
15809
|
const rx = -edge;
|
|
15716
15810
|
const ry = -low;
|
|
15811
|
+
this.o.kitEnergy?.begin(b);
|
|
15717
15812
|
w[2] += dw;
|
|
15718
15813
|
v[0] += -dw * ry;
|
|
15719
15814
|
v[1] += dw * rx;
|
|
15720
15815
|
} else {
|
|
15721
15816
|
const edge = dirZ > 0 ? z1 : z0;
|
|
15722
15817
|
const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN, this.turningOf(b, 0)) * dt : 0;
|
|
15818
|
+
if (dw === 0) return;
|
|
15723
15819
|
const rz = -edge;
|
|
15724
15820
|
const ry = -low;
|
|
15821
|
+
this.o.kitEnergy?.begin(b);
|
|
15725
15822
|
w[0] += dw;
|
|
15726
15823
|
v[1] += -dw * rz;
|
|
15727
15824
|
v[2] += dw * ry;
|
|
15728
15825
|
}
|
|
15826
|
+
this.o.kitEnergy?.end(KIT_RULE.TOPPLE, b);
|
|
15729
15827
|
}
|
|
15730
15828
|
/** Propped pieces lose most of their friction until they move or sleep (the push only presses them into the prop: an energy-free way to end a wedge). */
|
|
15731
15829
|
slip(b, link, isSlipping) {
|
|
@@ -16476,6 +16574,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16476
16574
|
__publicField(this, "supportNormal", UP16);
|
|
16477
16575
|
__publicField(this, "supportFriction", null);
|
|
16478
16576
|
__publicField(this, "supportBody", null);
|
|
16577
|
+
/** What each rule of the kit gave the pieces it pushed (`ruleImpulse`, and the engine's own `topple`). */
|
|
16578
|
+
__publicField(this, "kitEnergy");
|
|
16479
16579
|
/** A piece is asleep on both sides (the engine's too): nothing of it changes until it wakes. */
|
|
16480
16580
|
__publicField(this, "isSettled", (body) => this.engine.isSettled(body));
|
|
16481
16581
|
__publicField(this, "measureAwake", (body) => {
|
|
@@ -16509,7 +16609,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16509
16609
|
this.loop = resolved.loop;
|
|
16510
16610
|
this.stepsItself = resolved.stepsItself;
|
|
16511
16611
|
this.trail = o.interpolate ? new PoseTrail() : null;
|
|
16612
|
+
this.kitEnergy = new KitEnergyLedger(o.onKitEnergy);
|
|
16512
16613
|
this.engine = new EnginePieces(THREE, resolved.loop.world, {
|
|
16614
|
+
kitEnergy: this.kitEnergy,
|
|
16513
16615
|
groundAt: o.terrainAt ?? o.groundAt,
|
|
16514
16616
|
...o.terrainRollingAt ? { groundRollingAt: o.terrainRollingAt } : {},
|
|
16515
16617
|
...o.terrainRollingDampingAt ? { groundRollingDampingAt: o.terrainRollingDampingAt } : {},
|
|
@@ -16851,6 +16953,20 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16851
16953
|
b.still = 0;
|
|
16852
16954
|
b.calmAt = null;
|
|
16853
16955
|
}
|
|
16956
|
+
/** `impulse` given by a rule of the kit on its own, measured by its name (`kitEnergy`). */
|
|
16957
|
+
ruleImpulse(rule, b, impulse, point) {
|
|
16958
|
+
this.kitEnergy.begin(b);
|
|
16959
|
+
this.impulse(b, impulse, point);
|
|
16960
|
+
this.kitEnergy.end(rule, b);
|
|
16961
|
+
}
|
|
16962
|
+
/** Spin (rad/s, world axes x and z) added by a rule of the kit on its own, measured by its name (`kitEnergy`). */
|
|
16963
|
+
ruleSpin(rule, b, x, z) {
|
|
16964
|
+
this.kitEnergy.begin(b);
|
|
16965
|
+
b.angularVelocity[0] += x;
|
|
16966
|
+
b.angularVelocity[2] += z;
|
|
16967
|
+
b.sleeping = false;
|
|
16968
|
+
this.kitEnergy.end(rule, b);
|
|
16969
|
+
}
|
|
16854
16970
|
/** I^-1 * (x, y, z) in world space for a box with the body's half extents and mass (needs `this.m` to hold the body's rotation). */
|
|
16855
16971
|
mulInvInertia(b, x, y, z) {
|
|
16856
16972
|
this.m.makeRotationFromQuaternion(b.root.quaternion);
|
|
@@ -18636,7 +18752,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
18636
18752
|
for (const [a, b] of bars) length += Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]) + Math.abs(a[2] - b[2]);
|
|
18637
18753
|
return Math.PI * (diameter / 2) * (diameter / 2) * length * density;
|
|
18638
18754
|
};
|
|
18639
|
-
var
|
|
18755
|
+
var GRAVITY4 = 9.81;
|
|
18640
18756
|
var MPA = 1e6;
|
|
18641
18757
|
var FLEXURE_DEFAULTS = {
|
|
18642
18758
|
enabled: true,
|
|
@@ -18739,7 +18855,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
18739
18855
|
var sectionWidth = (g, axis2) => g.member ? g.dims[g.depthAxes.find((a) => a !== axis2) ?? axis2] : 1;
|
|
18740
18856
|
var lineLoad = (g, load) => {
|
|
18741
18857
|
const area = g.member ? g.dims[g.spanAxes[0]] : g.dims[g.spanAxes[0]] * g.dims[g.spanAxes[1]];
|
|
18742
|
-
return load *
|
|
18858
|
+
return load * GRAVITY4 / Math.max(area, 1e-6);
|
|
18743
18859
|
};
|
|
18744
18860
|
var spanOf = (g, contacts, samples = 9) => {
|
|
18745
18861
|
if (contacts.length === 0) return 0;
|
|
@@ -19379,7 +19495,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
19379
19495
|
let anyFoundation = false;
|
|
19380
19496
|
for (let i = 0; i < parts.length; i++) {
|
|
19381
19497
|
const p = parts[i];
|
|
19382
|
-
weight += p.mass *
|
|
19498
|
+
weight += p.mass * GRAVITY4;
|
|
19383
19499
|
wu += p.mass * g[i].u;
|
|
19384
19500
|
if (p.kind === "foundation") {
|
|
19385
19501
|
anyFoundation = true;
|
|
@@ -19398,7 +19514,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
19398
19514
|
if (!anyFoundation) {
|
|
19399
19515
|
for (let i = 0; i < parts.length; i++) if (parts[i].min[1] - ground < 0.1) footEnd = Math.max(footEnd, g[i].u + g[i].du / 2);
|
|
19400
19516
|
}
|
|
19401
|
-
const totalMass = weight /
|
|
19517
|
+
const totalMass = weight / GRAVITY4;
|
|
19402
19518
|
const uCg = totalMass > 0 ? wu / totalMass : 0;
|
|
19403
19519
|
const width = vmax.map((hi, j) => hi > vmin[j] ? hi - vmin[j] : 0);
|
|
19404
19520
|
const widest = Math.max(...width);
|
|
@@ -21030,7 +21146,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
21030
21146
|
const steel = bars * Math.PI * (part.reinforcement.diameter / 2) ** 2;
|
|
21031
21147
|
newtons = m.concreteFactor * fc * section + steel * resolveFlexure(options.flexure).rebarYieldMPa * 1e6;
|
|
21032
21148
|
}
|
|
21033
|
-
return Math.max(1, newtons /
|
|
21149
|
+
return Math.max(1, newtons / GRAVITY4 * foundation);
|
|
21034
21150
|
};
|
|
21035
21151
|
var fragility = (ductility, thickness) => {
|
|
21036
21152
|
if (ductility >= 0.3) return 1;
|
|
@@ -21941,7 +22057,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
21941
22057
|
const width = sectionWidth(g, axis2);
|
|
21942
22058
|
const impulse = sum / offsets.length * cos2 * reach2 * width * L;
|
|
21943
22059
|
const weight = axis2 === g.gravity ? p.bendLoad : p.st.mass;
|
|
21944
|
-
const kinetic = impulseEnergy(impulse, lineLoad(g, weight) /
|
|
22060
|
+
const kinetic = impulseEnergy(impulse, lineLoad(g, weight) / GRAVITY4 * L, flexure);
|
|
21945
22061
|
const sec = sectionOf(p, axis2);
|
|
21946
22062
|
const EI = s.elasticGPa * 1e9 * sec.section.b * sec.section.h ** 3 / 12;
|
|
21947
22063
|
const along2 = axis2 === g.gravity ? -Math.sign(away[axis2] * g.up[axis2]) : 0;
|
|
@@ -22196,8 +22312,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
22196
22312
|
const dead = p.st.load ?? p.st.mass;
|
|
22197
22313
|
const force = N * cfg.loadFactor;
|
|
22198
22314
|
let stress = 0;
|
|
22199
|
-
if (force >= 0) stress = (dead * structureSafety + force /
|
|
22200
|
-
else if (dead + force /
|
|
22315
|
+
if (force >= 0) stress = (dead * structureSafety + force / GRAVITY4) / (p.cap * capacityScale(p));
|
|
22316
|
+
else if (dead + force / GRAVITY4 < 0) {
|
|
22201
22317
|
let cap = w.tension.get(i);
|
|
22202
22318
|
if (cap === void 0) {
|
|
22203
22319
|
const r = p.spec.reinforcement;
|
|
@@ -22210,7 +22326,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
22210
22326
|
});
|
|
22211
22327
|
w.tension.set(i, cap);
|
|
22212
22328
|
}
|
|
22213
|
-
stress = Math.min(10, -(dead + force /
|
|
22329
|
+
stress = Math.min(10, -(dead + force / GRAVITY4) * GRAVITY4 / Math.max(cap * capacityScale(p), 1));
|
|
22214
22330
|
}
|
|
22215
22331
|
if (stress > (p.st.stress ?? 0)) p.st.stress = stress;
|
|
22216
22332
|
if ((p.st.stress ?? 0) > o.maxStress) o.maxStress = p.st.stress ?? 0;
|
|
@@ -22352,7 +22468,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
22352
22468
|
m += p.st.mass;
|
|
22353
22469
|
for (let k = 0; k < 3; k++) c[k] += p.st.mass * p.pos[k];
|
|
22354
22470
|
}
|
|
22355
|
-
return { w: m *
|
|
22471
|
+
return { w: m * GRAVITY4, c: m > 0 ? [c[0] / m, c[1] / m, c[2] / m] : c };
|
|
22356
22472
|
};
|
|
22357
22473
|
const initSoil = (o, profile, carried, carrySets) => {
|
|
22358
22474
|
const so = { profile, s: 0, a: 0, b: 0, imp: [0, 0], pivot: [0, 0, 0], dirty: true, sets: /* @__PURE__ */ new Map(), emitted: { t: -Infinity, s: 0, tilt: 0, status: "stable" } };
|
|
@@ -22517,7 +22633,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
22517
22633
|
if (flat < 0.5) return pieces;
|
|
22518
22634
|
const side = hashOf(p.spec.id) & 1 ? -1 : 1;
|
|
22519
22635
|
const nx = side * across[0] / flat, nz = side * across[2] / flat;
|
|
22520
|
-
const spin = Math.sqrt(3 *
|
|
22636
|
+
const spin = Math.sqrt(3 * GRAVITY4 / height);
|
|
22521
22637
|
const foot = box.min[1];
|
|
22522
22638
|
return pieces.map((f) => {
|
|
22523
22639
|
const up = Math.max(0, f.center[1] - foot);
|
|
@@ -22745,7 +22861,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
22745
22861
|
loadFactor: structureSafety,
|
|
22746
22862
|
points: over2.map(({ q }) => {
|
|
22747
22863
|
const c = aabbOf(q.spec.shape, q.pos, q.q);
|
|
22748
|
-
return { weight: (q.st.load ?? q.st.mass) *
|
|
22864
|
+
return { weight: (q.st.load ?? q.st.mass) * GRAVITY4, side: Math.min(c.max[0] - c.min[0], c.max[2] - c.min[2]) };
|
|
22749
22865
|
})
|
|
22750
22866
|
});
|
|
22751
22867
|
if (fp.share > 1 - 1 / soilCfg.safety) return { status: "unsupported", failed: [], cracks: [] };
|
|
@@ -29427,6 +29543,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29427
29543
|
...o.groundWorkerFrames !== void 0 ? { groundWorkerFrames: o.groundWorkerFrames } : {},
|
|
29428
29544
|
...this.blastDebris ? { keep: { maxLive: this.blastDebris.maxLivePieces, far: this.blastDebris.far, ...o.focus ? { focus: o.focus } : {}, onFade: (b) => this.fadePiece(b) } } : {},
|
|
29429
29545
|
onHardLanding: (p, point, speed) => this.hardLanding(p, point, speed),
|
|
29546
|
+
...o.onKitEnergy ? { onKitEnergy: o.onKitEnergy } : {},
|
|
29430
29547
|
sweep: (p, from, to) => this.sweepPiece(p, from, to),
|
|
29431
29548
|
onSlam: (p, hit, speed) => this.slam(p, hit, speed),
|
|
29432
29549
|
// two pieces knocked together: each sounds as its material does (a can on a can, a bottle on a table's leg)
|
|
@@ -29878,6 +29995,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29878
29995
|
const piece = this.pieceSys.get(objectId);
|
|
29879
29996
|
return piece && !piece.debris ? piece : null;
|
|
29880
29997
|
}
|
|
29998
|
+
/** What each rule of the kit that moves a piece by itself (`KIT_RULE`) gave the pieces it pushed, against their own fall (see `RendererOptions.onKitEnergy`). */
|
|
29999
|
+
kitEnergy() {
|
|
30000
|
+
return this.pieceSys.kitEnergy.tally();
|
|
30001
|
+
}
|
|
29881
30002
|
impulse(objectId, impulse, point) {
|
|
29882
30003
|
const p = this.pieceSys.get(objectId);
|
|
29883
30004
|
if (p) this.pieceSys.impulse(p, impulse, point);
|
|
@@ -31555,9 +31676,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31555
31676
|
this.setContacts(b, b.piece ?? piece, left);
|
|
31556
31677
|
const loose = b.piece;
|
|
31557
31678
|
if (away && loose) {
|
|
31558
|
-
|
|
31559
|
-
loose.angularVelocity[2] -= away.x * EDGE_NUDGE;
|
|
31560
|
-
loose.sleeping = false;
|
|
31679
|
+
this.pieceSys.ruleSpin(KIT_RULE.LOOSEN_IF_FOOTLESS, loose, away.z * EDGE_NUDGE, -away.x * EDGE_NUDGE);
|
|
31561
31680
|
} else this.tipIfTopHeavy(b);
|
|
31562
31681
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
31563
31682
|
}
|
|
@@ -31653,7 +31772,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31653
31772
|
body.sleeping = false;
|
|
31654
31773
|
body.still = 0;
|
|
31655
31774
|
body.calmAt = null;
|
|
31656
|
-
if (held.length > 0 && length > 1e-6) this.pieceSys.
|
|
31775
|
+
if (held.length > 0 && length > 1e-6) this.pieceSys.ruleImpulse(KIT_RULE.CHECK_UNDERMINED, body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + gx, floor2, centre[2] + gz]);
|
|
31657
31776
|
if (!was) this.o.onLoosened?.(b.id, body, "ground");
|
|
31658
31777
|
}
|
|
31659
31778
|
}
|
|
@@ -31670,7 +31789,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31670
31789
|
if (this.standsWith(held, null, centre, feet.floor)) return;
|
|
31671
31790
|
const inside = insideBy(convexHull2(held), [centre[0], centre[2]]);
|
|
31672
31791
|
const reach2 = this.reachAlong(body, inside.out.x, inside.out.z);
|
|
31673
|
-
this.pieceSys.
|
|
31792
|
+
this.pieceSys.ruleImpulse(KIT_RULE.GO_OVER_IF_BALANCED, body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + inside.out.x * reach2, feet.floor, centre[2] + inside.out.z * reach2]);
|
|
31674
31793
|
}
|
|
31675
31794
|
/** How far (m) the box of a piece reaches from its middle along the level direction (x, z), turned as it is: the support of its box that way. */
|
|
31676
31795
|
reachAlong(body, x, z) {
|