Skip to content

🎥 Make videos programmatically with React

Refer to video textures in <ThreeCanvas> docs

Jonny Burger0cfff02c525d
diff --git a/packages/docs/docs/three-canvas.mdx b/packages/docs/docs/three-canvas.mdx
index b26ec13c49..dc30435474 100644
--- a/packages/docs/docs/three-canvas.mdx
+++ b/packages/docs/docs/three-canvas.mdx
@@ -2,7 +2,7 @@
image: /generated/articles-docs-three-canvas.png
id: three-canvas
title: <ThreeCanvas>
-crumb: "@remotion/three"
+crumb: '@remotion/three'
---
A wrapper for [React Three Fiber](https://github.com/pmndrs/react-three-fiber)'s `<Canvas />` which synchronizes with Remotions [`useCurrentFrame()`](/docs/use-current-frame).
@@ -18,12 +18,12 @@ A browser bug [would normally cause the layout to be broken](https://github.com/
A spinning, color changing, scaling cube. This example can also be found in the `examples` folder of the Remotion repo.
```tsx twoslash
-import { ThreeCanvas } from "@remotion/three";
-import { interpolate, useCurrentFrame, useVideoConfig } from "remotion";
+import {ThreeCanvas} from '@remotion/three';
+import {interpolate, useCurrentFrame, useVideoConfig} from 'remotion';
const ThreeBasic: React.FC = () => {
const frame = useCurrentFrame();
- const { width, height } = useVideoConfig();
+ const {width, height} = useVideoConfig();
return (
<ThreeCanvas
@@ -31,25 +31,15 @@ const ThreeBasic: React.FC = () => {
width={width}
height={height}
style={{
- backgroundColor: "white",
+ backgroundColor: 'white',
}}
- camera={{ fov: 75, position: [0, 0, 470] }}
+ camera={{fov: 75, position: [0, 0, 470]}}
>
<ambientLight intensity={0.15} />
<pointLight args={[undefined, 0.4]} position={[200, 200, 0]} />
- <mesh
- position={[0, 0, 0]}
- rotation={[frame * 0.06 * 0.5, frame * 0.07 * 0.5, frame * 0.08 * 0.5]}
- scale={interpolate(Math.sin(frame / 10), [-1, 1], [0.8, 1.2])}
- >
+ <mesh position={[0, 0, 0]} rotation={[frame * 0.06 * 0.5, frame * 0.07 * 0.5, frame * 0.08 * 0.5]} scale={interpolate(Math.sin(frame / 10), [-1, 1], [0.8, 1.2])}>
<boxGeometry args={[100, 100, 100]} />
- <meshStandardMaterial
- color={[
- Math.sin(frame * 0.12) * 0.5 + 0.5,
- Math.cos(frame * 0.11) * 0.5 + 0.5,
- Math.sin(frame * 0.08) * 0.5 + 0.5,
- ]}
- />
+ <meshStandardMaterial color={[Math.sin(frame * 0.12) * 0.5 + 0.5, Math.cos(frame * 0.11) * 0.5 + 0.5, Math.sin(frame * 0.08) * 0.5 + 0.5]} />
</mesh>
</ThreeCanvas>
);
@@ -62,6 +52,10 @@ export default ThreeBasic;
A [`<Sequence>`](/docs/sequence) by default will return a `<div>` component which is not allowed inside a `<ThreeCanvas>`. To avoid an error, pass `layout="none"` to `<Sequence>`.
+## Using videos inside a `<ThreeCanvas>`
+
+You can create a Three.js texture backed by a [`<Video>`](/docs/media/video) by using [this](/docs/videos/as-threejs-texture) approach.
+
## See also
- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/three/src/ThreeCanvas.tsx)