🎥 Make videos programmatically with React
add docs
Igor Samokhovets48e14cc6aa86
diff --git a/packages/docs/docs/three.md b/packages/docs/docs/three.mdindex 552f89e3fc..6851d11494 100644--- a/packages/docs/docs/three.md+++ b/packages/docs/docs/three.md@@ -15,6 +15,8 @@ is a package for integrating [React Three Fiber](https://github.com/pmndrs/react- [`useVideoTexture()`](/docs/use-video-texture) allows you to use a Remotion [`<Video />`](/docs/video) as a texture map.+- [`useOffthreadVideoTexture()`](/docs/use-offthread-video-texture) is an equivalent to [`useVideoTexture()`](/docs/use-video-texture), but displays the exact frame as an `Three.ImageTexture` during rendering, simillarly to [`<OffthreadVideo />`](/docs/offthread-video).+These are the only two APIs provided - for everything else you can use the standard [React Three Fiber](https://github.com/pmndrs/react-three-fiber) APIs.## Starter templatediff --git a/packages/docs/docs/use-offthread-video-texture.md b/packages/docs/docs/use-offthread-video-texture.mdnew file mode 100644index 0000000000..1ca451ab7f--- /dev/null+++ b/packages/docs/docs/use-offthread-video-texture.md@@ -0,0 +1,48 @@+---+image: /generated/articles-docs-use-video-texture.png+id: use-offthread-video-texture+title: useOffthreadVideoTexture()+crumb: "@remotion/three"+---++Allows you to use a video in React Three Fiber that is synchronized with Remotion's `useCurrentFrame()`, simillar to [`useVideoTexture()`](/docs/use-video-texture), but during rendering extracts precise frames from a video during rendering and wraps them into a `THREE.ImageTexture.`++This hook was designed to combat limitations of the default `<Video>` element that is used with `useVideoTexture` hook.+See: [`<OffthreadVideo> vs <Video>`](/docs/video-vs-offthreadvideo)++Under the hood, uses `useVideoTexture()` in Remotion Studio and Remotion Player.++The return type of it is a `THREE.Texture | null` which you can assign as a `map` to for example `meshBasicMaterial`. We recommend to only render the material when the texture is not `null` to prevent bugs.++```tsx twoslash+import { ThreeCanvas, useOffthreadVideoTexture } from "@remotion/three";+import { staticFile, useVideoConfig } from "remotion";++const videoSrc = staticFile("/vid.mp4");++const My3dVideo = () => {+ const { width, height } = useVideoConfig();++ const videoTexture = useOffthreadVideoTexture({+ src: videoSrc,+ loop: false,+ transparent: false,+ playbackRate: 1,+ });++ return (+ <ThreeCanvas width={width} height={height}>+ <mesh>+ {videoTexture ? <meshBasicMaterial map={videoTexture} /> : null}+ </mesh>+ </ThreeCanvas>+ );+};+```++## See also++- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/three/src/use-offthread-video-texture.ts)+- [`useVideoTexture()`](/docs/use-video-texture)+- [`<ThreeCanvas />`](/docs/three-canvas)+- [`<OffthreadVideo> vs <Video>`](/docs/video-vs-offthreadvideo)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 0552199c8d..62474a1ff7 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -269,7 +269,11 @@ module.exports = {type: "doc",id: "three",},- items: ["three-canvas", "use-video-texture"],+ items: [+ "three-canvas",+ "use-video-texture",+ "use-offthread-video-texture",+ ],},{type: "category",diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 64660c3174..17d29403fe 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -2766,6 +2766,13 @@ export const articles = [compId: "articles-docs-use-video-texture",crumb: "@remotion/three",},+ {+ id: "use-offthread-video-texture",+ title: "useOffthreadVideoTexture()",+ relativePath: "docs/use-offthread-video-texture.md",+ compId: "articles-docs-use-offthread-video-texture",+ crumb: "@remotion/three",+ },{id: "using-audio",title: "Using audio",