feat(world): Gebäude, die ein Ort ersetzt, beim Chunk-Aufbau weglassen
withoutReplacedBuildings filtert die Grundrisse, in denen ein Weltpunkt aus PLACES[].replaces liegt; ChunkStreamer baut die Geometrie daraus, main.js übergibt die Punkte aller Orte. Damit entfallen Kasten, Schatten und Kollision des alten Gebäudes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f7506ac556
commit
e33c1817ec
3 files changed
+80
-8
No files matched your search
+18
-3
@@ -1,6 +1,7 @@
|
||||
import { Group, Mesh } from "three";
|
||||
import { CHUNKS_PER_SIDE, CHUNK_SIZE, SLICE } from "./coords.js";
|
||||
import { buildChunkGeometry } from "./geometry.js";
|
||||
import { pointInPolygon } from "./props.js";
|
||||
|
||||
const key = (i, j) => `${i}_${j}`;
|
||||
const DECALS = new Set(["roads", "sand", "park", "urban"]);
|
||||
@@ -31,9 +32,23 @@ function dist(k, position) {
|
||||
return Math.hypot(c.x - position.x, c.z - position.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Der Chunk ohne die Gebäudegrundrisse, die ein Ort ersetzt (PLACES[].replaces in src/world/places.js):
|
||||
* jeder Grundriss, in dem einer der Weltpunkte [x, y] liegt, entfällt — und mit ihm Kasten, Schatten und
|
||||
* Kollision. Wirkt wie remove_building der Feinkalibrierung, nur zur Laufzeit. Trifft kein Punkt, kommt
|
||||
* derselbe Chunk zurück.
|
||||
*/
|
||||
export function withoutReplacedBuildings(chunk, points) {
|
||||
if (points.length === 0) return chunk;
|
||||
const [ox, oz] = chunk.origin;
|
||||
const buildings = chunk.buildings.filter((building) =>
|
||||
!points.some(([x, y]) => pointInPolygon(x - ox, -y - oz, building.poly)));
|
||||
return buildings.length === chunk.buildings.length ? chunk : { ...chunk, buildings };
|
||||
}
|
||||
|
||||
export class ChunkStreamer {
|
||||
constructor({ scene, player, materials, props, baseUrl = "./data/vice-a", pinned = [] }) {
|
||||
Object.assign(this, { scene, player, materials, props, baseUrl });
|
||||
constructor({ scene, player, materials, props, baseUrl = "./data/vice-a", pinned = [], replacedBuildings = [] }) {
|
||||
Object.assign(this, { scene, player, materials, props, baseUrl, replacedBuildings });
|
||||
this.active = new Map(); // key -> { group, handle }
|
||||
this.pending = new Set();
|
||||
this.queue = [];
|
||||
@@ -63,7 +78,7 @@ export class ChunkStreamer {
|
||||
const [i, j] = k.split("_").map(Number);
|
||||
const group = new Group();
|
||||
group.position.set(chunk.origin[0], 0, chunk.origin[1]);
|
||||
const geos = buildChunkGeometry(chunk);
|
||||
const geos = buildChunkGeometry(withoutReplacedBuildings(chunk, this.replacedBuildings));
|
||||
const collide = new Group();
|
||||
for (const [name, geo] of Object.entries(geos)) {
|
||||
if (!geo) continue;
|
||||
|
||||
Reference in new issue
Block a user