Skip to content

Commit 62a9b24

Browse files
committed
Fill gaps in map
1 parent 954fa5a commit 62a9b24

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/browser/main.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,25 @@ function BuildMap(dat: Uint8Array, offset: number, tiles1: Mesh[], tiles2: Mesh[
3939
let tile = dat[mapoffsetLocal + (i + j * 32) * 2 + 0];
4040
const rot = dat[mapoffsetLocal + (i + j * 32) * 2 + 1] >> 6;
4141
const height = dat[mapoffsetLocal + (i + j * 32) * 2 + 1] & 0x3F;
42-
let ob: THREE.Object3D | null = null;
42+
let obMesh: Mesh | null = null;
4343
if (tile < 0x40) {
4444
if (tile < tiles2.length)
45-
ob = tiles2[tile].obj!.clone();
45+
obMesh = tiles2[tile];
4646
} else {
4747
tile -= 0x40;
4848
if (tile < tiles1.length)
49-
ob = tiles1[tile].obj!.clone();
49+
obMesh = tiles1[tile];
50+
}
51+
if (obMesh == null || obMesh.vertices.length === 0) {
52+
console.log("No object found or empty geometry for tile " + tile + ", falling back to tile 0");
53+
if (tiles2.length > 0)
54+
obMesh = tiles2[0];
55+
}
56+
let ob: THREE.Object3D | null = null;
57+
if (obMesh != null && obMesh.obj != null) {
58+
ob = obMesh.obj.clone();
5059
}
5160
if (ob == null) {
52-
console.log("No object found " + tile + " " + tiles2.length + " " + tiles1.length);
5361
continue;
5462
}
5563
ob.rotation.z += -Math.PI / 2 * (rot);

src/shared/mapgen.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ export function BuildMap(dat: Uint8Array, offset: number, tiles1: Mesh[], tiles2
4646
if (tile < tiles1.length)
4747
ob = tiles1[tile];
4848
}
49-
if (ob == null) {
50-
console.log("No object found " + tile + " " + tiles2.length + " " + tiles1.length);
49+
if (ob == null || ob.vertices.length === 0) {
50+
console.log("No object found or empty geometry for tile " + tile + ", falling back to tile 0");
51+
if (tiles2.length > 0)
52+
ob = tiles2[0];
53+
}
54+
if (ob == null || ob.vertices.length === 0) {
5155
continue;
5256
}
5357
const obt = CloneMesh(

0 commit comments

Comments
 (0)