mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-04-20 11:55:37 +00:00
move non-Next components out of app folder
This commit is contained in:
parent
fdd27b26d7
commit
beade00727
14 changed files with 41 additions and 44 deletions
43
src/components/WaterBlock.tsx
Normal file
43
src/components/WaterBlock.tsx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { Suspense, useMemo } from "react";
|
||||
import { useTexture } from "@react-three/drei";
|
||||
import { textureToUrl } from "../loaders";
|
||||
import {
|
||||
ConsoleObject,
|
||||
getPosition,
|
||||
getProperty,
|
||||
getRotation,
|
||||
getScale,
|
||||
} from "../mission";
|
||||
import { setupColor } from "../textureUtils";
|
||||
|
||||
export function WaterMaterial({ surfaceTexture }: { surfaceTexture: string }) {
|
||||
const url = textureToUrl(surfaceTexture);
|
||||
const texture = useTexture(url, (texture) => setupColor(texture, [8, 8]));
|
||||
|
||||
return <meshStandardMaterial map={texture} transparent opacity={0.8} />;
|
||||
}
|
||||
|
||||
export function WaterBlock({ object }: { object: ConsoleObject }) {
|
||||
const [z, y, x] = useMemo(() => getPosition(object), [object]);
|
||||
const [scaleZ, scaleY, scaleX] = useMemo(() => getScale(object), [object]);
|
||||
const q = useMemo(() => getRotation(object, true), [object]);
|
||||
|
||||
const surfaceTexture =
|
||||
getProperty(object, "surfaceTexture")?.value ?? "liquidTiles/BlueWater";
|
||||
|
||||
return (
|
||||
<mesh
|
||||
position={[x - 1024 + scaleX / 2, y + scaleY / 2, z - 1024 + scaleZ / 2]}
|
||||
quaternion={q}
|
||||
>
|
||||
<boxGeometry args={[scaleZ, scaleY, scaleX]} />
|
||||
<Suspense
|
||||
fallback={
|
||||
<meshStandardMaterial color="blue" transparent opacity={0.3} />
|
||||
}
|
||||
>
|
||||
<WaterMaterial surfaceTexture={surfaceTexture} />
|
||||
</Suspense>
|
||||
</mesh>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue