import { test } from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { Mesh, MeshBasicMaterial, Raycaster, Vector3 } from 'three'; import { createTerrainGeometry, terrainGeometryHeightAt } from '../src/scene/terrainGeometry.ts'; import { applySummitTerrain } from '../src/scene/summitTerrain.ts'; import { SUMMIT_TERRAIN } from '../src/constants/summitTerrain.ts'; import { SUMMIT_PLATEAU } from '../src/constants/summitPlateau.ts'; import { structurePosition } from '../src/scene/structures.ts'; import { STRUCTURES } from '../src/constants/structures.ts'; const meta = JSON.parse(readFileSync(new URL('../public/terrain/gwanaksan.json', import.meta.url), 'utf8')); const bytes = readFileSync(new URL('../public/terrain/gwanaksan.f32', import.meta.url)); const heights = new Float32Array(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)); const start = structurePosition(SUMMIT_TERRAIN.start.latitude, SUMMIT_TERRAIN.start.longitude, meta.origin); test('authored terrain edges join the surrounding slope without vertical steps', () => { const geometry = createTerrainGeometry(meta, heights, true); applySummitTerrain(geometry, meta); const [left, top, right, bottom] = SUMMIT_PLATEAU.atlasBounds; const height = (x: number, z: number) => terrainGeometryHeightAt(geometry, start.x+x, start.z+z); try { // Scan across all four seams, including the last authored half-metre cell. for (const [edge, from, to, horizontal] of [ [left, top, bottom, true], [right, top, bottom, true], [top, left, right, false], [bottom, left, right, false], ] as const) { for (let along = from; along <= to; along += .5) { for (let offset = -1; offset < 1; offset += .25) { const a = horizontal ? height(edge+offset, along) : height(along, edge+offset); const b = horizontal ? height(edge+offset+.25, along) : height(along, edge+offset+.25); assert.ok(Math.abs(b-a) < .5, `terrain seam at ${edge}, ${along}: ${Math.abs(b-a)}m step over 0.25m`); } } } } finally { geometry.dispose(); } }); test('local reconstruction preserves source data and every vertex outside 200m', () => { const geometry = createTerrainGeometry(meta, heights, true); const p = geometry.getAttribute('position'); const before = p.array.slice(); const source = heights.slice(); applySummitTerrain(geometry, meta); let changed = 0; for (let i=0; i