fix: a pb with octree

This commit is contained in:
Tom Boullay
2026-05-11 16:43:02 +02:00
parent 6f5137229d
commit ff21b80d57
3 changed files with 28 additions and 8 deletions
+4 -1
View File
@@ -8,6 +8,7 @@ export function useOctreeGraphNode(
graphNodeRef: RefObject<Object3D | null>, graphNodeRef: RefObject<Object3D | null>,
onOctreeReady: OctreeReadyHandler, onOctreeReady: OctreeReadyHandler,
rebuildKey: string | number = 0, rebuildKey: string | number = 0,
enabled = true,
): void { ): void {
const octreeBuilt = useRef(false); const octreeBuilt = useRef(false);
@@ -16,6 +17,8 @@ export function useOctreeGraphNode(
}, [rebuildKey]); }, [rebuildKey]);
useEffect(() => { useEffect(() => {
if (!enabled) return;
const graphNode = graphNodeRef.current; const graphNode = graphNodeRef.current;
if (octreeBuilt.current || !graphNode) return; if (octreeBuilt.current || !graphNode) return;
octreeBuilt.current = true; octreeBuilt.current = true;
@@ -25,5 +28,5 @@ export function useOctreeGraphNode(
const octree = new Octree(); const octree = new Octree();
octree.fromGraphNode(graphNode); octree.fromGraphNode(graphNode);
onOctreeReady(octree); onOctreeReady(octree);
}, [graphNodeRef, onOctreeReady, rebuildKey]); }, [enabled, graphNodeRef, onOctreeReady, rebuildKey]);
} }
+6 -2
View File
@@ -62,13 +62,17 @@ class ModelErrorBoundary extends Component<
interface GameMapProps { interface GameMapProps {
onOctreeReady: OctreeReadyHandler; onOctreeReady: OctreeReadyHandler;
buildOctree?: boolean;
} }
export function GameMap({ onOctreeReady }: GameMapProps): React.JSX.Element { export function GameMap({
onOctreeReady,
buildOctree = true,
}: GameMapProps): React.JSX.Element {
const [mapNodes, setMapNodes] = useState<LoadedMapNode[]>([]); const [mapNodes, setMapNodes] = useState<LoadedMapNode[]>([]);
const groupRef = useRef<THREE.Group>(null); const groupRef = useRef<THREE.Group>(null);
useOctreeGraphNode(groupRef, onOctreeReady, mapNodes.length); useOctreeGraphNode(groupRef, onOctreeReady, mapNodes.length, buildOctree);
useEffect(() => { useEffect(() => {
const loadMap = async () => { const loadMap = async () => {
+18 -5
View File
@@ -19,10 +19,21 @@ import { GameStageContent } from "@/world/GameStageContent";
import { Player } from "@/world/player/Player"; import { Player } from "@/world/player/Player";
import { TestMap } from "@/world/debug/TestMap"; import { TestMap } from "@/world/debug/TestMap";
function hasBootFlag(name: string): boolean {
if (typeof window === "undefined") return false;
return new URLSearchParams(window.location.search).has(name);
}
export function World(): React.JSX.Element { export function World(): React.JSX.Element {
const cameraMode = useCameraMode(); const cameraMode = useCameraMode();
const sceneMode = useSceneMode(); const sceneMode = useSceneMode();
const [octree, setOctree] = useState<Octree | null>(null); const [octree, setOctree] = useState<Octree | null>(null);
const noCinematics = hasBootFlag("noCinematics");
const noDialogues = hasBootFlag("noDialogues");
const noMap = hasBootFlag("noMap");
const noMusic = hasBootFlag("noMusic");
const noOctree = hasBootFlag("noOctree");
const noPlayer = hasBootFlag("noPlayer");
const playerSpawnPosition = const playerSpawnPosition =
sceneMode === "game" sceneMode === "game"
? PLAYER_SPAWN_POSITION_GAME ? PLAYER_SPAWN_POSITION_GAME
@@ -43,17 +54,19 @@ export function World(): React.JSX.Element {
{sceneMode === "game" ? ( {sceneMode === "game" ? (
<> <>
<GameMusic /> {noMusic ? null : <GameMusic />}
<GameCinematics /> {noCinematics ? null : <GameCinematics />}
<GameDialogues /> {noDialogues ? null : <GameDialogues />}
<GameMap onOctreeReady={setOctree} /> {noMap ? null : (
<GameMap onOctreeReady={setOctree} buildOctree={!noOctree} />
)}
<GameStageContent /> <GameStageContent />
</> </>
) : ( ) : (
<TestMap onOctreeReady={setOctree} /> <TestMap onOctreeReady={setOctree} />
)} )}
{cameraMode !== "debug" ? ( {cameraMode !== "debug" && !noPlayer ? (
<Player octree={octree} spawnPosition={playerSpawnPosition} /> <Player octree={octree} spawnPosition={playerSpawnPosition} />
) : null} ) : null}
</> </>