refactor: nettoie l'architecture monde et les docs
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import {
|
||||
GAME_SCENE_FALLBACK_BACKGROUND_COLOR,
|
||||
GAME_SCENE_FALLBACK_SKY_MODEL_PATH,
|
||||
GAME_SCENE_FALLBACK_SKY_MODEL_SCALE,
|
||||
GAME_SCENE_SKY_MODEL_PATH,
|
||||
GAME_SCENE_SKY_MODEL_SCALE,
|
||||
PHYSICS_SCENE_BACKGROUND_COLOR,
|
||||
@@ -37,8 +35,6 @@ export function Environment(): React.JSX.Element {
|
||||
{showSky ? (
|
||||
<SkyModel
|
||||
fallbackColor={GAME_SCENE_FALLBACK_BACKGROUND_COLOR}
|
||||
fallbackModelPath={GAME_SCENE_FALLBACK_SKY_MODEL_PATH}
|
||||
fallbackScale={GAME_SCENE_FALLBACK_SKY_MODEL_SCALE}
|
||||
modelPath={GAME_SCENE_SKY_MODEL_PATH}
|
||||
scale={GAME_SCENE_SKY_MODEL_SCALE}
|
||||
/>
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import * as THREE from "three";
|
||||
import { InstancedMapAsset } from "@/world/map-instancing/InstancedMapAsset";
|
||||
import {
|
||||
PATH_DEBUG_PREVIEW_ENABLED,
|
||||
PATH_TILE_RENDER_ENABLED,
|
||||
PATH_TILE_MODEL_PATH,
|
||||
} from "@/data/world/pathConfig";
|
||||
import { usePathTileData } from "@/world/paths/usePathTileData";
|
||||
import type { MapAssetInstance } from "@/hooks/world/useMapInstancingData";
|
||||
|
||||
export function PathSystem(): React.JSX.Element | null {
|
||||
if (!PATH_DEBUG_PREVIEW_ENABLED && !PATH_TILE_RENDER_ENABLED) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <PathTiles />;
|
||||
}
|
||||
|
||||
function PathTiles(): React.JSX.Element | null {
|
||||
const pathTiles = usePathTileData();
|
||||
|
||||
if (pathTiles.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (PATH_DEBUG_PREVIEW_ENABLED) {
|
||||
return <PathDebugPreview instances={pathTiles} />;
|
||||
}
|
||||
|
||||
if (!PATH_TILE_RENDER_ENABLED) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<InstancedMapAsset
|
||||
castShadow={false}
|
||||
instances={pathTiles}
|
||||
modelPath={PATH_TILE_MODEL_PATH}
|
||||
receiveShadow
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function PathDebugPreview({
|
||||
instances,
|
||||
}: {
|
||||
instances: MapAssetInstance[];
|
||||
}): React.JSX.Element {
|
||||
const instancedMeshRef = useRef<THREE.InstancedMesh>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const instancedMesh = instancedMeshRef.current;
|
||||
if (!instancedMesh) return;
|
||||
|
||||
const matrix = new THREE.Matrix4();
|
||||
const position = new THREE.Vector3();
|
||||
const quaternion = new THREE.Quaternion();
|
||||
const scale = new THREE.Vector3(1, 1, 1);
|
||||
|
||||
for (let i = 0; i < instances.length; i++) {
|
||||
const instance = instances[i];
|
||||
if (!instance) continue;
|
||||
|
||||
position.set(
|
||||
instance.position[0],
|
||||
instance.position[1] + 0.08,
|
||||
instance.position[2],
|
||||
);
|
||||
matrix.compose(position, quaternion, scale);
|
||||
instancedMesh.setMatrixAt(i, matrix);
|
||||
}
|
||||
|
||||
instancedMesh.instanceMatrix.needsUpdate = true;
|
||||
instancedMesh.computeBoundingSphere();
|
||||
}, [instances]);
|
||||
|
||||
return (
|
||||
<instancedMesh
|
||||
ref={instancedMeshRef}
|
||||
args={[undefined, undefined, instances.length]}
|
||||
>
|
||||
<boxGeometry args={[0.35, 0.08, 0.35]} />
|
||||
<meshBasicMaterial color="#ff00ff" />
|
||||
</instancedMesh>
|
||||
);
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
import { useMemo } from "react";
|
||||
import { TERRAIN_SURFACE_PROJECTION } from "@/data/world/terrainConfig";
|
||||
import { useTerrainHeightSampler } from "@/hooks/three/useTerrainHeight";
|
||||
import { useTerrainSurfaceData } from "@/hooks/world/useTerrainSurfaceData";
|
||||
import type { Vector3Tuple } from "@/types/three/three";
|
||||
import { sampleTerrainSurfaceAtXZ } from "@/utils/world/terrainSurfaceSampler";
|
||||
import type { MapAssetInstance } from "@/hooks/world/useMapInstancingData";
|
||||
import {
|
||||
PATH_TILE_MAX_COUNT,
|
||||
PATH_SURFACE_KEY,
|
||||
PATH_TILE_ROTATION,
|
||||
PATH_TILE_SAMPLE_STEP,
|
||||
PATH_TILE_SCALE,
|
||||
} from "@/data/world/pathConfig";
|
||||
|
||||
function createSampleCenters(min: number, max: number, step: number): number[] {
|
||||
const start = Math.ceil(min / step) * step + step * 0.5;
|
||||
const centers: number[] = [];
|
||||
|
||||
for (let value = start; value <= max; value += step) {
|
||||
centers.push(value);
|
||||
}
|
||||
|
||||
return centers;
|
||||
}
|
||||
|
||||
export function usePathTileData(): MapAssetInstance[] {
|
||||
const terrainSurfaceData = useTerrainSurfaceData();
|
||||
const terrainHeight = useTerrainHeightSampler();
|
||||
|
||||
return useMemo(() => {
|
||||
if (!terrainSurfaceData) return [];
|
||||
|
||||
const instances: MapAssetInstance[] = [];
|
||||
const xCenters = createSampleCenters(
|
||||
terrainSurfaceData.bounds.minX,
|
||||
terrainSurfaceData.bounds.maxX,
|
||||
PATH_TILE_SAMPLE_STEP,
|
||||
);
|
||||
const zCenters = createSampleCenters(
|
||||
terrainSurfaceData.bounds.minZ,
|
||||
terrainSurfaceData.bounds.maxZ,
|
||||
PATH_TILE_SAMPLE_STEP,
|
||||
);
|
||||
|
||||
for (const x of xCenters) {
|
||||
for (const z of zCenters) {
|
||||
if (instances.length >= PATH_TILE_MAX_COUNT) return instances;
|
||||
|
||||
const sample = sampleTerrainSurfaceAtXZ(
|
||||
terrainSurfaceData.imageData,
|
||||
x,
|
||||
z,
|
||||
terrainSurfaceData.bounds,
|
||||
TERRAIN_SURFACE_PROJECTION,
|
||||
);
|
||||
|
||||
if (sample.key !== PATH_SURFACE_KEY) continue;
|
||||
|
||||
const height = terrainHeight.getHeight(x, z) ?? 0;
|
||||
|
||||
instances.push({
|
||||
position: [x, height, z],
|
||||
rotation: [...PATH_TILE_ROTATION] as Vector3Tuple,
|
||||
scale: [...PATH_TILE_SCALE] as Vector3Tuple,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return instances;
|
||||
}, [terrainHeight, terrainSurfaceData]);
|
||||
}
|
||||
Reference in New Issue
Block a user