@adatechnology/game-urban-three 0.4.0 → 0.5.1
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 +25 -0
- package/dist/{chunk-LRUZVUOV.js → chunk-JTXGLKOL.js} +469 -10
- package/dist/chunk-JTXGLKOL.js.map +1 -0
- package/dist/index.d.ts +63 -2
- package/dist/index.global.js +32486 -31861
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +3 -1
- package/dist/testing.js +1 -1
- package/package.json +6 -6
- package/dist/chunk-LRUZVUOV.js.map +0 -1
package/README.md
CHANGED
|
@@ -28,6 +28,31 @@ scene.add(drawn.root)
|
|
|
28
28
|
- A `placement` part (a vehicle of the fleet, a species of the pack) becomes a group at the spot, turned and scaled, holding the object a resolver made: `createUrbanThree(THREE, { resolvers: { vehicle: createVehicleResolver(vehiclesThree), plant: createPlantResolver(THREE) } })`. The vehicle resolver uses the `lite` build of `game-vehicles-three` (six fused meshes) and the plant resolver `generate` and `createPlantObject` of `game-vegetation`; each is built once for an id and paint (or seed) and cloned for every spot, sharing geometry and materials. An id the package does not know leaves the spot empty. `resolver.dispose()` frees them.
|
|
29
29
|
- `draw(scene, { root })` draws into a group of yours. Works on three r160 and later.
|
|
30
30
|
|
|
31
|
+
## Utility networks
|
|
32
|
+
|
|
33
|
+
`drawNetworks(networks, options)` draws the aerial networks of `@adatechnology/game-urban/networks` (`generateNetworks`):
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const drawn = createUrbanThree(THREE, { lights, physicalLights: true, flickerLenses: true })
|
|
37
|
+
.drawNetworks(generated.networks, { isNight, lamps: { lit: 0.8, flicker: 0.15 }, surfaceAt: generated.surfaceAt, poles: urban.poles })
|
|
38
|
+
scene.add(drawn.root)
|
|
39
|
+
// each frame: drawn.animate(t); when the camera moved: drawn.setFocus(x, z)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- Each `concrete_distribution` pole (or any registry pole with `slots`) stands at its node, turned with its arm toward its lamp: the mast
|
|
43
|
+
instanced per spec, the hardware of `distributionHardwareOf` (crossarm and pin insulators where it carries medium voltage, the low-voltage
|
|
44
|
+
clamp, one telecom clamp per cable, the arm and luminaire, the transformer's bracket and bushings) one instanced mesh of boxes, the
|
|
45
|
+
transformer tanks and reserve coils one instanced mesh of cylinders, the lenses one more.
|
|
46
|
+
- The conductors hang from the pole's slots with the sag the generator laid them with (`y − 4·sag·t·(1 − t)`, 8 stretches): three bare
|
|
47
|
+
medium-voltage phases, one multiplexed low-voltage cable, the telecom bundle (a cable per clamp), the drops (power from the low-voltage clamp,
|
|
48
|
+
telecom from the top cable) to each lot's anchor, and a guy against each pull of a corner or end pole, anchored on the sidewalk (`surfaceAt`).
|
|
49
|
+
Each class is one merged tube mesh; `spans` maps every edge to its index range there and in the far lines (R8).
|
|
50
|
+
- Level of detail: `setFocus(x, z)` keeps the spans within `nearDistance` (90 m) as tubes and draws the others as one `LineSegments`, by
|
|
51
|
+
rewriting each index buffer once when a span changes side. About ten draw calls near for a whole district, one far.
|
|
52
|
+
- The lamps are the network's `light` nodes with `networkLampsOf` (the `lampStateOf` of #470 by the seed and the node's place); a lit one is a
|
|
53
|
+
source of the host's light budget, a failing one blinks its lens and its light on its flicker group.
|
|
54
|
+
- `dispose()` removes the sources and frees every geometry and material it made.
|
|
55
|
+
|
|
31
56
|
The scene hash, the lists of instances and the surface of each material (shadows, roughness, metalness, flat shading) of 34 cases are tested against the page.
|
|
32
57
|
|
|
33
58
|
## Geometry
|
|
@@ -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 shapeGeometries5 } from "@adatechnology/game-shapes-three";
|
|
6
6
|
|
|
7
7
|
// src/draw.ts
|
|
8
|
-
import { markKitOrigin } from "@adatechnology/game-contracts";
|
|
9
|
-
import { LIGHT_PRIORITY } from "@adatechnology/game-render-three";
|
|
10
|
-
import { shapeGeometries as
|
|
8
|
+
import { markKitOrigin as markKitOrigin2 } from "@adatechnology/game-contracts";
|
|
9
|
+
import { LIGHT_PRIORITY as LIGHT_PRIORITY2 } from "@adatechnology/game-render-three";
|
|
10
|
+
import { shapeGeometries as shapeGeometries4, 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 };
|
|
@@ -95,6 +95,463 @@ function createTextTexture(THREE, document, lines, o) {
|
|
|
95
95
|
return texture;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
// src/networks/draw-networks.ts
|
|
99
|
+
import { markKitOrigin } from "@adatechnology/game-contracts";
|
|
100
|
+
import { LIGHT_PRIORITY } from "@adatechnology/game-render-three";
|
|
101
|
+
import { shapeGeometries as shapeGeometries3 } from "@adatechnology/game-shapes-three";
|
|
102
|
+
import { DEFAULT_POLES } from "@adatechnology/game-urban";
|
|
103
|
+
import { networkLampsOf, slotsOfPole } from "@adatechnology/game-urban/networks";
|
|
104
|
+
|
|
105
|
+
// src/networks/draw-pieces.ts
|
|
106
|
+
import { shapeGeometries as shapeGeometries2 } from "@adatechnology/game-shapes-three";
|
|
107
|
+
var CYLINDER_SEGMENTS = 10;
|
|
108
|
+
function drawPieces(THREE, { masts, boxes, cylinders, specOf }) {
|
|
109
|
+
const T = shapeGeometries2(THREE);
|
|
110
|
+
const owned = [];
|
|
111
|
+
const meshes = [];
|
|
112
|
+
const matrix = new THREE.Matrix4();
|
|
113
|
+
const quaternion = new THREE.Quaternion();
|
|
114
|
+
const position = new THREE.Vector3();
|
|
115
|
+
const scale = new THREE.Vector3();
|
|
116
|
+
const up = new THREE.Vector3(0, 1, 0);
|
|
117
|
+
const axis = new THREE.Vector3();
|
|
118
|
+
const color = new THREE.Color();
|
|
119
|
+
const instanced = (geometry, material, count, name) => {
|
|
120
|
+
owned.push(geometry, material);
|
|
121
|
+
const mesh = new THREE.InstancedMesh(geometry, material, count);
|
|
122
|
+
mesh.name = name;
|
|
123
|
+
mesh.castShadow = true;
|
|
124
|
+
mesh.receiveShadow = true;
|
|
125
|
+
meshes.push(mesh);
|
|
126
|
+
return mesh;
|
|
127
|
+
};
|
|
128
|
+
for (const specId of new Set(masts.map((mast) => mast.specId))) {
|
|
129
|
+
const { mast } = specOf(specId);
|
|
130
|
+
const geometry = new T.CylinderGeometry(mast.radiusTop, mast.radiusBottom, mast.height, mast.segments ?? 4).rotateY(Math.PI / 4).translate(0, mast.height / 2, 0);
|
|
131
|
+
const own = masts.filter((item) => item.specId === specId);
|
|
132
|
+
const mesh = instanced(geometry, new THREE.MeshStandardMaterial({ color: mast.color, roughness: 0.9 }), own.length, `network:masts:${specId}`);
|
|
133
|
+
own.forEach((item, index) => mesh.setMatrixAt(index, matrix.compose(position.set(item.x, item.y, item.z), quaternion.setFromAxisAngle(up, item.ry), scale.set(1, 1, 1))));
|
|
134
|
+
}
|
|
135
|
+
if (boxes.length > 0) {
|
|
136
|
+
const mesh = instanced(new T.BoxGeometry(1, 1, 1), new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.75 }), boxes.length, "network:hardware");
|
|
137
|
+
boxes.forEach((box, index) => {
|
|
138
|
+
mesh.setMatrixAt(index, matrix.compose(position.set(box.x, box.y, box.z), quaternion.setFromAxisAngle(up, box.ry), scale.set(box.width, box.height, box.depth)));
|
|
139
|
+
mesh.setColorAt(index, color.set(box.color));
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (cylinders.length > 0) {
|
|
143
|
+
const mesh = instanced(new T.CylinderGeometry(1, 1, 1, CYLINDER_SEGMENTS), new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.6, metalness: 0.3 }), cylinders.length, "network:cylinders");
|
|
144
|
+
cylinders.forEach((cylinder, index) => {
|
|
145
|
+
quaternion.setFromUnitVectors(up, axis.set(cylinder.axis[0], cylinder.axis[1], cylinder.axis[2]).normalize());
|
|
146
|
+
mesh.setMatrixAt(index, matrix.compose(position.set(cylinder.x, cylinder.y, cylinder.z), quaternion, scale.set(cylinder.radius, cylinder.height, cylinder.radius)));
|
|
147
|
+
mesh.setColorAt(index, color.set(cylinder.color));
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
meshes,
|
|
152
|
+
dispose() {
|
|
153
|
+
for (const mesh of meshes) mesh.dispose();
|
|
154
|
+
for (const item of owned.splice(0)) item.dispose();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/networks/catenary.ts
|
|
160
|
+
var SPAN_SEGMENTS = 8;
|
|
161
|
+
var TUBE_SIDES = 4;
|
|
162
|
+
function catenaryPoints({ from, to, sag, segments = SPAN_SEGMENTS }) {
|
|
163
|
+
return Array.from({ length: segments + 1 }, (_, index) => {
|
|
164
|
+
const t = index / segments;
|
|
165
|
+
return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t - 4 * sag * t * (1 - t), from[2] + (to[2] - from[2]) * t];
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
var emptyMesh = () => ({ positions: [], normals: [], indices: [] });
|
|
169
|
+
var normalize = (v) => {
|
|
170
|
+
const length = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
171
|
+
return [v[0] / length, v[1] / length, v[2] / length];
|
|
172
|
+
};
|
|
173
|
+
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]];
|
|
174
|
+
function sectionAxes(tangent) {
|
|
175
|
+
const level = cross(tangent, [0, 1, 0]);
|
|
176
|
+
const side = Math.hypot(...level) < 1e-6 ? [1, 0, 0] : normalize(level);
|
|
177
|
+
return [side, normalize(cross(side, tangent))];
|
|
178
|
+
}
|
|
179
|
+
function appendTube({ mesh, points, radius }) {
|
|
180
|
+
const base = mesh.positions.length / 3;
|
|
181
|
+
const start = mesh.indices.length;
|
|
182
|
+
points.forEach((point, index) => {
|
|
183
|
+
const previous = points[Math.max(index - 1, 0)];
|
|
184
|
+
const next = points[Math.min(index + 1, points.length - 1)];
|
|
185
|
+
const [side, up] = sectionAxes(normalize([next[0] - previous[0], next[1] - previous[1], next[2] - previous[2]]));
|
|
186
|
+
for (let k = 0; k < TUBE_SIDES; k++) {
|
|
187
|
+
const angle = (k + 0.5) / TUBE_SIDES * 2 * Math.PI;
|
|
188
|
+
const normal = [0, 1, 2].map((axis) => Math.cos(angle) * side[axis] + Math.sin(angle) * up[axis]);
|
|
189
|
+
mesh.normals.push(normal[0], normal[1], normal[2]);
|
|
190
|
+
mesh.positions.push(point[0] + normal[0] * radius, point[1] + normal[1] * radius, point[2] + normal[2] * radius);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
for (let ring = 0; ring + 1 < points.length; ring++) {
|
|
194
|
+
for (let k = 0; k < TUBE_SIDES; k++) {
|
|
195
|
+
const a = base + ring * TUBE_SIDES + k;
|
|
196
|
+
const b = base + ring * TUBE_SIDES + (k + 1) % TUBE_SIDES;
|
|
197
|
+
const c = a + TUBE_SIDES;
|
|
198
|
+
const d = b + TUBE_SIDES;
|
|
199
|
+
mesh.indices.push(a, c, b, b, c, d);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return [start, mesh.indices.length - start];
|
|
203
|
+
}
|
|
204
|
+
var emptyLines = () => ({ positions: [], colors: [], indices: [] });
|
|
205
|
+
function appendLine({ lines, points, color }) {
|
|
206
|
+
const base = lines.positions.length / 3;
|
|
207
|
+
const start = lines.indices.length;
|
|
208
|
+
for (const point of points) {
|
|
209
|
+
lines.positions.push(point[0], point[1], point[2]);
|
|
210
|
+
lines.colors.push(color[0], color[1], color[2]);
|
|
211
|
+
}
|
|
212
|
+
for (let index = 0; index + 1 < points.length; index++) lines.indices.push(base + index, base + index + 1);
|
|
213
|
+
return [start, lines.indices.length - start];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/networks/pole-frames.ts
|
|
217
|
+
import { distributionHardwareOf } from "@adatechnology/game-urban/networks";
|
|
218
|
+
var LINE_EDGES = /* @__PURE__ */ new Set(["mv_span", "lv_span", "telecom_span"]);
|
|
219
|
+
function worldOf(frame, local) {
|
|
220
|
+
return [frame.x + local[0] * frame.road[0] + local[2] * frame.line[0], frame.y + local[1], frame.z + local[0] * frame.road[1] + local[2] * frame.line[1]];
|
|
221
|
+
}
|
|
222
|
+
var unit = (x, z) => {
|
|
223
|
+
const length = Math.hypot(x, z);
|
|
224
|
+
return length < 1e-9 ? [1, 0] : [x / length, z / length];
|
|
225
|
+
};
|
|
226
|
+
function indexOf(networks) {
|
|
227
|
+
const at = /* @__PURE__ */ new Map();
|
|
228
|
+
for (const edge of networks.edges) {
|
|
229
|
+
for (const end of [edge.from, edge.to]) at.set(end, [...at.get(end) ?? [], edge]);
|
|
230
|
+
}
|
|
231
|
+
return { nodes: new Map(networks.nodes.map((node) => [node.id, node])), at };
|
|
232
|
+
}
|
|
233
|
+
function lineDirectionsOf(index, pole) {
|
|
234
|
+
const out = [];
|
|
235
|
+
for (const edge of index.at.get(pole.id) ?? []) {
|
|
236
|
+
if (!LINE_EDGES.has(edge.kind)) continue;
|
|
237
|
+
const other = index.nodes.get(edge.from === pole.id ? edge.to : edge.from);
|
|
238
|
+
if (!other || other.kind === "transformer") continue;
|
|
239
|
+
const far = other.kind === "splice" ? farEndOf(index, other, pole.id) : other;
|
|
240
|
+
const direction = unit(far.at[0] - pole.at[0], far.at[2] - pole.at[2]);
|
|
241
|
+
if (!out.some((seen) => seen[0] * direction[0] + seen[1] * direction[1] > 0.94)) out.push(direction);
|
|
242
|
+
}
|
|
243
|
+
return out;
|
|
244
|
+
}
|
|
245
|
+
function farEndOf(index, splice, from) {
|
|
246
|
+
const next = (index.at.get(splice.id) ?? []).map((edge) => edge.from === splice.id ? edge.to : edge.from).find((id) => id !== from);
|
|
247
|
+
return next && index.nodes.get(next) || splice;
|
|
248
|
+
}
|
|
249
|
+
function roadOf(index, pole) {
|
|
250
|
+
const lamp = index.nodes.get(`light:${pole.id}`);
|
|
251
|
+
if (lamp) return unit(lamp.at[0] - pole.at[0], lamp.at[2] - pole.at[2]);
|
|
252
|
+
const along = lineDirectionsOf(index, pole)[0] ?? [1, 0];
|
|
253
|
+
const across = [-along[1], along[0]];
|
|
254
|
+
const lot = (index.at.get(pole.id) ?? []).filter((edge) => edge.kind === "service_drop" && edge.from === pole.id).map((edge) => index.nodes.get(edge.to))[0];
|
|
255
|
+
if (!lot) return across;
|
|
256
|
+
const toward = (lot.at[0] - pole.at[0]) * across[0] + (lot.at[2] - pole.at[2]) * across[1];
|
|
257
|
+
return toward > 0 ? [-across[0], -across[1]] : across;
|
|
258
|
+
}
|
|
259
|
+
function cablesAt(index, pole) {
|
|
260
|
+
return Math.max(0, ...(index.at.get(pole.id) ?? []).filter((edge) => edge.kind === "telecom_span").map((edge) => edge.conductors ?? 1));
|
|
261
|
+
}
|
|
262
|
+
function poleFramesOf({ networks, index, specOf }) {
|
|
263
|
+
return networks.nodes.filter((node) => node.kind === "pole").map((node) => {
|
|
264
|
+
const specId = node.spec ?? "concrete_distribution";
|
|
265
|
+
const spec = specOf(specId);
|
|
266
|
+
const road = roadOf(index, node);
|
|
267
|
+
const hardware = distributionHardwareOf(spec, {
|
|
268
|
+
mv: node.carries.includes("power_mv"),
|
|
269
|
+
transformer: index.nodes.has(`transformer:${node.id}`),
|
|
270
|
+
lamp: index.nodes.has(`light:${node.id}`),
|
|
271
|
+
cables: cablesAt(index, node),
|
|
272
|
+
cableGap: networks.rules.layout.telecom.cableGap
|
|
273
|
+
});
|
|
274
|
+
return { id: node.id, specId, spec, x: node.at[0], y: node.at[1], z: node.at[2], ry: Math.atan2(-road[1], road[0]), road, line: [-road[1], road[0]], hardware, guyed: node.guyed === true };
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/networks/wire-runs.ts
|
|
279
|
+
var WIRE_CLASSES = ["mv", "lv", "telecom", "drops", "guys"];
|
|
280
|
+
var MIN_LENGTH = 0.05;
|
|
281
|
+
var CLASS_OF = { mv_span: "mv", lv_span: "lv", telecom_span: "telecom", service_drop: "drops", telecom_drop: "drops" };
|
|
282
|
+
function pointsOn(frame, kind, conductors) {
|
|
283
|
+
const { attachments } = frame.hardware;
|
|
284
|
+
if (kind === "mv_span") return attachments.mv;
|
|
285
|
+
if (kind === "telecom_span") return attachments.telecom.slice(0, conductors);
|
|
286
|
+
if (kind === "telecom_drop") return attachments.telecom.slice(0, 1);
|
|
287
|
+
return [attachments.lv];
|
|
288
|
+
}
|
|
289
|
+
function frameNear({ frames, index }, node, other) {
|
|
290
|
+
const own = frames.get(other);
|
|
291
|
+
if (own) return own;
|
|
292
|
+
const near = (index.at.get(node.id) ?? []).map((edge) => edge.from === node.id ? edge.to : edge.from).find((id) => frames.has(id));
|
|
293
|
+
return near === void 0 ? void 0 : frames.get(near);
|
|
294
|
+
}
|
|
295
|
+
function endOf(ends, edge, id, other) {
|
|
296
|
+
const node = ends.index.nodes.get(id);
|
|
297
|
+
if (!node) return [];
|
|
298
|
+
const conductors = edge.kind === "telecom_span" ? edge.conductors ?? 1 : edge.kind === "mv_span" ? 3 : 1;
|
|
299
|
+
const pole = ends.frames.get(id);
|
|
300
|
+
if (pole) return pointsOn(pole, edge.kind, conductors).map((point) => worldOf(pole, point));
|
|
301
|
+
if (node.kind === "transformer") {
|
|
302
|
+
const host = ends.frames.get(id.slice("transformer:".length));
|
|
303
|
+
const points = host?.hardware.attachments.transformer;
|
|
304
|
+
if (!host || !points) return [];
|
|
305
|
+
return (edge.kind === "mv_span" ? points.mv : [points.lv]).map((point) => worldOf(host, point));
|
|
306
|
+
}
|
|
307
|
+
if (node.kind === "connection") return [node.at];
|
|
308
|
+
const near = frameNear(ends, node, other);
|
|
309
|
+
if (!near) return [node.at];
|
|
310
|
+
const placed = { ...near, x: node.at[0], z: node.at[2], y: 0 };
|
|
311
|
+
return pointsOn(near, edge.kind, conductors).map((point) => worldOf(placed, point));
|
|
312
|
+
}
|
|
313
|
+
function wireRunsOf(ends, edges) {
|
|
314
|
+
const runs = [];
|
|
315
|
+
for (const edge of edges) {
|
|
316
|
+
const wireClass = CLASS_OF[edge.kind];
|
|
317
|
+
if (!wireClass) continue;
|
|
318
|
+
const from = endOf(ends, edge, edge.from, edge.to);
|
|
319
|
+
const to = endOf(ends, edge, edge.to, edge.from);
|
|
320
|
+
const count = Math.min(from.length, to.length);
|
|
321
|
+
if (count === 0) continue;
|
|
322
|
+
const conductors = Array.from({ length: count }, (_, k) => catenaryPoints({ from: from[k], to: to[k], sag: edge.sag ?? 0 }));
|
|
323
|
+
if (Math.hypot(from[0][0] - to[0][0], from[0][1] - to[0][1], from[0][2] - to[0][2]) < MIN_LENGTH) continue;
|
|
324
|
+
runs.push({ id: edge.id, wireClass, conductors });
|
|
325
|
+
}
|
|
326
|
+
return runs;
|
|
327
|
+
}
|
|
328
|
+
var GUY_SHARES = [1, 0.75, 0.5, 0.35];
|
|
329
|
+
function guysOf({ index, frames, surfaceAt }) {
|
|
330
|
+
const out = [];
|
|
331
|
+
for (const frame of frames.values()) {
|
|
332
|
+
const node = index.nodes.get(frame.id);
|
|
333
|
+
if (!frame.guyed || !node) continue;
|
|
334
|
+
lineDirectionsOf(index, node).forEach((pull, k) => {
|
|
335
|
+
const share = GUY_SHARES.find((s) => {
|
|
336
|
+
const [x, z] = [frame.x - pull[0] * frame.spec.guy.reach * s, frame.z - pull[1] * frame.spec.guy.reach * s];
|
|
337
|
+
return surfaceAt === void 0 || surfaceAt(x, z) === "sidewalk";
|
|
338
|
+
});
|
|
339
|
+
if (share === void 0) return;
|
|
340
|
+
const reach = frame.spec.guy.reach * share;
|
|
341
|
+
out.push({ id: `guy:${frame.id}:${k}`, pole: frame.id, from: worldOf(frame, frame.hardware.attachments.guy), at: [frame.x - pull[0] * reach, frame.y, frame.z - pull[1] * reach] });
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return out;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/networks/draw-wires.ts
|
|
348
|
+
var WIRE_STYLE = {
|
|
349
|
+
mv: { radius: 7e-3, color: 9343639, metalness: 0.5, roughness: 0.5 },
|
|
350
|
+
lv: { radius: 0.016, color: 1776670, metalness: 0, roughness: 0.8 },
|
|
351
|
+
telecom: { radius: 8e-3, color: 1316118, metalness: 0, roughness: 0.85 },
|
|
352
|
+
drops: { radius: 7e-3, color: 1842206, metalness: 0, roughness: 0.8 },
|
|
353
|
+
guys: { radius: 5e-3, color: 8027262, metalness: 0.6, roughness: 0.5 }
|
|
354
|
+
};
|
|
355
|
+
var rgb = (THREE, hex) => {
|
|
356
|
+
const color = new THREE.Color(hex);
|
|
357
|
+
return [color.r, color.g, color.b];
|
|
358
|
+
};
|
|
359
|
+
var distanceToSegment = (x, z, a, b) => {
|
|
360
|
+
const [dx, dz] = [b[0] - a[0], b[2] - a[2]];
|
|
361
|
+
const t = Math.max(0, Math.min(1, ((x - a[0]) * dx + (z - a[2]) * dz) / (dx * dx + dz * dz || 1)));
|
|
362
|
+
return Math.hypot(a[0] + dx * t - x, a[2] + dz * t - z);
|
|
363
|
+
};
|
|
364
|
+
var apply = (attribute, original, ranges, shown) => {
|
|
365
|
+
const array = attribute.array;
|
|
366
|
+
ranges.forEach((range, span) => {
|
|
367
|
+
if (!range) return;
|
|
368
|
+
const [start, count] = range;
|
|
369
|
+
if (shown[span]) array.set(original.subarray(start, start + count), start);
|
|
370
|
+
else array.fill(0, start, start + count);
|
|
371
|
+
});
|
|
372
|
+
attribute.needsUpdate = true;
|
|
373
|
+
};
|
|
374
|
+
function drawWires(THREE, { runs, guys }) {
|
|
375
|
+
const all = [...runs, ...guys.map((guy) => ({ id: guy.id, wireClass: "guys", conductors: [[guy.from, guy.at]] }))];
|
|
376
|
+
const meshes = new Map(WIRE_CLASSES.map((wireClass) => [wireClass, emptyMesh()]));
|
|
377
|
+
const lines = emptyLines();
|
|
378
|
+
const spans = /* @__PURE__ */ new Map();
|
|
379
|
+
for (const run of all) {
|
|
380
|
+
const mesh = meshes.get(run.wireClass);
|
|
381
|
+
const { radius, color } = WIRE_STYLE[run.wireClass];
|
|
382
|
+
const nearRanges = run.conductors.map((points) => appendTube({ mesh, points, radius }));
|
|
383
|
+
const farRanges = run.conductors.map((points) => appendLine({ lines, points, color: rgb(THREE, color) }));
|
|
384
|
+
const span = (ranges) => [ranges[0][0], ranges.reduce((sum, range) => sum + range[1], 0)];
|
|
385
|
+
spans.set(run.id, { wireClass: run.wireClass, near: span(nearRanges), far: span(farRanges) });
|
|
386
|
+
}
|
|
387
|
+
const owned = [];
|
|
388
|
+
const near = WIRE_CLASSES.filter((wireClass) => meshes.get(wireClass).indices.length > 0).map((wireClass) => {
|
|
389
|
+
const data = meshes.get(wireClass);
|
|
390
|
+
const geometry = new THREE.BufferGeometry();
|
|
391
|
+
geometry.setAttribute("position", new THREE.Float32BufferAttribute(data.positions, 3));
|
|
392
|
+
geometry.setAttribute("normal", new THREE.Float32BufferAttribute(data.normals, 3));
|
|
393
|
+
geometry.setIndex(new THREE.BufferAttribute(new Uint32Array(data.indices), 1));
|
|
394
|
+
const style = WIRE_STYLE[wireClass];
|
|
395
|
+
const material = new THREE.MeshStandardMaterial({ color: style.color, metalness: style.metalness, roughness: style.roughness });
|
|
396
|
+
owned.push(geometry, material);
|
|
397
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
398
|
+
mesh.name = `network:${wireClass}`;
|
|
399
|
+
mesh.castShadow = true;
|
|
400
|
+
return mesh;
|
|
401
|
+
});
|
|
402
|
+
const lineGeometry = new THREE.BufferGeometry();
|
|
403
|
+
lineGeometry.setAttribute("position", new THREE.Float32BufferAttribute(lines.positions, 3));
|
|
404
|
+
lineGeometry.setAttribute("color", new THREE.Float32BufferAttribute(lines.colors, 3));
|
|
405
|
+
lineGeometry.setIndex(new THREE.BufferAttribute(new Uint32Array(lines.indices), 1));
|
|
406
|
+
const lineMaterial = new THREE.LineBasicMaterial({ vertexColors: true });
|
|
407
|
+
owned.push(lineGeometry, lineMaterial);
|
|
408
|
+
const far = new THREE.LineSegments(lineGeometry, lineMaterial);
|
|
409
|
+
far.name = "network:far";
|
|
410
|
+
far.visible = false;
|
|
411
|
+
const ids = [...spans.keys()];
|
|
412
|
+
const ends = all.map((run) => [run.conductors[0][0], run.conductors[0][run.conductors[0].length - 1]]);
|
|
413
|
+
const originals = new Map(near.map((mesh) => [mesh, mesh.geometry.index.array.slice()]));
|
|
414
|
+
const farOriginal = lineGeometry.index.array.slice();
|
|
415
|
+
let shown = ids.map(() => true);
|
|
416
|
+
return {
|
|
417
|
+
near,
|
|
418
|
+
far,
|
|
419
|
+
spans,
|
|
420
|
+
setFocus(x, z, distance) {
|
|
421
|
+
const next = ends.map(([a, b]) => distanceToSegment(x, z, a, b) <= distance);
|
|
422
|
+
if (next.every((value, span) => value === shown[span])) return;
|
|
423
|
+
shown = next;
|
|
424
|
+
for (const mesh of near) {
|
|
425
|
+
const wireClass = mesh.name.slice("network:".length);
|
|
426
|
+
apply(mesh.geometry.index, originals.get(mesh), ids.map((id) => spans.get(id).wireClass === wireClass ? spans.get(id).near : void 0), shown);
|
|
427
|
+
mesh.visible = ids.some((id, span) => shown[span] && spans.get(id).wireClass === wireClass);
|
|
428
|
+
}
|
|
429
|
+
apply(lineGeometry.index, farOriginal, ids.map((id) => spans.get(id).far), shown.map((value) => !value));
|
|
430
|
+
far.visible = shown.some((value) => !value);
|
|
431
|
+
},
|
|
432
|
+
dispose() {
|
|
433
|
+
for (const item of owned.splice(0)) item.dispose();
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/networks/pieces.ts
|
|
439
|
+
var SPLICE = { width: 0.16, height: 0.3, depth: 0.42, drop: 0.28, color: 2763822 };
|
|
440
|
+
var COIL = { radius: 0.32, thickness: 0.07, along: 0.75, drop: 0.5, color: 1974049 };
|
|
441
|
+
var ANCHOR = { width: 0.08, height: 0.3, depth: 0.08, sunk: 0.1 };
|
|
442
|
+
var boxIn = (frame, box) => {
|
|
443
|
+
const [x, y, z] = worldOf(frame, [box.x, box.y + box.height / 2, box.z]);
|
|
444
|
+
return { x, y, z, ry: frame.ry, width: box.width, height: box.height, depth: box.depth, color: box.color };
|
|
445
|
+
};
|
|
446
|
+
function piecesOf({ frames, index, guys }) {
|
|
447
|
+
const out = { masts: [], boxes: [], cylinders: [], lenses: [] };
|
|
448
|
+
for (const frame of frames.values()) {
|
|
449
|
+
out.masts.push({ specId: frame.specId, x: frame.x, y: frame.y, z: frame.z, ry: frame.ry });
|
|
450
|
+
for (const box of frame.hardware.boxes) out.boxes.push(boxIn(frame, box));
|
|
451
|
+
for (const cylinder of frame.hardware.cylinders) {
|
|
452
|
+
const [x, y, z] = worldOf(frame, [cylinder.x, cylinder.y + cylinder.height / 2, cylinder.z]);
|
|
453
|
+
out.cylinders.push({ x, y, z, axis: [0, 1, 0], radius: cylinder.radius, height: cylinder.height, color: cylinder.color });
|
|
454
|
+
}
|
|
455
|
+
if (frame.hardware.lens) out.lenses.push({ pole: frame.id, box: boxIn(frame, frame.hardware.lens) });
|
|
456
|
+
}
|
|
457
|
+
for (const guy of guys) {
|
|
458
|
+
const frame = frames.get(guy.pole);
|
|
459
|
+
if (frame) out.boxes.push({ x: guy.at[0], y: guy.at[1] + ANCHOR.height / 2 - ANCHOR.sunk, z: guy.at[2], ry: frame.ry, width: ANCHOR.width, height: ANCHOR.height, depth: ANCHOR.depth, color: frame.spec.guy.color });
|
|
460
|
+
}
|
|
461
|
+
for (const node of index.nodes.values()) {
|
|
462
|
+
if (node.kind !== "splice") continue;
|
|
463
|
+
const pole = (index.at.get(node.id) ?? []).map((edge) => edge.from === node.id ? edge.to : edge.from).map((id) => frames.get(id)).find((frame) => frame !== void 0);
|
|
464
|
+
if (!pole) continue;
|
|
465
|
+
const at = { ...pole, x: node.at[0], z: node.at[2], y: 0 };
|
|
466
|
+
const ox = pole.hardware.attachments.telecom[0]?.[0] ?? 0;
|
|
467
|
+
const [x, , z] = worldOf(at, [ox, 0, 0]);
|
|
468
|
+
out.boxes.push({ x, y: node.at[1] - SPLICE.drop, z, ry: pole.ry, width: SPLICE.width, height: SPLICE.height, depth: SPLICE.depth, color: SPLICE.color });
|
|
469
|
+
const coil = worldOf(at, [ox, node.at[1] - COIL.drop, COIL.along]);
|
|
470
|
+
out.cylinders.push({ x: coil[0], y: coil[1], z: coil[2], axis: [pole.road[0], 0, pole.road[1]], radius: COIL.radius, height: COIL.thickness, color: COIL.color });
|
|
471
|
+
}
|
|
472
|
+
return out;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// src/networks/draw-networks.ts
|
|
476
|
+
var ALL_LAMPS_WORK = { lit: 1, flicker: 0 };
|
|
477
|
+
var NEAR_DISTANCE = 90;
|
|
478
|
+
var specResolver = (poles) => {
|
|
479
|
+
return (id) => {
|
|
480
|
+
const def = poles ? poles.get(id).def : DEFAULT_POLES.find((pole) => pole.id === id);
|
|
481
|
+
if (!def || !slotsOfPole({ id, shape: "distribution", spec: def.spec })) throw new Error(`the pole "${id}" a network stands on has no slots (a distribution pole)`);
|
|
482
|
+
return def.spec;
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
function drawNetworks(THREE, { networks, options, budget, physicalLights }) {
|
|
486
|
+
const root = markKitOrigin(options.root ?? new THREE.Group(), { owner: "game-urban-three", kind: "networks" });
|
|
487
|
+
const specOf = specResolver(options.poles);
|
|
488
|
+
const index = indexOf(networks);
|
|
489
|
+
const frames = new Map(poleFramesOf({ networks, index, specOf }).map((frame) => [frame.id, frame]));
|
|
490
|
+
const guys = guysOf({ index, frames, ...options.surfaceAt ? { surfaceAt: options.surfaceAt } : {} });
|
|
491
|
+
const wires = drawWires(THREE, { runs: wireRunsOf({ frames, index }, networks.edges), guys });
|
|
492
|
+
const pieces = piecesOf({ frames, index, guys });
|
|
493
|
+
const drawn = drawPieces(THREE, { masts: pieces.masts, boxes: pieces.boxes, cylinders: pieces.cylinders, specOf });
|
|
494
|
+
const lamps = networkLampsOf({ networks, shares: options.lamps ?? ALL_LAMPS_WORK, isNight: options.isNight ?? false });
|
|
495
|
+
const byPole = new Map(lamps.map((lamp) => [lamp.pole, lamp]));
|
|
496
|
+
const lensMaterial = new THREE.MeshBasicMaterial({ color: 16777215 });
|
|
497
|
+
const lenses = new THREE.InstancedMesh(new (shapeGeometries3(THREE)).BoxGeometry(1, 1, 1), lensMaterial, Math.max(pieces.lenses.length, 1));
|
|
498
|
+
lenses.name = "network:lenses";
|
|
499
|
+
lenses.count = pieces.lenses.length;
|
|
500
|
+
const matrix = new THREE.Matrix4();
|
|
501
|
+
const color = new THREE.Color();
|
|
502
|
+
const flickering = [];
|
|
503
|
+
pieces.lenses.forEach((lens, slot) => {
|
|
504
|
+
const { box } = lens;
|
|
505
|
+
lenses.setMatrixAt(slot, matrix.compose(new THREE.Vector3(box.x, box.y, box.z), new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), box.ry), new THREE.Vector3(box.width, box.height, box.depth)));
|
|
506
|
+
const lamp = byPole.get(lens.pole);
|
|
507
|
+
const spec = frames.get(lens.pole).spec;
|
|
508
|
+
lenses.setColorAt(slot, color.set(lamp?.on ? spec.lens.lit : spec.lens.unlit));
|
|
509
|
+
if (lamp?.flicker && lamp.flickerPhase !== void 0) flickering.push({ index: slot, lit: spec.lens.lit, phase: flickerGroupPhase(flickerGroupOf(lamp.flickerPhase)) });
|
|
510
|
+
});
|
|
511
|
+
const lights = [];
|
|
512
|
+
const animators = [];
|
|
513
|
+
for (const lamp of lamps) {
|
|
514
|
+
const frame = frames.get(lamp.pole);
|
|
515
|
+
if (!lamp.on || !frame || !budget) continue;
|
|
516
|
+
const { light } = frame.spec;
|
|
517
|
+
const bulb = new THREE.Object3D();
|
|
518
|
+
bulb.position.set(...worldOf(frame, [light.reach ?? frame.spec.lamp.reach, light.y, light.z ?? 0]));
|
|
519
|
+
root.add(bulb);
|
|
520
|
+
const intensity = physicalLights ? physicalIntensityOf({ intensity: light.intensity, distance: light.distance, decay: 2, y: light.y }) : light.intensity;
|
|
521
|
+
const source = budget.addSource({ owner: "urban.light", priority: LIGHT_PRIORITY.street, color: light.color, intensity, distance: light.distance, decay: 2, position: [0, 0, 0], follow: bulb });
|
|
522
|
+
lights.push({ bulb, lamp, source });
|
|
523
|
+
if (lamp.flicker && lamp.flickerPhase !== void 0) {
|
|
524
|
+
const phase = flickerGroupPhase(flickerGroupOf(lamp.flickerPhase));
|
|
525
|
+
animators.push((t) => source.update({ intensity: intensity * flickerLevel(t, phase) }));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
root.add(...drawn.meshes, ...wires.near, wires.far, lenses);
|
|
529
|
+
const nearDistance = options.nearDistance ?? NEAR_DISTANCE;
|
|
530
|
+
return {
|
|
531
|
+
root,
|
|
532
|
+
lamps,
|
|
533
|
+
lights,
|
|
534
|
+
spans: wires.spans,
|
|
535
|
+
drawCalls: () => ({ near: [...drawn.meshes, ...wires.near, lenses].filter((mesh) => mesh.visible && (!(mesh instanceof THREE.InstancedMesh) || mesh.count > 0)).length, far: wires.far.visible ? 1 : 0 }),
|
|
536
|
+
setFocus: (x, z) => wires.setFocus(x, z, nearDistance),
|
|
537
|
+
animate(t) {
|
|
538
|
+
for (const step of animators) step(t);
|
|
539
|
+
if (flickering.length === 0) return;
|
|
540
|
+
for (const item of flickering) lenses.setColorAt(item.index, color.set(item.lit).multiplyScalar(flickerLevel(t, item.phase)));
|
|
541
|
+
lenses.instanceColor.needsUpdate = true;
|
|
542
|
+
},
|
|
543
|
+
dispose() {
|
|
544
|
+
for (const light of lights) light.source.remove();
|
|
545
|
+
root.parent?.remove(root);
|
|
546
|
+
wires.dispose();
|
|
547
|
+
drawn.dispose();
|
|
548
|
+
lenses.dispose();
|
|
549
|
+
lenses.geometry.dispose();
|
|
550
|
+
lensMaterial.dispose();
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
|
|
98
555
|
// src/draw.ts
|
|
99
556
|
var DEFAULT_ROUGHNESS = 0.9;
|
|
100
557
|
var DEFAULT_METALNESS = 0;
|
|
@@ -105,7 +562,7 @@ var SIGN_FONT = '700 56px "Arial Narrow", Arial, sans-serif';
|
|
|
105
562
|
var SIGN_CANVAS = { width: 512, height: 128 };
|
|
106
563
|
var PLANE_LAYER_GAP = 2e-3;
|
|
107
564
|
function createUrbanThree(THREE, options = {}) {
|
|
108
|
-
const T =
|
|
565
|
+
const T = shapeGeometries4(THREE);
|
|
109
566
|
const geometries = /* @__PURE__ */ new Map();
|
|
110
567
|
const materials = /* @__PURE__ */ new Map();
|
|
111
568
|
const disposables = [];
|
|
@@ -177,7 +634,7 @@ function createUrbanThree(THREE, options = {}) {
|
|
|
177
634
|
const aimAt = (node, from, to) => {
|
|
178
635
|
node.quaternion.setFromUnitVectors(forward, new THREE.Vector3(to.x - from.x, to.y - from.y, to.z - from.z).normalize());
|
|
179
636
|
};
|
|
180
|
-
const sourceOf = (part, bulb, extra) => options.lights.addSource({ owner: "urban.light", priority:
|
|
637
|
+
const sourceOf = (part, bulb, extra) => options.lights.addSource({ owner: "urban.light", priority: LIGHT_PRIORITY2.street, color: part.color, intensity: part.intensity, distance: part.distance, decay: part.decay, position: [0, 0, 0], follow: bulb, ...extra });
|
|
181
638
|
const pageFlicker = (t, x) => Math.sin(t * 23 + x) > 0.3 || Math.sin(t * 3.1) > 0.85 ? 0.15 : 1;
|
|
182
639
|
const groupedPhaseOf = (part) => options.flickerLenses && part.kind === "point" && part.flickerPhase !== void 0 ? flickerGroupPhase(flickerGroupOf(part.flickerPhase)) : void 0;
|
|
183
640
|
const drawBudgetedLight = (part, animators, lights) => {
|
|
@@ -414,7 +871,7 @@ function createUrbanThree(THREE, options = {}) {
|
|
|
414
871
|
};
|
|
415
872
|
};
|
|
416
873
|
function draw(scene, drawOptions = {}) {
|
|
417
|
-
const root =
|
|
874
|
+
const root = markKitOrigin2(drawOptions.root ?? new THREE.Group(), { owner: "game-urban-three", kind: "urban" });
|
|
418
875
|
const animators = [];
|
|
419
876
|
const lights = [];
|
|
420
877
|
animatedLenses = /* @__PURE__ */ new Set();
|
|
@@ -451,7 +908,8 @@ function createUrbanThree(THREE, options = {}) {
|
|
|
451
908
|
}
|
|
452
909
|
};
|
|
453
910
|
}
|
|
454
|
-
|
|
911
|
+
const networks = (data, drawOptions = {}) => drawNetworks(THREE, { networks: data, options: drawOptions, ...options.lights ? { budget: options.lights } : {}, ...options.physicalLights ? { physicalLights: true } : {} });
|
|
912
|
+
return { THREE, draw, drawNetworks: networks };
|
|
455
913
|
}
|
|
456
914
|
|
|
457
915
|
// src/resolvers.ts
|
|
@@ -943,7 +1401,7 @@ function createUrbanTestModule(options = {}) {
|
|
|
943
1401
|
for (const lamp of entry.drawn.lights) {
|
|
944
1402
|
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;
|
|
945
1403
|
if (!light) continue;
|
|
946
|
-
const reach = new three.Mesh(new (
|
|
1404
|
+
const reach = new three.Mesh(new (shapeGeometries5(three)).SphereGeometry(Math.min(light.distance || 10, 60), 14, 8), new three.MeshBasicMaterial({ color: light.color ?? 16764006, wireframe: true, transparent: true, opacity: 0.25 }));
|
|
947
1405
|
reach.position.copy(light.node.position);
|
|
948
1406
|
mark(light.node.parent ?? entry.root, reach);
|
|
949
1407
|
}
|
|
@@ -1071,6 +1529,7 @@ export {
|
|
|
1071
1529
|
createRoundedBox,
|
|
1072
1530
|
createPrism,
|
|
1073
1531
|
createTextTexture,
|
|
1532
|
+
WIRE_STYLE,
|
|
1074
1533
|
createUrbanThree,
|
|
1075
1534
|
createVehicleResolver,
|
|
1076
1535
|
createPlantResolver,
|
|
@@ -1082,4 +1541,4 @@ export {
|
|
|
1082
1541
|
createUrbanTestModule,
|
|
1083
1542
|
loadUrbanTestModule
|
|
1084
1543
|
};
|
|
1085
|
-
//# sourceMappingURL=chunk-
|
|
1544
|
+
//# sourceMappingURL=chunk-JTXGLKOL.js.map
|