@adatechnology/game-interactables-three 0.2.16 → 0.2.18

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
@@ -145,6 +145,10 @@ frame. A host that sets `renderer.info.autoReset = false` and resets it itself i
145
145
  `createCord(THREE, points, radius, material)` builds a tube; `catenary(a, b, sag, n)` returns `n` points of a hanging cord whose lowest
146
146
  point is `sag` meters below the chord.
147
147
 
148
+ `wireMeshes(THREE, spec.wires)` draws the wires an object spec leaves to the host (conduit runs, cables, cords, drops): one tube per wire of two
149
+ points or more, named by its id, in the colour of its kind (`WIRE_COLORS`, the houses' colours), radius `WIRE_RADIUS` when the wire gives none.
150
+ Add them to the object's group; a house folds its wires into its own batches instead.
151
+
148
152
  ## Notes
149
153
 
150
154
  - `poseOf` converts the pose math of the interactables package (same defaults) to a quaternion, so the rendered part always matches the engine.
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import * as ThreeNS from 'three';
4
4
  import { PropsApi } from '@adatechnology/game-props3d';
5
5
  import { catenary } from '@adatechnology/game-shapes-three';
6
6
  export { catenary, createCord } from '@adatechnology/game-shapes-three';
7
+ import { ShapeSchema } from '@adatechnology/game-shapes';
7
8
 
8
9
  /** The kinds of particle pool of the effects, as `effects.ts` draws them. */
9
10
  type PoolKind = 'smoke' | 'steam' | 'fire' | 'spark' | 'water';
@@ -127,6 +128,8 @@ interface MeshApiOptions {
127
128
  * volumes (clothes on a line) into one mesh per material (see `mergeParts`). Needs the spec in `finish`. Default: on in `game` quality.
128
129
  */
129
130
  mergeParts?: boolean;
131
+ /** Move the pieces that share a plane with another apart by 2 mm (CLAUDE.md §13, `standOutCoincidentBoxes`). Off by default: it costs about as much as the build itself (shapes-bench); the builders draw their own gaps. */
132
+ standOut?: boolean;
130
133
  /** Idle flutter of merged cloth. Default 0.04. */
131
134
  swayAmplitude?: number;
132
135
  /**
@@ -375,6 +378,13 @@ interface ThreeAdapter {
375
378
  /** Binds the host's `THREE` (and shared options) once, so the rest of the host code never passes it around. */
376
379
  declare function createThreeAdapter(THREE: ThreeLib, options?: ThreeAdapterOptions): ThreeAdapter;
377
380
 
381
+ /**
382
+ * Makes the boxes (and cylinders) of a schema stop sharing planes: when two pieces have a face on one plane, looking the same way and
383
+ * overlapping, the smaller piece's face sinks 2 mm into the piece (or grows 2 mm out when the piece is thinner than 12 mm), CLAUDE.md §13.
384
+ * Mutates the schema's nodes and returns it.
385
+ */
386
+ declare function standOutCoincidentBoxes(schema: ShapeSchema): ShapeSchema;
387
+
378
388
  interface MergeOptions {
379
389
  /** Idle flutter of merged cloth (see `SwayOptions.amplitude`). Default 0.04. */
380
390
  swayAmplitude?: number;
@@ -413,4 +423,12 @@ type MergedGroup = ThreeNS.Group & {
413
423
  */
414
424
  declare function mergeParts(THREE: ThreeLib, root: ThreeNS.Group, parts: Record<string, ThreeNS.Group>, spec: ObjectSpec, options?: MergeOptions): void;
415
425
 
416
- export { type CanvasFactory, type Effects, type EffectsOptions, type EffectsStats, type FinishOptions, type HouseholdApi, MATERIAL_KEYS, type MaterialKey, type MaterialMap, type MergeOptions, type MergedGroup, type MeshApi, type MeshApiOptions, type MeshResult, type MirrorCandidate, type MirrorOptions, type Mirrors, type PerspectiveLike, type PoolKind, type Pose, type PoseBatch, type Quality, type ReflectorConstructor, type Screen, type ScreenOptions, type SwayBatch, type SwayHandle, type SwayOptions, type SwayUniforms, type SyncOptions, type ThreeAdapter, type ThreeAdapterOptions, type ThreeLib, type Vec3, applyPose, attachSway, createDefaultMaterials, createEffects, createMeshApi, createMirrors, createScreen, createThreeAdapter, mergeParts, patchSwayShader, poseOf, rememberRest, swayMaterial, syncObject };
426
+ type Wire = NonNullable<ObjectSpec['wires']>[number];
427
+ /** The colour each kind of wire is drawn in (a grey PVC conduit, a black cable, a dark cord). */
428
+ declare const WIRE_COLORS: Readonly<Record<Wire['kind'], number>>;
429
+ /** Radius a wire is drawn with when its spec gives none, metres. */
430
+ declare const WIRE_RADIUS = 0.006;
431
+ /** One tube per wire with two points or more, named by the wire's id, in the object's own space. */
432
+ declare function wireMeshes(THREE: ThreeLib, wires: ObjectSpec['wires']): ThreeNS.Mesh[];
433
+
434
+ export { type CanvasFactory, type Effects, type EffectsOptions, type EffectsStats, type FinishOptions, type HouseholdApi, MATERIAL_KEYS, type MaterialKey, type MaterialMap, type MergeOptions, type MergedGroup, type MeshApi, type MeshApiOptions, type MeshResult, type MirrorCandidate, type MirrorOptions, type Mirrors, type PerspectiveLike, type PoolKind, type Pose, type PoseBatch, type Quality, type ReflectorConstructor, type Screen, type ScreenOptions, type SwayBatch, type SwayHandle, type SwayOptions, type SwayUniforms, type SyncOptions, type ThreeAdapter, type ThreeAdapterOptions, type ThreeLib, type Vec3, WIRE_COLORS, WIRE_RADIUS, applyPose, attachSway, createDefaultMaterials, createEffects, createMeshApi, createMirrors, createScreen, createThreeAdapter, mergeParts, patchSwayShader, poseOf, rememberRest, standOutCoincidentBoxes, swayMaterial, syncObject, wireMeshes };
@@ -22,6 +22,8 @@ var GameInteractablesThree = (() => {
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
24
  MATERIAL_KEYS: () => MATERIAL_KEYS,
25
+ WIRE_COLORS: () => WIRE_COLORS,
26
+ WIRE_RADIUS: () => WIRE_RADIUS,
25
27
  applyPose: () => applyPose,
26
28
  attachSway: () => attachSway,
27
29
  catenary: () => catenary,
@@ -36,8 +38,10 @@ var GameInteractablesThree = (() => {
36
38
  patchSwayShader: () => patchSwayShader,
37
39
  poseOf: () => poseOf2,
38
40
  rememberRest: () => rememberRest,
41
+ standOutCoincidentBoxes: () => standOutCoincidentBoxes,
39
42
  swayMaterial: () => swayMaterial,
40
- syncObject: () => syncObject
43
+ syncObject: () => syncObject,
44
+ wireMeshes: () => wireMeshes
41
45
  });
42
46
 
43
47
  // ../game-contracts/dist/index.js
@@ -46,15 +50,37 @@ var GameInteractablesThree = (() => {
46
50
  var DEFERRED_QUEUE_ID = {
47
51
  DESTRUCTION_EVENTS: "destruction.events",
48
52
  BREACH_PAINT: "floorplan.breach-paint",
53
+ BREACH_CUT: "floorplan.breach-cut",
49
54
  AUDIO_VOICES: "audio.voices",
50
- VEHICLE_CREASE: "vehicles.crease"
55
+ VEHICLE_CREASE: "vehicles.crease",
56
+ AUDIO_OCCLUSION: "audio.occlusion",
57
+ FLUID_FILM: "fluids.film",
58
+ VEHICLE_LOD_BATCH: "vehicles.lod-batch",
59
+ SETTLED_BATCH: "destruction.settled-batch",
60
+ STATIC_BATCH: "render.static-batch",
61
+ ANIMALS_STATIC_BATCH: "animals.static-batch",
62
+ CHARACTERS_STATIC_BATCH: "characters.static-batch",
63
+ HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
64
+ DESTRUCTION_PREFIT: "destruction.prefit"
51
65
  };
52
66
  var DEFERRED_PRIORITY = {
53
67
  [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
54
- [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
68
+ // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
69
+ [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
70
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
55
71
  [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
56
- [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
72
+ [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
73
+ [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
74
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
75
+ [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
76
+ [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
77
+ [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
78
+ [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
79
+ [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
80
+ [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
81
+ [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
57
82
  };
83
+ var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
58
84
  var WARNED_KEY = /* @__PURE__ */ Symbol.for("@adatechnology/game-contracts.warned");
59
85
  var warnedKeys = () => {
60
86
  const holder = globalThis;
@@ -118,6 +144,22 @@ var GameInteractablesThree = (() => {
118
144
  var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
119
145
  var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
120
146
  var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
147
+ var WORKER_KIND_ID = {
148
+ GROUND_TILES: "destruction.ground-tiles",
149
+ CROWD_PHYSICS: "crowd.physics",
150
+ PIECE_BOXES: "destruction.piece-boxes",
151
+ STATIC_COLLIDERS: "destruction.static-colliders",
152
+ SHAPES_GENERATE: "shapes.generate",
153
+ WORLD_REGION: "world.region"
154
+ };
155
+ var WORKER_KIND_DEFAULTS = {
156
+ [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
157
+ [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
158
+ [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
159
+ [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
160
+ [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
161
+ [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
162
+ };
121
163
 
122
164
  // src/routed-particles.ts
123
165
  var channel = (value) => Math.round(Math.min(1, Math.max(0, value)) * 255);
@@ -822,7 +864,7 @@ void main() {
822
864
  };
823
865
  }
824
866
 
825
- // ../game-shapes/dist/chunk-FZQTELDQ.js
867
+ // ../game-shapes/dist/chunk-E3X7UDDV.js
826
868
  var __defProp2 = Object.defineProperty;
827
869
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
828
870
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -2896,6 +2938,11 @@ void main() {
2896
2938
  };
2897
2939
  }
2898
2940
 
2941
+ // ../game-shapes/dist/index.js
2942
+ var SAME_COLOUR = 1 / 512;
2943
+ var SAME_FACING = 1 - 1e-6;
2944
+ var PARALLEL = Math.cos(2 * Math.PI / 180);
2945
+
2899
2946
  // ../game-shapes-three/dist/index.js
2900
2947
  function catenary(a, b, sag, n = 12) {
2901
2948
  const count = Math.max(2, Math.floor(n));
@@ -3014,14 +3061,14 @@ void main() {
3014
3061
  const normals = [];
3015
3062
  const uvs = [];
3016
3063
  const indices = [];
3017
- for (const side of [1, -1]) {
3064
+ for (const side2 of [1, -1]) {
3018
3065
  const base = positions.length / 3;
3019
3066
  for (let i = 0; i < 4; i++) {
3020
3067
  positions.push(f[i * 3], f[i * 3 + 1], f[i * 3 + 2]);
3021
- normals.push(0, 0, side);
3068
+ normals.push(0, 0, side2);
3022
3069
  uvs.push(f[i * 3] + 0.5, f[i * 3 + 1]);
3023
3070
  }
3024
- if (side === 1) indices.push(base, base + 2, base + 1, base + 1, base + 2, base + 3);
3071
+ if (side2 === 1) indices.push(base, base + 2, base + 1, base + 1, base + 2, base + 3);
3025
3072
  else indices.push(base, base + 1, base + 2, base + 1, base + 3, base + 2);
3026
3073
  }
3027
3074
  return { positions, normals, uvs, indices };
@@ -3475,6 +3522,249 @@ ${QROT}${shader.vertexShader}`;
3475
3522
  return map.get(id) ?? 0;
3476
3523
  }
3477
3524
 
3525
+ // src/stand-out.ts
3526
+ var GAP = 2e-3;
3527
+ var SAME_PLANE = 105e-5;
3528
+ var SAME_DIRECTION = 15e-4;
3529
+ var MIN_OVERLAP_AREA = 5e-5;
3530
+ var MIN_THICKNESS_TO_SINK = 0.012;
3531
+ var MAX_ROUNDS = 6;
3532
+ var IDENTITY = [1, 0, 0, 0, 1, 0, 0, 0, 1];
3533
+ var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
3534
+ var cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
3535
+ function multiply2(a, b) {
3536
+ const out = [];
3537
+ for (let row = 0; row < 3; row++) for (let column = 0; column < 3; column++) out.push(a[row * 3] * b[column] + a[row * 3 + 1] * b[3 + column] + a[row * 3 + 2] * b[6 + column]);
3538
+ return out;
3539
+ }
3540
+ function rotationAbout(axis, angle) {
3541
+ const c = Math.cos(angle);
3542
+ const s = Math.sin(angle);
3543
+ if (axis === 0) return [1, 0, 0, 0, c, -s, 0, s, c];
3544
+ if (axis === 1) return [c, 0, s, 0, 1, 0, -s, 0, c];
3545
+ return [c, -s, 0, s, c, 0, 0, 0, 1];
3546
+ }
3547
+ function rotationOf(node) {
3548
+ let matrix = node.heading ? rotationAbout(1, node.heading) : IDENTITY;
3549
+ if (node.rotation) {
3550
+ for (const letter of node.rotationOrder ?? "XYZ") matrix = multiply2(matrix, rotationAbout("XYZ".indexOf(letter), node.rotation["XYZ".indexOf(letter)]));
3551
+ }
3552
+ return matrix;
3553
+ }
3554
+ function apply(matrix, vector) {
3555
+ return [0, 1, 2].map((row) => matrix[row * 3] * vector[0] + matrix[row * 3 + 1] * vector[1] + matrix[row * 3 + 2] * vector[2]);
3556
+ }
3557
+ function transpose(matrix) {
3558
+ return [matrix[0], matrix[3], matrix[6], matrix[1], matrix[4], matrix[7], matrix[2], matrix[5], matrix[8]];
3559
+ }
3560
+ function pieceOf(node, parentOrigin, parentRotation) {
3561
+ if (node.matrix || node.size || !Array.isArray(node.scale) || !node.position) return void 0;
3562
+ const isCylinder = node.kind === "cylinder";
3563
+ const isPlane = node.kind === "plane";
3564
+ if (isCylinder && (node.radiusTop ?? 1) !== (node.radiusBottom ?? 1)) return void 0;
3565
+ const rotation = multiply2(parentRotation, rotationOf(node));
3566
+ const axes = [0, 1, 2].map((column) => [rotation[column], rotation[3 + column], rotation[6 + column]]);
3567
+ const half = isCylinder ? [node.scale[0], node.scale[1] / 2, node.scale[2]] : isPlane ? [node.scale[0] / 2, node.scale[1] / 2, 0] : [node.scale[0] / 2, node.scale[1] / 2, node.scale[2] / 2];
3568
+ const offset = apply(parentRotation, node.position);
3569
+ return { node, parentRotation, center: [parentOrigin[0] + offset[0], parentOrigin[1] + offset[1], parentOrigin[2] + offset[2]], axes, half, isCylinder, isPlane };
3570
+ }
3571
+ function collect(nodes, origin, rotation, out) {
3572
+ for (const source of nodes) {
3573
+ const node = source;
3574
+ if (node.kind === "group") {
3575
+ if (node.matrix || node.scale !== void 0) continue;
3576
+ const offset = apply(rotation, node.position ?? [0, 0, 0]);
3577
+ collect(node.children ?? [], [origin[0] + offset[0], origin[1] + offset[1], origin[2] + offset[2]], multiply2(rotation, rotationOf(node)), out);
3578
+ } else if (node.kind === "box" || node.kind === "cylinder" || node.kind === "plane") {
3579
+ const piece = pieceOf(node, origin, rotation);
3580
+ if (piece) out.push(piece);
3581
+ }
3582
+ }
3583
+ }
3584
+ function faceOf(piece, axis, sign2) {
3585
+ const normal = [piece.axes[axis][0] * sign2, piece.axes[axis][1] * sign2, piece.axes[axis][2] * sign2];
3586
+ return { piece, axis, sign: sign2, normal, offset: dot(normal, piece.center) + piece.half[axis] };
3587
+ }
3588
+ function facesOf(piece) {
3589
+ if (piece.isPlane) return [faceOf(piece, 2, 1)];
3590
+ return (piece.isCylinder ? [1] : [0, 1, 2]).flatMap((axis) => [faceOf(piece, axis, 1), faceOf(piece, axis, -1)]);
3591
+ }
3592
+ function cornersOf(face, u, v) {
3593
+ const { piece, axis } = face;
3594
+ const [first, second] = [0, 1, 2].filter((other) => other !== axis);
3595
+ return [[1, 1], [1, -1], [-1, -1], [-1, 1]].map(([a, b]) => {
3596
+ const point = [0, 1, 2].map((k) => piece.center[k] + piece.axes[first][k] * piece.half[first] * a + piece.axes[second][k] * piece.half[second] * b);
3597
+ return [dot(point, u), dot(point, v)];
3598
+ });
3599
+ }
3600
+ var side = (p, a, b) => (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]);
3601
+ function overlapArea(subject, clip) {
3602
+ let output = subject;
3603
+ const orientation = Math.sign(side(clip[2], clip[0], clip[1])) || 1;
3604
+ for (let i = 0; i < clip.length && output.length; i++) {
3605
+ const a = clip[i];
3606
+ const b = clip[(i + 1) % clip.length];
3607
+ const input = output;
3608
+ output = [];
3609
+ for (let j = 0; j < input.length; j++) {
3610
+ const current = input[j];
3611
+ const previous = input[(j + input.length - 1) % input.length];
3612
+ const currentInside = side(current, a, b) * orientation >= 0;
3613
+ if (currentInside !== side(previous, a, b) * orientation >= 0) {
3614
+ const t = side(previous, a, b) / (side(previous, a, b) - side(current, a, b));
3615
+ output.push([previous[0] + (current[0] - previous[0]) * t, previous[1] + (current[1] - previous[1]) * t]);
3616
+ }
3617
+ if (currentInside) output.push(current);
3618
+ }
3619
+ }
3620
+ let area3 = 0;
3621
+ for (let i = 0; i < output.length; i++) {
3622
+ const p = output[i];
3623
+ const q = output[(i + 1) % output.length];
3624
+ area3 += p[0] * q[1] - q[0] * p[1];
3625
+ }
3626
+ return Math.abs(area3) / 2;
3627
+ }
3628
+ function planeBasis(normal) {
3629
+ const side2 = cross(normal, Math.abs(normal[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0]);
3630
+ const length = Math.hypot(...side2);
3631
+ const u = [side2[0] / length, side2[1] / length, side2[2] / length];
3632
+ return [u, cross(normal, u)];
3633
+ }
3634
+ function faceReach(face, k) {
3635
+ const { piece, axis } = face;
3636
+ let reach = 0;
3637
+ for (let other = 0; other < 3; other++) if (other !== axis) reach += Math.abs(piece.axes[other][k]) * piece.half[other];
3638
+ return reach;
3639
+ }
3640
+ function facesNear(a, b, slack = SAME_PLANE) {
3641
+ for (let k = 0; k < 3; k++) {
3642
+ const centreA = a.piece.center[k] + a.normal[k] * a.piece.half[a.axis];
3643
+ const centreB = b.piece.center[k] + b.normal[k] * b.piece.half[b.axis];
3644
+ if (Math.abs(centreA - centreB) > faceReach(a, k) + faceReach(b, k) + slack) return false;
3645
+ }
3646
+ return true;
3647
+ }
3648
+ function fight(a, b) {
3649
+ if (Math.abs(a.offset - b.offset) > SAME_PLANE) return false;
3650
+ if ([0, 1, 2].some((k) => Math.abs(a.normal[k] - b.normal[k]) > SAME_DIRECTION)) return false;
3651
+ if (!facesNear(a, b)) return false;
3652
+ const [u, v] = planeBasis(a.normal);
3653
+ return overlapArea(cornersOf(a, u, v), cornersOf(b, u, v)) > MIN_OVERLAP_AREA;
3654
+ }
3655
+ function moveFace(face, amount) {
3656
+ const { piece, axis } = face;
3657
+ const scale = piece.node.scale;
3658
+ if (!piece.isPlane) {
3659
+ scale[axis] = scale[axis] + amount;
3660
+ piece.half[axis] = piece.half[axis] + amount / 2;
3661
+ }
3662
+ const shift = face.normal.map((component) => component * amount / (piece.isPlane ? 1 : 2));
3663
+ for (let k = 0; k < 3; k++) piece.center[k] = piece.center[k] + shift[k];
3664
+ const inParent = apply(transpose(piece.parentRotation), shift);
3665
+ const position = piece.node.position;
3666
+ for (let k = 0; k < 3; k++) position[k] = position[k] + inParent[k];
3667
+ }
3668
+ var DIRECTION_SPAN = 2048;
3669
+ var directionKey = (normal) => ((Math.round(normal[0] / SAME_DIRECTION) + DIRECTION_SPAN / 2) * DIRECTION_SPAN + Math.round(normal[1] / SAME_DIRECTION) + DIRECTION_SPAN / 2) * DIRECTION_SPAN + Math.round(normal[2] / SAME_DIRECTION) + DIRECTION_SPAN / 2;
3670
+ function groupFaces(pieces) {
3671
+ const groups = /* @__PURE__ */ new Map();
3672
+ for (const piece of pieces) {
3673
+ for (const face of facesOf(piece)) {
3674
+ const key = directionKey(face.normal);
3675
+ const group = groups.get(key);
3676
+ if (group) group.push(face);
3677
+ else groups.set(key, [face]);
3678
+ }
3679
+ }
3680
+ return groups;
3681
+ }
3682
+ var liveFace = (face) => faceOf(face.piece, face.axis, face.sign);
3683
+ function clearFace(face, groups) {
3684
+ const { piece, axis, sign: sign2 } = face;
3685
+ const thick = piece.half[axis] * 2 >= MIN_THICKNESS_TO_SINK;
3686
+ const steps = piece.isPlane ? [GAP, 2 * GAP, 3 * GAP] : [GAP, -GAP, 2 * GAP, -2 * GAP].map((step) => thick ? -step : step);
3687
+ const fits = (step) => piece.isPlane || piece.half[axis] * 2 + step >= 2 * GAP;
3688
+ const reach = 2 * GAP * 3 + 2 * SAME_PLANE;
3689
+ const neighbours = (groups.get(directionKey(face.normal)) ?? []).filter((candidate) => candidate.piece !== piece && Math.abs(candidate.offset - face.offset) <= reach && facesNear(face, candidate, reach));
3690
+ const clear = () => {
3691
+ const moved = faceOf(piece, axis, sign2);
3692
+ return neighbours.every((candidate) => !fight(moved, liveFace(candidate)));
3693
+ };
3694
+ let applied = 0;
3695
+ for (const step of steps.filter(fits)) {
3696
+ moveFace(face, step - applied);
3697
+ applied = step;
3698
+ if (clear()) return;
3699
+ }
3700
+ moveFace(face, steps[0] - applied);
3701
+ }
3702
+ function separateRadii(a, b) {
3703
+ if (!a.isCylinder || !b.isCylinder || Math.abs(dot(a.axes[1], b.axes[1])) < 0.9999) return false;
3704
+ const between = [b.center[0] - a.center[0], b.center[1] - a.center[1], b.center[2] - a.center[2]];
3705
+ const along = dot(between, a.axes[1]);
3706
+ if (Math.hypot(between[0] - a.axes[1][0] * along, between[1] - a.axes[1][1] * along, between[2] - a.axes[1][2] * along) > SAME_PLANE) return false;
3707
+ if (Math.abs(along) > a.half[1] + b.half[1] - 5e-3 || Math.abs(a.half[0] - b.half[0]) > SAME_PLANE * 1.1) return false;
3708
+ const [mover, other] = volumeOf(a) < volumeOf(b) ? [a, b] : [b, a];
3709
+ const amount = mover.half[0] >= other.half[0] ? GAP : -GAP;
3710
+ const scale = mover.node.scale;
3711
+ scale[0] = scale[0] + amount;
3712
+ scale[2] = scale[2] + amount;
3713
+ mover.half[0] += amount;
3714
+ mover.half[2] += amount;
3715
+ return true;
3716
+ }
3717
+ var volumeOf = (piece) => piece.half[0] * piece.half[1] * piece.half[2];
3718
+ function forEachPlaneMate(groups, visit) {
3719
+ for (const group of groups.values()) {
3720
+ if (group.length < 2) continue;
3721
+ group.sort((a, b) => a.offset - b.offset);
3722
+ for (let i = 0; i < group.length; i++) {
3723
+ const a = group[i];
3724
+ for (let j = i + 1; j < group.length && group[j].offset - a.offset <= 2 * SAME_PLANE; j++) {
3725
+ if (group[j].piece !== a.piece) visit(a, group[j]);
3726
+ }
3727
+ }
3728
+ }
3729
+ }
3730
+ function separateAllRadii(cylinders, moved) {
3731
+ for (let i = 0; i < cylinders.length; i++) {
3732
+ for (let j = i + 1; j < cylinders.length; j++) {
3733
+ const a = cylinders[i];
3734
+ const b = cylinders[j];
3735
+ const reach = Math.max(a.half[0], a.half[1]) + Math.max(b.half[0], b.half[1]) + 0.01;
3736
+ if (Math.abs(a.center[0] - b.center[0]) > reach || Math.abs(a.center[1] - b.center[1]) > reach || Math.abs(a.center[2] - b.center[2]) > reach) continue;
3737
+ if (separateRadii(a, b)) {
3738
+ moved.add(a);
3739
+ moved.add(b);
3740
+ }
3741
+ }
3742
+ }
3743
+ }
3744
+ function standOutCoincidentBoxes(schema) {
3745
+ const pieces = [];
3746
+ collect(schema.root.children ?? [], [0, 0, 0], IDENTITY, pieces);
3747
+ const cylinders = pieces.filter((piece) => piece.isCylinder);
3748
+ let movedLast;
3749
+ for (let round = 0; round < MAX_ROUNDS; round++) {
3750
+ const movedNow = /* @__PURE__ */ new Set();
3751
+ separateAllRadii(cylinders, movedNow);
3752
+ const groups = groupFaces(pieces);
3753
+ forEachPlaneMate(groups, (first, second) => {
3754
+ if (movedLast && !movedLast.has(first.piece) && !movedLast.has(second.piece)) return;
3755
+ const a = liveFace(first);
3756
+ const b = liveFace(second);
3757
+ if (!fight(a, b)) return;
3758
+ const mover = volumeOf(a.piece) < volumeOf(b.piece) ? a : b;
3759
+ clearFace(mover, groups);
3760
+ movedNow.add(mover.piece);
3761
+ });
3762
+ if (!movedNow.size) break;
3763
+ movedLast = movedNow;
3764
+ }
3765
+ return schema;
3766
+ }
3767
+
3478
3768
  // src/mesh.ts
3479
3769
  function createDefaultMaterials(THREE, quality = "high") {
3480
3770
  const defined = (o) => {
@@ -3572,7 +3862,7 @@ ${QROT}${shader.vertexShader}`;
3572
3862
  const materialFor = finishOptions?.materialFor ?? options.materialFor;
3573
3863
  if (finished) throw new Error("createMeshApi: finish() was already called");
3574
3864
  finished = true;
3575
- const buffers = generate(recorder.schema(), {
3865
+ const buffers = generate(options.standOut === true ? standOutCoincidentBoxes(recorder.schema()) : recorder.schema(), {
3576
3866
  colors: colorSpaceOf(THREE),
3577
3867
  materials: MATERIAL_KEYS,
3578
3868
  fallbackMaterial: "plain",
@@ -3840,12 +4130,12 @@ ${QROT}${shader.vertexShader}`;
3840
4130
  }
3841
4131
  texture.needsUpdate = true;
3842
4132
  };
3843
- const apply = () => {
4133
+ const apply2 = () => {
3844
4134
  material.emissiveIntensity = on ? intensity : 0;
3845
4135
  material.color.setHex(on ? 1118481 : 0);
3846
4136
  draw();
3847
4137
  };
3848
- apply();
4138
+ apply2();
3849
4139
  return {
3850
4140
  material,
3851
4141
  texture,
@@ -3859,7 +4149,7 @@ ${QROT}${shader.vertexShader}`;
3859
4149
  setOn(value) {
3860
4150
  on = !!value;
3861
4151
  acc = 0;
3862
- apply();
4152
+ apply2();
3863
4153
  },
3864
4154
  setChannel(n) {
3865
4155
  channel2 = Math.max(0, Math.floor(n));
@@ -3977,6 +4267,21 @@ uniform float swayAmplitude;
3977
4267
  catenary
3978
4268
  };
3979
4269
  }
4270
+
4271
+ // src/wires.ts
4272
+ var WIRE_COLORS = { conduit: 13618628, cable: 2762532, drop: 1381653, cord: 1776413 };
4273
+ var WIRE_RADIUS = 6e-3;
4274
+ function wireMeshes(THREE, wires) {
4275
+ const meshes = [];
4276
+ for (const wire of wires ?? []) {
4277
+ if (wire.points.length < 2) continue;
4278
+ const material = new THREE.MeshStandardMaterial({ color: WIRE_COLORS[wire.kind], roughness: 0.8 });
4279
+ const mesh2 = createCord(THREE, wire.points, wire.radius ?? WIRE_RADIUS, material);
4280
+ mesh2.name = wire.id;
4281
+ meshes.push(mesh2);
4282
+ }
4283
+ return meshes;
4284
+ }
3980
4285
  return __toCommonJS(index_exports);
3981
4286
  })();
3982
4287
  //# sourceMappingURL=index.global.js.map