Skip to content

🎥 Make videos programmatically with React

three html in testbed

Jonny Burger4e6876cfa825
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 2347b39449..d42ab5f7d1 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -104,6 +104,7 @@ const INCLUDE_COMP_BREAKING_GET_COMPOSITIONS = false;
// @ts-expect-error no types
import styles from './styles.module.scss';
+import { ThreeHtml } from './ThreeHtml/ThreeHtml';
class Vector2 {
readonly x: number;
@@ -909,6 +910,14 @@ export const Index: React.FC = () => {
fps={30}
durationInFrames={600}
/>
+ <Composition
+ id="three-html"
+ component={ThreeHtml}
+ width={1280}
+ height={720}
+ fps={30}
+ durationInFrames={600}
+ />
<Composition
id="use-video-texture"
component={VideoTextureDemo}
diff --git a/packages/example/src/ThreeHtml/ThreeHtml.tsx b/packages/example/src/ThreeHtml/ThreeHtml.tsx
new file mode 100644
index 0000000000..7e4fda28ca
--- /dev/null
+++ b/packages/example/src/ThreeHtml/ThreeHtml.tsx
@@ -0,0 +1,58 @@
+import {Html} from '@react-three/drei';
+import {ThreeCanvas} from '@remotion/three';
+import {useRef} from 'react';
+import {
+ Internals,
+ interpolate,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+const Content = () => {
+ return <h1>{useCurrentFrame()}</h1>;
+};
+
+const Box = ({portalTarget}) => {
+ const frame = useCurrentFrame();
+ const rotation = interpolate(frame, [0, 1_000], [0, -5], {
+ extrapolateRight: 'clamp',
+ extrapolateLeft: 'clamp',
+ });
+
+ const contexts = Internals.useRemotionContexts();
+
+ return (
+ <group position={[0, 0.05, -0.75]} rotation={[0, rotation, 0]}>
+ <mesh position={[0, 0.05, -0.7]}>
+ <boxGeometry args={[2, 2, 0.1]} />
+ <meshStandardMaterial color="#f00" />
+
+ <Html transform portal={portalTarget}>
+ <Internals.RemotionContextProvider contexts={contexts}>
+ <Content />
+ </Internals.RemotionContextProvider>
+ </Html>
+ </mesh>
+ </group>
+ );
+};
+
+export const ThreeHtml = () => {
+ const portalRef = useRef(null);
+
+ const {width, height} = useVideoConfig();
+
+ return (
+ <div style={{background: 'rgba(0, 0, 0, 0.5)'}}>
+ <div ref={portalRef} data-portal />
+ <ThreeCanvas
+ camera={{position: [0, 2, 5], fov: 50}}
+ width={width}
+ height={height}
+ >
+ <pointLight position={[10, 10, 10]} />
+ <Box portalTarget={portalRef} />
+ </ThreeCanvas>
+ </div>
+ );
+};