diff --git a/src/hooks/three/useOctreeGraphNode.ts b/src/hooks/three/useOctreeGraphNode.ts index 741eb05..baf2ca0 100644 --- a/src/hooks/three/useOctreeGraphNode.ts +++ b/src/hooks/three/useOctreeGraphNode.ts @@ -3,6 +3,7 @@ import type { RefObject } from "react"; import type { Object3D } from "three"; import { Octree } from "three/addons/math/Octree.js"; import type { OctreeReadyHandler } from "@/types/three/three"; +import { logger } from "@/utils/core/Logger"; export function useOctreeGraphNode( graphNodeRef: RefObject, @@ -17,16 +18,25 @@ export function useOctreeGraphNode( }, [rebuildKey]); useEffect(() => { + logger.debug("useOctreeGraphNode", "Check", { + enabled, + octreeBuilt: octreeBuilt.current, + hasGraphNode: !!graphNodeRef.current, + rebuildKey, + }); + if (!enabled) return; const graphNode = graphNodeRef.current; if (!enabled || octreeBuilt.current || !graphNode) return; octreeBuilt.current = true; + logger.info("useOctreeGraphNode", "Building octree from graph node"); graphNode.updateMatrixWorld(true); const octree = new Octree(); octree.fromGraphNode(graphNode); + logger.info("useOctreeGraphNode", "Octree built, calling onOctreeReady"); onOctreeReady(octree); }, [enabled, graphNodeRef, onOctreeReady, rebuildKey]); } diff --git a/src/hooks/world/useWorldSceneLoading.ts b/src/hooks/world/useWorldSceneLoading.ts index 24020af..4810f14 100644 --- a/src/hooks/world/useWorldSceneLoading.ts +++ b/src/hooks/world/useWorldSceneLoading.ts @@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from "react"; import type { Octree } from "three/addons/math/Octree.js"; import type { SceneMode } from "@/types/debug/debug"; import type { SceneLoadingChangeHandler } from "@/types/world/sceneLoading"; +import { logger } from "@/utils/core/Logger"; interface UseWorldSceneLoadingOptions { onLoadingStateChange?: SceneLoadingChangeHandler | undefined; @@ -31,10 +32,12 @@ export function useWorldSceneLoading({ (sceneMode === "physics" && octree !== null); const handleGameMapLoaded = useCallback(() => { + logger.info("WorldSceneLoading", "GameMap loaded"); setGameMapLoaded(true); }, []); const handleGameStageLoaded = useCallback(() => { + logger.info("WorldSceneLoading", "GameStage loaded"); setGameStageLoaded(true); onLoadingStateChange?.({ currentStep: "Initialisation gameplay", @@ -45,6 +48,7 @@ export function useWorldSceneLoading({ const handleOctreeReady = useCallback( (nextOctree: Octree) => { + logger.info("WorldSceneLoading", "Octree ready"); setOctree(nextOctree); onLoadingStateChange?.({ currentStep: "Collision prĂȘte", diff --git a/src/world/GameMapCollision.tsx b/src/world/GameMapCollision.tsx index 2f5d16b..4939cfc 100644 --- a/src/world/GameMapCollision.tsx +++ b/src/world/GameMapCollision.tsx @@ -14,6 +14,7 @@ import { useOctreeGraphNode } from "@/hooks/three/useOctreeGraphNode"; import type { MapNode } from "@/types/editor/editor"; import type { OctreeReadyHandler } from "@/types/three/three"; import type { SceneLoadingChangeHandler } from "@/types/world/sceneLoading"; +import { logger } from "@/utils/core/Logger"; import { logModelLoadError } from "@/utils/three/modelLoadLogger"; export interface GameMapCollisionNode { @@ -108,6 +109,14 @@ export function GameMapCollision({ const collisionReady = mapReady && settledCollisionNodeCount >= collisionNodes.length; + logger.debug("GameMapCollision", "State", { + mapReady, + collisionNodesCount: collisionNodes.length, + settledCollisionNodeCount, + collisionReady, + buildOctree, + }); + const notifyLoaded = useCallback(() => { if (loadedNotifiedRef.current) return; @@ -124,6 +133,7 @@ export function GameMapCollision({ const handleOctreeReady = useCallback( (octree) => { + logger.info("GameMapCollision", "Octree built, calling onOctreeReady"); onLoadingStateChange?.({ currentStep: "Collision prĂȘte", progress: 0.92,