Skip to content

πŸŽ₯ Make videos programmatically with React

awesome

Jonny Burgera887e0adc350
diff --git a/packages/docs/src/components/DoMoreHero/DoMoreHero.tsx b/packages/docs/src/components/DoMoreHero/DoMoreHero.tsx
deleted file mode 100644
index d35dfcc6a8..0000000000
--- a/packages/docs/src/components/DoMoreHero/DoMoreHero.tsx
+++ /dev/null
@@ -1,167 +0,0 @@
-import {useColorMode} from '@docusaurus/theme-common';
-import {getBoundingBox, parsePath, resetPath} from '@remotion/paths';
-import {Player} from '@remotion/player';
-import {makeTriangle} from '@remotion/shapes';
-import {
- extrudeElement,
- rotateX,
- rotateY,
- rotateZ,
- scaled,
- transformElement,
- translateX,
- translateY,
- translateZ,
-} from '@remotion/svg-3d-engine';
-import React, {useMemo} from 'react';
-import {
- AbsoluteFill,
- interpolate,
- spring,
- useCurrentFrame,
- useVideoConfig,
-} from 'remotion';
-import {useMobileLayout} from '../../helpers/mobile-layout';
-import {Faces} from './Faces';
-import styles from './more.module.css';
-
-const InFrameLogo: React.FC<{
- readonly background: string;
- readonly dark: boolean;
-}> = ({background, dark}) => {
- const {width: bBoxWidth, height: bBoxHeight, fps} = useVideoConfig();
- const viewBox = [-bBoxWidth / 2, -bBoxHeight / 2, bBoxWidth, bBoxHeight].join(
- ' ',
- );
- const frame = useCurrentFrame();
-
- const zoomIn = (Math.sin(frame / 100) + 1) * 0.2;
-
- const delayedFrame = Math.max(frame - 80, 0);
-
- const paths = new Array(3).fill(true).map((_, i) => {
- const triangle = makeTriangle({
- direction: 'right',
- length: 1500 + i * 675,
- edgeRoundness: 0.71,
- });
- const path = resetPath(triangle.path);
- const parsed = parsePath(path);
-
- const boundingBox = getBoundingBox(path);
- const width = boundingBox.x2 - boundingBox.x1;
- const height = boundingBox.y2 - boundingBox.y1;
-
- const depth = 20 * 7.5;
- const spread =
- depth +
- (Math.sin(frame / 200) +
- (1 +
- spring({
- frame,
- fps,
- config: {
- damping: 200,
- },
- durationInFrames: 200,
- delay: 80,
- }))) *
- 500;
-
- const darkColor = i === 2 ? '#bbb' : i === 1 ? '#ddd' : '#fff';
- const color = i === 2 ? '#E9F3FD' : i === 1 ? '#C1DBF9' : '#0b84f3';
-
- const actualColor = dark ? darkColor : color;
-
- const extruded = extrudeElement({
- backFaceColor: actualColor,
- sideColor: 'black',
- frontFaceColor: actualColor,
- depth,
- points: parsed,
- strokeWidth: 20,
- description: `triangle-${i}`,
- strokeColor: 'black',
- crispEdges: false,
- });
- const projected = transformElement(extruded, [
- translateZ(spread * i - spread),
- translateX(-width / 2),
- translateY(-height / 2 + 20),
- rotateX(-(i * delayedFrame) / 300),
- rotateY(delayedFrame / 100),
- rotateZ(delayedFrame / 100),
- scaled(0.3 + zoomIn),
- ]);
-
- return projected;
- });
-
- return (
- <AbsoluteFill
- style={{
- backgroundColor: background,
- }}
- >
- <svg
- viewBox={viewBox}
- style={{
- overflow: 'visible',
- opacity: interpolate(frame, [0, 70], [0, 1]),
- }}
- >
- <Faces elements={paths.reverse()} />
- </svg>
- </AbsoluteFill>
- );
-};
-
-export const DoMoreHero: React.FC = () => {
- const mobile = useMobileLayout();
- const theme = useColorMode();
-
- const dimensions = mobile
- ? {
- width: 1080 * 2,
- height: 1920 * 0.8,
- }
- : {
- width: 1920 * 2,
- height: 1080 * 1.4,
- };
-
- const inputProps = useMemo(() => {
- return {dark: theme.colorMode === 'dark'};
- }, [theme.colorMode]);
-
- return (
- <div
- style={{
- position: 'relative',
- }}
- >
- <Player
- component={InFrameLogo}
- compositionWidth={dimensions.width}
- compositionHeight={dimensions.height}
- durationInFrames={100000}
- fps={30}
- loop
- autoPlay
- style={{
- width: '100%',
- }}
- inputProps={inputProps}
- />
- <div
- className={styles.gradient}
- style={{
- height: '20vw',
- marginTop: '-20vw',
- width: '100%',
- position: 'absolute',
- }}
- />
- </div>
- );
-};
diff --git a/packages/docs/src/components/DoMoreHero/Faces.tsx b/packages/docs/src/components/DoMoreHero/Faces.tsx
deleted file mode 100644
index 19a4278d4e..0000000000
--- a/packages/docs/src/components/DoMoreHero/Faces.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-import type {ThreeDElement} from '@remotion/svg-3d-engine/src/elements';
-import type {FaceType} from '@remotion/svg-3d-engine/src/map-face';
-import React from 'react';
-import type {FaceSVGProps} from './Face';
-import {Face} from './Face';
-
-const sortFacesZIndex = (face: FaceType[]): FaceType[] => {
- return face.slice().sort((a, b) => {
- return b.centerPoint[2] - a.centerPoint[2];
- });
-};
-
-export const Faces: React.FC<
- {
- readonly elements: ThreeDElement[];
- readonly noSort?: boolean;
- } & FaceSVGProps
-> = ({elements, noSort, ...svgProps}) => {
- const sortedElement = noSort
- ? elements
- : elements.sort((a, b) => {
- return b.centerPoint[2] - a.centerPoint[2];
- });
-
- return (
- <>
- {sortedElement.map((element, i) => {
- const sortedFaces = sortFacesZIndex(element.faces);
-
- return (
- // eslint-disable-next-line react/no-array-index-key
- <React.Fragment key={i}>
- {sortedFaces.map(
- ({points, color, strokeWidth, strokeColor, crispEdges}, idx) => {
- return (
- <Face
- // eslint-disable-next-line react/no-array-index-key
- key={JSON.stringify(points) + idx}
- strokeColor={strokeColor}
- color={color}
- points={points}
- strokeWidth={strokeWidth}
- crispEdges={crispEdges}
- {...svgProps}
- />
- );
- },
- )}
- </React.Fragment>
- );
- })}
- </>
- );
-};
diff --git a/packages/docs/src/pages/4/index.tsx b/packages/docs/src/pages/4/index.tsx
deleted file mode 100644
index fa9c83285b..0000000000
--- a/packages/docs/src/pages/4/index.tsx
+++ /dev/null
@@ -1,241 +0,0 @@
-/* eslint-disable no-alert */
-import Head from '@docusaurus/Head';
-import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
-import Layout from '@theme/Layout';
-import React, {useCallback, useMemo, useState} from 'react';
-import {CoolInput} from '../../../components/TextInput';
-import {PlainButton} from '../../../components/layout/Button';
-import {Spacer} from '../../../components/layout/Spacer';
-import {DoMoreHero} from '../../components/DoMoreHero/DoMoreHero';
-import {Seo} from '../../components/Seo';
-import styles from './v4.module.css';
-
-const spacer: React.CSSProperties = {
- height: '10px',
-};
-
-const errorStyle: React.CSSProperties = {
- color: '#FF3232',
- textAlign: 'center',
-};
-
-export const EventComp: React.FC<{
- readonly date: string;
- readonly title: string;
- readonly description: string;
- readonly youtubeId?: string;
-}> = ({date, title, description, youtubeId}) => {
- return (
- <div
- style={{
- border: '2px solid var(--ifm-font-color-base)',
- borderBottomWidth: 4,
- borderRadius: 8,
- padding: 10,
- }}
- >
- <p className={styles.date}>{date}</p>
- <p className={styles.eventtitle}>{title}</p>
- <p>{description}</p>
- {youtubeId ? (
- <iframe
- style={{
- width: '100%',
- aspectRatio: '16 / 9',
- }}
- src={`https://www.youtube.com/embed/${youtubeId}`}
- title="YouTube video player"
- frameBorder="0"
- allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
- allowFullScreen
- />
- ) : (
- <div
- style={{
- width: '100%',
- aspectRatio: '16 / 9',
- backgroundColor: 'var(--ifm-out-of-focus)',
- borderRadius: 5,
- display: 'flex',
- justifyContent: 'center',
- alignItems: 'center',
- }}
- >
- <div
- style={{
- color: 'var(--ifm-subtitle)',
- justifyContent: 'center',
- alignItems: 'center',
- fontWeight: 'bold',
- }}
- >
- Check back {date}
- </div>
- </div>
- )}
- </div>
- );
-};
-
-const V4: React.FC = () => {
- const context = useDocusaurusContext();
-
- const [email, setEmail] = useState<string | null>(null);
- const [loading, setLoading] = useState<boolean>(false);
- const [subscribed, setSubscribed] = useState<boolean>(false);
- const [error, setError] = useState<string | null>(null);
- const buttonLabel = useMemo(() => {
- if (subscribed) {
- return "You're signed up!";
- }
-
- return loading ? 'Signing up...' : 'Sign up';
- }, [loading, subscribed]);
- const isValidEmail = (inputMail: string) =>
- /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(inputMail);
-
- const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
- (e) => {
- setEmail(e.target.value);
- },
- [],
- );
-
- const onSubmit: React.FormEventHandler = useCallback(
- async (e) => {
- try {
- e.preventDefault();
- setSubscribed(false);
- setError(null);
-
- if (email && isValidEmail(email)) {
- setLoading(true);
- const res = await fetch('https://www.remotion.pro/api/newsletter', {
- method: 'POST',
- body: JSON.stringify({email}),
- headers: {'content-type': 'application/json'},
- });
- const json = await res.json();
- if (json.success) {
- setSubscribed(true);
- } else {
- setLoading(false);
- alert('Something went wrong. Please try again later.');
- }
- } else {
- setError('Invalid email provided');
- }
- } catch (err) {
- setLoading(false);
- alert('Something went wrong. Please try again later');
- console.error(err);
- }
- },
- [email],
- );
-
- return (
- <Layout>
- <Head>
- {Seo.renderTitle('Do more with React | Remotion 4.0')}
- {Seo.renderImage('/img/remotion4.png', context.siteConfig.url)}
- </Head>
- <DoMoreHero />
-
- <div className={styles.container}>
- <div className={styles.wrapper}>
- <h1 className={styles.pagetitle}>Do more with React</h1>
- <div style={{display: 'flex', justifyContent: 'center'}}>
- <p className={styles.title}>
- Discover the new capabilities of Remotion 4.0 from July 3 – July 7
- </p>
- </div>
- <br />
- <div
- style={{
- textAlign: 'center',
- display: 'flex',
- justifyContent: 'center',
- }}
- >
- <a
- style={{
- textDecoration: 'none',
- }}
- className={styles.a}
- href="/blog/4-0"
- >
- <PlainButton size="sm" loading={false} fullWidth={false}>
- View announcement blog post
- </PlainButton>
- </a>
- </div>
-
- <br />
- <div className={styles.grid}>
- <EventComp
- description="Celebrate the launch of Remotion 4.0 and experience the new possibilities of media creation with React."
- date="July 3rd"
- title="Keynote"
- youtubeId="S3C9wlPNhkQ"
- />
- <EventComp
- date="July 4th"
- title="Visual editing"
- description="Expose parameters to the user interface, edit them, see the result in real-time and save them back to code."
- youtubeId="NX9YTOsLGpQ"
- />
- <EventComp
- date="July 5th"
- title="Render button"
- description="Configure, queue and track renders with the newest way to render using Remotion."
- youtubeId="ywRZvG94SPI"
- />
- <EventComp
- description="Leverage the new system for data fetching and dynamically calculating the duration and dimensions of your video."
- date="July 6th"
- title="Data-driven videos"
- youtubeId="JrxL3mYY22c"
- />
- <EventComp
- description="A rundown of the remaining improvements coming with Remotion 4.0."
- date="July 7th"
- title="Last but not least"
- youtubeId="UCJn8uiWNxQ"
- />
- <div className={styles.panel}>
- <div style={{marginBottom: 10}}>
- Sign up for our newsletter to stay up to date:
- </div>
- <form style={{width: '100%'}} onSubmit={onSubmit}>
- <CoolInput
- type="email"
- autoComplete="none"
- onChange={onChange}
- placeholder="Your email adress"
- style={{width: '100%', fontFamily: 'GTPlanar'}}
- />
- <Spacer />
- <div>
- <button
- type="submit"
- className={styles.submitbutton}
- disabled={loading || subscribed}
- >
- {buttonLabel}
- </button>
- </div>
- </form>
- <Spacer />
- <div style={errorStyle}>{error}</div>
- </div>
- </div>
- <div style={spacer} />
- <div style={spacer} />
- </div>
- </div>
- </Layout>
- );
-};
-
-export default V4;
diff --git a/packages/example/src/3DContext/Div3D.tsx b/packages/example/src/3DContext/Div3D.tsx
index 5c330a45cc..37d8ab0d5a 100644
--- a/packages/example/src/3DContext/Div3D.tsx
+++ b/packages/example/src/3DContext/Div3D.tsx
@@ -1,6 +1,8 @@
import {DivExtrusion} from './DivExtrusion';
-import {FrontFace} from './FrontFace';
+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;
@@ -8,12 +10,29 @@ export const Div3D: React.FC<{
height: number;
depth: number;
cornerRadius: number;
-}> = ({children, width, height, depth, cornerRadius}) => {
+ backFace?: React.ReactNode;
+}> = ({children, width, height, depth, cornerRadius, backFace}) => {
+ const frontFace = isBacksideVisible(useTransformations());
+
return (
<RectProvider height={height} width={width} cornerRadius={cornerRadius}>
- <div style={{width, height, position: 'relative'}}>
+ <div
+ style={{
+ width,
+ height,
+ position: 'relative',
+ }}
+ >
<DivExtrusion depth={depth} />
- <FrontFace depth={depth}>{children}</FrontFace>
+ {frontFace ? (
+ <Face type="front" depth={depth}>
+ {children}
+ </Face>
+ ) : (
+ <Face type="back" depth={depth}>
+ {backFace}
+ </Face>
+ )}
</div>
</RectProvider>
);
diff --git a/packages/example/src/3DContext/Extrusion.tsx b/packages/example/src/3DContext/Extrusion.tsx
index 2d2f63aafb..444db9f93c 100644
--- a/packages/example/src/3DContext/Extrusion.tsx
+++ b/packages/example/src/3DContext/Extrusion.tsx
@@ -8,7 +8,6 @@ import {
import {Faces} from '../3DEngine/Faces';
import {useRect} from './path-context';
import {useTransformations} from './transformation-context';
-import {isBacksideVisible} from './viewing-frontside';
export const SvgExtrusion: React.FC<{
depth: number;
@@ -29,8 +28,7 @@ export const SvgExtrusion: React.FC<{
translateY(height / 2),
]);
- const {inbetween, scaledBackFace} = extrudeAndTransformElement({
- backFaceColor: 'white',
+ const inbetween = extrudeAndTransformElement({
sideColor: 'black',
crispEdges: false,
depth,
@@ -39,9 +37,5 @@ export const SvgExtrusion: React.FC<{
transformations: centerOriented,
});
- const extruded = isBacksideVisible(centerOriented)
- ? [...inbetween, scaledBackFace]
- : [scaledBackFace, ...inbetween];
-
- return <Faces elements={extruded} />;
+ return <Faces elements={inbetween} />;
};
diff --git a/packages/example/src/3DContext/FrontFace.tsx b/packages/example/src/3DContext/FrontFace.tsx
index 7e20f9c51e..9e08b1da5d 100644
--- a/packages/example/src/3DContext/FrontFace.tsx
+++ b/packages/example/src/3DContext/FrontFace.tsx
@@ -1,16 +1,22 @@
import {
makeMatrix3dTransform,
reduceMatrices,
+ scaleY,
translateZ,
} from '@remotion/svg-3d-engine';
import {useRect} from './path-context';
import {useTransformations} from './transformation-context';
-export const FrontFace: React.FC<{
+export const Face: React.FC<{
children: React.ReactNode;
depth: number;
-}> = ({children, depth}) => {
- const frontFace = reduceMatrices([translateZ(-depth), useTransformations()]);
+ type: 'front' | 'back';
+}> = ({children, depth, type}) => {
+ const frontFace = reduceMatrices([
+ type === 'back' ? scaleY(-1) : null,
+ translateZ(type === 'front' ? -depth : 0.01 * depth),
+ useTransformations(),
+ ]);
const {height, width} = useRect();
return (
@@ -20,7 +26,7 @@ export const FrontFace: React.FC<{
display: 'flex',
width,
height,
- backfaceVisibility: 'hidden',
+ position: 'absolute',
}}
>
{children}
diff --git a/packages/example/src/3DContext/FrontFaceG.tsx b/packages/example/src/3DContext/FrontFaceG.tsx
index a9ae2601ba..c04a15060e 100644
--- a/packages/example/src/3DContext/FrontFaceG.tsx
+++ b/packages/example/src/3DContext/FrontFaceG.tsx
@@ -1,16 +1,21 @@
import {
makeMatrix3dTransform,
reduceMatrices,
+ scaleY,
translateZ,
} from '@remotion/svg-3d-engine';
import {useTransformations} from './transformation-context';
-import {isBacksideVisible} from './viewing-frontside';
export const FrontFaceG: React.FC<{
children: React.ReactNode;
depth: number;
-}> = ({children, depth}) => {
- const frontFace = reduceMatrices([translateZ(-depth), useTransformations()]);
+ type: 'front' | 'back';
+}> = ({children, depth, type}) => {
+ const frontFace = reduceMatrices([
+ type === 'back' ? scaleY(-1) : null,
+ translateZ(type === 'front' ? -depth : 0.01 * depth),
+ useTransformations(),
+ ]);
return (
<g
@@ -18,7 +23,6 @@ export const FrontFaceG: React.FC<{
transform: makeMatrix3dTransform(frontFace),
transformBox: 'fill-box',
transformOrigin: 'center center',
- opacity: isBacksideVisible(frontFace) ? 0 : 1,
}}
>
{children}
diff --git a/packages/example/src/3DContext/index.tsx b/packages/example/src/3DContext/index.tsx
index 4cd9e8330d..16973b351a 100644
--- a/packages/example/src/3DContext/index.tsx
+++ b/packages/example/src/3DContext/index.tsx
@@ -18,7 +18,27 @@ const Comp = () => {
<RotateX radians={progress / 10}>
<RotateX radians={Math.sin(angle) / 4}>
<RotateY radians={-Math.cos(angle) / 4}>
- <Div3D width={width} height={height} depth={40} cornerRadius={10}>
+ <Div3D
+ width={width}
+ height={height}
+ depth={40}
+ cornerRadius={10}
+ backFace={
+ <div
+ style={{
+ borderRadius: cornerRadius,
+ width,
+ height,
+ fontFamily: 'GT Planar',
+ backgroundColor: 'white',
+ border: '2px solid black',
+ }}
+ className="text-red-800 flex justify-center items-center font-sans text-2xl border-solid border-black font-bold cursor-pointer"
+ >
+ Back side
+ </div>
+ }
+ >
<div
style={{
borderRadius: cornerRadius,
diff --git a/packages/example/src/3DEngine/Face.tsx b/packages/example/src/3DEngine/Face.tsx
deleted file mode 100644
index 7b7849fdc9..0000000000
--- a/packages/example/src/3DEngine/Face.tsx
+++ /dev/null
@@ -1,6 +0,0 @@
-import React from 'react';
-
-export type FaceSVGProps = {
- readonly strokeLinecap?: React.SVGAttributes<SVGPathElement>['strokeLinecap'];
- readonly strokeMiterlimit?: React.SVGAttributes<SVGPathElement>['strokeMiterlimit'];
-};
diff --git a/packages/example/src/3DEngine/Faces.tsx b/packages/example/src/3DEngine/Faces.tsx
index 3747be4341..3e4a920686 100644
--- a/packages/example/src/3DEngine/Faces.tsx
+++ b/packages/example/src/3DEngine/Faces.tsx
@@ -1,13 +1,10 @@
import {threeDIntoSvgPath} from '@remotion/svg-3d-engine';
import type {FaceType} from '@remotion/svg-3d-engine/src/map-face';
import React from 'react';
-import {FaceSVGProps} from './Face';
-export const Faces: React.FC<
- {
- readonly elements: FaceType[];
- } & FaceSVGProps
-> = ({elements, ...svgProps}) => {
+export const Faces: React.FC<{
+ readonly elements: FaceType[];
+}> = ({elements, ...svgProps}) => {
return (
<>
{elements.map(({points, color, crispEdges}, idx) => {
diff --git a/packages/example/src/3DEngine/Outer.tsx b/packages/example/src/3DEngine/Outer.tsx
index abebba5117..4ff0e0d988 100644
--- a/packages/example/src/3DEngine/Outer.tsx
+++ b/packages/example/src/3DEngine/Outer.tsx
@@ -15,7 +15,6 @@ import {
} from '@remotion/svg-3d-engine';
import {useRef} from 'react';
import {interpolate} from 'remotion';
-import {isBacksideVisible} from '../3DContext/viewing-frontside';
import {Faces} from './Faces';
import {
useClickTransforms,
@@ -70,8 +69,7 @@ export const Outer: React.FC<{
const {viewBox} = PathInternals.getBoundingBoxFromInstructions(
reduceInstructions(instructions),
);
- const {inbetween, scaledBackFace} = extrudeAndTransformElement({
- backFaceColor: 'black',
+ const inbetween = extrudeAndTransformElement({
sideColor: 'black',
crispEdges: false,
depth,
@@ -80,10 +78,6 @@ export const Outer: React.FC<{
transformations: centerOriented,
});
- const extruded = isBacksideVisible(centerOriented)
- ? [...inbetween, scaledBackFace]
- : [scaledBackFace, ...inbetween];
-
return (
<div ref={ref} className="relative" style={{width, height}}>
<svg
@@ -97,7 +91,7 @@ export const Outer: React.FC<{
}}
pointerEvents="none"
>
- <Faces elements={extruded} />
+ <Faces elements={inbetween} />
</svg>
<div
style={{
diff --git a/packages/example/src/3DSvgContent/G3D.tsx b/packages/example/src/3DSvgContent/G3D.tsx
index 2727d1c5a7..1db6699b7f 100644
--- a/packages/example/src/3DSvgContent/G3D.tsx
+++ b/packages/example/src/3DSvgContent/G3D.tsx
@@ -3,15 +3,21 @@ import React, {useMemo} from 'react';
import {SvgExtrusion} from '../3DContext/Extrusion';
import {FrontFaceG} from '../3DContext/FrontFaceG';
import {PathProvider} from '../3DContext/path-context';
+import {useTransformations} from '../3DContext/transformation-context';
+import {isBacksideVisible} from '../3DContext/viewing-frontside';
export const G3D: React.FC<
{
readonly d: string;
readonly children: React.ReactNode;
+ readonly backFace: string;
readonly depth: number;
readonly strokeWidth?: number;
} & React.SVGAttributes<SVGGElement>
-> = ({d, children, depth, strokeWidth}) => {
+> = ({d, children, depth, strokeWidth, backFace}) => {
+ const isFrontFacing = isBacksideVisible(useTransformations());
+ const backFaceEl = <path d={d} fill={backFace} />;
+
const scaledPath = useMemo(() => {
if (!strokeWidth) {
return d;
@@ -27,11 +33,20 @@ export const G3D: React.FC<
-(strokeWidth ?? 0) / 2,
);
}, [d, strokeWidth]);
+ console.log({isFrontFacing});
return (
<PathProvider d={scaledPath}>
{depth > 0 ? <SvgExtrusion depth={depth} /> : null}
- <FrontFaceG depth={depth}>{children}</FrontFaceG>
+ {!isFrontFacing ? (
+ <FrontFaceG type="front" depth={depth}>
+ {children}
+ </FrontFaceG>
+ ) : (
+ <FrontFaceG type="back" depth={depth}>
+ {backFaceEl}
+ </FrontFaceG>
+ )}
</PathProvider>
);
};
diff --git a/packages/example/src/3DSvgContent/index.tsx b/packages/example/src/3DSvgContent/index.tsx
index 386bb3aa9c..444a031a1d 100644
--- a/packages/example/src/3DSvgContent/index.tsx
+++ b/packages/example/src/3DSvgContent/index.tsx
@@ -16,7 +16,7 @@ export const ThreeDSvgContent: React.FC = () => {
>
<rect width="574" height="434" fill="#F8FAFC" />
<RotateX radians={0}>
- <G3D d="M 0 0 L 574 434" depth={0}>
+ <G3D backFace="red" d="M 0 0 L 574 434" depth={0}>
<g id="remotionwebcodecs">
<text
id="@remotion/webcodecs"
@@ -62,6 +62,7 @@ export const ThreeDSvgContent: React.FC = () => {
</g>
<SpinEffect>
<G3D
+ backFace="red"
d="M212 81C212 76.0294 216.029 72 221 72H353C357.971 72 362 76.0294 362 81V185C362 189.971 357.971 194 353 194H221C216.029 194 212 189.971 212 185V81Z"
depth={10}
id="Group 30"
@@ -518,6 +519,7 @@ export const ThreeDSvgContent: React.FC = () => {
</g>
<SpinEffect>
<G3D
+ backFace="green"
d={translatePath(
makeRect({width: 150, height: 124, cornerRadius: 9}).path,
212,
@@ -634,6 +636,7 @@ export const ThreeDSvgContent: React.FC = () => {
</g>
<SpinEffect delay={2}>
<G3D
+ backFace="blue"
d={translatePath(
makeCircle({radius: 6}).path,
232 - 6,
diff --git a/packages/svg-3d-engine/bundle.ts b/packages/svg-3d-engine/bundle.ts
index fe49d9b1fb..c6efbad60c 100644
--- a/packages/svg-3d-engine/bundle.ts
+++ b/packages/svg-3d-engine/bundle.ts
@@ -20,3 +20,4 @@ const text = await file.text();
await Bun.write('dist/esm/index.mjs', text);
export {};
+console.log('Generated.');
diff --git a/packages/svg-3d-engine/src/extrude-element.ts b/packages/svg-3d-engine/src/extrude-element.ts
index 102d1fe2e5..9c23892754 100644
--- a/packages/svg-3d-engine/src/extrude-element.ts
+++ b/packages/svg-3d-engine/src/extrude-element.ts
@@ -56,7 +56,6 @@ const inverseInstruction = (
type ExtrudeElementOptions = {
depth: number;
sideColor: string;
- backFaceColor: string;
points: Instruction[];
description?: string;
crispEdges: boolean;
@@ -68,11 +67,7 @@ export const extrudeElement = ({
points,
description = 'extruded',
crispEdges,
- backFaceColor,
-}: ExtrudeElementOptions): {
- inbetween: FaceType[];
- scaledBackFace: FaceType;
-} => {
+}: ExtrudeElementOptions): FaceType[] => {
const threeD = turnInto3D(points);
const instructions: FaceType = {
centerPoint: [0, 0, 0, 1],
@@ -139,26 +134,17 @@ export const extrudeElement = ({
};
});
- const scaledBackFace: FaceType = {
- ...transformFace(unscaledBackFace, [translateZ(-depth * 0.01)]),
- color: backFaceColor,
- description: description + '(back)',
- };
-
- return {inbetween, scaledBackFace};
+ return inbetween;
};
export const extrudeAndTransformElement = (
options: ExtrudeElementOptions & {
transformations: MatrixTransform4D;
},
-): {inbetween: FaceType[]; scaledBackFace: FaceType} => {
- const {inbetween, scaledBackFace} = extrudeElement(options);
-
- return {
- inbetween: inbetween.map((face) => ({
- ...transformFace(face, [options.transformations]),
- })),
- scaledBackFace: transformFace(scaledBackFace, [options.transformations]),
- };
+): FaceType[] => {
+ const inbetween = extrudeElement(options);
+
+ return inbetween.map((face) => ({
+ ...transformFace(face, [options.transformations]),
+ }));
};
diff --git a/packages/svg-3d-engine/src/index.ts b/packages/svg-3d-engine/src/index.ts
index ea26d0b5e0..825647402e 100644
--- a/packages/svg-3d-engine/src/index.ts
+++ b/packages/svg-3d-engine/src/index.ts
@@ -12,6 +12,8 @@ export {
rotateX,
rotateY,
rotateZ,
+ scaleX,
+ scaleY,
scaled,
translateX,
translateY,
diff --git a/packages/svg-3d-engine/src/matrix.ts b/packages/svg-3d-engine/src/matrix.ts
index 12626604fb..58b255c5fd 100644
--- a/packages/svg-3d-engine/src/matrix.ts
+++ b/packages/svg-3d-engine/src/matrix.ts
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import type {ThreeDReducedInstruction} from './3d-svg';
+import {truthy} from './truthy';
export const stride = function ({
v,
@@ -155,9 +156,10 @@ export const multiplyMatrices = (
};
export const reduceMatrices = (
- matrices: MatrixTransform4D[],
+ matrices: (MatrixTransform4D | null)[],
): MatrixTransform4D => {
return matrices
+ .filter(truthy)
.slice()
.reverse()
.reduce((acc, cur) => {
@@ -222,6 +224,14 @@ export const scaled = function (value: number | Vector) {
return stride({v: vec, m: identity4(), width: 4, offset: 0, colStride: 1});
};
+export const scaleX = (x: number) => {
+ return scaled([x, 1, 1]);
+};
+
+export const scaleY = (y: number) => {
+ return scaled([1, y, 1]);
+};
+
const rotatedUnitSinCos = function (
axisVec: Vector,
sinAngle: number,