@adatechnology/game-interactables-three 0.2.15 → 0.2.17

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 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,4 @@ 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
+ 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, standOutCoincidentBoxes, swayMaterial, syncObject };
@@ -36,6 +36,7 @@ var GameInteractablesThree = (() => {
36
36
  patchSwayShader: () => patchSwayShader,
37
37
  poseOf: () => poseOf2,
38
38
  rememberRest: () => rememberRest,
39
+ standOutCoincidentBoxes: () => standOutCoincidentBoxes,
39
40
  swayMaterial: () => swayMaterial,
40
41
  syncObject: () => syncObject
41
42
  });
@@ -46,15 +47,37 @@ var GameInteractablesThree = (() => {
46
47
  var DEFERRED_QUEUE_ID = {
47
48
  DESTRUCTION_EVENTS: "destruction.events",
48
49
  BREACH_PAINT: "floorplan.breach-paint",
50
+ BREACH_CUT: "floorplan.breach-cut",
49
51
  AUDIO_VOICES: "audio.voices",
50
- VEHICLE_CREASE: "vehicles.crease"
52
+ VEHICLE_CREASE: "vehicles.crease",
53
+ AUDIO_OCCLUSION: "audio.occlusion",
54
+ FLUID_FILM: "fluids.film",
55
+ VEHICLE_LOD_BATCH: "vehicles.lod-batch",
56
+ SETTLED_BATCH: "destruction.settled-batch",
57
+ STATIC_BATCH: "render.static-batch",
58
+ ANIMALS_STATIC_BATCH: "animals.static-batch",
59
+ CHARACTERS_STATIC_BATCH: "characters.static-batch",
60
+ HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
61
+ DESTRUCTION_PREFIT: "destruction.prefit"
51
62
  };
52
63
  var DEFERRED_PRIORITY = {
53
64
  [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
54
- [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
65
+ // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
66
+ [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
67
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
55
68
  [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
56
- [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
69
+ [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
70
+ [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
71
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
72
+ [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
73
+ [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
74
+ [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
75
+ [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
76
+ [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
77
+ [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
78
+ [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
57
79
  };
80
+ var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
58
81
  var WARNED_KEY = /* @__PURE__ */ Symbol.for("@adatechnology/game-contracts.warned");
59
82
  var warnedKeys = () => {
60
83
  const holder = globalThis;
@@ -118,6 +141,22 @@ var GameInteractablesThree = (() => {
118
141
  var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
119
142
  var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
120
143
  var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
144
+ var WORKER_KIND_ID = {
145
+ GROUND_TILES: "destruction.ground-tiles",
146
+ CROWD_PHYSICS: "crowd.physics",
147
+ PIECE_BOXES: "destruction.piece-boxes",
148
+ STATIC_COLLIDERS: "destruction.static-colliders",
149
+ SHAPES_GENERATE: "shapes.generate",
150
+ WORLD_REGION: "world.region"
151
+ };
152
+ var WORKER_KIND_DEFAULTS = {
153
+ [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
154
+ [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
155
+ [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
156
+ [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
157
+ [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
158
+ [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
159
+ };
121
160
 
122
161
  // src/routed-particles.ts
123
162
  var channel = (value) => Math.round(Math.min(1, Math.max(0, value)) * 255);
@@ -822,7 +861,7 @@ void main() {
822
861
  };
823
862
  }
824
863
 
825
- // ../game-shapes/dist/chunk-FZQTELDQ.js
864
+ // ../game-shapes/dist/chunk-E3X7UDDV.js
826
865
  var __defProp2 = Object.defineProperty;
827
866
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
828
867
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -2896,6 +2935,11 @@ void main() {
2896
2935
  };
2897
2936
  }
2898
2937
 
2938
+ // ../game-shapes/dist/index.js
2939
+ var SAME_COLOUR = 1 / 512;
2940
+ var SAME_FACING = 1 - 1e-6;
2941
+ var PARALLEL = Math.cos(2 * Math.PI / 180);
2942
+
2899
2943
  // ../game-shapes-three/dist/index.js
2900
2944
  function catenary(a, b, sag, n = 12) {
2901
2945
  const count = Math.max(2, Math.floor(n));
@@ -3014,14 +3058,14 @@ void main() {
3014
3058
  const normals = [];
3015
3059
  const uvs = [];
3016
3060
  const indices = [];
3017
- for (const side of [1, -1]) {
3061
+ for (const side2 of [1, -1]) {
3018
3062
  const base = positions.length / 3;
3019
3063
  for (let i = 0; i < 4; i++) {
3020
3064
  positions.push(f[i * 3], f[i * 3 + 1], f[i * 3 + 2]);
3021
- normals.push(0, 0, side);
3065
+ normals.push(0, 0, side2);
3022
3066
  uvs.push(f[i * 3] + 0.5, f[i * 3 + 1]);
3023
3067
  }
3024
- if (side === 1) indices.push(base, base + 2, base + 1, base + 1, base + 2, base + 3);
3068
+ if (side2 === 1) indices.push(base, base + 2, base + 1, base + 1, base + 2, base + 3);
3025
3069
  else indices.push(base, base + 1, base + 2, base + 1, base + 3, base + 2);
3026
3070
  }
3027
3071
  return { positions, normals, uvs, indices };
@@ -3475,6 +3519,249 @@ ${QROT}${shader.vertexShader}`;
3475
3519
  return map.get(id) ?? 0;
3476
3520
  }
3477
3521
 
3522
+ // src/stand-out.ts
3523
+ var GAP = 2e-3;
3524
+ var SAME_PLANE = 105e-5;
3525
+ var SAME_DIRECTION = 15e-4;
3526
+ var MIN_OVERLAP_AREA = 5e-5;
3527
+ var MIN_THICKNESS_TO_SINK = 0.012;
3528
+ var MAX_ROUNDS = 6;
3529
+ var IDENTITY = [1, 0, 0, 0, 1, 0, 0, 0, 1];
3530
+ var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
3531
+ 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]];
3532
+ function multiply2(a, b) {
3533
+ const out = [];
3534
+ 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]);
3535
+ return out;
3536
+ }
3537
+ function rotationAbout(axis, angle) {
3538
+ const c = Math.cos(angle);
3539
+ const s = Math.sin(angle);
3540
+ if (axis === 0) return [1, 0, 0, 0, c, -s, 0, s, c];
3541
+ if (axis === 1) return [c, 0, s, 0, 1, 0, -s, 0, c];
3542
+ return [c, -s, 0, s, c, 0, 0, 0, 1];
3543
+ }
3544
+ function rotationOf(node) {
3545
+ let matrix = node.heading ? rotationAbout(1, node.heading) : IDENTITY;
3546
+ if (node.rotation) {
3547
+ for (const letter of node.rotationOrder ?? "XYZ") matrix = multiply2(matrix, rotationAbout("XYZ".indexOf(letter), node.rotation["XYZ".indexOf(letter)]));
3548
+ }
3549
+ return matrix;
3550
+ }
3551
+ function apply(matrix, vector) {
3552
+ return [0, 1, 2].map((row) => matrix[row * 3] * vector[0] + matrix[row * 3 + 1] * vector[1] + matrix[row * 3 + 2] * vector[2]);
3553
+ }
3554
+ function transpose(matrix) {
3555
+ return [matrix[0], matrix[3], matrix[6], matrix[1], matrix[4], matrix[7], matrix[2], matrix[5], matrix[8]];
3556
+ }
3557
+ function pieceOf(node, parentOrigin, parentRotation) {
3558
+ if (node.matrix || node.size || !Array.isArray(node.scale) || !node.position) return void 0;
3559
+ const isCylinder = node.kind === "cylinder";
3560
+ const isPlane = node.kind === "plane";
3561
+ if (isCylinder && (node.radiusTop ?? 1) !== (node.radiusBottom ?? 1)) return void 0;
3562
+ const rotation = multiply2(parentRotation, rotationOf(node));
3563
+ const axes = [0, 1, 2].map((column) => [rotation[column], rotation[3 + column], rotation[6 + column]]);
3564
+ 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];
3565
+ const offset = apply(parentRotation, node.position);
3566
+ return { node, parentRotation, center: [parentOrigin[0] + offset[0], parentOrigin[1] + offset[1], parentOrigin[2] + offset[2]], axes, half, isCylinder, isPlane };
3567
+ }
3568
+ function collect(nodes, origin, rotation, out) {
3569
+ for (const source of nodes) {
3570
+ const node = source;
3571
+ if (node.kind === "group") {
3572
+ if (node.matrix || node.scale !== void 0) continue;
3573
+ const offset = apply(rotation, node.position ?? [0, 0, 0]);
3574
+ collect(node.children ?? [], [origin[0] + offset[0], origin[1] + offset[1], origin[2] + offset[2]], multiply2(rotation, rotationOf(node)), out);
3575
+ } else if (node.kind === "box" || node.kind === "cylinder" || node.kind === "plane") {
3576
+ const piece = pieceOf(node, origin, rotation);
3577
+ if (piece) out.push(piece);
3578
+ }
3579
+ }
3580
+ }
3581
+ function faceOf(piece, axis, sign2) {
3582
+ const normal = [piece.axes[axis][0] * sign2, piece.axes[axis][1] * sign2, piece.axes[axis][2] * sign2];
3583
+ return { piece, axis, sign: sign2, normal, offset: dot(normal, piece.center) + piece.half[axis] };
3584
+ }
3585
+ function facesOf(piece) {
3586
+ if (piece.isPlane) return [faceOf(piece, 2, 1)];
3587
+ return (piece.isCylinder ? [1] : [0, 1, 2]).flatMap((axis) => [faceOf(piece, axis, 1), faceOf(piece, axis, -1)]);
3588
+ }
3589
+ function cornersOf(face, u, v) {
3590
+ const { piece, axis } = face;
3591
+ const [first, second] = [0, 1, 2].filter((other) => other !== axis);
3592
+ return [[1, 1], [1, -1], [-1, -1], [-1, 1]].map(([a, b]) => {
3593
+ 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);
3594
+ return [dot(point, u), dot(point, v)];
3595
+ });
3596
+ }
3597
+ var side = (p, a, b) => (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]);
3598
+ function overlapArea(subject, clip) {
3599
+ let output = subject;
3600
+ const orientation = Math.sign(side(clip[2], clip[0], clip[1])) || 1;
3601
+ for (let i = 0; i < clip.length && output.length; i++) {
3602
+ const a = clip[i];
3603
+ const b = clip[(i + 1) % clip.length];
3604
+ const input = output;
3605
+ output = [];
3606
+ for (let j = 0; j < input.length; j++) {
3607
+ const current = input[j];
3608
+ const previous = input[(j + input.length - 1) % input.length];
3609
+ const currentInside = side(current, a, b) * orientation >= 0;
3610
+ if (currentInside !== side(previous, a, b) * orientation >= 0) {
3611
+ const t = side(previous, a, b) / (side(previous, a, b) - side(current, a, b));
3612
+ output.push([previous[0] + (current[0] - previous[0]) * t, previous[1] + (current[1] - previous[1]) * t]);
3613
+ }
3614
+ if (currentInside) output.push(current);
3615
+ }
3616
+ }
3617
+ let area3 = 0;
3618
+ for (let i = 0; i < output.length; i++) {
3619
+ const p = output[i];
3620
+ const q = output[(i + 1) % output.length];
3621
+ area3 += p[0] * q[1] - q[0] * p[1];
3622
+ }
3623
+ return Math.abs(area3) / 2;
3624
+ }
3625
+ function planeBasis(normal) {
3626
+ const side2 = cross(normal, Math.abs(normal[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0]);
3627
+ const length = Math.hypot(...side2);
3628
+ const u = [side2[0] / length, side2[1] / length, side2[2] / length];
3629
+ return [u, cross(normal, u)];
3630
+ }
3631
+ function faceReach(face, k) {
3632
+ const { piece, axis } = face;
3633
+ let reach = 0;
3634
+ for (let other = 0; other < 3; other++) if (other !== axis) reach += Math.abs(piece.axes[other][k]) * piece.half[other];
3635
+ return reach;
3636
+ }
3637
+ function facesNear(a, b, slack = SAME_PLANE) {
3638
+ for (let k = 0; k < 3; k++) {
3639
+ const centreA = a.piece.center[k] + a.normal[k] * a.piece.half[a.axis];
3640
+ const centreB = b.piece.center[k] + b.normal[k] * b.piece.half[b.axis];
3641
+ if (Math.abs(centreA - centreB) > faceReach(a, k) + faceReach(b, k) + slack) return false;
3642
+ }
3643
+ return true;
3644
+ }
3645
+ function fight(a, b) {
3646
+ if (Math.abs(a.offset - b.offset) > SAME_PLANE) return false;
3647
+ if ([0, 1, 2].some((k) => Math.abs(a.normal[k] - b.normal[k]) > SAME_DIRECTION)) return false;
3648
+ if (!facesNear(a, b)) return false;
3649
+ const [u, v] = planeBasis(a.normal);
3650
+ return overlapArea(cornersOf(a, u, v), cornersOf(b, u, v)) > MIN_OVERLAP_AREA;
3651
+ }
3652
+ function moveFace(face, amount) {
3653
+ const { piece, axis } = face;
3654
+ const scale = piece.node.scale;
3655
+ if (!piece.isPlane) {
3656
+ scale[axis] = scale[axis] + amount;
3657
+ piece.half[axis] = piece.half[axis] + amount / 2;
3658
+ }
3659
+ const shift = face.normal.map((component) => component * amount / (piece.isPlane ? 1 : 2));
3660
+ for (let k = 0; k < 3; k++) piece.center[k] = piece.center[k] + shift[k];
3661
+ const inParent = apply(transpose(piece.parentRotation), shift);
3662
+ const position = piece.node.position;
3663
+ for (let k = 0; k < 3; k++) position[k] = position[k] + inParent[k];
3664
+ }
3665
+ var DIRECTION_SPAN = 2048;
3666
+ 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;
3667
+ function groupFaces(pieces) {
3668
+ const groups = /* @__PURE__ */ new Map();
3669
+ for (const piece of pieces) {
3670
+ for (const face of facesOf(piece)) {
3671
+ const key = directionKey(face.normal);
3672
+ const group = groups.get(key);
3673
+ if (group) group.push(face);
3674
+ else groups.set(key, [face]);
3675
+ }
3676
+ }
3677
+ return groups;
3678
+ }
3679
+ var liveFace = (face) => faceOf(face.piece, face.axis, face.sign);
3680
+ function clearFace(face, groups) {
3681
+ const { piece, axis, sign: sign2 } = face;
3682
+ const thick = piece.half[axis] * 2 >= MIN_THICKNESS_TO_SINK;
3683
+ const steps = piece.isPlane ? [GAP, 2 * GAP, 3 * GAP] : [GAP, -GAP, 2 * GAP, -2 * GAP].map((step) => thick ? -step : step);
3684
+ const fits = (step) => piece.isPlane || piece.half[axis] * 2 + step >= 2 * GAP;
3685
+ const reach = 2 * GAP * 3 + 2 * SAME_PLANE;
3686
+ const neighbours = (groups.get(directionKey(face.normal)) ?? []).filter((candidate) => candidate.piece !== piece && Math.abs(candidate.offset - face.offset) <= reach && facesNear(face, candidate, reach));
3687
+ const clear = () => {
3688
+ const moved = faceOf(piece, axis, sign2);
3689
+ return neighbours.every((candidate) => !fight(moved, liveFace(candidate)));
3690
+ };
3691
+ let applied = 0;
3692
+ for (const step of steps.filter(fits)) {
3693
+ moveFace(face, step - applied);
3694
+ applied = step;
3695
+ if (clear()) return;
3696
+ }
3697
+ moveFace(face, steps[0] - applied);
3698
+ }
3699
+ function separateRadii(a, b) {
3700
+ if (!a.isCylinder || !b.isCylinder || Math.abs(dot(a.axes[1], b.axes[1])) < 0.9999) return false;
3701
+ const between = [b.center[0] - a.center[0], b.center[1] - a.center[1], b.center[2] - a.center[2]];
3702
+ const along = dot(between, a.axes[1]);
3703
+ 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;
3704
+ 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;
3705
+ const [mover, other] = volumeOf(a) < volumeOf(b) ? [a, b] : [b, a];
3706
+ const amount = mover.half[0] >= other.half[0] ? GAP : -GAP;
3707
+ const scale = mover.node.scale;
3708
+ scale[0] = scale[0] + amount;
3709
+ scale[2] = scale[2] + amount;
3710
+ mover.half[0] += amount;
3711
+ mover.half[2] += amount;
3712
+ return true;
3713
+ }
3714
+ var volumeOf = (piece) => piece.half[0] * piece.half[1] * piece.half[2];
3715
+ function forEachPlaneMate(groups, visit) {
3716
+ for (const group of groups.values()) {
3717
+ if (group.length < 2) continue;
3718
+ group.sort((a, b) => a.offset - b.offset);
3719
+ for (let i = 0; i < group.length; i++) {
3720
+ const a = group[i];
3721
+ for (let j = i + 1; j < group.length && group[j].offset - a.offset <= 2 * SAME_PLANE; j++) {
3722
+ if (group[j].piece !== a.piece) visit(a, group[j]);
3723
+ }
3724
+ }
3725
+ }
3726
+ }
3727
+ function separateAllRadii(cylinders, moved) {
3728
+ for (let i = 0; i < cylinders.length; i++) {
3729
+ for (let j = i + 1; j < cylinders.length; j++) {
3730
+ const a = cylinders[i];
3731
+ const b = cylinders[j];
3732
+ const reach = Math.max(a.half[0], a.half[1]) + Math.max(b.half[0], b.half[1]) + 0.01;
3733
+ 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;
3734
+ if (separateRadii(a, b)) {
3735
+ moved.add(a);
3736
+ moved.add(b);
3737
+ }
3738
+ }
3739
+ }
3740
+ }
3741
+ function standOutCoincidentBoxes(schema) {
3742
+ const pieces = [];
3743
+ collect(schema.root.children ?? [], [0, 0, 0], IDENTITY, pieces);
3744
+ const cylinders = pieces.filter((piece) => piece.isCylinder);
3745
+ let movedLast;
3746
+ for (let round = 0; round < MAX_ROUNDS; round++) {
3747
+ const movedNow = /* @__PURE__ */ new Set();
3748
+ separateAllRadii(cylinders, movedNow);
3749
+ const groups = groupFaces(pieces);
3750
+ forEachPlaneMate(groups, (first, second) => {
3751
+ if (movedLast && !movedLast.has(first.piece) && !movedLast.has(second.piece)) return;
3752
+ const a = liveFace(first);
3753
+ const b = liveFace(second);
3754
+ if (!fight(a, b)) return;
3755
+ const mover = volumeOf(a.piece) < volumeOf(b.piece) ? a : b;
3756
+ clearFace(mover, groups);
3757
+ movedNow.add(mover.piece);
3758
+ });
3759
+ if (!movedNow.size) break;
3760
+ movedLast = movedNow;
3761
+ }
3762
+ return schema;
3763
+ }
3764
+
3478
3765
  // src/mesh.ts
3479
3766
  function createDefaultMaterials(THREE, quality = "high") {
3480
3767
  const defined = (o) => {
@@ -3572,7 +3859,7 @@ ${QROT}${shader.vertexShader}`;
3572
3859
  const materialFor = finishOptions?.materialFor ?? options.materialFor;
3573
3860
  if (finished) throw new Error("createMeshApi: finish() was already called");
3574
3861
  finished = true;
3575
- const buffers = generate(recorder.schema(), {
3862
+ const buffers = generate(options.standOut === true ? standOutCoincidentBoxes(recorder.schema()) : recorder.schema(), {
3576
3863
  colors: colorSpaceOf(THREE),
3577
3864
  materials: MATERIAL_KEYS,
3578
3865
  fallbackMaterial: "plain",
@@ -3840,12 +4127,12 @@ ${QROT}${shader.vertexShader}`;
3840
4127
  }
3841
4128
  texture.needsUpdate = true;
3842
4129
  };
3843
- const apply = () => {
4130
+ const apply2 = () => {
3844
4131
  material.emissiveIntensity = on ? intensity : 0;
3845
4132
  material.color.setHex(on ? 1118481 : 0);
3846
4133
  draw();
3847
4134
  };
3848
- apply();
4135
+ apply2();
3849
4136
  return {
3850
4137
  material,
3851
4138
  texture,
@@ -3859,7 +4146,7 @@ ${QROT}${shader.vertexShader}`;
3859
4146
  setOn(value) {
3860
4147
  on = !!value;
3861
4148
  acc = 0;
3862
- apply();
4149
+ apply2();
3863
4150
  },
3864
4151
  setChannel(n) {
3865
4152
  channel2 = Math.max(0, Math.floor(n));