From e1813e83e0656ce6bc230fb292204265372563c2 Mon Sep 17 00:00:00 2001 From: ad044 Date: Thu, 3 Dec 2020 19:52:07 +0400 Subject: [PATCH] basic animation done! gotta clean up and add some more details --- src/components/MainScene/Pause.tsx | 161 ++++++++++++------ src/components/MainScene/PauseSquare.tsx | 47 ++--- .../TextRenderer/StaticBigLetter.tsx | 36 +++- 3 files changed, 169 insertions(+), 75 deletions(-) diff --git a/src/components/MainScene/Pause.tsx b/src/components/MainScene/Pause.tsx index 8bbe9a9..3112752 100644 --- a/src/components/MainScene/Pause.tsx +++ b/src/components/MainScene/Pause.tsx @@ -1,15 +1,18 @@ -import React, { useCallback, useMemo } from "react"; +import React, { useCallback, useEffect, useMemo, useState } from "react"; import * as THREE from "three"; import PauseSquare from "./PauseSquare"; import StaticBigLetter from "../TextRenderer/StaticBigLetter"; import { usePauseStore } from "../../store"; const Pause = () => { + const [intro, setIntro] = useState(true); + const componentMatrixIdx = usePauseStore((state) => state.componentMatrixIdx); const activeComponent = usePauseStore( - useCallback((state) => state.componentMatrix[componentMatrixIdx], [ - componentMatrixIdx, - ]) + useCallback( + (state) => (intro ? "" : state.componentMatrix[componentMatrixIdx]), + [componentMatrixIdx, intro] + ) ); const generateSqaureGeom = useCallback((row: number, square: number) => { @@ -35,21 +38,37 @@ const Pause = () => { [generateSqaureGeom] ); + useEffect(() => { + setTimeout(() => { + setIntro(false); + }, 2000); + }, []); return ( {[0, 1, 2, 3, 2, 1, 0].map((row: number, rowIdx: number) => [0, 1, 2, 3, 4, 5, 6].map((col: number) => { if (rowIdx === 5 && col > 0 && col < 5) { return col === 1 ? ( - + <> + + + ) : ( { ); } else if (rowIdx === 4 && col > 4 && col < 7) { return col === 5 ? ( - + <> + + + ) : ( { ); } else if (rowIdx === 3 && col > 2 && col < 7) { return col === 3 ? ( - + <> + + + ) : ( { ); } else if (rowIdx === 1 && col > 0 && col < 5) { return col === 1 ? ( - + <> + + + ) : ( { ); } else if (rowIdx === 0 && col > 4 && col < 7) { return col === 5 ? ( - + <> + + + ) : ( { @@ -30,37 +32,37 @@ const PauseSquare = (props: PauseSquareProps) => { const rotX = toggle.to([0, 1], [-Math.PI, 0]); const rotY = toggle.to([0, 1], [Math.PI / 2, 0]); - const introRotX = introToggle.to([0, 1], [0, 2 * Math.PI]); - const introRotY = introToggle.to([0, 1], [0, 2 * Math.PI]); + const introRotX = introToggle.to([0, 1], [Math.PI, 0]); + const introRotY = introToggle.to( + [0, 1], + [Math.PI, props.shouldDisappear ? Math.PI / 2 : 0] + ); useEffect(() => { setTimeout(() => { - setIntroAnimToggle(true); - }, (props.rowIdx + props.colIdx) * 100); + setTimeout(() => { + setIntroAnimToggle(true); + }, (props.rowIdx + props.colIdx) * 100); - setTimeout(() => { - setIntro(false); - }, 5000); + setTimeout(() => { + setIntro(false); + }, 1500); + }, 500); }, [props.colIdx, props.rowIdx]); - const side = useMemo(() => { - if (intro) return THREE.DoubleSide; - else { - if ( - (props.colIdx > 3 && props.rowIdx <= 3) || - (props.colIdx <= 3 && props.rowIdx > 3) - ) { - return THREE.FrontSide; - } else { - return THREE.BackSide; - } - } - }, [intro, props.colIdx, props.rowIdx]); + const initialState = useSpring({ + posX: props.colIdx / 2.8, + posY: props.rowIdx / 2.8, + rotZ: 0, + from: { posX: 1.05, posY: 1.07, rotZ: -1 }, + config: { duration: 500 }, + }); return ( 3 ? -0.25 : 0.25, props.rowIdx <= 3 ? -0.25 : 0.25, @@ -68,6 +70,7 @@ const PauseSquare = (props: PauseSquareProps) => { ]} rotation-x={intro ? introRotX : rotX} rotation-y={intro ? introRotY : rotY} + rotation-z={initialState.rotZ} > { const { toggle } = useSpring({ toggle: Number(props.active), @@ -23,6 +25,17 @@ const StaticBigLetter = (props: { const rotX = toggle.to([0, 1], [-Math.PI, 0]); const rotY = toggle.to([0, 1], [Math.PI / 2, 0]); + const [intro, setIntro] = useState(!!(props.rowIdx && props.colIdx)); + const [introAnimToggle, setIntroAnimToggle] = useState(false); + + const { introToggle } = useSpring({ + introToggle: Number(introAnimToggle), + config: { duration: 200 }, + }); + + const introRotX = introToggle.to([0, 1], [Math.PI, 0]); + const introRotY = introToggle.to([0, 1], [Math.PI * 2, 0]); + const colorToTexture = (color: string) => { const colorTexture = { orange: orangeFont, @@ -99,6 +112,20 @@ const StaticBigLetter = (props: { return geometry; }, [letterData, lineYOffsets, props.letter]); + useEffect(() => { + setTimeout(() => { + if (props.rowIdx && props.colIdx) { + setTimeout(() => { + setIntroAnimToggle(true); + }, (props.rowIdx + props.colIdx) * 100); + + setTimeout(() => { + setIntro(false); + }, 1500); + } + }, 500); + }, [props.colIdx, props.rowIdx]); + return ( );