mirror of
https://github.com/Floriansylvain/generic-threejs-game.git
synced 2026-08-19 11:43:18 +02:00
feat: improved render distance system + camera culling
This commit is contained in:
+6
-2
@@ -31,7 +31,12 @@ function App() {
|
|||||||
className="container"
|
className="container"
|
||||||
onClick={() => container.current?.requestPointerLock()}
|
onClick={() => container.current?.requestPointerLock()}
|
||||||
>
|
>
|
||||||
<Canvas className="canvas" ref={container} shadows camera={{ fov: 50 }}>
|
<Canvas
|
||||||
|
className="canvas"
|
||||||
|
ref={container}
|
||||||
|
shadows
|
||||||
|
camera={{ fov: 50, frustumCulled: true, near: 0.1, far: 100 }}
|
||||||
|
>
|
||||||
<Cubes cubesPosition={cubes}></Cubes>
|
<Cubes cubesPosition={cubes}></Cubes>
|
||||||
|
|
||||||
<mesh
|
<mesh
|
||||||
@@ -63,7 +68,6 @@ function App() {
|
|||||||
<ambientLight intensity={Math.PI / 2} />
|
<ambientLight intensity={Math.PI / 2} />
|
||||||
|
|
||||||
<color args={["lightblue"]} attach={"background"}></color>
|
<color args={["lightblue"]} attach={"background"}></color>
|
||||||
<fog attach={"fog"} args={["lightblue", 0, 100]}></fog>
|
|
||||||
{/* <gridHelper args={[100, 100]}></gridHelper> */}
|
{/* <gridHelper args={[100, 100]}></gridHelper> */}
|
||||||
{/* <axesHelper args={[100]}></axesHelper> */}
|
{/* <axesHelper args={[100]}></axesHelper> */}
|
||||||
<EffectComposer enableNormalPass>
|
<EffectComposer enableNormalPass>
|
||||||
|
|||||||
@@ -20,14 +20,17 @@ export interface KeyPressed {
|
|||||||
sprint: boolean;
|
sprint: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PLAYER_SPEED = 4.75;
|
const PLAYER_SPEED = 4.75 * 10;
|
||||||
const SHADOW_DRAW_DISTANCE = 30;
|
const DRAW_DISTANCE = 50;
|
||||||
|
const SHADOW_RESOLUTION = 2048;
|
||||||
const MOUSE_X_SENSITIVITY = 0.002;
|
const MOUSE_X_SENSITIVITY = 0.002;
|
||||||
const MOUSE_Y_SENSITIVITY = 0.001;
|
const MOUSE_Y_SENSITIVITY = 0.001;
|
||||||
const ANIM_SPEED = 0.2;
|
const ANIM_SPEED = 0.2;
|
||||||
const CAMERA_RADIUS = 2;
|
const CAMERA_RADIUS = 2;
|
||||||
const CAMERA_HEIGHT = 1.5;
|
const CAMERA_HEIGHT = 1.5;
|
||||||
|
|
||||||
|
const SHADOW_DRAW_DISTANCE = DRAW_DISTANCE * 1.2;
|
||||||
|
|
||||||
export function Player(): JSX.Element {
|
export function Player(): JSX.Element {
|
||||||
const model = useGLTF("/Adventurer.glb");
|
const model = useGLTF("/Adventurer.glb");
|
||||||
const anims = useAnimations(model.animations, model.scene);
|
const anims = useAnimations(model.animations, model.scene);
|
||||||
@@ -206,7 +209,7 @@ export function Player(): JSX.Element {
|
|||||||
100,
|
100,
|
||||||
model.scene.position.z + 100,
|
model.scene.position.z + 100,
|
||||||
]}
|
]}
|
||||||
shadow-mapSize={[2048, 2048]}
|
shadow-mapSize={[SHADOW_RESOLUTION, SHADOW_RESOLUTION]}
|
||||||
intensity={6}
|
intensity={6}
|
||||||
>
|
>
|
||||||
<orthographicCamera
|
<orthographicCamera
|
||||||
@@ -219,6 +222,10 @@ export function Player(): JSX.Element {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</directionalLight>
|
</directionalLight>
|
||||||
|
<fog
|
||||||
|
attach={"fog"}
|
||||||
|
args={["lightblue", DRAW_DISTANCE * 0.8, DRAW_DISTANCE]}
|
||||||
|
></fog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user