@adatechnology/game-urban-three 0.5.1 → 0.5.3
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 +7 -0
- package/dist/{chunk-JTXGLKOL.js → chunk-QS2K4DEO.js} +315 -11
- package/dist/chunk-QS2K4DEO.js.map +1 -0
- package/dist/index.d.ts +35 -2
- package/dist/index.global.js +536 -52
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/testing.js +1 -1
- package/package.json +6 -6
- package/dist/chunk-JTXGLKOL.js.map +0 -1
package/README.md
CHANGED
|
@@ -39,6 +39,13 @@ scene.add(drawn.root)
|
|
|
39
39
|
// each frame: drawn.animate(t); when the camera moved: drawn.setFocus(x, z)
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
|
|
43
|
+
`drawNetworkSurface(networks, { surfaceAt })` draws what shows of the buried networks (`surfacePiecesOf`): PV and gallery box covers flush with the road
|
|
44
|
+
(2 mm over the frame, 2 mm over the lid), the inlets' grates, cleanout and valve covers, hydrants, the outfalls' wing walls, and at each lot the inspection
|
|
45
|
+
cover, the meter box and the downspout's mouth, in two instanced draw calls. `remove(id)` takes a piece off the ground (a cover thrown by a blast).
|
|
46
|
+
`drawBuriedNetworks(networks, { surfaceAt })` draws the pipes (two instanced halves each, so `sever(id, share)` can break one) and the pits under the covers
|
|
47
|
+
at their depths, in three draw calls: the terrain hides them and a crater deeper than their cover shows them.
|
|
48
|
+
|
|
42
49
|
- Each `concrete_distribution` pole (or any registry pole with `slots`) stands at its node, turned with its arm toward its lamp: the mast
|
|
43
50
|
instanced per spec, the hardware of `distributionHardwareOf` (crossarm and pin insulators where it carries medium voltage, the low-voltage
|
|
44
51
|
clamp, one telecom clamp per cable, the arm and luminaire, the transformer's bracket and bushings) one instanced mesh of boxes, the
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { isLightBudget } from "@adatechnology/game-render-three";
|
|
3
3
|
import { discardObject3D } from "@adatechnology/game-shapes-three";
|
|
4
4
|
import { createPlantProvider as createPlantProvider2, createUrban as createUrban2, createVehicleProvider as createVehicleProvider2, SAMPLE_CELLS } from "@adatechnology/game-urban";
|
|
5
|
-
import { shapeGeometries as
|
|
5
|
+
import { shapeGeometries as shapeGeometries8 } from "@adatechnology/game-shapes-three";
|
|
6
6
|
|
|
7
7
|
// src/draw.ts
|
|
8
|
-
import { markKitOrigin as
|
|
8
|
+
import { markKitOrigin as markKitOrigin5 } from "@adatechnology/game-contracts";
|
|
9
9
|
import { LIGHT_PRIORITY as LIGHT_PRIORITY2 } from "@adatechnology/game-render-three";
|
|
10
|
-
import { shapeGeometries as
|
|
10
|
+
import { shapeGeometries as shapeGeometries7, standOutCoincident } from "@adatechnology/game-shapes-three";
|
|
11
11
|
|
|
12
12
|
// src/lamp-light.ts
|
|
13
13
|
var LAMP_FLICKER = { dim: 0.15, fast: 23, slow: 3.1, fastAbove: 0.3, slowAbove: 0.85, groups: 4 };
|
|
@@ -552,6 +552,307 @@ function drawNetworks(THREE, { networks, options, budget, physicalLights }) {
|
|
|
552
552
|
};
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
+
// src/networks/draw-buried.ts
|
|
556
|
+
import { markKitOrigin as markKitOrigin2 } from "@adatechnology/game-contracts";
|
|
557
|
+
import { shapeGeometries as shapeGeometries4 } from "@adatechnology/game-shapes-three";
|
|
558
|
+
import { pipePiecesOf, surfacePiecesOf } from "@adatechnology/game-urban/networks";
|
|
559
|
+
var PIPE_COLOR = { sewage: 12090186, water: 3108014, stormwater: 9342343 };
|
|
560
|
+
var SHAFT_COLOR = { concrete: 9342343, plastic: 12090186, cast_iron: 3882562 };
|
|
561
|
+
var PIPE_SEGMENTS = 8;
|
|
562
|
+
var SHAFT_SEGMENTS = 14;
|
|
563
|
+
var BREAK_GAP = 1.2;
|
|
564
|
+
var FLOOR = 0.1;
|
|
565
|
+
var ROOF_DEPTH = 4e-3;
|
|
566
|
+
function drawBuried(THREE, { networks, root, options }) {
|
|
567
|
+
const T = shapeGeometries4(THREE);
|
|
568
|
+
const group = markKitOrigin2(root ?? new THREE.Group(), { owner: "game-urban-three", kind: "network-buried" });
|
|
569
|
+
const pipes = pipePiecesOf(networks);
|
|
570
|
+
const shafts = surfacePiecesOf(networks, options).flatMap((piece) => piece.shaft === void 0 ? [] : [{ piece, shaft: piece.shaft }]);
|
|
571
|
+
const round2 = shafts.filter(({ shaft }) => shaft.shape === "round");
|
|
572
|
+
const square = shafts.filter(({ shaft }) => shaft.shape === "square");
|
|
573
|
+
const material = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.85 });
|
|
574
|
+
const openMaterial = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.85, side: THREE.DoubleSide });
|
|
575
|
+
const geometries = [new T.CylinderGeometry(1, 1, 1, PIPE_SEGMENTS), new T.CylinderGeometry(1, 1, 1, SHAFT_SEGMENTS, 1, true), new T.BoxGeometry(1, 1, 1)];
|
|
576
|
+
const make = (geometry, count, name, using) => {
|
|
577
|
+
const mesh = new THREE.InstancedMesh(geometry, using, Math.max(count, 1));
|
|
578
|
+
mesh.name = name;
|
|
579
|
+
mesh.count = count;
|
|
580
|
+
mesh.frustumCulled = false;
|
|
581
|
+
return mesh;
|
|
582
|
+
};
|
|
583
|
+
const pipeMesh = make(geometries[0], pipes.length * 2, "network:buried:pipes", material);
|
|
584
|
+
const roundMesh = make(geometries[1], round2.length, "network:buried:shafts", openMaterial);
|
|
585
|
+
const squareMesh = make(geometries[2], square.length, "network:buried:boxes", material);
|
|
586
|
+
const up = new THREE.Vector3(0, 1, 0);
|
|
587
|
+
const matrix = new THREE.Matrix4();
|
|
588
|
+
const color = new THREE.Color();
|
|
589
|
+
const place = (mesh, slot, from, to, radius) => {
|
|
590
|
+
const axis = new THREE.Vector3(to[0] - from[0], to[1] - from[1], to[2] - from[2]);
|
|
591
|
+
const length = axis.length();
|
|
592
|
+
const quaternion = new THREE.Quaternion().setFromUnitVectors(up, length === 0 ? up : axis.clone().normalize());
|
|
593
|
+
mesh.setMatrixAt(slot, matrix.compose(new THREE.Vector3((from[0] + to[0]) / 2, (from[1] + to[1]) / 2, (from[2] + to[2]) / 2), quaternion, new THREE.Vector3(radius, length, radius)));
|
|
594
|
+
};
|
|
595
|
+
const along = (pipe, share) => [pipe.from[0] + (pipe.to[0] - pipe.from[0]) * share, pipe.from[1] + (pipe.to[1] - pipe.from[1]) * share, pipe.from[2] + (pipe.to[2] - pipe.from[2]) * share];
|
|
596
|
+
const trimmed = (pipe, index) => {
|
|
597
|
+
const length = Math.hypot(pipe.to[0] - pipe.from[0], pipe.to[1] - pipe.from[1], pipe.to[2] - pipe.from[2]);
|
|
598
|
+
if (length < 0.1) return pipe;
|
|
599
|
+
const [start, end] = [(index % 7 + 1) * 3e-3, (index % 5 + 1) * 4e-3];
|
|
600
|
+
const at = (share) => along(pipe, share);
|
|
601
|
+
return { ...pipe, from: at(start / length), to: at(1 - end / length) };
|
|
602
|
+
};
|
|
603
|
+
const halves = (whole, index, gap) => {
|
|
604
|
+
const pipe = trimmed(whole, index);
|
|
605
|
+
if (gap[0] === gap[1]) {
|
|
606
|
+
place(pipeMesh, index * 2, pipe.from, pipe.to, pipe.diameter / 2);
|
|
607
|
+
pipeMesh.setMatrixAt(index * 2 + 1, matrix.makeScale(0, 0, 0));
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
place(pipeMesh, index * 2, pipe.from, along(pipe, gap[0]), pipe.diameter / 2);
|
|
611
|
+
place(pipeMesh, index * 2 + 1, along(pipe, gap[1]), pipe.to, pipe.diameter / 2);
|
|
612
|
+
};
|
|
613
|
+
const slotOf = new Map(pipes.map((pipe, index) => [pipe.id, index]));
|
|
614
|
+
pipes.forEach((pipe, index) => {
|
|
615
|
+
halves(pipe, index, [0.5, 0.5]);
|
|
616
|
+
for (const slot of [index * 2, index * 2 + 1]) pipeMesh.setColorAt(slot, color.set(PIPE_COLOR[pipe.content]));
|
|
617
|
+
});
|
|
618
|
+
round2.forEach(({ piece, shaft }, slot) => {
|
|
619
|
+
const [x, , z] = piece.at;
|
|
620
|
+
place(roundMesh, slot, [x, shaft.bottom - FLOOR, z], [x, shaft.top, z], shaft.width / 2);
|
|
621
|
+
roundMesh.setColorAt(slot, color.set(SHAFT_COLOR[shaft.material]));
|
|
622
|
+
});
|
|
623
|
+
square.forEach(({ piece, shaft }, slot) => {
|
|
624
|
+
const height = shaft.top - ROOF_DEPTH - shaft.bottom + FLOOR;
|
|
625
|
+
squareMesh.setMatrixAt(slot, matrix.compose(new THREE.Vector3(piece.at[0], shaft.top - ROOF_DEPTH - height / 2, piece.at[2]), new THREE.Quaternion().setFromAxisAngle(up, piece.ry), new THREE.Vector3(shaft.width, height, shaft.depth)));
|
|
626
|
+
squareMesh.setColorAt(slot, color.set(SHAFT_COLOR[shaft.material]));
|
|
627
|
+
});
|
|
628
|
+
group.add(pipeMesh, roundMesh, squareMesh);
|
|
629
|
+
return {
|
|
630
|
+
root: group,
|
|
631
|
+
pipes,
|
|
632
|
+
drawCalls: () => [pipeMesh, roundMesh, squareMesh].filter((mesh) => mesh.count > 0).length,
|
|
633
|
+
sever(id, share) {
|
|
634
|
+
const index = slotOf.get(id);
|
|
635
|
+
const pipe = index === void 0 ? void 0 : pipes[index];
|
|
636
|
+
if (index === void 0 || pipe === void 0) return;
|
|
637
|
+
const length = Math.hypot(pipe.to[0] - pipe.from[0], pipe.to[1] - pipe.from[1], pipe.to[2] - pipe.from[2]);
|
|
638
|
+
const half = Math.min(0.5, BREAK_GAP / 2 / Math.max(length, 1e-6));
|
|
639
|
+
halves(pipe, index, [Math.max(0, share - half), Math.min(1, share + half)]);
|
|
640
|
+
pipeMesh.instanceMatrix.needsUpdate = true;
|
|
641
|
+
},
|
|
642
|
+
mend(id) {
|
|
643
|
+
const index = slotOf.get(id);
|
|
644
|
+
const pipe = index === void 0 ? void 0 : pipes[index];
|
|
645
|
+
if (index === void 0 || pipe === void 0) return;
|
|
646
|
+
halves(pipe, index, [0.5, 0.5]);
|
|
647
|
+
pipeMesh.instanceMatrix.needsUpdate = true;
|
|
648
|
+
},
|
|
649
|
+
dispose() {
|
|
650
|
+
group.parent?.remove(group);
|
|
651
|
+
for (const mesh of [pipeMesh, roundMesh, squareMesh]) mesh.dispose();
|
|
652
|
+
for (const item of [...geometries, material, openMaterial]) item.dispose();
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/networks/draw-lid.ts
|
|
658
|
+
import { markKitOrigin as markKitOrigin3 } from "@adatechnology/game-contracts";
|
|
659
|
+
import { shapeGeometries as shapeGeometries5 } from "@adatechnology/game-shapes-three";
|
|
660
|
+
import { COVER_PLATE_PART } from "@adatechnology/game-urban/networks";
|
|
661
|
+
|
|
662
|
+
// src/networks/surface-parts.ts
|
|
663
|
+
var IRON = 3882562;
|
|
664
|
+
var IRON_WORN = 5593438;
|
|
665
|
+
var CONCRETE = 10197652;
|
|
666
|
+
var CONCRETE_LID = 11052960;
|
|
667
|
+
var VOID = 723724;
|
|
668
|
+
var HYDRANT_RED = 11545122;
|
|
669
|
+
var FRAME_TOP = 2e-3;
|
|
670
|
+
var LID_TOP = 4e-3;
|
|
671
|
+
var RIB_TOP = 9e-3;
|
|
672
|
+
var CROSS_RIB_TOP = 0.011;
|
|
673
|
+
var THICK = 0.03;
|
|
674
|
+
var flat = (shape, top, size, color) => shape === "box" ? { shape, centre: [0, top - THICK / 2, 0], size: [size[0], THICK, size[1]], color } : { shape, centre: [0, top - THICK / 2, 0], size: [size[0], THICK, size[0]], color };
|
|
675
|
+
var rib = (size, top, at) => ({ shape: "box", centre: [at[0], top - size[1] / 2, at[1]], size, color: IRON_WORN });
|
|
676
|
+
function cover(piece) {
|
|
677
|
+
const [width, , depth] = piece.size;
|
|
678
|
+
const shape = piece.shape === "round" ? "cylinder" : "box";
|
|
679
|
+
const [frame, lid] = piece.shape === "round" ? [(width + 0.12) / 2, width / 2] : [width + 0.12, width];
|
|
680
|
+
const colors = piece.material === "concrete" ? [IRON, CONCRETE_LID] : [IRON, IRON_WORN];
|
|
681
|
+
const parts = [flat(shape, FRAME_TOP, [frame, piece.shape === "round" ? frame : depth + 0.12], colors[0]), flat(shape, LID_TOP, [lid, piece.shape === "round" ? lid : depth], colors[1])];
|
|
682
|
+
if (piece.kind === "inspection_cover") return [...parts, rib([0.14, 6e-3, 0.03], RIB_TOP, [0, 0])];
|
|
683
|
+
if (piece.shape === "round") return [...parts, rib([lid * 1.7, 5e-3, 0.04], RIB_TOP, [0, 0]), rib([0.04, 5e-3, lid * 1.7], CROSS_RIB_TOP, [0, 0])];
|
|
684
|
+
return [...parts, ...[-0.15, 0, 0.15].map((z) => rib([lid * 0.85, 5e-3, 0.03], RIB_TOP, [0, z]))];
|
|
685
|
+
}
|
|
686
|
+
function grate() {
|
|
687
|
+
const bars = [-0.2, -0.1, 0, 0.1, 0.2].map((z) => ({ shape: "box", centre: [0, RIB_TOP - 6e-3, z], size: [0.9, 0.012, 0.025], color: IRON_WORN }));
|
|
688
|
+
const brace = { shape: "box", centre: [0, 55e-4, 0], size: [0.03, 3e-3, 0.5], color: IRON };
|
|
689
|
+
return [
|
|
690
|
+
{ shape: "box", centre: [0, FRAME_TOP - THICK / 2, 0], size: [1, THICK, 0.6], color: IRON },
|
|
691
|
+
{ shape: "box", centre: [0, 25e-4, 0], size: [0.9, 1e-3, 0.5], color: VOID },
|
|
692
|
+
...bars,
|
|
693
|
+
brace
|
|
694
|
+
];
|
|
695
|
+
}
|
|
696
|
+
function hydrant() {
|
|
697
|
+
const part = (y, radius, length, axis, at = [0, 0]) => ({ shape: "cylinder", centre: [at[0], y, at[1]], size: [radius, length, radius], axis, color: HYDRANT_RED });
|
|
698
|
+
return [part(0.02, 0.1, 0.04, "y"), part(0.38, 0.065, 0.68, "y"), part(0.74, 0.085, 0.06, "y"), part(0.55, 0.032, 0.26, "x"), part(0.5, 0.045, 0.14, "z", [0, 0.1])];
|
|
699
|
+
}
|
|
700
|
+
function wingWall(piece) {
|
|
701
|
+
const [width, height, depth] = piece.size;
|
|
702
|
+
return [
|
|
703
|
+
{ shape: "box", centre: [0, (height - 0.4) / 2, 0], size: [width, height + 0.4, 0.25], color: CONCRETE },
|
|
704
|
+
...[-1, 1].map((side) => ({ shape: "box", centre: [side * (width / 2 - 0.135), (height - 0.2 - 0.4) / 2 + 0.01, depth / 2], size: [0.25, height - 0.2 + 0.4 - 0.02, depth], color: CONCRETE })),
|
|
705
|
+
{ shape: "box", centre: [0, 0.01 - 0.075, depth / 2], size: [width - 0.6, 0.15, depth - 0.1], color: CONCRETE_LID }
|
|
706
|
+
];
|
|
707
|
+
}
|
|
708
|
+
function meterBox(piece) {
|
|
709
|
+
const [width, height, depth] = piece.size;
|
|
710
|
+
return [
|
|
711
|
+
{ shape: "box", centre: [0, height / 2, 0], size: [width, height, depth], color: CONCRETE },
|
|
712
|
+
{ shape: "box", centre: [0, height, 0], size: [width - 0.06, 8e-3, depth - 0.06], color: IRON }
|
|
713
|
+
];
|
|
714
|
+
}
|
|
715
|
+
function mouth() {
|
|
716
|
+
return [
|
|
717
|
+
{ shape: "box", centre: [0, FRAME_TOP - 0.01, 0], size: [0.3, 0.02, 0.2], color: CONCRETE },
|
|
718
|
+
{ shape: "box", centre: [0, 25e-4, 0], size: [0.2, 1e-3, 0.08], color: VOID }
|
|
719
|
+
];
|
|
720
|
+
}
|
|
721
|
+
function partsOf(piece) {
|
|
722
|
+
switch (piece.kind) {
|
|
723
|
+
case "inlet_grate":
|
|
724
|
+
return grate();
|
|
725
|
+
case "hydrant":
|
|
726
|
+
return hydrant();
|
|
727
|
+
case "wing_wall":
|
|
728
|
+
return wingWall(piece);
|
|
729
|
+
case "meter_box":
|
|
730
|
+
return meterBox(piece);
|
|
731
|
+
case "downspout_mouth":
|
|
732
|
+
return mouth();
|
|
733
|
+
default:
|
|
734
|
+
return cover(piece);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// src/networks/draw-lid.ts
|
|
739
|
+
var CYLINDER_SEGMENTS2 = 14;
|
|
740
|
+
function drawLid(THREE, piece) {
|
|
741
|
+
const T = shapeGeometries5(THREE);
|
|
742
|
+
const [frame, second, ...over] = partsOf(piece);
|
|
743
|
+
const [lid, ...ribs] = piece.kind === "inlet_grate" ? [frame, ...over] : second === void 0 ? [] : [second, ...over];
|
|
744
|
+
if (lid === void 0) throw new Error(`game-urban-three: "${piece.id}" has no lid to draw`);
|
|
745
|
+
const lift = lid.size[1] / 2 - lid.centre[1];
|
|
746
|
+
const group = markKitOrigin3(new THREE.Group(), { owner: "game-urban-three", kind: "network-lid" });
|
|
747
|
+
group.name = `network:lid:${piece.id}`;
|
|
748
|
+
const geometries = { box: new T.BoxGeometry(1, 1, 1), cylinder: new T.CylinderGeometry(1, 1, 1, CYLINDER_SEGMENTS2) };
|
|
749
|
+
const materials = /* @__PURE__ */ new Map();
|
|
750
|
+
const axisTurn = { x: [0, 0, Math.PI / 2], y: [0, 0, 0], z: [Math.PI / 2, 0, 0] };
|
|
751
|
+
for (const part of [lid, ...ribs]) {
|
|
752
|
+
let material = materials.get(part.color);
|
|
753
|
+
if (material === void 0) materials.set(part.color, material = new THREE.MeshStandardMaterial({ color: part.color, roughness: 0.7, metalness: 0.2 }));
|
|
754
|
+
const mesh = new THREE.Mesh(geometries[part.shape], material);
|
|
755
|
+
mesh.position.set(part.centre[0], part.centre[1] + lift, part.centre[2]);
|
|
756
|
+
mesh.scale.set(part.size[0], part.size[1], part.size[2]);
|
|
757
|
+
const [turnX, turnY, turnZ] = axisTurn[part.axis ?? "y"];
|
|
758
|
+
mesh.rotation.set(turnX, turnY, turnZ);
|
|
759
|
+
mesh.userData.destructionPart = COVER_PLATE_PART;
|
|
760
|
+
mesh.castShadow = true;
|
|
761
|
+
mesh.receiveShadow = true;
|
|
762
|
+
group.add(mesh);
|
|
763
|
+
}
|
|
764
|
+
return {
|
|
765
|
+
root: group,
|
|
766
|
+
dispose() {
|
|
767
|
+
group.parent?.remove(group);
|
|
768
|
+
for (const geometry of Object.values(geometries)) geometry.dispose();
|
|
769
|
+
for (const material of materials.values()) material.dispose();
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// src/networks/draw-surface.ts
|
|
775
|
+
import { markKitOrigin as markKitOrigin4 } from "@adatechnology/game-contracts";
|
|
776
|
+
import { shapeGeometries as shapeGeometries6 } from "@adatechnology/game-shapes-three";
|
|
777
|
+
import { surfacePiecesOf as surfacePiecesOf2 } from "@adatechnology/game-urban/networks";
|
|
778
|
+
var CYLINDER_SEGMENTS3 = 14;
|
|
779
|
+
function drawSurface(THREE, { networks, pieces, root, options }) {
|
|
780
|
+
const list = pieces ?? surfacePiecesOf2(networks ?? { nodes: [], edges: [] }, options);
|
|
781
|
+
const T = shapeGeometries6(THREE);
|
|
782
|
+
const group = markKitOrigin4(root ?? new THREE.Group(), { owner: "game-urban-three", kind: "network-surface" });
|
|
783
|
+
const boxes = [];
|
|
784
|
+
const cylinders = [];
|
|
785
|
+
const ranges = /* @__PURE__ */ new Map();
|
|
786
|
+
for (const piece of list) {
|
|
787
|
+
const parts = partsOf(piece);
|
|
788
|
+
const range = { box: [boxes.length, 0], cylinder: [cylinders.length, 0] };
|
|
789
|
+
for (const part of parts) (part.shape === "box" ? boxes : cylinders).push({ piece, part });
|
|
790
|
+
range.box[1] = boxes.length - range.box[0];
|
|
791
|
+
range.cylinder[1] = cylinders.length - range.cylinder[0];
|
|
792
|
+
ranges.set(piece.id, range);
|
|
793
|
+
}
|
|
794
|
+
const material = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.7, metalness: 0.2 });
|
|
795
|
+
const boxGeometry = new T.BoxGeometry(1, 1, 1);
|
|
796
|
+
const cylinderGeometry = new T.CylinderGeometry(1, 1, 1, CYLINDER_SEGMENTS3);
|
|
797
|
+
const matrix = new THREE.Matrix4();
|
|
798
|
+
const turn = new THREE.Quaternion();
|
|
799
|
+
const spin = new THREE.Quaternion();
|
|
800
|
+
const local = new THREE.Matrix4();
|
|
801
|
+
const color = new THREE.Color();
|
|
802
|
+
const axisTurn = { x: new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 0, 1), Math.PI / 2), y: new THREE.Quaternion(), z: new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1, 0, 0), Math.PI / 2) };
|
|
803
|
+
const fill2 = (mesh, items, [start, count] = [0, items.length]) => {
|
|
804
|
+
for (let slot = start; slot < start + count; slot++) {
|
|
805
|
+
const { piece, part } = items[slot];
|
|
806
|
+
turn.setFromAxisAngle(new THREE.Vector3(0, 1, 0), piece.ry);
|
|
807
|
+
matrix.compose(new THREE.Vector3(piece.at[0], piece.at[1], piece.at[2]), turn, new THREE.Vector3(1, 1, 1));
|
|
808
|
+
spin.copy(axisTurn[part.axis ?? "y"]);
|
|
809
|
+
local.compose(new THREE.Vector3(...part.centre), spin, new THREE.Vector3(...part.size));
|
|
810
|
+
mesh.setMatrixAt(slot, matrix.multiply(local));
|
|
811
|
+
mesh.setColorAt(slot, color.set(part.color));
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
const make = (geometry, items, name) => {
|
|
815
|
+
const mesh = new THREE.InstancedMesh(geometry, material, Math.max(items.length, 1));
|
|
816
|
+
mesh.name = name;
|
|
817
|
+
mesh.count = items.length;
|
|
818
|
+
mesh.receiveShadow = true;
|
|
819
|
+
fill2(mesh, items);
|
|
820
|
+
return mesh;
|
|
821
|
+
};
|
|
822
|
+
const boxMesh = make(boxGeometry, boxes, "network:surface:boxes");
|
|
823
|
+
const cylinderMesh = make(cylinderGeometry, cylinders, "network:surface:cylinders");
|
|
824
|
+
group.add(boxMesh, cylinderMesh);
|
|
825
|
+
const hide = (mesh, [start, count]) => {
|
|
826
|
+
matrix.makeScale(0, 0, 0);
|
|
827
|
+
for (let slot = start; slot < start + count; slot++) mesh.setMatrixAt(slot, matrix);
|
|
828
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
829
|
+
};
|
|
830
|
+
return {
|
|
831
|
+
root: group,
|
|
832
|
+
pieces: list,
|
|
833
|
+
drawCalls: () => [boxMesh, cylinderMesh].filter((mesh) => mesh.count > 0).length,
|
|
834
|
+
remove(id) {
|
|
835
|
+
const range = ranges.get(id);
|
|
836
|
+
if (range === void 0) return;
|
|
837
|
+
hide(boxMesh, range.box);
|
|
838
|
+
hide(cylinderMesh, range.cylinder);
|
|
839
|
+
},
|
|
840
|
+
restore(id) {
|
|
841
|
+
const range = ranges.get(id);
|
|
842
|
+
if (range === void 0) return;
|
|
843
|
+
fill2(boxMesh, boxes, range.box);
|
|
844
|
+
fill2(cylinderMesh, cylinders, range.cylinder);
|
|
845
|
+
boxMesh.instanceMatrix.needsUpdate = true;
|
|
846
|
+
cylinderMesh.instanceMatrix.needsUpdate = true;
|
|
847
|
+
},
|
|
848
|
+
dispose() {
|
|
849
|
+
group.parent?.remove(group);
|
|
850
|
+
for (const mesh of [boxMesh, cylinderMesh]) mesh.dispose();
|
|
851
|
+
for (const item of [boxGeometry, cylinderGeometry, material]) item.dispose();
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
|
|
555
856
|
// src/draw.ts
|
|
556
857
|
var DEFAULT_ROUGHNESS = 0.9;
|
|
557
858
|
var DEFAULT_METALNESS = 0;
|
|
@@ -562,17 +863,17 @@ var SIGN_FONT = '700 56px "Arial Narrow", Arial, sans-serif';
|
|
|
562
863
|
var SIGN_CANVAS = { width: 512, height: 128 };
|
|
563
864
|
var PLANE_LAYER_GAP = 2e-3;
|
|
564
865
|
function createUrbanThree(THREE, options = {}) {
|
|
565
|
-
const T =
|
|
866
|
+
const T = shapeGeometries7(THREE);
|
|
566
867
|
const geometries = /* @__PURE__ */ new Map();
|
|
567
868
|
const materials = /* @__PURE__ */ new Map();
|
|
568
869
|
const disposables = [];
|
|
569
|
-
const standard = (color, style,
|
|
870
|
+
const standard = (color, style, flat2 = false) => {
|
|
570
871
|
const roughness = style?.roughness ?? DEFAULT_ROUGHNESS;
|
|
571
872
|
const metalness = style?.metalness ?? DEFAULT_METALNESS;
|
|
572
|
-
const key = `s|${color}|${roughness}|${metalness}|${
|
|
873
|
+
const key = `s|${color}|${roughness}|${metalness}|${flat2 ? 1 : 0}`;
|
|
573
874
|
let material = materials.get(key);
|
|
574
875
|
if (!material) {
|
|
575
|
-
material = new THREE.MeshStandardMaterial({ color, roughness, metalness, flatShading:
|
|
876
|
+
material = new THREE.MeshStandardMaterial({ color, roughness, metalness, flatShading: flat2 });
|
|
576
877
|
materials.set(key, material);
|
|
577
878
|
}
|
|
578
879
|
return material;
|
|
@@ -871,7 +1172,7 @@ function createUrbanThree(THREE, options = {}) {
|
|
|
871
1172
|
};
|
|
872
1173
|
};
|
|
873
1174
|
function draw(scene, drawOptions = {}) {
|
|
874
|
-
const root =
|
|
1175
|
+
const root = markKitOrigin5(drawOptions.root ?? new THREE.Group(), { owner: "game-urban-three", kind: "urban" });
|
|
875
1176
|
const animators = [];
|
|
876
1177
|
const lights = [];
|
|
877
1178
|
animatedLenses = /* @__PURE__ */ new Set();
|
|
@@ -909,7 +1210,10 @@ function createUrbanThree(THREE, options = {}) {
|
|
|
909
1210
|
};
|
|
910
1211
|
}
|
|
911
1212
|
const networks = (data, drawOptions = {}) => drawNetworks(THREE, { networks: data, options: drawOptions, ...options.lights ? { budget: options.lights } : {}, ...options.physicalLights ? { physicalLights: true } : {} });
|
|
912
|
-
|
|
1213
|
+
const networkSurface = (data, surfaceOptions) => drawSurface(THREE, { networks: data, ...surfaceOptions ? { options: surfaceOptions } : {} });
|
|
1214
|
+
const buriedNetworks = (data, surfaceOptions) => drawBuried(THREE, { networks: data, ...surfaceOptions ? { options: surfaceOptions } : {} });
|
|
1215
|
+
const coverLid = (piece) => drawLid(THREE, piece);
|
|
1216
|
+
return { THREE, draw, drawNetworks: networks, drawNetworkSurface: networkSurface, drawBuriedNetworks: buriedNetworks, drawCoverLid: coverLid };
|
|
913
1217
|
}
|
|
914
1218
|
|
|
915
1219
|
// src/resolvers.ts
|
|
@@ -1401,7 +1705,7 @@ function createUrbanTestModule(options = {}) {
|
|
|
1401
1705
|
for (const lamp of entry.drawn.lights) {
|
|
1402
1706
|
const light = "bulb" in lamp ? { node: lamp.bulb, distance: lamp.part.distance, color: lamp.part.color } : lamp.isLight ? { node: lamp, distance: lamp.distance, color: lamp.color } : null;
|
|
1403
1707
|
if (!light) continue;
|
|
1404
|
-
const reach = new three.Mesh(new (
|
|
1708
|
+
const reach = new three.Mesh(new (shapeGeometries8(three)).SphereGeometry(Math.min(light.distance || 10, 60), 14, 8), new three.MeshBasicMaterial({ color: light.color ?? 16764006, wireframe: true, transparent: true, opacity: 0.25 }));
|
|
1405
1709
|
reach.position.copy(light.node.position);
|
|
1406
1710
|
mark(light.node.parent ?? entry.root, reach);
|
|
1407
1711
|
}
|
|
@@ -1541,4 +1845,4 @@ export {
|
|
|
1541
1845
|
createUrbanTestModule,
|
|
1542
1846
|
loadUrbanTestModule
|
|
1543
1847
|
};
|
|
1544
|
-
//# sourceMappingURL=chunk-
|
|
1848
|
+
//# sourceMappingURL=chunk-QS2K4DEO.js.map
|