Skip to content

🎥 Make videos programmatically with React

add 3d example into 3d skill

Jonny Burger4436f3f93080
diff --git a/packages/skills/skills/3d/SKILL.md b/packages/skills/skills/3d/SKILL.md
index e06082cb9a..e997f6b750 100644
--- a/packages/skills/skills/3d/SKILL.md
+++ b/packages/skills/skills/3d/SKILL.md
@@ -118,4 +118,4 @@ Position camera at reasonable distance for scene visibility.
## Complete Examples
For full working code examples, see:
-- [Falling Spheres Example](../example-falling-spheres/SKILL.md) - 3D bouncing spheres with physics simulation
+- [Falling Spheres Example](assets/falling-spheres.tsx) - 3D bouncing spheres with physics simulation
diff --git a/packages/skills/skills/3d/assets/falling-spheres.tsx b/packages/skills/skills/3d/assets/falling-spheres.tsx
new file mode 100644
index 0000000000..4ef63d6f02
--- /dev/null
+++ b/packages/skills/skills/3d/assets/falling-spheres.tsx
@@ -0,0 +1,120 @@
+import {AbsoluteFill, useCurrentFrame, useVideoConfig} from 'remotion';
+import {ThreeCanvas} from '@remotion/three';
+
+export const MyAnimation = () => {
+ const frame = useCurrentFrame();
+ const {width, height, fps} = useVideoConfig();
+
+ const spheres = [
+ {x: -1.5, z: -0.5, delay: 0, radius: 0.4, restitution: 0.75},
+ {x: 0, z: 0, delay: 20, radius: 0.5, restitution: 0.75},
+ {x: 1.5, z: 0.5, delay: 40, radius: 0.35, restitution: 0.75},
+ {x: -0.8, z: 1, delay: 60, radius: 0.45, restitution: 0.75},
+ {x: 0.8, z: -1, delay: 80, radius: 0.38, restitution: 0.75},
+ ];
+
+ const gravity = 12;
+ const groundY = -2;
+
+ const simulateBounce = (
+ f: number,
+ delay: number,
+ radius: number,
+ restitution: number,
+ ) => {
+ const elapsed = Math.max(0, f - delay);
+ const t = elapsed / fps;
+ const startY = 6;
+ const surfaceY = groundY + radius;
+
+ const firstImpactTime = Math.sqrt((2 * (startY - surfaceY)) / gravity);
+
+ if (t <= firstImpactTime) {
+ const y = startY - 0.5 * gravity * t * t;
+ return {y, squash: 1};
+ }
+
+ let currentVelocity = gravity * firstImpactTime;
+ let bounceStartTime = firstImpactTime;
+
+ for (let bounce = 0; bounce < 20; bounce++) {
+ currentVelocity *= restitution;
+
+ if (currentVelocity < 0.5) {
+ return {y: surfaceY, squash: 1};
+ }
+
+ const bounceDuration = (2 * currentVelocity) / gravity;
+ const timeInBounce = t - bounceStartTime;
+
+ if (timeInBounce <= bounceDuration) {
+ const y =
+ surfaceY +
+ currentVelocity * timeInBounce -
+ 0.5 * gravity * timeInBounce * timeInBounce;
+ const impactProximity = Math.abs(y - surfaceY);
+ const squash =
+ impactProximity < 0.08
+ ? 0.65 + (impactProximity / 0.08) * 0.35
+ : 1;
+ return {y: Math.max(surfaceY, y), squash};
+ }
+
+ bounceStartTime += bounceDuration;
+ }
+
+ return {y: surfaceY, squash: 1};
+ };
+
+ return (
+ <AbsoluteFill style={{backgroundColor: '#000000'}}>
+ <ThreeCanvas
+ width={width}
+ height={height}
+ camera={{position: [0, 3, 8], fov: 40}}
+ >
+ <ambientLight intensity={0.05} />
+
+ <mesh rotation={[-Math.PI / 2, 0, 0]} position={[0, groundY, 0]}>
+ <planeGeometry args={[20, 20]} />
+ <meshStandardMaterial
+ color="#0a0a0a"
+ metalness={0.9}
+ roughness={0.3}
+ />
+ </mesh>
+
+ {spheres.map((sphere, i) => {
+ const {y, squash} = simulateBounce(
+ frame,
+ sphere.delay,
+ sphere.radius,
+ sphere.restitution,
+ );
+ const stretch = 1 / squash;
+
+ return (
+ <group key={i} position={[sphere.x, y, sphere.z]}>
+ <pointLight
+ color="#ffd700"
+ intensity={0.8}
+ distance={4}
+ decay={2}
+ />
+ <mesh scale={[1, squash, stretch]}>
+ <sphereGeometry args={[sphere.radius, 32, 32]} />
+ <meshStandardMaterial
+ color="#ffd700"
+ emissive="#cc7a00"
+ emissiveIntensity={0.15}
+ metalness={0.4}
+ roughness={0.6}
+ />
+ </mesh>
+ </group>
+ );
+ })}
+ </ThreeCanvas>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/skills/skills/example-falling-spheres/SKILL.md b/packages/skills/skills/example-falling-spheres/SKILL.md
deleted file mode 100644
index 154c750a21..0000000000
--- a/packages/skills/skills/example-falling-spheres/SKILL.md
+++ /dev/null
@@ -1,23 +0,0 @@
----
-name: example-falling-spheres
-description: Complete working example of 3D bouncing golden spheres with physics simulation using @remotion/three.
-metadata:
- category: 3D
- durationInFrames: 450
- fps: 60
----
-
-## Falling Spheres Example
-
-Glowing golden spheres with realistic bounce physics and 3D rendering.
-
-See the full implementation in [assets/example.tsx](assets/example.tsx).
-
-### Key Features
-
-- ThreeCanvas setup with proper lighting
-- Realistic gravity and bounce physics simulation
-- Multiple spheres with staggered delays
-- Squash/stretch deformation on impact
-- Emissive glow effects on materials
-- Ground plane with metallic material
diff --git a/packages/skills/skills/example-falling-spheres/assets/example.tsx b/packages/skills/skills/example-falling-spheres/assets/example.tsx
deleted file mode 100644
index 12b9cdcaaf..0000000000
--- a/packages/skills/skills/example-falling-spheres/assets/example.tsx
+++ /dev/null
@@ -1,104 +0,0 @@
-import { AbsoluteFill, useCurrentFrame, useVideoConfig } from "remotion";
-import { ThreeCanvas } from "@remotion/three";
-
-export const MyAnimation = () => {
- const frame = useCurrentFrame();
- const { width, height, fps } = useVideoConfig();
-
- const spheres = [
- { x: -1.5, z: -0.5, delay: 0, radius: 0.4, restitution: 0.75 },
- { x: 0, z: 0, delay: 20, radius: 0.5, restitution: 0.75 },
- { x: 1.5, z: 0.5, delay: 40, radius: 0.35, restitution: 0.75 },
- { x: -0.8, z: 1, delay: 60, radius: 0.45, restitution: 0.75 },
- { x: 0.8, z: -1, delay: 80, radius: 0.38, restitution: 0.75 },
- ];
-
- const gravity = 12;
- const groundY = -2;
-
- // Realistic bounce physics simulation
- const simulateBounce = (f: number, delay: number, radius: number, restitution: number) => {
- const elapsed = Math.max(0, f - delay);
- const t = elapsed / fps;
- const startY = 6;
- const surfaceY = groundY + radius;
-
- // Calculate time to first impact
- const firstImpactTime = Math.sqrt(2 * (startY - surfaceY) / gravity);
-
- if (t <= firstImpactTime) {
- const y = startY - 0.5 * gravity * t * t;
- return { y, squash: 1 };
- }
-
- // After first impact, simulate bounces
- let currentVelocity = gravity * firstImpactTime;
- let bounceStartTime = firstImpactTime;
-
- for (let bounce = 0; bounce < 20; bounce++) {
- currentVelocity *= restitution;
-
- if (currentVelocity < 0.5) {
- return { y: surfaceY, squash: 1 };
- }
-
- const bounceDuration = 2 * currentVelocity / gravity;
- const timeInBounce = t - bounceStartTime;
-
- if (timeInBounce <= bounceDuration) {
- const y = surfaceY + currentVelocity * timeInBounce - 0.5 * gravity * timeInBounce * timeInBounce;
- const impactProximity = Math.abs(y - surfaceY);
- const squash = impactProximity < 0.08 ? 0.65 + (impactProximity / 0.08) * 0.35 : 1;
- return { y: Math.max(surfaceY, y), squash };
- }
-
- bounceStartTime += bounceDuration;
- }
-
- return { y: surfaceY, squash: 1 };
- };
-
- return (
- <AbsoluteFill style={{ backgroundColor: "#000000" }}>
- <ThreeCanvas
- width={width}
- height={height}
- camera={{ position: [0, 3, 8], fov: 40 }}
- >
- <ambientLight intensity={0.05} />
-
- <mesh rotation={[-Math.PI / 2, 0, 0]} position={[0, groundY, 0]}>
- <planeGeometry args={[20, 20]} />
- <meshStandardMaterial color="#0a0a0a" metalness={0.9} roughness={0.3} />
- </mesh>
-
- {spheres.map((sphere, i) => {
- const { y, squash } = simulateBounce(frame, sphere.delay, sphere.radius, sphere.restitution);
- const stretch = 1 / squash;
-
- return (
- <group key={i} position={[sphere.x, y, sphere.z]}>
- <pointLight
- color="#ffd700"
- intensity={0.8}
- distance={4}
- decay={2}
- />
- {/* Golden sphere */}
- <mesh scale={[1, squash, stretch]}>
- <sphereGeometry args={[sphere.radius, 32, 32]} />
- <meshStandardMaterial
- color="#ffd700"
- emissive="#cc7a00"
- emissiveIntensity={0.15}
- metalness={0.4}
- roughness={0.6}
- />
- </mesh>
- </group>
- );
- })}
- </ThreeCanvas>
- </AbsoluteFill>
- );
-};
diff --git a/packages/skills/skills/example-morphing-hexagons/SKILL.md b/packages/skills/skills/example-morphing-hexagons/SKILL.md
deleted file mode 100644
index 03f1731d31..0000000000
--- a/packages/skills/skills/example-morphing-hexagons/SKILL.md
+++ /dev/null
@@ -1,23 +0,0 @@
----
-name: example-morphing-hexagons
-description: Complete working example of a mesmerizing hexagon grid with pulsing, color-shifting, and glow effects.
-metadata:
- category: Other
- durationInFrames: 240
- fps: 30
----
-
-## Morphing Hexagons Example
-
-Mesmerizing hexagon grid with pulsing and color-shifting effects.
-
-See the full implementation in [assets/example.tsx](assets/example.tsx).
-
-### Key Features
-
-- Procedurally generated hexagon grid
-- Wave-based pulsing animation
-- Dynamic HSL color shifting
-- SVG glow filter effect
-- Spring-based entrance animations
-- Staggered delays based on grid position
diff --git a/packages/skills/skills/example-morphing-hexagons/assets/example.tsx b/packages/skills/skills/example-morphing-hexagons/assets/example.tsx
deleted file mode 100644
index 0da651ac06..0000000000
--- a/packages/skills/skills/example-morphing-hexagons/assets/example.tsx
+++ /dev/null
@@ -1,91 +0,0 @@
-import { AbsoluteFill, useCurrentFrame, useVideoConfig, interpolate, spring } from "remotion";
-
-export const MyAnimation = () => {
- const frame = useCurrentFrame();
- const { fps } = useVideoConfig();
-
- const hexSize = 50;
- const cols = 7;
- const rows = 5;
-
- const hexagons: Array<{ x: number; y: number; delay: number }> = [];
- for (let row = 0; row < rows; row++) {
- for (let col = 0; col < cols; col++) {
- const offsetX = row % 2 === 0 ? 0 : hexSize * 0.866;
- hexagons.push({
- x: col * hexSize * 1.732 + offsetX,
- y: row * hexSize * 1.5,
- delay: (row + col) * 3,
- });
- }
- }
-
- const gridWidth = (cols - 1) * hexSize * 1.732 + hexSize;
- const gridHeight = (rows - 1) * hexSize * 1.5 + hexSize * 2;
-
- return (
- <AbsoluteFill
- style={{
- backgroundColor: "#0a0a0f",
- justifyContent: "center",
- alignItems: "center",
- }}
- >
- <svg
- width={gridWidth + 100}
- height={gridHeight + 100}
- viewBox={`-50 -50 ${gridWidth + 100} ${gridHeight + 100}`}
- >
- <defs>
- <filter id="glow">
- <feGaussianBlur stdDeviation="3" result="coloredBlur" />
- <feMerge>
- <feMergeNode in="coloredBlur" />
- <feMergeNode in="SourceGraphic" />
- </feMerge>
- </filter>
- </defs>
- {hexagons.map((hex, i) => {
- const wave = Math.sin((frame - hex.delay) * 0.08);
- const pulse = interpolate(wave, [-1, 1], [0.6, 1]);
-
- const hue = interpolate(
- (frame + hex.delay * 2) % 240,
- [0, 120, 240],
- [280, 200, 280]
- );
-
- const opacity = interpolate(wave, [-1, 1], [0.3, 0.9]);
-
- const scale = interpolate(wave, [-1, 1], [0.7, 1]);
-
- const entrance = spring({
- frame: frame - hex.delay,
- fps,
- config: { damping: 15, stiffness: 120 },
- });
-
- const points: string[] = [];
- for (let j = 0; j < 6; j++) {
- const angle = (Math.PI / 3) * j - Math.PI / 6;
- const px = hex.x + hexSize * scale * entrance * Math.cos(angle);
- const py = hex.y + hexSize * scale * entrance * Math.sin(angle);
- points.push(`${px},${py}`);
- }
-
- return (
- <polygon
- key={i}
- points={points.join(" ")}
- fill="none"
- stroke={`hsl(${hue}, 80%, 60%)`}
- strokeWidth={2 * pulse}
- opacity={opacity * entrance}
- filter="url(#glow)"
- />
- );
- })}
- </svg>
- </AbsoluteFill>
- );
-};
diff --git a/packages/skills/src/Root.tsx b/packages/skills/src/Root.tsx
index debfbe48d6..798e6655f5 100644
--- a/packages/skills/src/Root.tsx
+++ b/packages/skills/src/Root.tsx
@@ -7,7 +7,7 @@ import {
import {MyAnimation as BarChartAnimation} from '../skills/charts/assets/bar-chart';
import {MyAnimation as ChatMessagesAnimation} from '../skills/example-chat-messages/assets/example';
import {MyAnimation as CounterAnimation} from '../skills/example-counter/assets/example';
-import {MyAnimation as FallingSpheresAnimation} from '../skills/example-falling-spheres/assets/example';
+import {MyAnimation as FallingSpheresAnimation} from '../skills/3d/assets/falling-spheres';
import {MyAnimation as StaggeredListAnimation} from '../skills/example-staggered-list/assets/example';
import {MyAnimation as TextRotationAnimation} from '../skills/example-text-rotation/assets/example';
import {MyAnimation as TypewriterHighlightAnimation} from '../skills/example-typewriter-highlight/assets/example';