-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScene.jsx
135 lines (117 loc) · 3.33 KB
/
Scene.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React, { useEffect, useRef } from 'react';
import { Canvas, useThree, useFrame } from '@react-three/fiber';
import { OrbitControls, useGLTF } from '@react-three/drei';
import * as THREE from 'three';
import Particles from './Particles';
import gsap from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import Buttons from './Buttons';
gsap.registerPlugin(ScrollTrigger);
// Componente para el modelo 3D
const Model = () => {
const { scene } = useGLTF('./Template.glb');
React.useEffect(() => {
// Escalar el modelo
scene.scale.set(0.3, 0.3, 0.3);
// Centrar el modelo
const box = new THREE.Box3().setFromObject(scene);
const center = box.getCenter(new THREE.Vector3());
scene.position.sub(center);
return () => {
// Limpieza
useGLTF.preload('./Template.glb');
};
}, [scene]);
return <primitive object={scene} />;
};
// Componente para las luces
const Lights = () => {
return (
<>
<directionalLight position={[5, 5, 5]} intensity={1} />
<directionalLight position={[-5, -5, -5]} intensity={1} />
</>
);
};
// Componente que escucha los eventos de navegación y mueve la cámara
const CameraController = () => {
const { camera } = useThree();
const controlsRef = useRef();
// Posiciones de la cámara para diferentes secciones
const cameraPositions = {
inicio: { x: 0, y: 2, z: 20 },
"sobre-mi": { x: 20, y: 2, z: 0 },
proyectos: { x: -20, y: 2, z: 0 },
habilidades: { x: 0, y: 20, z: 0 },
contacto: { x: 0, y: 2, z: -20 },
cv: { x: 0, y: -10, z: 10 }
};
// Escuchar eventos de navegación
useEffect(() => {
const handleCameraNavigation = (event) => {
const { section } = event.detail;
const position = cameraPositions[section];
if (!position) return;
gsap.to(camera.position, {
x: position.x,
y: position.y,
z: position.z,
duration: 2,
ease: "power2.inOut",
onUpdate: () => {
camera.lookAt(0, 0, 0);
if (controlsRef.current) {
controlsRef.current.target.set(0, 0, 0);
controlsRef.current.update();
}
}
});
};
window.addEventListener('camera-navigation', handleCameraNavigation);
return () => {
window.removeEventListener('camera-navigation', handleCameraNavigation);
};
}, [camera]);
// Actualizar los controles en cada frame
useFrame(() => {
if (controlsRef.current) {
controlsRef.current.update();
}
});
return (
<OrbitControls
ref={controlsRef}
enableDamping
dampingFactor={0.05}
enableZoom
enablePan
enableRotate
/>
);
};
const Scene = () => {
return (
<div style={{ position: 'relative', width: '100vw', height: '100vh' }}>
<Canvas
style={{
width: '100%',
height: '100%',
zIndex: 0,
pointerEvents: 'auto',
touchAction: 'none'
}}
camera={{ position: [0, 2, 20], fov: 75, near: 0.1, far: 1000 }}
>
<color attach="background" args={[0xf8fafc]} />
<Lights />
<Model />
<CameraController />
</Canvas>
<Particles />
<div style={{ position: 'absolute', top: 0, left: 0, zIndex: 10 }}>
<Buttons />
</div>
</div>
);
};
export default Scene;