Changed around line 1
+ let scene, camera, renderer, brain;
+
+ function init() {
+ scene = new THREE.Scene();
+ camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
+ renderer = new THREE.WebGLRenderer({ antialias: true });
+ renderer.setSize(window.innerWidth, window.innerHeight);
+ document.getElementById('brain-container').appendChild(renderer.domElement);
+
+ const loader = new THREE.GLTFLoader();
+ loader.load('/brain.gltf', function(gltf) {
+ brain = gltf.scene;
+ scene.add(brain);
+ animate();
+ });
+
+ camera.position.z = 5;
+
+ window.addEventListener('resize', onWindowResize, false);
+ window.addEventListener('scroll', onScroll, false);
+ }
+
+ function onWindowResize() {
+ camera.aspect = window.innerWidth / window.innerHeight;
+ camera.updateProjectionMatrix();
+ renderer.setSize(window.innerWidth, window.innerHeight);
+ }
+
+ function onScroll() {
+ const scrollY = window.scrollY;
+ const rotation = scrollY * 0.01;
+ const zoom = 5 - scrollY * 0.01;
+
+ if (brain) {
+ brain.rotation.y = rotation;
+ }
+ camera.position.z = Math.max(zoom, 1);
+ }
+
+ function animate() {
+ requestAnimationFrame(animate);
+ renderer.render(scene, camera);
+ }
+
+ init();