/* eslint-disable */
import * as THREE from "three";
import { useLayoutEffect, useRef, useState, useEffect } from "react";
import { Canvas, applyProps, useFrame, useThree } from "@react-three/fiber";
import {
PerformanceMonitor,
AccumulativeShadows,
RandomizedLight,
Environment,
Lightformer,
Float,
useGLTF,
} from "@react-three/drei";
import { useTheme } from "next-themes";
export function MiniModel() {
const [degraded, degrade] = useState(false);
const { resolvedTheme } = useTheme();
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) return null;
return (
);
}
function Background({ theme }: { theme: string | undefined }) {
const { scene } = useThree();
useEffect(() => {
scene.background = new THREE.Color(theme === "dark" ? "#0f1217" : "white");
}, [theme, scene]);
return null;
}
function Mini(props: any) {
const { scene, nodes, materials } = useGLTF("/mini.glb") as any;
useLayoutEffect(() => {
Object.values(nodes).forEach((node) => {
if (node instanceof THREE.Mesh) {
node.receiveShadow = true;
node.castShadow = true;
}
});
if (materials["CAR_BODY_PAINT"]) {
applyProps(materials["CAR_BODY_PAINT"], {
color: "black",
roughness: 0.45,
metalness: 0.8,
envMapIntensity: 2,
});
}
if (materials["MATT"]) {
applyProps(materials["MATT"], {
color: "black",
roughness: 0.45,
metalness: 0.8,
envMapIntensity: 2,
});
}
if (materials["WINDOW_GLASS"]) {
applyProps(materials["WINDOW_GLASS"], {
color: "black",
roughness: 0,
clearcoat: 0.1,
});
}
if (materials["LIGHT_GLASS"]) {
applyProps(materials["LIGHT_GLASS"], {
color: "black",
roughness: 0,
clearcoat: 0.1,
});
}
if (materials["LIGHTS_POD"]) {
applyProps(materials["LIGHTS_POD"], {
roughness: 0,
clearcoat: 0.1,
});
}
if (materials["SHINY_METAL"]) {
applyProps(materials["SHINY_METAL"], {
color: "black",
envMapIntensity: 4,
roughness: 0.5,
metalness: 1,
});
}
if (materials["CALIPER"]) {
applyProps(materials["CALIPER"], {
color: "red",
envMapIntensity: 4,
roughness: 0.5,
metalness: 1,
});
}
}, [nodes, materials]);
return ;
}
function CameraRig({ v = new THREE.Vector3() }) {
return useFrame((state) => {
const t = state.clock.elapsedTime;
state.camera.position.lerp(
v.set(Math.sin(t / 2) * 1.2, 0, 12 + Math.cos(t / 5) / 2),
0.05
);
state.camera.lookAt(0, 0, 0);
});
}
function Lightformers({ positions = [2, 0, 2, 0, 2, 0, 2, 0] }) {
const group = useRef(null);
useFrame(
(state, delta) =>
(group.current!.position.z += delta * 10) > 20 &&
(group.current!.position.z = -60)
);
return (
<>
{positions.map((x, i) => (
))}
{/* White environment background for reflections */}
>
);
}