@adatechnology/game-interactables 0.9.0 → 0.10.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 CHANGED
@@ -201,6 +201,10 @@ straight past its length it stretches as its material does (E·A·strain, `elast
201
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
202
  after it snapped. `createSpanWire` of game-interactables-three draws it.
203
203
 
204
+ A wire fixed along what it runs on (a conduit strapped up a pole, an earth cable clipped down it) is laid with `wireRuns({ points, step, holderOf })`: the
205
+ runs of the wire by the part under each stretch of it, two runs that follow each other sharing the point at the seam. Whole they read as one wire; when the
206
+ parts come apart each run goes with its own and the wire is broken at the seam.
207
+
204
208
  ## Português
205
209
 
206
210
  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
@@ -1139,6 +1139,21 @@ type HangTailParams = {
1139
1139
  /** Straight down from its anchor to the ground, and the rest of its length lying along the ground toward `toward`. */
1140
1140
  declare function hangTail(params: HangTailParams): Vec3[];
1141
1141
 
1142
+ /** One stretch of a wire and what holds it. */
1143
+ type WireRun<THolder> = {
1144
+ readonly holder: THolder;
1145
+ readonly points: Vec3[];
1146
+ };
1147
+ type WireRunsParams<THolder> = {
1148
+ readonly points: readonly Vec3[];
1149
+ /** Longest step (metres) between two points the holder is read at: where the holder changes is found within it. */
1150
+ readonly step: number;
1151
+ /** What holds the wire at a point (the part it is fixed on there). */
1152
+ readonly holderOf: (point: Vec3) => THolder;
1153
+ };
1154
+ /** The runs of a wire by what holds it, in order along it; two runs that follow each other share the point half way between their last and first readings. */
1155
+ declare function wireRuns<THolder>(params: WireRunsParams<THolder>): WireRun<THolder>[];
1156
+
1142
1157
  /**
1143
1158
  * 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
1144
1159
  * 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
@@ -1197,4 +1212,4 @@ declare function createObjectControls(options: ObjectControlsOptions): ObjectCon
1197
1212
  /** 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. */
1198
1213
  declare function fitsInVolume(size: readonly [number, number, number], half: Vec3): boolean;
1199
1214
 
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 };
1215
+ 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 WireRun, type WireRunsParams, 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, wireRuns, worldToLocal };
@@ -50,6 +50,7 @@ var GameInteractables = (() => {
50
50
  rotateAxis: () => rotateAxis,
51
51
  solveSpan: () => solveSpan,
52
52
  spanStrength: () => spanStrength,
53
+ wireRuns: () => wireRuns,
53
54
  worldToLocal: () => worldToLocal
54
55
  });
55
56
 
@@ -2457,6 +2458,38 @@ var GameInteractables = (() => {
2457
2458
  });
2458
2459
  }
2459
2460
 
2461
+ // src/wire-runs.ts
2462
+ var lerp = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
2463
+ function along(points, step) {
2464
+ const out = points.length ? [[...points[0]]] : [];
2465
+ for (let i = 1; i < points.length; i++) {
2466
+ const a = points[i - 1];
2467
+ const b = points[i];
2468
+ const steps = Math.max(1, Math.ceil(Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]) / step));
2469
+ for (let k = 1; k <= steps; k++) out.push(lerp(a, b, k / steps));
2470
+ }
2471
+ return out;
2472
+ }
2473
+ function wireRuns(params) {
2474
+ const points = along(params.points, Math.max(1e-3, params.step));
2475
+ if (points.length < 2) return [];
2476
+ const holders = points.map((p) => params.holderOf(p));
2477
+ const runs = [];
2478
+ let current = { holder: holders[0], points: [points[0]] };
2479
+ for (let i = 1; i < points.length; i++) {
2480
+ if (holders[i] === current.holder) {
2481
+ current.points.push(points[i]);
2482
+ continue;
2483
+ }
2484
+ const seam = lerp(points[i - 1], points[i], 0.5);
2485
+ current.points.push(seam);
2486
+ runs.push(current);
2487
+ current = { holder: holders[i], points: [[...seam], points[i]] };
2488
+ }
2489
+ runs.push(current);
2490
+ return runs;
2491
+ }
2492
+
2460
2493
  // src/fits-volume.ts
2461
2494
  function fitsInVolume(size, half) {
2462
2495
  const thing = [...size].sort((a, b) => b - a);