Files
webb/src/components/sections/HeroSection.tsx
T

610 lines
27 KiB
TypeScript
Raw Normal View History

'use client';
import React, { useState, useEffect, useRef } from 'react';
import Link from 'next/link';
import * as THREE from 'three';
import {
Sparkles,
ArrowRight,
Smartphone,
ArrowDown,
ShieldCheck,
LockKeyhole,
Check,
Zap,
SlidersHorizontal,
UploadCloud,
QrCode
} from 'lucide-react';
import { ToolItem, VariantSpec, resolveLocalised } from '@/types';
import { TextAnimate } from '@/components/magicui/text-animate';
import { Particles } from '@/components/magicui/particles';
import { TryItWidget } from './TryItWidget';
import { GrainTransformShowcase } from '@/components/ui/GrainTransformShowcase';
interface HeroSectionProps {
title?: Record<string, string> | string;
badge?: Record<string, string> | string;
subtitle?: Record<string, string> | string;
primaryCta?: { label?: Record<string, string> | string; href?: string };
secondaryCta?: { label?: Record<string, string> | string; href?: string };
variant?: string;
tool?: ToolItem;
homeApp?: any;
variants?: VariantSpec[];
locale?: string;
}
export function HeroSection({
title,
badge,
subtitle,
primaryCta,
secondaryCta,
variant = 'frontpage',
tool,
homeApp,
variants = [],
locale = 'en',
}: HeroSectionProps) {
const [mobileTab, setMobileTab] = useState<'upload' | 'compare'>('upload');
const resolvedBadge = resolveLocalised(badge, locale) || 'Next-Gen Creative Vision AI';
const primaryCtaLabel = resolveLocalised(primaryCta?.label, locale, 'Explore the Magic');
const primaryCtaHref = primaryCta?.href || '#our-tools';
const secondaryCtaLabel = resolveLocalised(secondaryCta?.label, locale, 'Mobile App Studio');
const secondaryCtaHref = secondaryCta?.href || '#recommended-apps';
// 1. Dedicated Tool Detail Page Hero (when viewing /tools/[slug] with variant='toolHero')
if (variant === 'toolHero' && tool) {
const appName = homeApp ? resolveLocalised(homeApp.name, locale) : 'Mobile App';
const toolMedia = (tool as any).media;
const primaryExample = tool.content?.examples?.[0] || {
before: toolMedia?.before || `/management/pages/tools/${tool.slug}/media/before.jpg`,
after: toolMedia?.after || `/management/pages/tools/${tool.slug}/media/after.jpg`,
caption: 'Sub-pixel neural transformation details',
};
return (
<section className="relative overflow-hidden bg-[#FAF8F5] border-b border-slate-900/[0.08] pt-24 sm:pt-28 pb-14 sm:pb-20 px-4 sm:px-6 lg:px-10">
<div className="max-w-[1640px] mx-auto">
{/* Breadcrumb Navigation */}
<nav className="flex items-center gap-2 text-xs font-mono text-slate-500 mb-8">
<Link href="/" className="hover:text-blue-700 transition-colors">Home</Link>
<span>/</span>
<Link href="/tools" className="hover:text-blue-700 transition-colors">Tools</Link>
<span>/</span>
<span className="text-slate-900 font-semibold">{resolveLocalised(tool.name, locale)}</span>
</nav>
{/* Heading & Subtitle */}
<div className="text-center max-w-4xl mx-auto mb-10 sm:mb-12">
<div className="inline-flex items-center gap-2 px-3 py-1 rounded-full text-xs font-mono font-semibold tracking-wider uppercase text-blue-700 bg-blue-50 border border-blue-200 shadow-2xs">
<Sparkles className="w-3.5 h-3.5 text-blue-600" />
<span>Studio Neural Tool</span>
</div>
<h1 className="mt-4 text-3xl sm:text-5xl lg:text-6xl font-display font-black tracking-tight text-slate-900 leading-[1.08]">
<TextAnimate animation="slideLeft" by="word">{resolveLocalised(tool.name, locale)}</TextAnimate>
</h1>
<p className="mt-4 text-base sm:text-lg leading-relaxed text-slate-600 max-w-2xl mx-auto font-sans">
<TextAnimate animation="fadeIn" by="word" delay={0.15}>{resolveLocalised(tool.summary, locale)}</TextAnimate>
</p>
{/* Mobile Tab Switcher */}
<div className="mt-7 flex lg:hidden items-center justify-center">
<div className="inline-flex p-1.5 rounded-2xl bg-slate-200/80 border border-slate-300 shadow-inner">
<button
type="button"
onClick={() => setMobileTab('upload')}
className={`flex items-center gap-2 px-5 py-2.5 rounded-xl text-xs font-bold transition-all ${
mobileTab === 'upload'
? 'bg-white text-blue-600 shadow-sm'
: 'text-slate-600 hover:text-slate-900'
}`}
>
<UploadCloud className="w-3.5 h-3.5" />
<span>Upload Photo</span>
</button>
<button
type="button"
onClick={() => setMobileTab('compare')}
className={`flex items-center gap-2 px-5 py-2.5 rounded-xl text-xs font-bold transition-all ${
mobileTab === 'compare'
? 'bg-blue-600 text-white shadow-sm'
: 'text-slate-600 hover:text-slate-900'
}`}
>
<SlidersHorizontal className="w-3.5 h-3.5" />
<span>Transform Result</span>
</button>
</div>
</div>
</div>
{/* Intelligent Side-by-Side Tool Studio */}
<div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-stretch max-w-7xl mx-auto" id="tool-studio">
{/* Column 1: Spacious, Prominent Upload Studio (lg:col-span-7) */}
<div className={`lg:col-span-7 flex flex-col ${mobileTab === 'upload' ? 'block' : 'hidden lg:flex'}`}>
<TryItWidget
tool={tool}
homeApp={homeApp}
variants={variants}
locale={locale}
className="h-full flex flex-col justify-between"
onSwitchToCompare={() => setMobileTab('compare')}
/>
</div>
{/* Column 2: Sleeker, Focused Neural Transformation Preview (lg:col-span-5) */}
<div className={`lg:col-span-5 flex flex-col ${mobileTab === 'compare' ? 'block' : 'hidden lg:flex'}`}>
<div className="h-full rounded-3xl overflow-hidden border border-slate-900/[0.1] shadow-cinematic-3d bg-slate-950 flex flex-col justify-between min-h-[380px] sm:min-h-[460px]">
<GrainTransformShowcase
beforeUrl={primaryExample.before}
afterUrl={primaryExample.after}
beforeLabel="BEFORE"
afterLabel="AFTER"
/>
</div>
{/* Mobile Jump to Upload (Only on small screens) */}
<div className="mt-3 lg:hidden">
<button
type="button"
onClick={() => setMobileTab('upload')}
className="w-full py-3 px-4 rounded-xl text-xs font-bold text-white bg-blue-600 hover:bg-blue-700 flex items-center justify-center gap-2 shadow-sm"
>
<UploadCloud className="w-4 h-4" />
<span>Upload Your Photo to Try</span>
</button>
</div>
</div>
</div>
{/* Clean Trust Indicators & Clickable App Links */}
<div className="mt-10 flex flex-wrap items-center justify-center gap-3 sm:gap-4 text-xs font-medium text-slate-600">
<span className="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-full bg-slate-100 text-slate-700">
<ShieldCheck className="h-3.5 w-3.5 text-emerald-600" />
<span>Zero Storage</span>
</span>
<span className="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-full bg-slate-100 text-slate-700">
<LockKeyhole className="h-3.5 w-3.5 text-blue-600" />
<span>Private Processing</span>
</span>
<span className="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-full bg-slate-100 text-slate-700">
<Check className="h-3.5 w-3.5 text-indigo-600" />
<span>Lossless Quality</span>
</span>
{/* Clickable Mobile App Button Link */}
{homeApp && (
<a
href="#app-handoff"
className="inline-flex items-center gap-2 px-4 py-2 rounded-full bg-blue-50 hover:bg-blue-100 border border-blue-200 text-blue-700 font-bold shadow-2xs hover:scale-105 active:scale-95 transition-all group"
>
<Smartphone className="h-4 w-4 text-blue-600 group-hover:scale-110 transition-transform" />
<span>Available in {appName} App</span>
<span className="text-[10px] font-mono bg-blue-600 text-white px-2 py-0.5 rounded-full font-bold">
50 Bonus Credits &amp; 4K ↗
</span>
</a>
)}
{/* Clickable QR Code Trigger Pill */}
{homeApp && (
<a
href="#app-handoff"
className="inline-flex items-center gap-1.5 text-xs font-mono font-semibold text-slate-700 hover:text-slate-950 bg-white hover:bg-slate-50 border border-slate-200 px-3.5 py-2 rounded-full shadow-2xs transition-all hover:scale-105 active:scale-95"
title="Scan QR Code to install mobile app"
>
<QrCode className="w-3.5 h-3.5 text-blue-600" />
<span>Scan QR</span>
</a>
)}
</div>
</div>
</section>
);
}
// 2. Centered Directory & Info Page Hero (for /tools, /apps, /pricing, /trust, /privacy, /terms)
if (variant === 'centered') {
const resolvedTitle = resolveLocalised(title, locale) || 'Creative Studio';
const resolvedSubtitle = resolveLocalised(subtitle, locale);
return (
<section className="relative overflow-hidden pt-28 pb-16 sm:pt-36 sm:pb-20 text-center bg-[#FAF8F5] border-b border-slate-900/[0.07]">
<div className="absolute top-0 left-1/2 -translate-x-1/2 w-full max-w-7xl h-96 bg-gradient-to-b from-blue-500/[0.04] to-transparent blur-3xl pointer-events-none -z-10" />
<div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 space-y-6 relative z-10">
{resolvedBadge && (
<div className="inline-flex items-center gap-2 px-4 py-1.5 rounded-full bg-blue-50 border border-blue-200 text-xs font-mono font-semibold text-blue-700 shadow-sm">
<Sparkles className="w-3.5 h-3.5 text-blue-600" />
<span>{resolvedBadge}</span>
</div>
)}
<h1 className="text-4xl sm:text-5xl lg:text-6xl font-display font-black text-slate-900 tracking-tight leading-tight">
{resolvedTitle}
</h1>
{resolvedSubtitle && (
<p className="text-base sm:text-lg text-slate-600 max-w-2xl mx-auto leading-relaxed font-sans">
{resolvedSubtitle}
</p>
)}
<div className="flex flex-wrap items-center justify-center gap-4 pt-3">
<Link
href="/#our-tools"
className="inline-flex items-center gap-2 px-6 py-3 rounded-full font-bold text-xs sm:text-sm text-white bg-slate-950 hover:bg-blue-600 shadow-sm transition-all hover:scale-105 active:scale-95"
>
<span>Explore Studio Suite</span>
<ArrowRight className="w-4 h-4" />
</Link>
<Link
href="/apps"
className="inline-flex items-center gap-2 px-6 py-3 rounded-full font-bold text-xs sm:text-sm text-slate-700 bg-white border border-slate-200 hover:bg-slate-50 transition-colors shadow-sm"
>
<Smartphone className="w-4 h-4 text-blue-600" />
<span>Mobile Apps Suite</span>
</Link>
</div>
</div>
</section>
);
}
// -------------------------------------------------------------
// 3. Pure Front Page Hero View (for homepage /):
// Ultra-refined Typography, Optical Crystal Prism & Ambient Particles
// -------------------------------------------------------------
return (
<section className="relative isolate min-h-[96vh] flex flex-col justify-center items-center text-center overflow-hidden bg-[#FAF8F5] pt-28 pb-20 px-4 sm:px-6 md:px-8 lg:px-12">
{/* 1. MagicUI Ambient Floating Particles */}
<Particles
className="absolute inset-0 -z-20 opacity-40 pointer-events-none"
quantity={60}
color="#3b82f6"
size={0.7}
/>
{/* 2. Interactive 3D WebGL Crystal Prism Canvas Rotating Behind the Text */}
<div className="absolute inset-0 -z-10 flex items-center justify-center pointer-events-none select-none overflow-hidden">
<div className="w-[700px] h-[700px] sm:w-[1000px] sm:h-[1000px] lg:w-[1300px] lg:h-[1300px] opacity-85 transform-gpu transition-opacity duration-1000">
<Hero3DCanvas className="w-full h-full" />
</div>
</div>
{/* 3. Radiant Multidimensional Chromatic Glow Mesh */}
<div
className="absolute inset-0 -z-30 pointer-events-none"
style={{
background: 'radial-gradient(circle at 50% 36%, rgba(59,130,246,0.12) 0%, rgba(99,102,241,0.08) 32%, rgba(6,182,212,0.04) 55%, transparent 75%)',
}}
/>
<div
className="absolute inset-0 -z-30 pointer-events-none opacity-50"
style={{
background: 'radial-gradient(ellipse at 78% 22%, rgba(236,72,153,0.06) 0%, transparent 50%), radial-gradient(ellipse at 22% 68%, rgba(16,185,129,0.05) 0%, transparent 50%)',
}}
/>
<div className="absolute inset-x-0 bottom-0 h-40 bg-gradient-to-t from-[#FAF8F5] via-[#FAF8F5]/80 to-transparent -z-10 pointer-events-none" />
{/* 4. Center Hero Typography & Visual Atmosphere */}
<div className="relative z-10 max-w-6xl mx-auto flex flex-col items-center justify-center w-full">
{/* Ambient Frosted Eyebrow Badge */}
<div className="inline-flex items-center gap-2.5 rounded-full border border-slate-900/[0.08] bg-white/80 backdrop-blur-xl px-4 py-1.5 text-xs font-mono font-medium tracking-wider uppercase text-slate-800 shadow-[0_2px_12px_-4px_rgba(15,23,42,0.06),inset_0_1px_0_rgba(255,255,255,0.8)] transition-all duration-300 hover:border-blue-500/30 hover:bg-white mb-8 sm:mb-9 group cursor-default">
<span className="flex h-2 w-2 relative">
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75" />
<span className="relative inline-flex rounded-full h-2 w-2 bg-gradient-to-r from-blue-600 to-cyan-500" />
</span>
<span className="text-slate-700 tracking-wider font-semibold text-[11px] sm:text-xs">
{resolvedBadge}
</span>
<span className="h-3 w-px bg-slate-200" />
<span className="text-[10px] font-mono font-bold uppercase tracking-wider text-blue-600 bg-blue-50 px-2 py-0.5 rounded-full border border-blue-200/50">
v4.2 PRO
</span>
</div>
{/* Grand Headline: Masterpiece Proportions, Zero Awkward Wraps */}
<h1 className="text-3xl sm:text-5xl md:text-6xl lg:text-[5.2rem] xl:text-[5.8rem] font-display font-extrabold tracking-[-0.035em] leading-[1.08] max-w-6xl mx-auto text-balance">
<span className="block text-slate-950 pb-1 sm:pb-2">
<TextAnimate animation="slideLeft" by="character">
Imagine. Transform.
</TextAnimate>
</span>
<span className="block mt-1 sm:mt-2 bg-gradient-to-r from-blue-600 via-indigo-600 to-cyan-500 bg-clip-text text-transparent pb-3 sm:whitespace-nowrap">
<TextAnimate animation="slideLeft" by="character" delay={0.15}>
Create the Impossible.
</TextAnimate>
</span>
</h1>
{/* Inspiring, Refined Editorial Subtitle */}
<p className="mt-6 sm:mt-7 text-base sm:text-lg md:text-xl text-slate-600/90 max-w-2xl sm:max-w-3xl mx-auto font-sans leading-relaxed tracking-[-0.01em] text-balance">
<TextAnimate animation="fadeIn" by="word" delay={0.25}>
Turn ordinary moments into extraordinary visual art. Instant, effortless, and private photo magic right in your browser.
</TextAnimate>
</p>
{/* Luxury CTA Action Buttons */}
<div className="mt-9 sm:mt-10 flex flex-wrap items-center justify-center gap-4 sm:gap-5">
<a
href={primaryCtaHref}
className="group relative inline-flex items-center gap-3 rounded-full bg-slate-950 px-8 sm:px-9 py-4 text-xs sm:text-sm font-semibold tracking-tight text-white border border-white/10 shadow-[0_4px_20px_-4px_rgba(15,23,42,0.3),0_0_0_1px_rgba(255,255,255,0.08)_inset] hover:shadow-[0_8px_30px_-6px_rgba(37,99,235,0.4),0_0_0_1px_rgba(59,130,246,0.3)] transition-all duration-300 ease-out hover:scale-[1.03] active:scale-[0.98] cursor-pointer"
>
<span>{primaryCtaLabel}</span>
<span className="w-6 h-6 rounded-full bg-white/10 flex items-center justify-center group-hover:bg-blue-600 transition-colors duration-300">
<ArrowDown className="w-3.5 h-3.5 transition-transform duration-300 ease-out group-hover:translate-y-0.5" />
</span>
</a>
<a
href={secondaryCtaHref}
className="group inline-flex items-center gap-2.5 rounded-full border border-slate-200/90 bg-white/80 hover:bg-white backdrop-blur-xl px-7 sm:px-8 py-4 text-xs sm:text-sm font-semibold tracking-tight text-slate-800 hover:text-slate-950 shadow-[0_4px_16px_-4px_rgba(15,23,42,0.06)] hover:shadow-[0_8px_24px_-6px_rgba(15,23,42,0.1)] hover:border-blue-400/60 transition-all duration-300 ease-out hover:scale-[1.03] active:scale-[0.98] cursor-pointer"
>
<Smartphone className="w-4 h-4 text-blue-600 group-hover:scale-110 transition-transform duration-300" />
<span>{secondaryCtaLabel}</span>
<span className="px-1.5 py-0.5 rounded text-[10px] font-mono font-bold bg-blue-50 text-blue-700 border border-blue-200/60">
iOS / Android
</span>
</a>
</div>
{/* Floating Glass Telemetry & Capability Capsule */}
<div className="mt-14 sm:mt-16 w-full max-w-4xl mx-auto rounded-2xl sm:rounded-full bg-white/85 backdrop-blur-2xl border border-slate-900/[0.08] shadow-[0_16px_40px_-16px_rgba(15,23,42,0.08),0_0_0_1px_rgba(255,255,255,0.8)_inset] p-4 sm:py-5 sm:px-8 grid grid-cols-2 sm:flex sm:items-center sm:justify-around gap-4 sm:gap-6 text-center transform-gpu">
{/* Metric 1 */}
<div className="flex flex-col items-center justify-center p-2 sm:p-0">
<div className="text-2xl sm:text-3xl font-display font-black tracking-tight bg-gradient-to-b from-slate-950 via-slate-900 to-slate-700 bg-clip-text text-transparent">
1.4M+
</div>
<div className="text-[11px] font-mono font-semibold uppercase tracking-wider text-slate-500 mt-1">
Photos Transformed
</div>
</div>
<div className="hidden sm:block w-px h-10 bg-gradient-to-b from-transparent via-slate-200 to-transparent" />
{/* Metric 2 */}
<div className="flex flex-col items-center justify-center p-2 sm:p-0">
<div className="text-2xl sm:text-3xl font-display font-black tracking-tight bg-gradient-to-r from-blue-600 to-cyan-500 bg-clip-text text-transparent">
&lt; 0.8s
</div>
<div className="text-[11px] font-mono font-semibold uppercase tracking-wider text-slate-500 mt-1">
Instant Inference
</div>
</div>
<div className="hidden sm:block w-px h-10 bg-gradient-to-b from-transparent via-slate-200 to-transparent" />
{/* Metric 3 */}
<div className="flex flex-col items-center justify-center p-2 sm:p-0">
<div className="text-2xl sm:text-3xl font-display font-black tracking-tight bg-gradient-to-r from-emerald-600 to-teal-500 bg-clip-text text-transparent">
100%
</div>
<div className="text-[11px] font-mono font-semibold uppercase tracking-wider text-slate-500 mt-1">
Client-Side Privacy
</div>
</div>
<div className="hidden sm:block w-px h-10 bg-gradient-to-b from-transparent via-slate-200 to-transparent" />
{/* Metric 4 */}
<div className="flex flex-col items-center justify-center p-2 sm:p-0">
<div className="text-2xl sm:text-3xl font-display font-black tracking-tight bg-gradient-to-r from-indigo-600 via-purple-600 to-pink-500 bg-clip-text text-transparent">
4K UHD
</div>
<div className="text-[11px] font-mono font-semibold uppercase tracking-wider text-slate-500 mt-1">
Studio Resolution
</div>
</div>
</div>
{/* Subtle Luxury Scroll Cue */}
<a
href="#our-tools"
aria-label="Scroll to our tools"
className="mt-8 sm:mt-10 inline-flex flex-col items-center gap-2 text-[10px] font-mono uppercase tracking-widest text-slate-400 hover:text-blue-600 transition-colors group cursor-pointer"
>
<span className="font-semibold tracking-widest text-slate-400 group-hover:text-blue-600 transition-colors">
Scroll to Explore
</span>
<span className="w-4 h-7 rounded-full border border-slate-300 group-hover:border-blue-400 flex justify-center p-1 transition-colors">
<span className="w-1 h-1.5 rounded-full bg-blue-600 animate-bounce" />
</span>
</a>
</div>
</section>
);
}
// -------------------------------------------------------------
// Interactive 3D WebGL Crystal Prism Background Canvas
// (Optimized with IntersectionObserver: 0% GPU when offscreen)
// -------------------------------------------------------------
function Hero3DCanvas({ className }: { className?: string }) {
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const container = containerRef.current;
if (!container) return;
let width = container.clientWidth || 800;
let height = container.clientHeight || 800;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 100);
camera.position.z = 4.8;
let renderer: THREE.WebGLRenderer | null = null;
try {
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true, powerPreference: 'high-performance' });
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
container.appendChild(renderer.domElement);
} catch (e) {
return;
}
// Master Group for smooth coordinated rotation
const masterGroup = new THREE.Group();
scene.add(masterGroup);
// 1. Central Optical Translucent Crystal (Icosahedron, non-obstructive)
const crystalGeo = new THREE.IcosahedronGeometry(1.25, 0);
const crystalMat = new THREE.MeshPhysicalMaterial({
color: 0x3b82f6,
emissive: 0x1d4ed8,
emissiveIntensity: 0.1,
roughness: 0.15,
metalness: 0.1,
transmission: 0.9,
transparent: true,
opacity: 0.11,
ior: 1.4,
});
const crystal = new THREE.Mesh(crystalGeo, crystalMat);
masterGroup.add(crystal);
// Wireframe Fine Lines for the Crystal
const wireGeo = new THREE.WireframeGeometry(crystalGeo);
const wireMat = new THREE.LineBasicMaterial({
color: 0x60a5fa,
transparent: true,
opacity: 0.22,
});
const wireframe = new THREE.LineSegments(wireGeo, wireMat);
crystal.add(wireframe);
// 2. Dual Gyro Gimbal Orbital Rings (Sleek Apple/Quantum Aesthetic)
// Ring 1 (Cyan orbital ring)
const ring1Geo = new THREE.TorusGeometry(2.15, 0.007, 16, 120);
const ring1Mat = new THREE.MeshBasicMaterial({
color: 0x38bdf8,
transparent: true,
opacity: 0.20,
});
const ring1 = new THREE.Mesh(ring1Geo, ring1Mat);
ring1.rotation.x = Math.PI / 3.2;
masterGroup.add(ring1);
// Ring 2 (Indigo tilted orbital ring)
const ring2Geo = new THREE.TorusGeometry(1.8, 0.007, 16, 100);
const ring2Mat = new THREE.MeshBasicMaterial({
color: 0x818cf8,
transparent: true,
opacity: 0.16,
});
const ring2 = new THREE.Mesh(ring2Geo, ring2Mat);
ring2.rotation.y = Math.PI / 4;
ring2.rotation.z = Math.PI / 6;
masterGroup.add(ring2);
// 3. Subtle Constellation of Ambient Starlight Particles
const particleCount = 40;
const particleGeo = new THREE.BufferGeometry();
const posArray = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount * 3; i++) {
posArray[i] = (Math.random() - 0.5) * 7.5;
}
particleGeo.setAttribute('position', new THREE.BufferAttribute(posArray, 3));
const particleMat = new THREE.PointsMaterial({
size: 0.03,
color: 0x93c5fa,
transparent: true,
opacity: 0.35,
});
const particles = new THREE.Points(particleGeo, particleMat);
masterGroup.add(particles);
// 4. Studio Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 1.2);
scene.add(ambientLight);
const cyanLight = new THREE.PointLight(0x06b6d4, 2.2, 12);
cyanLight.position.set(3.5, 3, 3);
scene.add(cyanLight);
const indigoLight = new THREE.PointLight(0x6366f1, 1.8, 12);
indigoLight.position.set(-3.5, -2, 2.5);
scene.add(indigoLight);
let animId = 0;
let clock = new THREE.Clock();
let isVisible = true;
// IntersectionObserver to pause loop when scrolled out of view (0% CPU/GPU offscreen)
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
isVisible = entry.isIntersecting;
});
},
{ threshold: 0.05 }
);
observer.observe(container);
const animate = () => {
animId = requestAnimationFrame(animate);
if (!isVisible) return;
const elapsed = clock.getElapsedTime();
// Fluid crystal rotation
crystal.rotation.x = elapsed * 0.12;
crystal.rotation.y = elapsed * 0.16;
// Gimbal ring orbital movements
ring1.rotation.z = elapsed * 0.14;
ring1.rotation.x = Math.PI / 3.2 + Math.sin(elapsed * 0.25) * 0.08;
ring2.rotation.y = -elapsed * 0.11;
ring2.rotation.z = Math.PI / 6 + Math.cos(elapsed * 0.2) * 0.1;
// Particle constellation subtle drift
particles.rotation.y = elapsed * 0.03;
particles.rotation.x = elapsed * 0.02;
if (renderer) renderer.render(scene, camera);
};
animate();
const handleResize = () => {
if (!container || !renderer) return;
const w = container.clientWidth;
const h = container.clientHeight;
camera.aspect = w / h;
camera.updateProjectionMatrix();
renderer.setSize(w, h);
};
window.addEventListener('resize', handleResize, { passive: true });
return () => {
cancelAnimationFrame(animId);
observer.disconnect();
window.removeEventListener('resize', handleResize);
if (renderer && renderer.domElement && container.contains(renderer.domElement)) {
container.removeChild(renderer.domElement);
}
crystalGeo.dispose();
crystalMat.dispose();
wireGeo.dispose();
wireMat.dispose();
ring1Geo.dispose();
ring1Mat.dispose();
ring2Geo.dispose();
ring2Mat.dispose();
particleGeo.dispose();
particleMat.dispose();
renderer?.dispose();
};
}, []);
return <div ref={containerRef} className={className} />;
}