Files
blitzkit/src/app/tools/tankopedia/[id]/components/SceneProps.tsx
T

30 lines
939 B
TypeScript
Raw Normal View History

2024-03-03 17:59:39 -06:00
import { useFrame, useLoader } from '@react-three/fiber';
import { clamp } from 'lodash';
import { useRef } from 'react';
import { MeshStandardMaterial, TextureLoader } from 'three';
2024-01-22 16:54:07 -06:00
import { useTankopediaPersistent } from '../../../../../stores/tankopedia';
2024-01-03 13:07:45 -06:00
export function SceneProps() {
2024-03-03 17:42:53 -06:00
const show = useTankopediaPersistent(
(state) =>
state.model.visual.showGrid && !state.model.visual.showEnvironment,
2024-02-01 12:28:56 -06:00
);
2024-03-03 17:59:39 -06:00
const texture = useLoader(TextureLoader, 'https://i.imgur.com/C28Z8nU.png');
const material = useRef<MeshStandardMaterial>(null);
useFrame(({ camera }) => {
if (!material.current) return;
material.current.opacity = clamp(0.1 * camera.position.y, 0, 1);
});
texture.anisotropy = 2;
2024-01-06 18:17:04 -06:00
2024-03-03 17:42:53 -06:00
if (!show) return null;
2024-01-09 22:31:34 -06:00
2024-01-03 13:07:45 -06:00
return (
2024-03-03 17:42:53 -06:00
<mesh rotation={[-Math.PI / 2, 0, 0]}>
<planeGeometry args={[10, 10]} />
2024-03-03 17:59:39 -06:00
<meshStandardMaterial ref={material} map={texture} transparent />
2024-03-03 17:42:53 -06:00
</mesh>
2024-01-03 13:07:45 -06:00
);
}