Neotech911's picture
Why isn't anything displaying in the preview
f1c0b68 verified
Raw History Blame Contribute Delete
6.27 kB
import React from 'react';
import ReactDOM from 'react-dom';
import { Canvas, useFrame, useThree } from '@react-three/fiber';
import { Stars, Text, Float, Sparkles, PerspectiveCamera, Environment } from '@react-three/drei';
import { useRef, useState } from 'react';
import { motion } from 'framer-motion';
// Main 3D Scene Component
function BirthdayScene() {
const meshRef = useRef();
const groupRef = useRef();
const [activeMessage, setActiveMessage] = useState(null);
const { mouse } = useThree();
const messages = [
"Your smile lights up every room",
"19 looks gorgeous on you",
"The world is better with you in it",
"Your kindness is unmatched",
"Forever young at heart",
"A soul as bright as the stars",
"Your laughter is contagious",
"Beautiful inside and out",
"A friend like no other",
"Your creativity inspires me",
"Simply one of a kind",
"The perfect blend of sweet and strong",
"Your energy is magnetic",
"A heart of pure gold",
"Wisdom beyond your years",
"Your spirit shines so bright",
"The definition of amazing",
"A light in everyone's life",
"My favorite person to celebrate"
];
useFrame((state, delta) => {
// Smooth floating animation
meshRef.current.position.y = Math.sin(state.clock.getElapsedTime() * 0.5) * 0.2;
meshRef.current.rotation.y += delta * 0.1;
// Parallax effect
groupRef.current.rotation.x = mouse.y * 0.1;
groupRef.current.rotation.y = mouse.x * 0.1;
});
return (
<group ref={groupRef}>
{/* Environment */}
<Environment preset="night" />
<Stars radius={100} depth={50} count={5000} factor={4} saturation={0} fade speed={1} />
<Sparkles count={200} scale={10} size={2} speed={0.1} color="#e2d4ff" />
{/* Main 19 Number */}
<Float speed={2} rotationIntensity={0.5} floatIntensity={1}>
<mesh ref={meshRef} position={[0, 0, 0]}>
<textGeometry args={["19", { size: 2, height: 0.5 }]} />
<meshPhysicalMaterial
transmission={0.9}
thickness={0.5}
roughness={0.1}
clearcoat={1}
clearcoatRoughness={0.1}
color="#e2d4ff"
ior={1.5}
envMapIntensity={1}
/>
</mesh>
</Float>
{/* Love Orbs */}
{Array.from({ length: 19 }).map((_, i) => {
const angle = (i / 19) * Math.PI * 2;
const radius = 4;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
return (
<LoveOrb
key={i}
position={[x, Math.sin(angle * 2) * 0.5, z]}
message={messages[i]}
onClick={() => setActiveMessage(messages[i])}
/>
);
})}
{/* Active Message Display */}
{activeMessage && (
<Text
position={[0, -3, 0]}
color="#e0bfb8"
fontSize={0.5}
maxWidth={8}
lineHeight={1}
letterSpacing={0.02}
textAlign="center"
anchorX="center"
anchorY="middle"
>
{activeMessage}
</Text>
)}
</group>
);
}
// Love Orb Component
function LoveOrb({ position, onClick, message }) {
const meshRef = useRef();
useFrame((state) => {
meshRef.current.position.y = position[1] + Math.sin(state.clock.getElapsedTime() * 0.5 + position[0]) * 0.2;
});
return (
<mesh
ref={meshRef}
position={position}
onClick={onClick}
onPointerOver={() => document.body.style.cursor = 'pointer'}
onPointerOut={() => document.body.style.cursor = 'auto'}
>
<sphereGeometry args={[0.3, 16, 16]} />
<meshStandardMaterial
color="#e0bfb8"
emissive="#e0bfb8"
emissiveIntensity={0.5}
roughness={0.2}
metalness={0.8}
/>
</mesh>
);
}
// Main App Component
function App() {
const [entered, setEntered] = useState(false);
const handleEnter = () => {
setEntered(true);
};
return (
<>
{!entered ? (
<div className="absolute inset-0 flex items-center justify-center z-20">
<motion.div
initial={{ opacity: 1 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="text-center"
>
<motion.button
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
onClick={handleEnter}
className="px-12 py-4 bg-rose-gold-500 text-obsidian-900 rounded-full text-2xl font-medium shadow-lg"
>
ENTER HER WORLD
</motion.button>
</motion.div>
</div>
) : null}
<Canvas dpr={[1, 2]} className="h-screen w-full">
<PerspectiveCamera makeDefault position={[0, 0, 10]} fov={45} />
<ambientLight intensity={0.2} />
<pointLight position={[10, 10, 10]} intensity={1} color="#e2d4ff" />
<BirthdayScene />
</Canvas>
</>
);
}
// Wait for DOM to load before rendering
document.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(<App />, document.getElementById('root'));
});