From 5d5a04cd5b3ecfe8e0b433e168f53c58e889f6e0 Mon Sep 17 00:00:00 2001
From: kdiffin <110340508+kdiffin@users.noreply.github.com>
Date: Fri, 29 Sep 2023 18:33:54 +0000
Subject: [PATCH] optimized prism
---
src/app/page.tsx | 4 +-
src/components/interactivePrism/Flare.tsx | 16 ++++---
src/components/interactivePrism/Prism.tsx | 8 ++--
src/components/interactivePrism/Rainbow.tsx | 15 ++++---
src/components/interactivePrism/index.tsx | 47 ++++++++++++---------
5 files changed, 53 insertions(+), 37 deletions(-)
diff --git a/src/app/page.tsx b/src/app/page.tsx
index 9f412ba..f4f1ae8 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -6,6 +6,7 @@ import GradientPlatform from "../components/GradientPlatform";
import LandingHero from "../components/LandingHero";
import AiInCLI from "../components/AiInCLI";
import Navbar from "../components/Navbar";
+import Customize from "../components/Customize";
export default function LandingPage() {
// const isMobile = useMediaQuery("(max-width: 768px)");
@@ -16,10 +17,9 @@ export default function LandingPage() {
- {/*{!isMobile ? : null}*/}
+ {/* {!isMobile ? : null} */}
- {/* */}
>
);
diff --git a/src/components/interactivePrism/Flare.tsx b/src/components/interactivePrism/Flare.tsx
index ca020fb..af7f39d 100644
--- a/src/components/interactivePrism/Flare.tsx
+++ b/src/components/interactivePrism/Flare.tsx
@@ -23,6 +23,7 @@ export const Flare = forwardRef(
};
useFrame((state) => {
+ if (visible) {
ref.current.children.forEach((instance) => {
instance.position.x =
(Math[instance.scale.x > 1 ? "sin" : "cos"](
@@ -36,9 +37,12 @@ export const Flare = forwardRef(
) *
instance.scale.x) /
5;
- });
+ })};
});
+
+
+
return (
@@ -46,13 +50,13 @@ export const Flare = forwardRef(
-
-
-
-
+
+
+
+
-
+
diff --git a/src/components/interactivePrism/Prism.tsx b/src/components/interactivePrism/Prism.tsx
index 9870ffb..9374011 100644
--- a/src/components/interactivePrism/Prism.tsx
+++ b/src/components/interactivePrism/Prism.tsx
@@ -11,10 +11,10 @@ export function Prism({ onRayOver, onRayOut, onRayMove, ...props }) {
);
return (
- {/* A low-res, invisible representation of the prism that gets hit by the raycaster */}
+ {/ A low-res, invisible representation of the prism that gets hit by the raycaster /}
);
-}
+}
\ No newline at end of file
diff --git a/src/components/interactivePrism/Rainbow.tsx b/src/components/interactivePrism/Rainbow.tsx
index 7ae3684..e055a35 100644
--- a/src/components/interactivePrism/Rainbow.tsx
+++ b/src/components/interactivePrism/Rainbow.tsx
@@ -119,12 +119,15 @@ export const Rainbow = forwardRef(
) => {
const material = useRef(null);
const { width, height } = useThree((state) => state.viewport);
- // calculate the maximum length the rainbow has to have to reach all screen corners
- const length = Math.hypot(width, height) + 2.5; // add 1.5 to due motion of the rainbow
- useFrame(
- (state, delta) =>
- (material.current.time += delta * material.current.speed),
- );
+ const length = Math.hypot(width, height) + 2.5;
+
+ useFrame((state, delta) => {
+ // Only update if material.current.speed is not zero
+ if (material.current.speed !== 0) {
+ material.current.time += delta * material.current.speed;
+ }
+ });
+
return (
diff --git a/src/components/interactivePrism/index.tsx b/src/components/interactivePrism/index.tsx
index 2d41265..b36534d 100644
--- a/src/components/interactivePrism/index.tsx
+++ b/src/components/interactivePrism/index.tsx
@@ -36,15 +36,15 @@ export function calculateRefractionAngle(
function Effects() {
const [hasEffects, setHasEffects] = useState(true);
- // usePerformanceMonitor({
- // onChange: ({ factor }) => {
- // if (hasEffects && factor > 0.5) {
- // // Decrease the qualityScale of your effects.
- // effect.qualityScale = round(0.5 + 0.5 * factor, 1);
- // }
- // // Handle other conditions for declining or inclining quality
- // },
- // });
+ usePerformanceMonitor({
+ onChange: ({ factor }) => {
+ if (hasEffects && factor > 0.5) {
+ // Decrease the qualityScale of your effects.
+ effect.qualityScale = round(0.5 + 0.5 * factor, 1);
+ }
+ // Handle other conditions for declining or inclining quality
+ },
+ });
return (
{/* Your post-processing effects here */}
@@ -136,15 +136,24 @@ function Scene({ isMobile }: { isMobile: boolean }) {
[0, 0, 0],
);
- lerp(
- rainbow.current.material,
- "emissiveIntensity",
- isPrismHit ? 2.5 : 0,
- 0.1,
- );
- spot.current.intensity = rainbow.current.material.emissiveIntensity;
-
- lerp(ambient.current, "intensity", 0, 0.25);
+ // Only update if isPrismHit has changed
+ if (
+ rainbow.current.material.emissiveIntensity !==
+ (isPrismHit ? 2.5 : 0)
+ ) {
+ lerp(
+ rainbow.current.material,
+ "emissiveIntensity",
+ isPrismHit ? 2.5 : 0,
+ 0.1,
+ );
+ spot.current.intensity = rainbow.current.material.emissiveIntensity;
+ }
+
+ // Only update if ambient intensity is not zero
+ if (ambient.current.intensity !== 0) {
+ lerp(ambient.current, "intensity", 0, 0.25);
+ }
});
return (
@@ -189,4 +198,4 @@ function Scene({ isMobile }: { isMobile: boolean }) {
/>
>
);
-}
+}
\ No newline at end of file