🎥 Make videos programmatically with React
3d nesting something to think about
Jonny Burger0454ab681e3d
diff --git a/packages/example/src/3DCheck/index.tsx b/packages/example/src/3DCheck/index.tsxindex 3281d1a0f7..19c010bc6e 100644--- a/packages/example/src/3DCheck/index.tsx+++ b/packages/example/src/3DCheck/index.tsx@@ -1,5 +1,5 @@import {AbsoluteFill, spring, useCurrentFrame, useVideoConfig} from 'remotion';-import {Div3D} from '../3DContext/Div3D';+import {ExtrudeDiv} from '../3DContext/Div3D';import {RotateY} from '../3DContext/transformation-context';const Comp = () => {@@ -18,7 +18,7 @@ const Comp = () => {return (<AbsoluteFill className="flex justify-center items-center bg-[#F8FAFC]"><RotateY radians={progress * Math.PI}>- <Div3D+ <ExtrudeDivwidth={width}height={height}depth={20}@@ -68,7 +68,7 @@ const Comp = () => {/></svg></div>- </Div3D>+ </ExtrudeDiv></RotateY></AbsoluteFill>);diff --git a/packages/example/src/3DContext/Div3D.tsx b/packages/example/src/3DContext/Div3D.tsxindex 131f8cff59..9184e18623 100644--- a/packages/example/src/3DContext/Div3D.tsx+++ b/packages/example/src/3DContext/Div3D.tsx@@ -1,17 +1,20 @@+import {makeMatrix3dTransform} from '@remotion/svg-3d-engine';+import React from 'react';import {DivExtrusion} from './DivExtrusion';import {Face} from './FrontFace';import {RectProvider} from './path-context';import {useTransformations} from './transformation-context';import {isBacksideVisible} from './viewing-frontside';-export const Div3D: React.FC<{- children: React.ReactNode;- width: number;- height: number;- depth: number;- cornerRadius: number;- backFace?: React.ReactNode;-}> = ({children, width, height, depth, cornerRadius, backFace}) => {+export const ExtrudeDiv: React.FC<{+ readonly children: React.ReactNode;+ readonly width: number;+ readonly height: number;+ readonly depth: number;+ readonly cornerRadius: number;+ readonly backFace?: React.ReactNode;+ readonly style?: React.CSSProperties;+}> = ({children, width, height, depth, cornerRadius, backFace, style}) => {const frontFace = isBacksideVisible(useTransformations());return (@@ -21,10 +24,11 @@ export const Div3D: React.FC<{width,height,position: 'relative',+ ...style,}}>- <DivExtrusion depth={depth} />- {!frontFace ? (+ {depth > 0 ? <DivExtrusion depth={depth} /> : children}+ {depth === 0 ? null : !frontFace ? (<Face type="front" depth={depth}>{children}</Face>@@ -37,3 +41,27 @@ export const Div3D: React.FC<{</RectProvider>);};++export const ThreeDPlane: React.FC<{+ readonly children: React.ReactNode;+ readonly width: number;+ readonly height: number;+ readonly cornerRadius: number;+ readonly style?: React.CSSProperties;+}> = ({children, width, height, cornerRadius, style}) => {+ return (+ <RectProvider height={height} width={width} cornerRadius={cornerRadius}>+ <div+ style={{+ width,+ height,+ position: 'relative',+ transform: makeMatrix3dTransform(useTransformations()),+ ...style,+ }}+ >+ {children}+ </div>+ </RectProvider>+ );+};diff --git a/packages/example/src/3DContext/index.tsx b/packages/example/src/3DContext/index.tsxindex 16973b351a..11d843968f 100644--- a/packages/example/src/3DContext/index.tsx+++ b/packages/example/src/3DContext/index.tsx@@ -1,5 +1,5 @@import {AbsoluteFill, useCurrentFrame} from 'remotion';-import {Div3D} from './Div3D';+import {ExtrudeDiv} from './Div3D';import {RotateX, RotateY, Scale} from './transformation-context';const Comp = () => {@@ -18,7 +18,7 @@ const Comp = () => {<RotateX radians={progress / 10}><RotateX radians={Math.sin(angle) / 4}><RotateY radians={-Math.cos(angle) / 4}>- <Div3D+ <ExtrudeDivwidth={width}height={height}depth={40}@@ -50,7 +50,7 @@ const Comp = () => {>Get started</div>- </Div3D>+ </ExtrudeDiv></RotateY></RotateX></RotateX>diff --git a/packages/example/src/ParseAndDownloadMedia/index.tsx b/packages/example/src/ParseAndDownloadMedia/index.tsxnew file mode 100644index 0000000000..aaed1a1f6c--- /dev/null+++ b/packages/example/src/ParseAndDownloadMedia/index.tsx@@ -0,0 +1,61 @@+import React from 'react';+import {+ AbsoluteFill,+ interpolate,+ spring,+ useCurrentFrame,+ useVideoConfig,+} from 'remotion';+import {ExtrudeDiv, ThreeDPlane} from '../3DContext/Div3D';+import {RotateX, RotateY} from '../3DContext/transformation-context';++export const ParseAndDownloadMedia: React.FC = () => {+ const frame = useCurrentFrame();+ const {fps, width, height} = useVideoConfig();++ const prog = spring({+ fps,+ frame,+ durationInFrames: 100,+ });++ const rotateX = interpolate(prog, [0, 1], [0, Math.PI / 2]);+ const rotateY = interpolate(prog, [0, 1], [0, Math.PI / 2]);++ return (+ <AbsoluteFill className="bg-white flex">+ <RotateY radians={rotateX}>+ <RotateX radians={rotateY}>+ <ThreeDPlane+ width={width}+ height={height}+ cornerRadius={0}+ style={{+ display: 'flex',+ justifyContent: 'center',+ alignItems: 'center',+ flexDirection: 'column',+ }}+ >+ <div className="text-3xl mb-10" style={{fontFamily: 'GT Planar'}}>+ hi there+ </div>+ <ExtrudeDiv depth={40} width={700} height={120} cornerRadius={10}>+ <div+ className="h-full w-full overflow-hidden border-black border-solid border-2"+ style={{borderRadius: 10, backgroundColor: 'white'}}+ >+ <div+ style={{+ width: `${interpolate(prog, [0, 1], [0, 100])}%`,+ }}+ className="bg-red-500 h-full"+ />+ </div>+ </ExtrudeDiv>+ </ThreeDPlane>+ </RotateX>+ </RotateY>+ </AbsoluteFill>+ );+};diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex 051bff695e..0dbee27fbb 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -118,6 +118,7 @@ import {ThreeDContext} from './3DContext';import {ThreeDEngine} from './3DEngine';import {ThreeDSvgContent} from './3DSvgContent';import {AnimatedImages} from './AnimatedImage/Avif';+import {ParseAndDownloadMedia} from './ParseAndDownloadMedia';import {SmoothTextTransition} from './SmoothTextTransition';class Vector2 {@@ -1506,6 +1507,14 @@ export const Index: React.FC = () => {fps={30}durationInFrames={1000}/>+ <Composition+ id="ParseAndDownloadMedia"+ component={ParseAndDownloadMedia}+ width={1080}+ height={1080}+ fps={30}+ durationInFrames={1000}+ /><Compositionid="3DSVG"component={ThreeDSvgContent}