fix(environment): disable fog by default
This commit is contained in:
@@ -1,8 +1,22 @@
|
|||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
|
import * as THREE from "three";
|
||||||
import { useLoggedGLTF } from "@/hooks/three/useLoggedGLTF";
|
import { useLoggedGLTF } from "@/hooks/three/useLoggedGLTF";
|
||||||
import type { ModelTransformProps, Vector3Tuple } from "@/types/three/three";
|
import type { ModelTransformProps, Vector3Tuple } from "@/types/three/three";
|
||||||
import { disposeObject3D } from "@/utils/three/dispose";
|
import { disposeObject3D } from "@/utils/three/dispose";
|
||||||
|
|
||||||
|
function applyShadowSettings(
|
||||||
|
object: THREE.Object3D,
|
||||||
|
castShadow: boolean,
|
||||||
|
receiveShadow: boolean,
|
||||||
|
): void {
|
||||||
|
object.traverse((child) => {
|
||||||
|
if (!(child instanceof THREE.Mesh)) return;
|
||||||
|
|
||||||
|
child.castShadow = castShadow;
|
||||||
|
child.receiveShadow = receiveShadow;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export interface SimpleModelConfig extends ModelTransformProps {
|
export interface SimpleModelConfig extends ModelTransformProps {
|
||||||
modelPath: string;
|
modelPath: string;
|
||||||
castShadow?: boolean;
|
castShadow?: boolean;
|
||||||
@@ -30,6 +44,10 @@ export function SimpleModel({
|
|||||||
});
|
});
|
||||||
const model = useMemo(() => scene.clone(true), [scene]);
|
const model = useMemo(() => scene.clone(true), [scene]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
applyShadowSettings(model, castShadow, receiveShadow);
|
||||||
|
}, [castShadow, model, receiveShadow]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
disposeObject3D(model);
|
disposeObject3D(model);
|
||||||
@@ -41,13 +59,7 @@ export function SimpleModel({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<group position={position} rotation={rotation} scale={parsedScale}>
|
<group position={position} rotation={rotation} scale={parsedScale}>
|
||||||
{children ?? (
|
{children ?? <primitive object={model} />}
|
||||||
<primitive
|
|
||||||
object={model}
|
|
||||||
castShadow={castShadow}
|
|
||||||
receiveShadow={receiveShadow}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</group>
|
</group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { TERRAIN_COLORS } from "@/data/world/terrainConfig";
|
|||||||
export type FogMode = "linear" | "exp2";
|
export type FogMode = "linear" | "exp2";
|
||||||
|
|
||||||
export const FOG_CONFIG = {
|
export const FOG_CONFIG = {
|
||||||
enabled: true,
|
enabled: false,
|
||||||
mode: "exp2" as FogMode,
|
mode: "exp2" as FogMode,
|
||||||
color: "#dfe7d8",
|
color: "#dfe7d8",
|
||||||
near: 32,
|
near: 32,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
GAME_SCENE_SKY_MODEL_SCALE,
|
GAME_SCENE_SKY_MODEL_SCALE,
|
||||||
PHYSICS_SCENE_BACKGROUND_COLOR,
|
PHYSICS_SCENE_BACKGROUND_COLOR,
|
||||||
} from "@/data/world/environmentConfig";
|
} from "@/data/world/environmentConfig";
|
||||||
import { FOG_CONFIG, FOG_LIGHTING_COLOR_MIX } from "@/data/world/fogConfig";
|
import { FOG_LIGHTING_COLOR_MIX } from "@/data/world/fogConfig";
|
||||||
import { useCameraMode } from "@/hooks/debug/useCameraMode";
|
import { useCameraMode } from "@/hooks/debug/useCameraMode";
|
||||||
import { useSceneMode } from "@/hooks/debug/useSceneMode";
|
import { useSceneMode } from "@/hooks/debug/useSceneMode";
|
||||||
import { useFogSettings } from "@/hooks/world/useFogSettings";
|
import { useFogSettings } from "@/hooks/world/useFogSettings";
|
||||||
@@ -57,15 +57,13 @@ export function Environment(): React.JSX.Element {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{FOG_CONFIG.enabled &&
|
{fogEnabled &&
|
||||||
fogEnabled &&
|
|
||||||
sceneMode === "game" &&
|
sceneMode === "game" &&
|
||||||
cameraMode === "player" &&
|
cameraMode === "player" &&
|
||||||
fog.mode === "linear" ? (
|
fog.mode === "linear" ? (
|
||||||
<fog attach="fog" args={[fogColor, fog.near, fog.far]} />
|
<fog attach="fog" args={[fogColor, fog.near, fog.far]} />
|
||||||
) : null}
|
) : null}
|
||||||
{FOG_CONFIG.enabled &&
|
{fogEnabled &&
|
||||||
fogEnabled &&
|
|
||||||
sceneMode === "game" &&
|
sceneMode === "game" &&
|
||||||
cameraMode === "player" &&
|
cameraMode === "player" &&
|
||||||
fog.mode === "exp2" ? (
|
fog.mode === "exp2" ? (
|
||||||
|
|||||||
@@ -391,7 +391,13 @@ function FallbackMapNode({ node }: { node: MapNode }): React.JSX.Element {
|
|||||||
const normalizedScale = normalizeMapScale(scale);
|
const normalizedScale = normalizeMapScale(scale);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<mesh position={position} rotation={rotation} scale={normalizedScale}>
|
<mesh
|
||||||
|
castShadow
|
||||||
|
position={position}
|
||||||
|
receiveShadow
|
||||||
|
rotation={rotation}
|
||||||
|
scale={normalizedScale}
|
||||||
|
>
|
||||||
<boxGeometry args={[1, 1, 1]} />
|
<boxGeometry args={[1, 1, 1]} />
|
||||||
<meshStandardMaterial color="#64748b" wireframe />
|
<meshStandardMaterial color="#64748b" wireframe />
|
||||||
</mesh>
|
</mesh>
|
||||||
|
|||||||
Reference in New Issue
Block a user