Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/3d.md
1---2name: 3d3description: 3D content in Remotion using Three.js and React Three Fiber.4metadata:5tags: 3d, three, threejs6---78# Using Three.js and React Three Fiber in Remotion910Follow React Three Fiber and Three.js best practices.11Only the following Remotion-specific rules need to be followed:1213## Prerequisites1415First, the `@remotion/three` package needs to be installed.16If it is not, use the following command:1718```bash19npx remotion add @remotion/three # If project uses npm20bunx remotion add @remotion/three # If project uses bun21yarn remotion add @remotion/three # If project uses yarn22pnpm exec remotion add @remotion/three # If project uses pnpm23```2425## Using ThreeCanvas2627You MUST wrap 3D content in `<ThreeCanvas>` and include proper lighting.28`<ThreeCanvas>` MUST have a `width` and `height` prop.2930```tsx31import { ThreeCanvas } from "@remotion/three";32import { useVideoConfig } from "remotion";3334const { width, height } = useVideoConfig();3536<ThreeCanvas width={width} height={height}>37<ambientLight intensity={0.4} />38<directionalLight position={[5, 5, 5]} intensity={0.8} />39<mesh>40<sphereGeometry args={[1, 32, 32]} />41<meshStandardMaterial color="red" />42</mesh>43</ThreeCanvas>;44```4546## No animations not driven by `useCurrentFrame()`4748Shaders, models etc MUST NOT animate by themselves.49No animations are allowed unless they are driven by `useCurrentFrame()`.50Otherwise, it will cause flickering during rendering.5152Using `useFrame()` from `@react-three/fiber` is forbidden.5354## Animate using `useCurrentFrame()`5556Use `useCurrentFrame()` to perform animations.5758```tsx59const frame = useCurrentFrame();60const rotationY = frame * 0.02;6162<mesh rotation={[0, rotationY, 0]}>63<boxGeometry args={[2, 2, 2]} />64<meshStandardMaterial color="#4a9eff" />65</mesh>;66```6768## Using `<Sequence>` inside `<ThreeCanvas>`6970The `layout` prop of any `<Sequence>` inside a `<ThreeCanvas>` must be set to `none`.7172```tsx73import { Sequence } from "remotion";74import { ThreeCanvas } from "@remotion/three";7576const { width, height } = useVideoConfig();7778<ThreeCanvas width={width} height={height}>79<Sequence layout="none">80<mesh>81<boxGeometry args={[2, 2, 2]} />82<meshStandardMaterial color="#4a9eff" />83</mesh>84</Sequence>85</ThreeCanvas>;86```87