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

282 lines
10 KiB
TypeScript
Raw Normal View History

'use client';
import React, { useState, useEffect, useRef } from 'react';
import * as THREE from 'three';
import { UploadCloud, Cpu, Download, Sparkles, CheckCircle2, ArrowRight } from 'lucide-react';
import { TextAnimate } from '@/components/magicui/text-animate';
interface HowItWorks3DSectionProps {
title?: string;
badge?: string;
subtitle?: string;
}
export function HowItWorks3DSection({
title = 'How It Works',
badge = '3-STEP NEURAL PROCESS',
subtitle = 'From your browser to studio-grade 4K output in less than a second.',
}: HowItWorks3DSectionProps) {
const [activeStep, setActiveStep] = useState<number>(0);
const canvasContainerRef = useRef<HTMLDivElement>(null);
const steps = [
{
num: '01',
icon: UploadCloud,
title: 'Upload Your Photo',
desc: 'Select or drag any JPG, PNG, or WebP photo up to 12MB. No sign-up or credit card required.',
highlight: 'Lossless Drag & Drop',
},
{
num: '02',
icon: Cpu,
title: 'Neural AI Processing',
desc: 'Our high-performance vision models run sub-pore inference in under 800ms directly in session memory.',
highlight: 'Zero Data Retention',
},
{
num: '03',
icon: Download,
title: 'Download 4K Result',
desc: 'Get your full-resolution enhanced image instantly or scan the QR code to open in the native mobile app.',
highlight: 'Instant HD Download',
},
];
// Auto-advance steps every 4 seconds unless user clicked
useEffect(() => {
const timer = setInterval(() => {
setActiveStep((prev) => (prev + 1) % steps.length);
}, 4500);
return () => clearInterval(timer);
}, [steps.length]);
// 3D Canvas Visualizer
useEffect(() => {
const container = canvasContainerRef.current;
if (!container) return;
let width = container.clientWidth || 400;
let height = container.clientHeight || 340;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(40, 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 });
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
container.appendChild(renderer.domElement);
} catch {
return;
}
// Floating Holographic Photo Card
const cardGeo = new THREE.PlaneGeometry(2.4, 1.8, 16, 16);
const cardMat = new THREE.MeshStandardMaterial({
color: 0x2563eb,
metalness: 0.2,
roughness: 0.3,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
});
const cardMesh = new THREE.Mesh(cardGeo, cardMat);
scene.add(cardMesh);
// Glowing Scanning Laser Bar
const scanBarGeo = new THREE.BoxGeometry(0.04, 2.0, 0.08);
const scanBarMat = new THREE.MeshBasicMaterial({ color: 0x38bdf8 });
const scanBar = new THREE.Mesh(scanBarGeo, scanBarMat);
scene.add(scanBar);
// Surrounding Neural Data Particles
const particleCount = 45;
const particleGeo = new THREE.BufferGeometry();
const particlePositions = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount * 3; i += 3) {
particlePositions[i] = (Math.random() - 0.5) * 5;
particlePositions[i + 1] = (Math.random() - 0.5) * 4;
particlePositions[i + 2] = (Math.random() - 0.5) * 2;
}
particleGeo.setAttribute('position', new THREE.BufferAttribute(particlePositions, 3));
const particleMat = new THREE.PointsMaterial({
color: 0x93c5fd,
size: 0.05,
transparent: true,
opacity: 0.8,
});
const particlePoints = new THREE.Points(particleGeo, particleMat);
scene.add(particlePoints);
// Lighting
const ambLight = new THREE.AmbientLight(0xffffff, 1.2);
scene.add(ambLight);
const dirLight = new THREE.DirectionalLight(0x60a5fa, 2.0);
dirLight.position.set(3, 4, 3);
scene.add(dirLight);
let animId = 0;
let clock = new THREE.Clock();
const animate = () => {
animId = requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
// Card gentle floating tilt
cardMesh.rotation.y = Math.sin(elapsed * 0.8) * 0.18;
cardMesh.rotation.x = Math.cos(elapsed * 0.6) * 0.08;
cardMesh.position.y = Math.sin(elapsed * 1.2) * 0.08;
// Scanning bar sweeps back and forth
scanBar.position.x = Math.sin(elapsed * 1.8) * 1.25;
scanBar.position.y = cardMesh.position.y;
scanBar.rotation.y = cardMesh.rotation.y;
// Particles orbit
particlePoints.rotation.y = elapsed * 0.1;
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);
return () => {
cancelAnimationFrame(animId);
window.removeEventListener('resize', handleResize);
if (renderer && renderer.domElement && container.contains(renderer.domElement)) {
container.removeChild(renderer.domElement);
}
renderer?.dispose();
};
}, []);
return (
<section id="how-it-works" className="py-20 sm:py-28 px-4 sm:px-6 lg:px-8 bg-[#FAF8F5] relative overflow-hidden border-t border-slate-900/[0.06]">
<div className="max-w-7xl mx-auto space-y-14">
{/* Section Header */}
<div className="text-center max-w-3xl mx-auto space-y-4">
<div className="inline-flex items-center gap-2 px-3.5 py-1 rounded-full text-xs font-mono font-semibold tracking-wider uppercase text-blue-700 bg-blue-50 border border-blue-200">
<Sparkles className="w-3.5 h-3.5 text-blue-600" />
<span>{badge}</span>
</div>
<h2 className="text-3xl sm:text-5xl font-display font-extrabold text-slate-900 tracking-tight">
<TextAnimate animation="slideLeft" by="character">
{title}
</TextAnimate>
</h2>
<p className="text-sm sm:text-base text-slate-600 font-sans">
<TextAnimate animation="fadeIn" by="word" delay={0.2}>
{subtitle}
</TextAnimate>
</p>
</div>
{/* 3D Visualizer & Steps Grid */}
<div className="grid grid-cols-1 lg:grid-cols-12 gap-10 items-center">
{/* Column 1: Interactive 3D Scanning Canvas */}
<div className="lg:col-span-6 relative flex flex-col items-center">
<div className="relative w-full h-[360px] sm:h-[420px] rounded-3xl bg-slate-950 border border-slate-800 shadow-2xl overflow-hidden flex items-center justify-center p-4">
{/* Background Glow */}
<div className="absolute inset-0 bg-[radial-gradient(circle_at_50%_50%,rgba(37,99,235,0.25),transparent_70%)] pointer-events-none" />
{/* Three.js Canvas Container */}
<div ref={canvasContainerRef} className="w-full h-full relative z-10" />
{/* Status Pill on 3D Container */}
<div className="absolute top-4 left-4 z-20 flex items-center gap-2 px-3 py-1.5 rounded-full bg-slate-900/90 border border-slate-700/80 backdrop-blur-md text-[11px] font-mono text-cyan-400">
<span className="w-2 h-2 rounded-full bg-cyan-400 animate-ping" />
<span>ACTIVE STAGE: {steps[activeStep].title.toUpperCase()}</span>
</div>
{/* Bottom Quick Controls */}
<div className="absolute bottom-4 inset-x-4 z-20 flex justify-center gap-2">
{steps.map((st, sIdx) => (
<button
key={sIdx}
onClick={() => setActiveStep(sIdx)}
className={`px-3 py-1 rounded-full text-xs font-mono transition-all ${
activeStep === sIdx
? 'bg-blue-600 text-white font-bold shadow-md'
: 'bg-slate-900/80 text-slate-400 hover:text-white border border-slate-800'
}`}
>
Step {st.num}
</button>
))}
</div>
</div>
</div>
{/* Column 2: User-Friendly Step Cards */}
<div className="lg:col-span-6 space-y-4">
{steps.map((step, idx) => {
const Icon = step.icon;
const isActive = activeStep === idx;
return (
<div
key={idx}
onClick={() => setActiveStep(idx)}
className={`cursor-pointer rounded-2xl p-6 transition-all duration-300 border ${
isActive
? 'bg-white border-blue-500 shadow-cream-md scale-[1.02]'
: 'bg-white/60 border-slate-200/80 hover:bg-white hover:border-slate-300'
}`}
>
<div className="flex items-start gap-4">
<div
className={`w-12 h-12 rounded-xl flex items-center justify-center flex-shrink-0 transition-colors ${
isActive
? 'bg-blue-600 text-white shadow-md shadow-blue-500/25'
: 'bg-slate-100 text-slate-600'
}`}
>
<Icon className="w-5 h-5" />
</div>
<div className="flex-1">
<div className="flex items-center justify-between">
<span className="text-xs font-mono font-bold text-blue-600">
PHASE {step.num}
</span>
<span className="text-[10px] font-mono font-semibold px-2 py-0.5 rounded bg-blue-50 text-blue-700 border border-blue-200">
{step.highlight}
</span>
</div>
<h3 className="text-base sm:text-lg font-display font-bold text-slate-900 mt-1">
{step.title}
</h3>
<p className="text-xs sm:text-sm text-slate-600 mt-1.5 leading-relaxed font-sans">
{step.desc}
</p>
</div>
</div>
</div>
);
})}
</div>
</div>
</div>
</section>
);
}