diff --git a/src/components/Boot/BootAuthorizeUser.tsx b/src/components/Boot/BootAuthorizeUser.tsx index 160da5a..a48d6e4 100644 --- a/src/components/Boot/BootAuthorizeUser.tsx +++ b/src/components/Boot/BootAuthorizeUser.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useRef, useState } from "react"; +import React, { useRef } from "react"; import authorizeHeaderUnderline from "../../static/sprite/authorize_header_underline.png"; import authorizeGlass from "../../static/sprite/authorize_glass.png"; import authorizeGlassUnderline from "../../static/sprite/authorize_glass_underline.png"; @@ -37,6 +37,12 @@ const BootAuthorizeUser = (props: BootAuthorizeUserProps) => { const backgroundLetterRef = useRef(); + useFrame(() => { + if (backgroundLetterRef.current) { + // backgroundLetterRef.current.position.x += 0.01 + } + }); + return ( <> {props.visible ? ( @@ -73,6 +79,7 @@ const BootAuthorizeUser = (props: BootAuthorizeUserProps) => { map={authorizeGlassTex} attach="material" transparent={true} + depthTest={false} /> { map={authorizeOrangeSquareTex} attach="material" transparent={true} + depthTest={false} /> @@ -96,23 +104,25 @@ const BootAuthorizeUser = (props: BootAuthorizeUserProps) => { map={authorizeGlassUnderlineTex} attach="material" transparent={true} + depthTest={false} /> - - - - + + + + + + ) : ( <> diff --git a/src/components/Boot/BootLoadData.tsx b/src/components/Boot/BootLoadData.tsx index f2e673a..c770d03 100644 --- a/src/components/Boot/BootLoadData.tsx +++ b/src/components/Boot/BootLoadData.tsx @@ -7,10 +7,10 @@ import yes from "../../static/sprite/Yes.png"; import no from "../../static/sprite/No.png"; import * as THREE from "three"; import { useLoader } from "react-three-fiber"; -import { useBootStore } from "../../store"; type BootLoadDataProps = { visible: boolean; + activeBootElement: string; }; const BootLoadData = (props: BootLoadDataProps) => { @@ -30,8 +30,6 @@ const BootLoadData = (props: BootLoadDataProps) => { const yesTex = useLoader(THREE.TextureLoader, yes); const noTex = useLoader(THREE.TextureLoader, no); - const activeBootElement = useBootStore((state) => state.activeBootElement); - return ( <> {props.visible ? ( @@ -65,7 +63,7 @@ const BootLoadData = (props: BootLoadDataProps) => { scale={[0.7, 0.3, 0]} renderOrder={2} position={ - activeBootElement === "load_data_yes" + props.activeBootElement === "load_data_yes" ? [-1.2, -0.2, 0] : [1.2, -0.2, 0] } diff --git a/src/components/Boot/BootMainMenuComponents.tsx b/src/components/Boot/BootMainMenuComponents.tsx index 30137ec..dea2b5c 100644 --- a/src/components/Boot/BootMainMenuComponents.tsx +++ b/src/components/Boot/BootMainMenuComponents.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from "react"; +import React, { useEffect, useMemo } from "react"; import { a, useSpring } from "@react-spring/three"; import authorizeActive from "../../static/sprite/authorize_user_active.png"; import authorizeInactive from "../../static/sprite/authorize_user_inactive.png"; @@ -6,18 +6,16 @@ import loadDataActive from "../../static/sprite/load_data_active.png"; import loadDataInactive from "../../static/sprite/load_data_inactive.png"; import { useLoader } from "react-three-fiber"; import * as THREE from "three"; -import { useBootStore } from "../../store"; import authorizeUserHeader from "../../static/sprite/authorize_user_scene_header.png"; import loadDataHeader from "../../static/sprite/load_data_header.png"; type BootMainMenuProps = { visible: boolean; activeSubScene: string; + activeBootElement: string; }; const BootMainMenuComponents = (props: BootMainMenuProps) => { - const activeBootElement = useBootStore((state) => state.activeBootElement); - const authorizeActiveTex = useLoader(THREE.TextureLoader, authorizeActive); const authorizeInactiveTex = useLoader( THREE.TextureLoader, @@ -41,17 +39,17 @@ const BootMainMenuComponents = (props: BootMainMenuProps) => { } else { return { texture: - activeBootElement === "load_data" + props.activeBootElement === "load_data" ? loadDataActiveTex : loadDataInactiveTex, position: { x: 0, y: -0.5 }, }; } }, [ - activeBootElement, loadDataActiveTex, loadDataHeaderTex, loadDataInactiveTex, + props.activeBootElement, props.activeSubScene, ]); @@ -66,17 +64,17 @@ const BootMainMenuComponents = (props: BootMainMenuProps) => { return { scale: [1.8, 0.3, 0], texture: - activeBootElement === "authorize_user" + props.activeBootElement === "authorize_user" ? authorizeActiveTex : authorizeInactiveTex, position: { x: 0, y: 0.5 }, }; } }, [ - activeBootElement, authorizeActiveTex, authorizeInactiveTex, authorizeUserHeaderTex, + props.activeBootElement, props.activeSubScene, ]); diff --git a/src/components/MediaScene/AudioVisualizer/AudioVisualizer.tsx b/src/components/MediaScene/AudioVisualizer/AudioVisualizer.tsx index 5513511..142eb8c 100644 --- a/src/components/MediaScene/AudioVisualizer/AudioVisualizer.tsx +++ b/src/components/MediaScene/AudioVisualizer/AudioVisualizer.tsx @@ -2,74 +2,70 @@ import React, { createRef, MutableRefObject, useMemo } from "react"; import * as THREE from "three"; import { useFrame } from "react-three-fiber"; import AudioVisualizerColumn from "./AudioVisualizerColumn"; +import { useMediaStore } from "../../../store"; const AudioVisualizer = () => { - const analyser = useMemo(() => { - const listener = new THREE.AudioListener(); + const analyser = useMediaStore((state) => state.audioAnalyser); - const audio = new THREE.Audio(listener); - audio.setMediaElementSource( - document.getElementById("media") as HTMLMediaElement - ); - - return new THREE.AudioAnalyser(audio, 2048); - }, []); - - const columnRefs = useMemo(() => { - return Array.from({ length: 15 }, () => [ - createRef(), - createRef(), - createRef(), - createRef(), - ]); - }, []); + const columnRefs = useMemo( + () => + Array.from({ length: 15 }, () => [ + createRef(), + createRef(), + createRef(), + createRef(), + ]), + [] + ); useFrame(() => { - const frequencyData = analyser.getFrequencyData(); + if (analyser) { + const frequencyData = analyser.getFrequencyData(); - columnRefs.forEach((refArray, idx) => { - const ref1 = refArray[0]; - const ref2 = refArray[1]; - const ref3 = refArray[2]; - const ref4 = refArray[3]; + columnRefs.forEach((refArray, idx) => { + const ref1 = refArray[0]; + const ref2 = refArray[1]; + const ref3 = refArray[2]; + const ref4 = refArray[3]; - // we up it by 1.2 just so it becomes a bit more noticable, otherwise - // the visualizer is a bit too "calm" - const currentFrequency = frequencyData[32 * idx] * 1.2; + // we up it by 1.2 just so it becomes a bit more noticable, otherwise + // the visualizer is a bit too "calm" + const currentFrequency = frequencyData[32 * idx] * 1.2; - switch (true) { - case currentFrequency >= 255: - ref1.current!.visible = true; - ref2.current!.visible = true; - ref3.current!.visible = true; - ref4.current!.visible = true; - break; - case currentFrequency >= 192: - ref1.current!.visible = true; - ref2.current!.visible = true; - ref3.current!.visible = true; - ref4.current!.visible = false; - break; - case currentFrequency >= 128: - ref1.current!.visible = true; - ref2.current!.visible = true; - ref3.current!.visible = false; - ref4.current!.visible = false; - break; - case currentFrequency >= 64: - ref1.current!.visible = true; - ref2.current!.visible = false; - ref3.current!.visible = false; - ref4.current!.visible = false; - break; - default: - ref1.current!.visible = false; - ref2.current!.visible = false; - ref3.current!.visible = false; - ref4.current!.visible = false; - break; - } - }); + switch (true) { + case currentFrequency >= 255: + ref1.current!.visible = true; + ref2.current!.visible = true; + ref3.current!.visible = true; + ref4.current!.visible = true; + break; + case currentFrequency >= 192: + ref1.current!.visible = true; + ref2.current!.visible = true; + ref3.current!.visible = true; + ref4.current!.visible = false; + break; + case currentFrequency >= 128: + ref1.current!.visible = true; + ref2.current!.visible = true; + ref3.current!.visible = false; + ref4.current!.visible = false; + break; + case currentFrequency >= 64: + ref1.current!.visible = true; + ref2.current!.visible = false; + ref3.current!.visible = false; + ref4.current!.visible = false; + break; + default: + ref1.current!.visible = false; + ref2.current!.visible = false; + ref3.current!.visible = false; + ref4.current!.visible = false; + break; + } + }); + } }); return ( diff --git a/src/components/MediaScene/AudioVisualizer/AudioVisualizerColumn.tsx b/src/components/MediaScene/AudioVisualizer/AudioVisualizerColumn.tsx index 5b0544e..a01cb31 100644 --- a/src/components/MediaScene/AudioVisualizer/AudioVisualizerColumn.tsx +++ b/src/components/MediaScene/AudioVisualizer/AudioVisualizerColumn.tsx @@ -32,6 +32,7 @@ const AudioVisualizerColumn = (props: AudioVisualizerColumnProps) => { scale={[0.4, 0.4, 0.4]} position={[-5.2, 3.8, 0]} renderOrder={10} + visible={false} ref={ref1} > { scale={[0.4, 0.4, 0.4]} position={[-4.65, 3.8, 0]} ref={ref2} + visible={false} renderOrder={5} > { scale={[0.4, 0.4, 0.4]} position={[-4.1, 3.8, 0]} ref={ref3} + visible={false} renderOrder={5} > { scale={[0.4, 0.4, 0.4]} position={[-3.55, 3.8, 0]} renderOrder={10} + visible={false} ref={ref4} > {