|
| 1 | +import { ThreeCanvas } from "@remotion/three"; |
| 2 | +import { |
| 3 | + AbsoluteFill, |
| 4 | + Audio, |
| 5 | + interpolate, |
| 6 | + interpolateColors, |
| 7 | + spring, |
| 8 | + staticFile, |
| 9 | + useCurrentFrame, |
| 10 | + useVideoConfig, |
| 11 | +} from "remotion"; |
| 12 | +import { |
| 13 | + OrbitControls, |
| 14 | + Text, |
| 15 | + PerspectiveCamera, |
| 16 | + useGLTF, |
| 17 | + Sparkles, |
| 18 | +} from "@react-three/drei"; |
| 19 | +// import * as THREE from "three"; |
| 20 | +import { TextureLoader } from "three"; |
| 21 | +import { useLoader } from "@react-three/fiber"; |
| 22 | + |
| 23 | +const FireshipLogo = "/fireship-simple.glb"; |
| 24 | +const CodeReportText = "/code-report.glb"; |
| 25 | +const fireshipTexture = "/big-gradient.png"; |
| 26 | + |
| 27 | +const Animation = ({ AnimationAudioURL }) => { |
| 28 | + const frame = useCurrentFrame(); |
| 29 | + const { width, height, fps, durationInFrames } = useVideoConfig(); |
| 30 | + |
| 31 | + // Interpolate |
| 32 | + const cameraX = 0; |
| 33 | + const cameraY = interpolate(frame, [0, durationInFrames / 2], [0, 0], { |
| 34 | + extrapolateRight: "clamp", |
| 35 | + }); |
| 36 | + const cameraZ = interpolate(frame, [0, durationInFrames / 2], [-7, -7], { |
| 37 | + extrapolateRight: "clamp", |
| 38 | + }); |
| 39 | + |
| 40 | + const modelScale = interpolate(frame, [0, fps / 4], [30, 30], { |
| 41 | + extrapolateRight: "clamp", |
| 42 | + }); |
| 43 | + // const modelRotate = interpolate(frame, [0, durationInFrames], [0, 0]); |
| 44 | + const modelPositionY = interpolate(frame, [0, fps / 4], [-7, -3], { |
| 45 | + extrapolateRight: "clamp", |
| 46 | + }); |
| 47 | + const modelPositionZ = spring({ |
| 48 | + frame: frame - fps / 10, |
| 49 | + fps, |
| 50 | + config: { |
| 51 | + stiffness: 31, |
| 52 | + // mass: 0.5, |
| 53 | + }, |
| 54 | + from: -500, |
| 55 | + to: 0, |
| 56 | + durationInFrames: 30, |
| 57 | + }); |
| 58 | + |
| 59 | + const textPositionX = interpolate(frame, [0, fps / 4], [-3, -6.15], { |
| 60 | + extrapolateRight: "clamp", |
| 61 | + }); |
| 62 | + const textPositionY = modelPositionY - 8.5; |
| 63 | + const textPositionZ = spring({ |
| 64 | + frame: frame - 6, |
| 65 | + fps, |
| 66 | + config: { |
| 67 | + // stiffness: 31, |
| 68 | + damping: 2000, |
| 69 | + }, |
| 70 | + from: -850, |
| 71 | + to: 0, |
| 72 | + durationInFrames: 30, |
| 73 | + }); |
| 74 | + // const TextGradientColors = interpolateColors( |
| 75 | + // frame, |
| 76 | + // [0, durationInFrames / 2 - 10, durationInFrames * 0.75, durationInFrames], |
| 77 | + // ['#c4eeff', 'white', '#c4eeff', 'white'] |
| 78 | + // ); |
| 79 | + const TextGradientColors = "white"; |
| 80 | + const textScale = interpolate(frame, [0, fps / 4], [30, 40], { |
| 81 | + extrapolateRight: "clamp", |
| 82 | + }); |
| 83 | + const opacity = interpolate( |
| 84 | + frame, |
| 85 | + [durationInFrames / 2, durationInFrames - fps], |
| 86 | + [1, 1] |
| 87 | + ); |
| 88 | + |
| 89 | + // Load assets |
| 90 | + const FireshipLogoObject = useGLTF(FireshipLogo); |
| 91 | + const TextObject = useGLTF(CodeReportText); |
| 92 | + |
| 93 | + // Load gradient map |
| 94 | + const fireshipGradient = useLoader(TextureLoader, fireshipTexture); |
| 95 | + |
| 96 | + return ( |
| 97 | + <div |
| 98 | + style={{ |
| 99 | + backgroundColor: interpolateColors( |
| 100 | + frame, |
| 101 | + [0, durationInFrames], |
| 102 | + ["#18181F", "#000"] |
| 103 | + ), |
| 104 | + }} |
| 105 | + > |
| 106 | + <ThreeCanvas linear width={width} height={height}> |
| 107 | + <PerspectiveCamera position={[cameraX, cameraY, cameraZ]}> |
| 108 | + <group dispose={null}> |
| 109 | + <directionalLight |
| 110 | + intensity={interpolate( |
| 111 | + frame, |
| 112 | + [0, durationInFrames - 10, durationInFrames], |
| 113 | + [0.9, 0.7, 0] |
| 114 | + )} |
| 115 | + position={[ |
| 116 | + 10, |
| 117 | + |
| 118 | + interpolate( |
| 119 | + frame, |
| 120 | + [durationInFrames / 3, durationInFrames], |
| 121 | + [150, -50] |
| 122 | + ), |
| 123 | + |
| 124 | + 250, |
| 125 | + ]} |
| 126 | + args={["wireframe"]} |
| 127 | + /> |
| 128 | + <mesh |
| 129 | + position={[-5, modelPositionY, modelPositionZ]} |
| 130 | + geometry={FireshipLogoObject.nodes.Curve.geometry} |
| 131 | + scale={modelScale} |
| 132 | + material={FireshipLogoObject.materials.SVGMat} |
| 133 | + > |
| 134 | + <meshStandardMaterial map={fireshipGradient} /> |
| 135 | + </mesh> |
| 136 | + <mesh |
| 137 | + position={[textPositionX, textPositionY, textPositionZ]} |
| 138 | + geometry={TextObject.nodes.path240001.geometry} |
| 139 | + scale={textScale} |
| 140 | + material={TextObject.materials["SVGMat.015"]} |
| 141 | + > |
| 142 | + <meshStandardMaterial color={TextGradientColors} map={""} /> |
| 143 | + </mesh> |
| 144 | + </group> |
| 145 | + |
| 146 | + <Sparkles |
| 147 | + position={[ |
| 148 | + 0, |
| 149 | + 0, |
| 150 | + interpolate( |
| 151 | + frame, |
| 152 | + // [durationInFrames / 2, (3 * durationInFrames) / 4], |
| 153 | + [fps, durationInFrames], |
| 154 | + [-70, 160] |
| 155 | + // [80, -140] |
| 156 | + // [0, -150] |
| 157 | + ), |
| 158 | + ]} |
| 159 | + count={2000} |
| 160 | + speed={0} |
| 161 | + // noise={1} |
| 162 | + scale={200} |
| 163 | + size={30} |
| 164 | + /> |
| 165 | + |
| 166 | + <OrbitControls /> |
| 167 | + </PerspectiveCamera> |
| 168 | + </ThreeCanvas> |
| 169 | + |
| 170 | + <Audio src={AnimationAudioURL} /> |
| 171 | + {/* <Audio src={static1File(AnimationAudioURL)} /> */} |
| 172 | + </div> |
| 173 | + ); |
| 174 | +}; |
| 175 | + |
| 176 | +export default Animation; |
0 commit comments