fix: dupplicate buisson and ecole
This commit is contained in:
@@ -5,6 +5,7 @@ const MAP_JSON_PATH = "/map.json";
|
|||||||
const MODEL_FILE_NAMES = ["model.glb", "model.gltf"];
|
const MODEL_FILE_NAMES = ["model.glb", "model.gltf"];
|
||||||
const HTML_CONTENT_TYPE = "text/html";
|
const HTML_CONTENT_TYPE = "text/html";
|
||||||
const MAP_STRUCTURE_NODE_NAMES = new Set(["Scene", "blocking"]);
|
const MAP_STRUCTURE_NODE_NAMES = new Set(["Scene", "blocking"]);
|
||||||
|
const POSITION_PRECISION = 3;
|
||||||
type ModelEntry = [modelName: string, modelUrl: string];
|
type ModelEntry = [modelName: string, modelUrl: string];
|
||||||
|
|
||||||
let cachedSceneData: SceneData | null = null;
|
let cachedSceneData: SceneData | null = null;
|
||||||
@@ -45,7 +46,42 @@ async function loadMapSceneDataInternal(): Promise<SceneData | null> {
|
|||||||
|
|
||||||
const mapPayload: unknown = await response.json();
|
const mapPayload: unknown = await response.json();
|
||||||
const mapNodes = parseMapNodes(mapPayload);
|
const mapNodes = parseMapNodes(mapPayload);
|
||||||
return createSceneData(mapNodes);
|
const deduplicatedNodes = deduplicateMapNodes(mapNodes);
|
||||||
|
return createSceneData(deduplicatedNodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createPositionKey(node: MapNode): string {
|
||||||
|
const [x, y, z] = node.position;
|
||||||
|
const px = x.toFixed(POSITION_PRECISION);
|
||||||
|
const py = y.toFixed(POSITION_PRECISION);
|
||||||
|
const pz = z.toFixed(POSITION_PRECISION);
|
||||||
|
return `${node.name}:${px},${py},${pz}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deduplicateMapNodes(nodes: MapNode[]): MapNode[] {
|
||||||
|
const seen = new Set<string>();
|
||||||
|
const result: MapNode[] = [];
|
||||||
|
|
||||||
|
const sortedNodes = [...nodes].sort((a, b) => {
|
||||||
|
if (a.type === "Object3D" && b.type !== "Object3D") return -1;
|
||||||
|
if (a.type !== "Object3D" && b.type === "Object3D") return 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const node of sortedNodes) {
|
||||||
|
if (MAP_STRUCTURE_NODE_NAMES.has(node.name)) {
|
||||||
|
result.push(node);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = createPositionKey(node);
|
||||||
|
if (!seen.has(key)) {
|
||||||
|
seen.add(key);
|
||||||
|
result.push(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createSceneData(mapNodes: MapNode[]): Promise<SceneData> {
|
async function createSceneData(mapNodes: MapNode[]): Promise<SceneData> {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ interface LoadedMapNode {
|
|||||||
const MAP_STRUCTURE_NODE_NAMES = new Set(["Scene", "blocking"]);
|
const MAP_STRUCTURE_NODE_NAMES = new Set(["Scene", "blocking"]);
|
||||||
const LITE_MAP_SKIPPED_NODE_NAMES = new Set([
|
const LITE_MAP_SKIPPED_NODE_NAMES = new Set([
|
||||||
"arbre",
|
"arbre",
|
||||||
"buissons",
|
"buisson",
|
||||||
"champdeble",
|
"champdeble",
|
||||||
"champdesoja",
|
"champdesoja",
|
||||||
"champsdetournesol",
|
"champsdetournesol",
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ function extractVegetationData(mapNodes: MapNode[]): VegetationData {
|
|||||||
if (!config.enabled) continue;
|
if (!config.enabled) continue;
|
||||||
|
|
||||||
const instances = mapNodes
|
const instances = mapNodes
|
||||||
.filter((node) => node.name === config.mapName)
|
.filter(
|
||||||
|
(node) => node.name === config.mapName && node.type === "Object3D",
|
||||||
|
)
|
||||||
.map(mapNodeToInstance);
|
.map(mapNodeToInstance);
|
||||||
|
|
||||||
if (instances.length > 0) {
|
if (instances.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user