mirror of
https://github.com/ad044/lainTSX.git
synced 2024-10-22 23:19:06 +00:00
basic animation done! gotta clean up and add some more details
This commit is contained in:
parent
7db4906db1
commit
e1813e83e0
3 changed files with 169 additions and 75 deletions
|
@ -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,12 +38,18 @@ const Pause = () => {
|
|||
[generateSqaureGeom]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
setIntro(false);
|
||||
}, 2000);
|
||||
}, []);
|
||||
return (
|
||||
<group position={[-1, -0.8, 0]} scale={[0.9, 0.9, 0]}>
|
||||
{[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 ? (
|
||||
<>
|
||||
<StaticBigLetter
|
||||
color={"white"}
|
||||
letter={"L"}
|
||||
|
@ -49,7 +58,17 @@ const Pause = () => {
|
|||
scale={[0.25, 0.25, 0.25]}
|
||||
active={!(activeComponent === "load")}
|
||||
key={col}
|
||||
rowIdx={rowIdx}
|
||||
colIdx={col}
|
||||
/>
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
rowIdx={rowIdx}
|
||||
colIdx={col}
|
||||
key={col}
|
||||
shouldDisappear={true}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
|
@ -61,6 +80,7 @@ const Pause = () => {
|
|||
);
|
||||
} else if (rowIdx === 4 && col > 4 && col < 7) {
|
||||
return col === 5 ? (
|
||||
<>
|
||||
<StaticBigLetter
|
||||
color={"white"}
|
||||
letter={"A"}
|
||||
|
@ -69,7 +89,17 @@ const Pause = () => {
|
|||
scale={[0.25, 0.25, 0]}
|
||||
active={!(activeComponent === "about")}
|
||||
key={col}
|
||||
rowIdx={rowIdx}
|
||||
colIdx={col}
|
||||
/>
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
rowIdx={rowIdx}
|
||||
colIdx={col}
|
||||
key={col}
|
||||
shouldDisappear={true}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
|
@ -81,6 +111,7 @@ const Pause = () => {
|
|||
);
|
||||
} else if (rowIdx === 3 && col > 2 && col < 7) {
|
||||
return col === 3 ? (
|
||||
<>
|
||||
<StaticBigLetter
|
||||
color={"white"}
|
||||
letter={"C"}
|
||||
|
@ -89,7 +120,17 @@ const Pause = () => {
|
|||
scale={[0.25, 0.25, 0]}
|
||||
active={!(activeComponent === "change")}
|
||||
key={col}
|
||||
rowIdx={rowIdx}
|
||||
colIdx={col}
|
||||
/>
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
rowIdx={rowIdx}
|
||||
colIdx={col}
|
||||
key={col}
|
||||
shouldDisappear={true}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
|
@ -101,6 +142,7 @@ const Pause = () => {
|
|||
);
|
||||
} else if (rowIdx === 1 && col > 0 && col < 5) {
|
||||
return col === 1 ? (
|
||||
<>
|
||||
<StaticBigLetter
|
||||
color={"white"}
|
||||
letter={"S"}
|
||||
|
@ -109,7 +151,17 @@ const Pause = () => {
|
|||
scale={[0.25, 0.25, 0]}
|
||||
active={!(activeComponent === "save")}
|
||||
key={col}
|
||||
rowIdx={rowIdx}
|
||||
colIdx={col}
|
||||
/>
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
rowIdx={rowIdx}
|
||||
colIdx={col}
|
||||
key={col}
|
||||
shouldDisappear={true}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
|
@ -121,6 +173,7 @@ const Pause = () => {
|
|||
);
|
||||
} else if (rowIdx === 0 && col > 4 && col < 7) {
|
||||
return col === 5 ? (
|
||||
<>
|
||||
<StaticBigLetter
|
||||
color={"white"}
|
||||
letter={"E"}
|
||||
|
@ -129,7 +182,17 @@ const Pause = () => {
|
|||
scale={[0.25, 0.25, 0]}
|
||||
active={!(activeComponent === "exit")}
|
||||
key={col}
|
||||
rowIdx={1}
|
||||
colIdx={col}
|
||||
/>
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
rowIdx={rowIdx}
|
||||
colIdx={col}
|
||||
key={col}
|
||||
shouldDisappear={true}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<PauseSquare
|
||||
geometry={squareGeoms[row][col]}
|
||||
|
|
|
@ -3,12 +3,14 @@ import * as THREE from "three";
|
|||
import { useLoader } from "react-three-fiber";
|
||||
import pauseGrayBoxes from "../../static/sprite/pause_gray_boxes.png";
|
||||
import { a, useSpring } from "@react-spring/three";
|
||||
import { CurveUtils } from "three";
|
||||
|
||||
type PauseSquareProps = {
|
||||
colIdx: number;
|
||||
rowIdx: number;
|
||||
geometry: THREE.PlaneBufferGeometry;
|
||||
active: boolean;
|
||||
active?: boolean;
|
||||
shouldDisappear?: boolean;
|
||||
};
|
||||
|
||||
const PauseSquare = (props: PauseSquareProps) => {
|
||||
|
@ -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(() => {
|
||||
setTimeout(() => {
|
||||
setIntroAnimToggle(true);
|
||||
}, (props.rowIdx + props.colIdx) * 100);
|
||||
|
||||
setTimeout(() => {
|
||||
setIntro(false);
|
||||
}, 5000);
|
||||
}, 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 (
|
||||
<a.mesh
|
||||
geometry={props.geometry}
|
||||
position={[props.colIdx / 2.8, props.rowIdx / 2.8, 0]}
|
||||
position-x={initialState.posX}
|
||||
position-y={initialState.posY}
|
||||
scale={[
|
||||
props.colIdx > 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}
|
||||
>
|
||||
<meshBasicMaterial
|
||||
attach="material"
|
||||
|
|
|
@ -4,8 +4,8 @@ import whiteFont from "../../static/sprite/white_and_green_texture.png";
|
|||
import * as THREE from "three";
|
||||
import { useLoader } from "react-three-fiber";
|
||||
import orange_font_json from "../../resources/font_data/big_font.json";
|
||||
import { a, Interpolation, SpringValue, useSpring } from "@react-spring/three";
|
||||
import React, { useMemo } from "react";
|
||||
import { a, useSpring } from "@react-spring/three";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
|
||||
const StaticBigLetter = (props: {
|
||||
color: string;
|
||||
|
@ -14,6 +14,8 @@ const StaticBigLetter = (props: {
|
|||
position: number[];
|
||||
scale: number[];
|
||||
active: boolean;
|
||||
rowIdx?: number;
|
||||
colIdx?: number;
|
||||
}) => {
|
||||
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<boolean>(!!(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 (
|
||||
<a.mesh
|
||||
position={[
|
||||
|
@ -108,13 +135,14 @@ const StaticBigLetter = (props: {
|
|||
]}
|
||||
scale={props.scale as [number, number, number]}
|
||||
geometry={geom}
|
||||
rotation-x={rotX}
|
||||
rotation-y={rotY}
|
||||
rotation-x={intro ? introRotX : rotX}
|
||||
rotation-y={intro ? introRotY : rotY}
|
||||
>
|
||||
<meshBasicMaterial
|
||||
map={colorTexture}
|
||||
attach="material"
|
||||
transparent={true}
|
||||
side={THREE.FrontSide}
|
||||
/>
|
||||
</a.mesh>
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue