riffusion-app/components/ImagePlane.tsx

25 lines
619 B
TypeScript
Raw Normal View History

2022-11-20 14:39:15 -07:00
import * as THREE from "three";
import React, { Suspense } from "react";
import { useLoader } from "@react-three/fiber";
2022-11-20 14:39:15 -07:00
interface ImagePlaneProps {
url: string;
2022-11-23 22:46:32 -07:00
height: number;
}
2022-11-20 14:39:15 -07:00
/**
* Draw an image on a plane geometry.
*/
export default function ImagePlane(props: ImagePlaneProps) {
const texture = useLoader(THREE.TextureLoader, props.url);
2022-11-23 22:46:32 -07:00
2022-11-20 14:39:15 -07:00
return (
<Suspense fallback={null}>
<mesh rotation-z={-Math.PI / 2} position-y={props.height}>
<planeGeometry attach="geometry" args={[5, 5]} />
2022-11-20 14:39:15 -07:00
<meshBasicMaterial attach="material" map={texture} />
</mesh>
</Suspense>
);
}