55 lines
2.3 KiB
TypeScript
55 lines
2.3 KiB
TypeScript
import * as THREE from 'three';
|
|
import { describe, expect, it } from 'vitest';
|
|
import type { GroundMapLayer, TerrainGrid } from '../src/core/ground-model';
|
|
import { setTerrainMapMode, terrainMapGeometry } from '../src/view/terrain-map';
|
|
|
|
const layer: GroundMapLayer = {
|
|
id: 'satellite',
|
|
name: '위성사진',
|
|
mime_type: 'image/jpeg',
|
|
image: 'data:image/jpeg;base64,/9j/2Q==',
|
|
survey_corners: [[100, 200], [100, 220], [120, 200], [120, 220]],
|
|
};
|
|
|
|
describe('3D 위치 지도', () => {
|
|
it('maps swapped JSON X/Y corners into the terrain grid frame below its EL', () => {
|
|
const geometry = terrainMapGeometry(layer, { e: 210, n: 110 }, 25);
|
|
const positions = geometry.getAttribute('position') as THREE.BufferAttribute;
|
|
expect(new THREE.Vector3().fromBufferAttribute(positions, 0).toArray()).toEqual([-10, 25, -10]);
|
|
expect(new THREE.Vector3().fromBufferAttribute(positions, 1).toArray()).toEqual([10, 25, -10]);
|
|
expect(new THREE.Vector3().fromBufferAttribute(positions, 2).toArray()).toEqual([-10, 25, 10]);
|
|
expect(new THREE.Vector3().fromBufferAttribute(positions, 3).toArray()).toEqual([10, 25, 10]);
|
|
expect(Array.from(geometry.getAttribute('uv').array)).toEqual([0, 0, 1, 0, 0, 1, 1, 1]);
|
|
});
|
|
|
|
it('conforms the map vertices to the terrain grid elevations', () => {
|
|
const grid: TerrainGrid = {
|
|
origin: [100, 200],
|
|
step: 10,
|
|
nx: 3,
|
|
ny: 3,
|
|
z: [20, 21, 22, 23, 24, 25, 26, 27, 28],
|
|
};
|
|
const geometry = terrainMapGeometry(layer, { e: 210, n: 110 }, 25, grid);
|
|
const positions = geometry.getAttribute('position') as THREE.BufferAttribute;
|
|
expect(positions.count).toBeGreaterThanOrEqual(9);
|
|
expect(geometry.getIndex()?.count).toBeGreaterThan(0);
|
|
expect(Math.abs(positions.getY(0) - 20.08)).toBeLessThan(0.001);
|
|
});
|
|
|
|
it('switches between 2D and satellite layers without moving their coordinates', () => {
|
|
const group = new THREE.Group();
|
|
const satellite = new THREE.Mesh();
|
|
satellite.userData.mapId = 'satellite';
|
|
const ground = new THREE.Mesh();
|
|
ground.userData.mapId = 'ground';
|
|
group.add(satellite, ground);
|
|
setTerrainMapMode(group, 'ground');
|
|
expect(satellite.visible).toBe(false);
|
|
expect(ground.visible).toBe(true);
|
|
setTerrainMapMode(group, 'satellite');
|
|
expect(satellite.visible).toBe(true);
|
|
expect(ground.visible).toBe(false);
|
|
});
|
|
});
|