fix(map): align path preview with terrain projection

This commit is contained in:
Tom Boullay
2026-05-25 17:54:57 +02:00
parent 4f8355e934
commit 2b08665508
3 changed files with 13 additions and 5 deletions
+2 -2
View File
@@ -91,8 +91,8 @@ export function terrainSurfaceUvFromXZ(
): TerrainSurfaceUv { ): TerrainSurfaceUv {
const width = bounds.maxX - bounds.minX; const width = bounds.maxX - bounds.minX;
const depth = bounds.maxZ - bounds.minZ; const depth = bounds.maxZ - bounds.minZ;
let u = width === 0 ? 0 : (x - bounds.minX) / width; let u = width === 0 ? 0 : x / width + 0.5;
let v = depth === 0 ? 0 : (z - bounds.minZ) / depth; let v = depth === 0 ? 0 : z / depth + 0.5;
if (projection?.flipX) { if (projection?.flipX) {
u = 1 - u; u = 1 - u;
+5 -1
View File
@@ -62,7 +62,11 @@ function PathDebugPreview({
const instance = instances[i]; const instance = instances[i];
if (!instance) continue; if (!instance) continue;
position.set(instance.position[0], 0.08, instance.position[2]); position.set(
instance.position[0],
instance.position[1] + 0.08,
instance.position[2],
);
matrix.compose(position, quaternion, scale); matrix.compose(position, quaternion, scale);
instancedMesh.setMatrixAt(i, matrix); instancedMesh.setMatrixAt(i, matrix);
} }
+6 -2
View File
@@ -1,5 +1,6 @@
import { useMemo } from "react"; import { useMemo } from "react";
import { TERRAIN_SURFACE_PROJECTION } from "@/data/world/terrainConfig"; import { TERRAIN_SURFACE_PROJECTION } from "@/data/world/terrainConfig";
import { useTerrainHeightSampler } from "@/hooks/three/useTerrainHeight";
import { useTerrainSurfaceData } from "@/hooks/world/useTerrainSurfaceData"; import { useTerrainSurfaceData } from "@/hooks/world/useTerrainSurfaceData";
import type { Vector3Tuple } from "@/types/three/three"; import type { Vector3Tuple } from "@/types/three/three";
import { sampleTerrainSurfaceAtXZ } from "@/utils/world/terrainSurfaceSampler"; import { sampleTerrainSurfaceAtXZ } from "@/utils/world/terrainSurfaceSampler";
@@ -25,6 +26,7 @@ function createSampleCenters(min: number, max: number, step: number): number[] {
export function usePathTileData(): MapAssetInstance[] { export function usePathTileData(): MapAssetInstance[] {
const terrainSurfaceData = useTerrainSurfaceData(); const terrainSurfaceData = useTerrainSurfaceData();
const terrainHeight = useTerrainHeightSampler();
return useMemo(() => { return useMemo(() => {
if (!terrainSurfaceData) return []; if (!terrainSurfaceData) return [];
@@ -55,8 +57,10 @@ export function usePathTileData(): MapAssetInstance[] {
if (sample.key !== PATH_SURFACE_KEY) continue; if (sample.key !== PATH_SURFACE_KEY) continue;
const height = terrainHeight.getHeight(x, z) ?? 0;
instances.push({ instances.push({
position: [x, 0, z], position: [x, height, z],
rotation: [...PATH_TILE_ROTATION] as Vector3Tuple, rotation: [...PATH_TILE_ROTATION] as Vector3Tuple,
scale: [...PATH_TILE_SCALE] as Vector3Tuple, scale: [...PATH_TILE_SCALE] as Vector3Tuple,
}); });
@@ -64,5 +68,5 @@ export function usePathTileData(): MapAssetInstance[] {
} }
return instances; return instances;
}, [terrainSurfaceData]); }, [terrainHeight, terrainSurfaceData]);
} }