Skip to content

🎥 Make videos programmatically with React

3d engine experiments

Jonny Burgerf6737e21e113
diff --git a/packages/example/src/3DEngine/index.tsx b/packages/example/src/3DEngine/index.tsx
new file mode 100644
index 0000000000..83df49c59e
--- /dev/null
+++ b/packages/example/src/3DEngine/index.tsx
@@ -0,0 +1,57 @@
+import {getBoundingBox} from '@remotion/paths';
+import {makeRect} from '@remotion/shapes';
+import React, {useEffect, useRef, useState} from 'react';
+import {AbsoluteFill, useCurrentScale} from 'remotion';
+
+const measure = (
+ ref: React.RefObject<HTMLDivElement | null>,
+ scale: number,
+) => {
+ const reffed = ref.current?.getBoundingClientRect();
+ if (!reffed) {
+ throw new Error('No ref');
+ }
+ return {
+ width: reffed.width / scale,
+ height: reffed.height / scale,
+ };
+};
+
+export const ThreeDEngine = () => {
+ const ref = useRef<HTMLDivElement>(null);
+ const [svgShape, setSvgShape] = useState<string | null>(null);
+ const scale = useCurrentScale();
+
+ useEffect(() => {
+ const measured = measure(ref, scale);
+ const path = makeRect({
+ width: measured.width,
+ height: measured.height,
+ });
+
+ setSvgShape(path.path);
+ }, [scale]);
+
+ return (
+ <AbsoluteFill className="flex justify-center items-center">
+ <div
+ ref={ref}
+ className="bg-red-700 text-white w-[300px] h-[300px] flex justify-center items-center font-sans text-2xl"
+ >
+ hi there
+ </div>
+ {svgShape ? (
+ <svg
+ viewBox={getBoundingBox(svgShape).viewBox}
+ style={{
+ height: getBoundingBox(svgShape).height,
+ width: getBoundingBox(svgShape).width,
+ overflow: 'visible',
+ }}
+ >
+ <path d={svgShape} fill="gray" stroke="black" strokeWidth="1" />
+ </svg>
+ ) : null}
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 4403a53e34..a46a8398a5 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -113,6 +113,7 @@ if (alias !== 'alias') {
const INCLUDE_COMP_BREAKING_GET_COMPOSITIONS = false;
+import {ThreeDEngine} from './3DEngine';
import {AnimatedImages} from './AnimatedImage/Avif';
class Vector2 {
@@ -1494,6 +1495,12 @@ export const Index: React.FC = () => {
/>
<Still id="Emojis" component={EmojiTestbed} height={800} width={1024} />
<Still id="HugeImage" component={HugeImage} height={9000} width={9000} />
+ <Still
+ id="ThreeDEngine"
+ component={ThreeDEngine}
+ height={1000}
+ width={1000}
+ />
</>
);
};