@adatechnology/game-interactables 0.7.0 → 0.9.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 +10 -0
- package/dist/index.d.ts +87 -1
- package/dist/index.global.js +124 -3
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +124 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -191,6 +191,16 @@ the hand holds goes in when the access is open and it fits the inside, `fitsInVo
|
|
|
191
191
|
and `relieve` (a basin soiled, washed by the flush whose fixture `cleans` it). `state()` says what to draw (screens on and their channel, bowl levels, soil,
|
|
192
192
|
fires); `createControlsView` of game-interactables-three draws it.
|
|
193
193
|
|
|
194
|
+
## Wires strung between two points (`solveSpan`)
|
|
195
|
+
|
|
196
|
+
A wire with a `span` (`ObjectSpec.wires[].span`: the conductor's material and the section that carries the pull) is strung between two points: the drop of a
|
|
197
|
+
service entrance runs from the pole's head to the house. `solveSpan({ span, from, to, ground?, clearance? })` gives the shape it takes between where its ends
|
|
198
|
+
are now, the catenary of its strung length (`polylineLength` of its points), lying on the ground where it would hang lower, and the pull at its ends. Pulled
|
|
199
|
+
straight past its length it stretches as its material does (E·A·strain, `elasticGPa`), and past `ultimateMPa` it snaps at the end that pulls the harder
|
|
200
|
+
(`snaps`; `spanStrength` is its breaking pull). The material numbers are those of game-destruction (`MaterialDef.tension`, `density`). The ends are where the
|
|
201
|
+
host says: a wire never holds back a falling pole, since what it takes in before it snaps is a few joules. `hangTail` gives what is left hanging from one end
|
|
202
|
+
after it snapped. `createSpanWire` of game-interactables-three draws it.
|
|
203
|
+
|
|
194
204
|
## Português
|
|
195
205
|
|
|
196
206
|
Runtime sem renderer para objetos interativos do mundo: portas, gavetas e tampas que se movem, recipientes com itens e loot determinístico por
|
package/dist/index.d.ts
CHANGED
|
@@ -145,6 +145,15 @@ interface PartDestruction {
|
|
|
145
145
|
spacing: number;
|
|
146
146
|
diameter: number;
|
|
147
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* Masonry laid in units (a brick barbecue, a fireplace): the size of one unit (length, height, depth in metres), its bond and the SDK material of the joints. A host
|
|
150
|
+
* gives the masonry its units (`PartSpec.units` of the destruction SDK), so a hit knocks bricks out where it lands and the part breaks into bricks and rubble, not into blocks.
|
|
151
|
+
*/
|
|
152
|
+
units?: {
|
|
153
|
+
size: [number, number, number];
|
|
154
|
+
bond: 'running' | 'stack';
|
|
155
|
+
mortar: string;
|
|
156
|
+
};
|
|
148
157
|
}
|
|
149
158
|
/** One stack of items. `type` is an id from the content pack's item catalog. */
|
|
150
159
|
interface ItemStack {
|
|
@@ -483,6 +492,11 @@ type Action = {
|
|
|
483
492
|
circuit: string;
|
|
484
493
|
part?: string;
|
|
485
494
|
name?: string;
|
|
495
|
+
}
|
|
496
|
+
/** Flips the building's main breaker (the service entrance's, after the meter: `World.power.setMain`): off, nothing of the building has power. `part` is a rocker that mirrors it (t = 1 when on), refused while gated (a closed meter box door). */
|
|
497
|
+
| {
|
|
498
|
+
do: 'toggle_main';
|
|
499
|
+
part?: string;
|
|
486
500
|
} | {
|
|
487
501
|
do: 'toggle_fixture';
|
|
488
502
|
fixture: string;
|
|
@@ -558,6 +572,14 @@ interface ObjectSpec {
|
|
|
558
572
|
kind: 'drop' | 'conduit' | 'cord' | 'cable';
|
|
559
573
|
points: Vec3[];
|
|
560
574
|
radius?: number;
|
|
575
|
+
/**
|
|
576
|
+
* A wire strung between two points (a drop from a pole to a house): it hangs as a span of its strung length (`solveSpan`) between where its ends are, and snaps
|
|
577
|
+
* past its material's strength. `material`: the conductor's (a game-destruction material with `tension`); `section`: the cross-section that carries the pull, m².
|
|
578
|
+
*/
|
|
579
|
+
span?: {
|
|
580
|
+
material: string;
|
|
581
|
+
section: number;
|
|
582
|
+
};
|
|
561
583
|
}>;
|
|
562
584
|
}
|
|
563
585
|
type InteractablesLocale = 'en' | 'pt-BR';
|
|
@@ -686,6 +708,7 @@ type WorldEvent = {
|
|
|
686
708
|
} | {
|
|
687
709
|
type: 'power';
|
|
688
710
|
grid: boolean;
|
|
711
|
+
main: boolean;
|
|
689
712
|
}
|
|
690
713
|
/** A container without an access part was opened (open shelf): the host may show its contents. */
|
|
691
714
|
| {
|
|
@@ -826,6 +849,9 @@ interface World {
|
|
|
826
849
|
power: {
|
|
827
850
|
grid: boolean;
|
|
828
851
|
setGrid(on: boolean): void;
|
|
852
|
+
/** The building's main breaker (the service entrance's, after the meter): off, no device of the building is powered whatever the grid and the circuits. Default on. */
|
|
853
|
+
readonly main: boolean;
|
|
854
|
+
setMain(on: boolean): void;
|
|
829
855
|
setBreaker(circuit: string, on: boolean): void;
|
|
830
856
|
breaker(circuit: string): boolean;
|
|
831
857
|
isPowered(objectId: string, deviceId: string): boolean;
|
|
@@ -910,6 +936,8 @@ interface WorldState {
|
|
|
910
936
|
hp: Record<string, number>;
|
|
911
937
|
}>;
|
|
912
938
|
grid: boolean;
|
|
939
|
+
/** The main breaker (`World.power.main`); absent in a state saved before it existed, read as on. */
|
|
940
|
+
main?: boolean;
|
|
913
941
|
breakers: Record<string, boolean>;
|
|
914
942
|
seats: Record<string, {
|
|
915
943
|
object: string;
|
|
@@ -1053,6 +1081,64 @@ declare function disposeChain(world: SeamWorld, chain: Chain): void;
|
|
|
1053
1081
|
/** The two ends of every link now, as a polyline (x, y, z per point) for a host that draws the cord: the points a chain was built from, moved. */
|
|
1054
1082
|
declare function chainPoints(world: SeamWorld, chain: Chain, out: Float64Array): void;
|
|
1055
1083
|
|
|
1084
|
+
/** What a span is made of, in real units (`MaterialDef.tension` and `density` of game-destruction). */
|
|
1085
|
+
type SpanMaterial = {
|
|
1086
|
+
/** kg/m³ of the conductor. */
|
|
1087
|
+
readonly density: number;
|
|
1088
|
+
/** Modulus of elasticity, GPa. */
|
|
1089
|
+
readonly elasticGPa: number;
|
|
1090
|
+
/** Ultimate tensile strength, MPa. */
|
|
1091
|
+
readonly ultimateMPa: number;
|
|
1092
|
+
};
|
|
1093
|
+
/** A wire strung between two points. */
|
|
1094
|
+
type Span = {
|
|
1095
|
+
/** Length of the wire as it was strung, metres. */
|
|
1096
|
+
readonly length: number;
|
|
1097
|
+
/** Cross-section that carries the pull, m² (the conductors, not the insulation). */
|
|
1098
|
+
readonly section: number;
|
|
1099
|
+
readonly material: SpanMaterial;
|
|
1100
|
+
};
|
|
1101
|
+
/** Where a span's ends are and how it is drawn. */
|
|
1102
|
+
type SolveSpanParams = {
|
|
1103
|
+
readonly span: Span;
|
|
1104
|
+
readonly from: Vec3;
|
|
1105
|
+
readonly to: Vec3;
|
|
1106
|
+
/** Points along the wire, both ends included (default 16). */
|
|
1107
|
+
readonly segments?: number;
|
|
1108
|
+
/** Height of the ground under a point (x, z): the wire lies on it where it would hang lower. */
|
|
1109
|
+
readonly ground?: (x: number, z: number) => number;
|
|
1110
|
+
/** How far above the ground the wire's axis lies (its radius). */
|
|
1111
|
+
readonly clearance?: number;
|
|
1112
|
+
};
|
|
1113
|
+
/** The shape a span takes and the pull at its ends. */
|
|
1114
|
+
type SpanShape = {
|
|
1115
|
+
readonly points: Vec3[];
|
|
1116
|
+
/** The larger pull at an end, newtons. */
|
|
1117
|
+
readonly tension: number;
|
|
1118
|
+
/** Pulled straight past its strung length. */
|
|
1119
|
+
readonly taut: boolean;
|
|
1120
|
+
/** The end where the stress passed the material's strength, else null. */
|
|
1121
|
+
readonly snaps: 'from' | 'to' | null;
|
|
1122
|
+
};
|
|
1123
|
+
/** Length of a polyline. */
|
|
1124
|
+
declare function polylineLength(points: readonly Vec3[]): number;
|
|
1125
|
+
/** The breaking pull of a span, newtons. */
|
|
1126
|
+
declare function spanStrength(span: Span): number;
|
|
1127
|
+
/** The shape of a span between its ends now, the pull at its ends and whether it snaps (at the end that pulls the harder). */
|
|
1128
|
+
declare function solveSpan(params: SolveSpanParams): SpanShape;
|
|
1129
|
+
/** A wire hung by one end, the other loose: what a snapped span leaves on the end that held. */
|
|
1130
|
+
type HangTailParams = {
|
|
1131
|
+
readonly anchor: Vec3;
|
|
1132
|
+
readonly length: number;
|
|
1133
|
+
/** The way the loose end lies along the ground (horizontal; default +x). */
|
|
1134
|
+
readonly toward?: Vec3;
|
|
1135
|
+
readonly segments?: number;
|
|
1136
|
+
readonly ground?: (x: number, z: number) => number;
|
|
1137
|
+
readonly clearance?: number;
|
|
1138
|
+
};
|
|
1139
|
+
/** Straight down from its anchor to the ground, and the rest of its length lying along the ground toward `toward`. */
|
|
1140
|
+
declare function hangTail(params: HangTailParams): Vec3[];
|
|
1141
|
+
|
|
1056
1142
|
/**
|
|
1057
1143
|
* What an object does with the player's hand or on its own time (`ObjectSpec.uses`), for `createObjectControls`: a device's program that runs for its seconds, what
|
|
1058
1144
|
* the hand holds put inside when it fits, a container emptied, a bowl filled from the hand, a basin soiled and washed by its flush. The rules are the data's: the
|
|
@@ -1111,4 +1197,4 @@ declare function createObjectControls(options: ObjectControlsOptions): ObjectCon
|
|
|
1111
1197
|
/** Whether a thing of `size` (any turn of it) goes into a box of `half` sizes: each of its sides, longest first, against the box's, longest first. */
|
|
1112
1198
|
declare function fitsInVolume(size: readonly [number, number, number], half: Vec3): boolean;
|
|
1113
1199
|
|
|
1114
|
-
export { type Action, type ActiveEmitter, type BasinSpec, type BowlSpec, type BurnerSpec, CONTROLLED_OBJECT, type Chain, type ChainSpec, type ColliderOptions, type ColliderSpec, type ContainerSpec, type DamageKind, type DamageSpec, type DestructionDelegate, type DestructionJoint, type DeviceKind, type DeviceSpec, type EmitterBowl, type EmitterKind, type EmitterSpec, type EnginePartDriver, type EnginePartOptions, type EnginePartPhysics, FLUSH_RUN_SECONDS, type FixtureEmitters, type FixtureKind, type FixtureSpec, type FuelSourceSpec, type Interactable, type InteractablesLocale, type InteractionSpec, type ItemCatalog, type ItemDef, type ItemStack, type LootEntry, type LootTable, type LootTables, type MirrorSpec, type Motion, type MotionKind, type ObjectControls, type ObjectControlsOptions, type ObjectControlsState, type ObjectSpec, type PartDestruction, type PartDriver, type PartPhysics, type PartSpec, type Pose, type Rect, type RunningEmitter, type SeatPose, type SeatResult, type SeatSpec, type SlotSpec, type SocketSpec, type SoftDriver, type SoftSpec, type Soil, type Strings, type SwitchSpec, type TankSpec, type TargetOptions, type Transform, type UseSpec, type UsesState, type Vec3, type World, type WorldCollider, type WorldEvent, type WorldObject, type WorldOptions, type WorldState, alignY, buildChain, chainPoints, createEnginePartPhysics, createFixtureEmitters, createObjectControls, createWorld, disposeChain, fitsInVolume, fitsSize, fitsSlot, format, generateLoot, hashString, localToWorld, locales, mergeColliders, pickLocale, poseOf, resolveStrings, rng, rotY, rotateAxis, worldToLocal };
|
|
1200
|
+
export { type Action, type ActiveEmitter, type BasinSpec, type BowlSpec, type BurnerSpec, CONTROLLED_OBJECT, type Chain, type ChainSpec, type ColliderOptions, type ColliderSpec, type ContainerSpec, type DamageKind, type DamageSpec, type DestructionDelegate, type DestructionJoint, type DeviceKind, type DeviceSpec, type EmitterBowl, type EmitterKind, type EmitterSpec, type EnginePartDriver, type EnginePartOptions, type EnginePartPhysics, FLUSH_RUN_SECONDS, type FixtureEmitters, type FixtureKind, type FixtureSpec, type FuelSourceSpec, type HangTailParams, type Interactable, type InteractablesLocale, type InteractionSpec, type ItemCatalog, type ItemDef, type ItemStack, type LootEntry, type LootTable, type LootTables, type MirrorSpec, type Motion, type MotionKind, type ObjectControls, type ObjectControlsOptions, type ObjectControlsState, type ObjectSpec, type PartDestruction, type PartDriver, type PartPhysics, type PartSpec, type Pose, type Rect, type RunningEmitter, type SeatPose, type SeatResult, type SeatSpec, type SlotSpec, type SocketSpec, type SoftDriver, type SoftSpec, type Soil, type SolveSpanParams, type Span, type SpanMaterial, type SpanShape, type Strings, type SwitchSpec, type TankSpec, type TargetOptions, type Transform, type UseSpec, type UsesState, type Vec3, type World, type WorldCollider, type WorldEvent, type WorldObject, type WorldOptions, type WorldState, alignY, buildChain, chainPoints, createEnginePartPhysics, createFixtureEmitters, createObjectControls, createWorld, disposeChain, fitsInVolume, fitsSize, fitsSlot, format, generateLoot, hangTail, hashString, localToWorld, locales, mergeColliders, pickLocale, polylineLength, poseOf, resolveStrings, rng, rotY, rotateAxis, solveSpan, spanStrength, worldToLocal };
|
package/dist/index.global.js
CHANGED
|
@@ -36,16 +36,20 @@ var GameInteractables = (() => {
|
|
|
36
36
|
fitsSlot: () => fitsSlot,
|
|
37
37
|
format: () => format,
|
|
38
38
|
generateLoot: () => generateLoot,
|
|
39
|
+
hangTail: () => hangTail,
|
|
39
40
|
hashString: () => hashString,
|
|
40
41
|
localToWorld: () => localToWorld,
|
|
41
42
|
locales: () => locales,
|
|
42
43
|
mergeColliders: () => mergeColliders,
|
|
43
44
|
pickLocale: () => pickLocale,
|
|
45
|
+
polylineLength: () => polylineLength,
|
|
44
46
|
poseOf: () => poseOf,
|
|
45
47
|
resolveStrings: () => resolveStrings,
|
|
46
48
|
rng: () => rng,
|
|
47
49
|
rotY: () => rotY,
|
|
48
50
|
rotateAxis: () => rotateAxis,
|
|
51
|
+
solveSpan: () => solveSpan,
|
|
52
|
+
spanStrength: () => spanStrength,
|
|
49
53
|
worldToLocal: () => worldToLocal
|
|
50
54
|
});
|
|
51
55
|
|
|
@@ -234,6 +238,8 @@ var GameInteractables = (() => {
|
|
|
234
238
|
"prompt.read": "Read",
|
|
235
239
|
"prompt.breaker_on": "Switch on {circuit}",
|
|
236
240
|
"prompt.breaker_off": "Switch off {circuit}",
|
|
241
|
+
"prompt.main_on": "Switch on the main breaker",
|
|
242
|
+
"prompt.main_off": "Switch off the main breaker",
|
|
237
243
|
"prompt.open_valve": "Open valve",
|
|
238
244
|
"prompt.close_valve": "Close valve",
|
|
239
245
|
no_power: "No power",
|
|
@@ -285,6 +291,8 @@ var GameInteractables = (() => {
|
|
|
285
291
|
"prompt.read": "Ler",
|
|
286
292
|
"prompt.breaker_on": "Ligar {circuit}",
|
|
287
293
|
"prompt.breaker_off": "Desligar {circuit}",
|
|
294
|
+
"prompt.main_on": "Ligar o disjuntor geral",
|
|
295
|
+
"prompt.main_off": "Desligar o disjuntor geral",
|
|
288
296
|
"prompt.open_valve": "Abrir registro",
|
|
289
297
|
"prompt.close_valve": "Fechar registro",
|
|
290
298
|
no_power: "Sem energia",
|
|
@@ -420,6 +428,7 @@ var GameInteractables = (() => {
|
|
|
420
428
|
let locale = options.locale ?? "en";
|
|
421
429
|
let table = resolveStrings(locale, options.strings);
|
|
422
430
|
let grid = options.grid ?? true;
|
|
431
|
+
let main = true;
|
|
423
432
|
let rain = options.rain ?? 0;
|
|
424
433
|
let wind = options.wind ? [options.wind[0], options.wind[1]] : [0, 0];
|
|
425
434
|
let defaultTank = null;
|
|
@@ -768,7 +777,7 @@ var GameInteractables = (() => {
|
|
|
768
777
|
}
|
|
769
778
|
function devicePowered(o, d) {
|
|
770
779
|
if (d.spec.electric === false) return true;
|
|
771
|
-
if (!grid) return false;
|
|
780
|
+
if (!grid || !main) return false;
|
|
772
781
|
if (d.spec.circuit) return breaker(d.spec.circuit);
|
|
773
782
|
if (d.spec.socket === void 0) return false;
|
|
774
783
|
const sid = plugs.get(gid(o, d.spec.id));
|
|
@@ -1236,6 +1245,11 @@ var GameInteractables = (() => {
|
|
|
1236
1245
|
def = on ? "prompt.breaker_off" : "prompt.breaker_on";
|
|
1237
1246
|
break;
|
|
1238
1247
|
}
|
|
1248
|
+
case "toggle_main": {
|
|
1249
|
+
state = main ? "on" : "off";
|
|
1250
|
+
def = main ? "prompt.main_off" : "prompt.main_on";
|
|
1251
|
+
break;
|
|
1252
|
+
}
|
|
1239
1253
|
case "toggle_fixture": {
|
|
1240
1254
|
const on = !!o.fixtures.get(a.fixture)?.on;
|
|
1241
1255
|
state = on ? "on" : "off";
|
|
@@ -1307,7 +1321,8 @@ var GameInteractables = (() => {
|
|
|
1307
1321
|
const p = c?.access ? o.parts.get(c.access) : void 0;
|
|
1308
1322
|
return p && gated(o, p) ? "requires_open" : null;
|
|
1309
1323
|
}
|
|
1310
|
-
case "toggle_breaker":
|
|
1324
|
+
case "toggle_breaker":
|
|
1325
|
+
case "toggle_main": {
|
|
1311
1326
|
const rocker = a.part ? o.parts.get(a.part) : void 0;
|
|
1312
1327
|
return rocker && gated(o, rocker) ? "requires_open" : null;
|
|
1313
1328
|
}
|
|
@@ -1515,6 +1530,14 @@ var GameInteractables = (() => {
|
|
|
1515
1530
|
world.power.setBreaker(a.circuit, on);
|
|
1516
1531
|
return true;
|
|
1517
1532
|
}
|
|
1533
|
+
case "toggle_main": {
|
|
1534
|
+
const rocker = a.part ? o.parts.get(a.part) : void 0;
|
|
1535
|
+
if (rocker && gated(o, rocker)) return false;
|
|
1536
|
+
const on = !main;
|
|
1537
|
+
if (a.part) setPartTarget(o, a.part, on ? 1 : 0);
|
|
1538
|
+
world.power.setMain(on);
|
|
1539
|
+
return true;
|
|
1540
|
+
}
|
|
1518
1541
|
case "toggle_fixture":
|
|
1519
1542
|
return toggleFixture(o, a.fixture);
|
|
1520
1543
|
case "toggle_burner":
|
|
@@ -1782,6 +1805,7 @@ var GameInteractables = (() => {
|
|
|
1782
1805
|
version: 1,
|
|
1783
1806
|
objects,
|
|
1784
1807
|
grid,
|
|
1808
|
+
main,
|
|
1785
1809
|
breakers: Object.fromEntries(breakers),
|
|
1786
1810
|
seats: Object.fromEntries([...seats].map(([a, s]) => [a, { object: s.object, seat: s.seat }])),
|
|
1787
1811
|
defaultTank
|
|
@@ -1842,6 +1866,7 @@ var GameInteractables = (() => {
|
|
|
1842
1866
|
}
|
|
1843
1867
|
}
|
|
1844
1868
|
grid = state.grid;
|
|
1869
|
+
main = state.main ?? true;
|
|
1845
1870
|
breakers.clear();
|
|
1846
1871
|
for (const [k, v] of Object.entries(state.breakers)) breakers.set(k, v);
|
|
1847
1872
|
seats.clear();
|
|
@@ -1883,7 +1908,17 @@ var GameInteractables = (() => {
|
|
|
1883
1908
|
if (on === grid) return;
|
|
1884
1909
|
const before = powerSnapshot();
|
|
1885
1910
|
grid = on;
|
|
1886
|
-
emit({ type: "power", grid });
|
|
1911
|
+
emit({ type: "power", grid, main });
|
|
1912
|
+
emitPowerChanges(before);
|
|
1913
|
+
},
|
|
1914
|
+
get main() {
|
|
1915
|
+
return main;
|
|
1916
|
+
},
|
|
1917
|
+
setMain(on) {
|
|
1918
|
+
if (on === main) return;
|
|
1919
|
+
const before = powerSnapshot();
|
|
1920
|
+
main = on;
|
|
1921
|
+
emit({ type: "power", grid, main });
|
|
1887
1922
|
emitPowerChanges(before);
|
|
1888
1923
|
},
|
|
1889
1924
|
setBreaker(circuit, on) {
|
|
@@ -2336,6 +2371,92 @@ var GameInteractables = (() => {
|
|
|
2336
2371
|
return createLeafDriver({ world, leaf, frame, ownsFrame, joint, onDispose: request.onDispose, drive: { isHinge, axis, pivot, centre, range, speed, base: rotation } });
|
|
2337
2372
|
}
|
|
2338
2373
|
|
|
2374
|
+
// src/span.ts
|
|
2375
|
+
var GRAVITY = 9.81;
|
|
2376
|
+
var SHAPE_STEPS = 60;
|
|
2377
|
+
var VERTICAL_SPAN = 1e-4;
|
|
2378
|
+
function polylineLength(points) {
|
|
2379
|
+
let length2 = 0;
|
|
2380
|
+
for (let i = 1; i < points.length; i++) length2 += Math.hypot(points[i][0] - points[i - 1][0], points[i][1] - points[i - 1][1], points[i][2] - points[i - 1][2]);
|
|
2381
|
+
return length2;
|
|
2382
|
+
}
|
|
2383
|
+
function shapeOf(ratio) {
|
|
2384
|
+
let low = 1e-9;
|
|
2385
|
+
let high = 1;
|
|
2386
|
+
while (Math.sinh(high) / high < ratio && high < 700) high *= 2;
|
|
2387
|
+
for (let i = 0; i < SHAPE_STEPS; i++) {
|
|
2388
|
+
const mid = (low + high) / 2;
|
|
2389
|
+
if (Math.sinh(mid) / mid < ratio) low = mid;
|
|
2390
|
+
else high = mid;
|
|
2391
|
+
}
|
|
2392
|
+
return (low + high) / 2;
|
|
2393
|
+
}
|
|
2394
|
+
function spanStrength(span) {
|
|
2395
|
+
return span.material.ultimateMPa * 1e6 * span.section;
|
|
2396
|
+
}
|
|
2397
|
+
function straight(params, count, weight, chord) {
|
|
2398
|
+
const { span, from, to } = params;
|
|
2399
|
+
const pull = span.material.elasticGPa * 1e9 * span.section * ((chord - span.length) / span.length);
|
|
2400
|
+
const rise = to[1] - from[1];
|
|
2401
|
+
const points = Array.from({ length: count }, (_, i) => {
|
|
2402
|
+
const t = i / (count - 1);
|
|
2403
|
+
return [from[0] + (to[0] - from[0]) * t, from[1] + rise * t, from[2] + (to[2] - from[2]) * t];
|
|
2404
|
+
});
|
|
2405
|
+
return { points, pullFrom: pull + weight * (span.length - rise) / 2, pullTo: pull + weight * (span.length + rise) / 2 };
|
|
2406
|
+
}
|
|
2407
|
+
function loop(params, count, weight) {
|
|
2408
|
+
const { span, from, to } = params;
|
|
2409
|
+
const bottom = (from[1] + to[1] - span.length) / 2;
|
|
2410
|
+
const down = from[1] - bottom;
|
|
2411
|
+
const points = Array.from({ length: count }, (_, i) => {
|
|
2412
|
+
const s = i / (count - 1) * span.length;
|
|
2413
|
+
return s <= down ? [from[0], from[1] - s, from[2]] : [to[0], bottom + (s - down), to[2]];
|
|
2414
|
+
});
|
|
2415
|
+
return { points, pullFrom: weight * down, pullTo: weight * (to[1] - bottom) };
|
|
2416
|
+
}
|
|
2417
|
+
function hanging(params, count, weight, across) {
|
|
2418
|
+
const { span, from, to } = params;
|
|
2419
|
+
const rise = to[1] - from[1];
|
|
2420
|
+
const c = across / (2 * shapeOf(Math.sqrt(span.length * span.length - rise * rise) / across));
|
|
2421
|
+
const x0 = across / 2 - c * Math.atanh(rise / span.length);
|
|
2422
|
+
const base = Math.cosh(-x0 / c);
|
|
2423
|
+
const points = Array.from({ length: count }, (_, i) => {
|
|
2424
|
+
const t = i / (count - 1);
|
|
2425
|
+
return [from[0] + (to[0] - from[0]) * t, from[1] + c * (Math.cosh((across * t - x0) / c) - base), from[2] + (to[2] - from[2]) * t];
|
|
2426
|
+
});
|
|
2427
|
+
return { points, pullFrom: weight * c * base, pullTo: weight * c * Math.cosh((across - x0) / c) };
|
|
2428
|
+
}
|
|
2429
|
+
function solveSpan(params) {
|
|
2430
|
+
const { span, from, to } = params;
|
|
2431
|
+
const count = Math.max(2, Math.floor(params.segments ?? 16));
|
|
2432
|
+
const weight = span.material.density * span.section * GRAVITY;
|
|
2433
|
+
const across = Math.hypot(to[0] - from[0], to[2] - from[2]);
|
|
2434
|
+
const chord = Math.hypot(across, to[1] - from[1]);
|
|
2435
|
+
const taut = chord >= span.length;
|
|
2436
|
+
const shape = taut ? straight(params, count, weight, chord) : across < VERTICAL_SPAN ? loop(params, count, weight) : hanging(params, count, weight, across);
|
|
2437
|
+
const ground = params.ground;
|
|
2438
|
+
if (ground) for (const p of shape.points) p[1] = Math.max(p[1], ground(p[0], p[2]) + (params.clearance ?? 0));
|
|
2439
|
+
const tension = Math.max(shape.pullFrom, shape.pullTo);
|
|
2440
|
+
const snaps = tension > spanStrength(span) ? shape.pullFrom >= shape.pullTo ? "from" : "to" : null;
|
|
2441
|
+
return { points: shape.points, tension, taut, snaps };
|
|
2442
|
+
}
|
|
2443
|
+
function hangTail(params) {
|
|
2444
|
+
const { anchor, length: length2 } = params;
|
|
2445
|
+
const count = Math.max(2, Math.floor(params.segments ?? 16));
|
|
2446
|
+
const clearance = params.clearance ?? 0;
|
|
2447
|
+
const floorAt = (x, z) => params.ground ? params.ground(x, z) + clearance : -Infinity;
|
|
2448
|
+
const drop = Math.max(0, Math.min(length2, anchor[1] - floorAt(anchor[0], anchor[2])));
|
|
2449
|
+
const toward = params.toward ?? [1, 0, 0];
|
|
2450
|
+
const flat = Math.hypot(toward[0], toward[2]) || 1;
|
|
2451
|
+
return Array.from({ length: count }, (_, i) => {
|
|
2452
|
+
const s = i / (count - 1) * length2;
|
|
2453
|
+
if (s <= drop) return [anchor[0], anchor[1] - s, anchor[2]];
|
|
2454
|
+
const x = anchor[0] + toward[0] / flat * (s - drop);
|
|
2455
|
+
const z = anchor[2] + toward[2] / flat * (s - drop);
|
|
2456
|
+
return [x, Math.max(anchor[1] - drop, floorAt(x, z)), z];
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2339
2460
|
// src/fits-volume.ts
|
|
2340
2461
|
function fitsInVolume(size, half) {
|
|
2341
2462
|
const thing = [...size].sort((a, b) => b - a);
|