🎥 Make videos programmatically with React
Elements: Add Spinning Globe with Y-axis rotation
Jonny Burgerf6d5dd79e371
diff --git a/packages/docs/components/effects/effects-sphere-preview.tsx b/packages/docs/components/effects/effects-sphere-preview.tsxindex 158e2b6e1a..b50f4c985f 100644--- a/packages/docs/components/effects/effects-sphere-preview.tsx+++ b/packages/docs/components/effects/effects-sphere-preview.tsx@@ -11,8 +11,7 @@ import {// Source: https://www.naturalearthdata.com/downloads/50m-raster-data/50m-natural-earth-2/// Public domain; attribution is explicitly unnecessary:// https://www.naturalearthdata.com/about/terms-of-use/-export const SPHERE_GLOBE_TEXTURE_SRC =- 'https://remotion.media/natural-earth-2-4096-a45c3f8c73ed.jpg';+export const SPHERE_GLOBE_TEXTURE_SRC = 'https://remotion.media/earth.jpg';export const EffectsSpherePreview: React.FC<{readonly radius: number;@@ -44,7 +43,7 @@ export const SpinningGlobeDemo: React.FC = () => {radius={300}rotationX={0}rotationY={(frame / durationInFrames) * 360}- rotationZ={-23.4}+ rotationZ={0}position={[0.5, 0.5]}render="both"shading={0.35}diff --git a/packages/docs/docs/effects/sphere.mdx b/packages/docs/docs/effects/sphere.mdxindex 3964b7187d..d41613e8e5 100644--- a/packages/docs/docs/effects/sphere.mdx+++ b/packages/docs/docs/effects/sphere.mdx@@ -32,7 +32,7 @@ export const MyComp: React.FC = () => {return (<CanvasImage- src="https://remotion.media/natural-earth-2-4096-a45c3f8c73ed.jpg"+ src="https://remotion.media/earth.jpg"width={1280}height={720}fit="fill"@@ -40,7 +40,6 @@ export const MyComp: React.FC = () => {sphere({radius: 300,rotationY: frame * 1.5,- rotationZ: -23.4,}),]}/>diff --git a/packages/docs/elements/maps/spinning-globe/index.mdx b/packages/docs/elements/maps/spinning-globe/index.mdxnew file mode 100644index 0000000000..1f74079f21--- /dev/null+++ b/packages/docs/elements/maps/spinning-globe/index.mdx@@ -0,0 +1,14 @@+---+title: Spinning Globe+description: A globe rotating around its vertical axis, with editable speed, longitude, and shading.+image: https://remotion.media/elements/maps-spinning-globe-preview-519f9607-5856-4487-b5bf-8648f3c004af.png+---++import {getElementDefinition} from '@site/src/components/Elements/element-utils';+import {ElementPage} from '@site/src/components/Elements/ElementPage';++# Spinning Globe++<ElementPage definition={getElementDefinition('maps/spinning-globe')} sourceFile="./spinning-globe.tsx" />++Requires WebGPU. Change the rotation speed, starting longitude, and shading in the Inspector. Negative speed reverses the rotation. Replace the texture with another equirectangular image to make a different globe.diff --git a/packages/docs/elements/maps/spinning-globe/initial-props.ts b/packages/docs/elements/maps/spinning-globe/initial-props.tsnew file mode 100644index 0000000000..c28dec5a54--- /dev/null+++ b/packages/docs/elements/maps/spinning-globe/initial-props.ts@@ -0,0 +1,15 @@+import type {ElementAsset} from '@remotion/studio-protocol';+import type {ComponentProps} from 'react';+import type {SpinningGlobe} from './spinning-globe';++// Natural Earth II, public domain; attribution is not required.+// https://www.naturalearthdata.com/about/terms-of-use/+export const spinningGlobeTexture = {+ path: 'elements/spinning-globe/earth.jpg',+ type: 'url',+ url: 'https://remotion.media/earth.jpg',+} as const satisfies ElementAsset;++export const spinningGlobeInitialProps = {+ src: spinningGlobeTexture.url,+} satisfies ComponentProps<typeof SpinningGlobe>;diff --git a/packages/docs/elements/maps/spinning-globe/spinning-globe.tsx b/packages/docs/elements/maps/spinning-globe/spinning-globe.tsxnew file mode 100644index 0000000000..203ad54908--- /dev/null+++ b/packages/docs/elements/maps/spinning-globe/spinning-globe.tsx@@ -0,0 +1,85 @@+import {sphere} from '@remotion/effects/sphere';+import React from 'react';+import {+ CanvasImage,+ Interactive,+ useCurrentFrame,+ useVideoConfig,+ type InteractiveTransformProps,+ type InteractivitySchema,+} from 'remotion';++type SpinningGlobeProps = InteractiveTransformProps & {+ readonly src: string;+ readonly speed?: number;+ readonly longitude?: number;+ readonly shading?: number;+};++const spinningGlobeSchema = {+ src: {+ type: 'asset',+ assetType: 'image',+ default: 'https://remotion.media/earth.jpg',+ description: 'Globe texture',+ keyframable: false,+ },+ speed: {+ type: 'number',+ min: -1,+ max: 1,+ step: 0.01,+ default: 1 / 8,+ description: 'Revolutions per second',+ hiddenFromList: false,+ },+ longitude: {+ type: 'rotation-degrees',+ default: 0,+ description: 'Starting longitude',+ },+ shading: {+ type: 'number',+ min: 0,+ max: 1,+ step: 0.01,+ default: 0.35,+ description: 'Shading',+ hiddenFromList: false,+ },+} as const satisfies InteractivitySchema;++const SpinningGlobeInner: React.FC<SpinningGlobeProps> = ({+ src,+ speed = 1 / 8,+ longitude = 0,+ shading = 0.35,+ style,+}) => {+ const frame = useCurrentFrame();+ const {fps} = useVideoConfig();++ return (+ <div style={{width: 840, height: 840, ...style}}>+ <CanvasImage+ src={src}+ width={840}+ height={840}+ fit="fill"+ effects={[+ sphere({+ radius: 420,+ rotationY: longitude + (frame / fps) * speed * 360,+ shading,+ }),+ ]}+ />+ </div>+ );+};++export const SpinningGlobe = Interactive.create({+ Component: SpinningGlobeInner,+ componentName: '<SpinningGlobe>',+ schema: spinningGlobeSchema,+});diff --git a/packages/docs/src/components/Elements/element-definitions.ts b/packages/docs/src/components/Elements/element-definitions.tsindex f35b303d8d..89f3d7f433 100644--- a/packages/docs/src/components/Elements/element-definitions.ts+++ b/packages/docs/src/components/Elements/element-definitions.ts@@ -42,6 +42,11 @@ import {VerticalBarChart} from '../../../elements/data/vertical-bar-chart/verticimport {PictureInPictureTransition} from '../../../elements/layouts/picture-in-picture-transition/picture-in-picture-transition';import {SlideToSplitScreen} from '../../../elements/layouts/slide-to-split-screen/slide-to-split-screen';import {MapFlyover} from '../../../elements/maps/map-flyover/a-to-b-map-flyover';+import {+ spinningGlobeInitialProps,+ spinningGlobeTexture,+} from '../../../elements/maps/spinning-globe/initial-props';+import {SpinningGlobe} from '../../../elements/maps/spinning-globe/spinning-globe';import {WatercolorMap} from '../../../elements/maps/watercolor-map/watercolor-map';import {LocationLowerThird} from '../../../elements/overlays/location-lower-third/location-lower-third';import {NameLowerThird} from '../../../elements/overlays/name-lower-third/name-lower-third';@@ -875,6 +880,36 @@ const elementImplementations = [installationMode: 'component-owned-sequence',width: 1920,},+ {+ slug: 'maps/spinning-globe',+ assets: [spinningGlobeTexture],+ installationProps: {+ src: staticFileRef(spinningGlobeTexture.path),+ } as ElementInitialProps,+ component: SpinningGlobe,+ contributors: [],+ description:+ 'A globe rotating around its vertical axis, with editable speed, longitude, and shading.',+ dependencies: [{name: '@remotion/effects', version: null}],+ durationInFrames: 240,+ elementHeight: 840,+ elementWidth: 840,+ fps: 30,+ height: 1080,+ posterFrame: 0,+ preview: {+ previewLayout: 'composition',+ posterUrl:+ 'https://remotion.media/elements/maps-spinning-globe-preview-519f9607-5856-4487-b5bf-8648f3c004af.png',+ backgroundTheme: 'dark',+ videoUrl:+ 'https://remotion.media/elements/maps-spinning-globe-preview-519f9607-5856-4487-b5bf-8648f3c004af.mp4',+ },+ safeArea: 0,+ initialProps: spinningGlobeInitialProps,+ installationMode: 'component-owned-sequence',+ width: 1920,+ },{slug: 'maps/watercolor-map',assets: [],diff --git a/packages/docs/src/components/Elements/element-registry.ts b/packages/docs/src/components/Elements/element-registry.tsindex 71377321a6..1b53aae50e 100644--- a/packages/docs/src/components/Elements/element-registry.ts+++ b/packages/docs/src/components/Elements/element-registry.ts@@ -119,6 +119,10 @@ export const elementRegistry = {category: 'maps',displayName: 'A-to-B Map Flyover',},+ 'maps/spinning-globe': {+ category: 'maps',+ displayName: 'Spinning Globe',+ },'maps/watercolor-map': {category: 'maps',displayName: 'Watercolor Map',diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsxindex 748e75468b..c5e27c759b 100644--- a/packages/docs/src/remotion/Root.tsx+++ b/packages/docs/src/remotion/Root.tsx@@ -241,7 +241,7 @@ export const RemotionRoot: React.FC = () => {radius: 300,rotationX: 0,rotationY: -20,- rotationZ: -23.4,+ rotationZ: 0,position: [0.5, 0.5],render: 'both',shading: 0.35,diff --git a/packages/docs/static/img/effects-sphere-preview.png b/packages/docs/static/img/effects-sphere-preview.pngindex 8052b28beb..0fb24a73d8 100644Binary files a/packages/docs/static/img/effects-sphere-preview.png and b/packages/docs/static/img/effects-sphere-preview.png differ