update : add map model + octree algo

This commit is contained in:
2026-04-17 11:36:03 +02:00
parent ed7681a293
commit 20fbaf05e1
10 changed files with 319 additions and 68 deletions
+49
View File
@@ -0,0 +1,49 @@
import { useEffect, useRef } from "react";
import { Physics, RigidBody, CuboidCollider } from "@react-three/rapier";
import * as THREE from "three";
import { Octree } from "three/addons/math/Octree.js";
import { GrabCube } from "@/world/objects/GrabCube";
import { TriggerSphere } from "@/world/objects/TriggerSphere";
interface TestSceneProps {
onOctreeReady: (octree: Octree) => void;
}
export function TestScene({
onOctreeReady,
}: TestSceneProps): React.JSX.Element {
const floorRef = useRef<THREE.Group>(null);
const octreeBuilt = useRef(false);
useEffect(() => {
if (octreeBuilt.current || !floorRef.current) return;
octreeBuilt.current = true;
floorRef.current.updateMatrixWorld(true);
const octree = new Octree();
octree.fromGraphNode(floorRef.current);
onOctreeReady(octree);
}, [onOctreeReady]);
return (
<>
{/* Invisible floor mesh for Octree player collision */}
<group ref={floorRef}>
<mesh visible={false} position={[0, -0.5, 0]}>
<boxGeometry args={[200, 1, 200]} />
<meshBasicMaterial />
</mesh>
</group>
{/* Rapier physics for interactable objects */}
<Physics>
<RigidBody type="fixed">
<CuboidCollider args={[100, 0.5, 100]} position={[0, -0.5, 0]} />
</RigidBody>
<GrabCube />
<TriggerSphere />
</Physics>
</>
);
}