riffusion-app/components/ImagePlane.tsx

26 lines
652 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-25 00:26:44 -07:00
duration: number;
2022-11-23 22:46:32 -07:00
}
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}>
2022-11-25 00:26:44 -07:00
<planeGeometry attach="geometry" args={[props.duration, 5]} />
2022-11-20 14:39:15 -07:00
<meshBasicMaterial attach="material" map={texture} />
</mesh>
</Suspense>
);
}