query params and some fog stuff

This commit is contained in:
bmathews 2025-11-14 03:30:33 -08:00
parent 8ab6f63fee
commit 6ae7a19332
2 changed files with 22 additions and 5 deletions

View file

@ -184,8 +184,8 @@ export function Sky({ object }: { object: ConsoleObject }) {
<fog <fog
attach="fog" attach="fog"
color={fogColor[1]} color={fogColor[1]}
near={fogDistance / 2} near={100}
far={fogDistance * 2} far={Math.max(400, fogDistance * 2)}
/> />
) : null} ) : null}
</> </>

View file

@ -1,5 +1,5 @@
"use client"; "use client";
import { useState } from "react"; import { useState, useEffect } from "react";
import { Canvas } from "@react-three/fiber"; import { Canvas } from "@react-three/fiber";
import { Mission } from "./Mission"; import { Mission } from "./Mission";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
@ -8,14 +8,31 @@ import { InspectorControls } from "./InspectorControls";
import { SettingsProvider } from "./SettingsProvider"; import { SettingsProvider } from "./SettingsProvider";
import { PerspectiveCamera } from "@react-three/drei"; import { PerspectiveCamera } from "@react-three/drei";
import { EffectComposer, N8AO } from "@react-three/postprocessing"; import { EffectComposer, N8AO } from "@react-three/postprocessing";
import { useSearchParams, useRouter } from "next/navigation";
// three.js has its own loaders for textures and models, but we need to load other // three.js has its own loaders for textures and models, but we need to load other
// stuff too, e.g. missions, terrains, and more. This client is used for those. // stuff too, e.g. missions, terrains, and more. This client is used for those.
const queryClient = new QueryClient(); const queryClient = new QueryClient();
export default function HomePage() { export default function HomePage() {
const [missionName, setMissionName] = useState("TWL2_WoodyMyrk"); const searchParams = useSearchParams();
const [fogEnabled, setFogEnabled] = useState(false); const router = useRouter();
// Initialize state from query params
const [missionName, setMissionName] = useState(
searchParams.get("mission") || "TWL2_WoodyMyrk"
);
const [fogEnabled, setFogEnabled] = useState(
searchParams.get("fog") === "true"
);
// Update query params when state changes
useEffect(() => {
const params = new URLSearchParams();
params.set("mission", missionName);
params.set("fog", String(fogEnabled));
router.replace(`?${params.toString()}`, { scroll: false });
}, [missionName, fogEnabled, router]);
return ( return (
<SettingsProvider fogEnabled={fogEnabled}> <SettingsProvider fogEnabled={fogEnabled}>