import * as THREE from 'three'; import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'; import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'; import * as CANNON from 'cannon-es'; // Setup scene const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); // Lighting const light = new THREE.DirectionalLight(0xffffff, 1); light.position.set(10, 10, 10); scene.add(light); // Physics world const world = new CANNON.World(); world.gravity.set(0, -9.82, 0); // Ground plane const groundBody = new CANNON.Body({ type: CANNON.Body.STATIC, shape: new CANNON.Plane(), quaternion: new CANNON.Quaternion().setFromEuler(-Math.PI / 2, 0, 0) }); world.addBody(groundBody); // Load teacher model const loader = new GLTFLoader(); let teacher; loader.load('./models/areana-simple.glb', function (gltf) { teacher = gltf.scene; teacher.scale.set(1, 1, 1); scene.add(teacher); }, undefined, function (error) { console.error(error); }); // Students array let students = []; function spawnStudent() { const studentGeometry = new THREE.SphereGeometry(0.5, 16, 16); const studentMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 }); const student = new THREE.Mesh(studentGeometry, studentMaterial); student.position.set(Math.random() * 10 - 5, 0.5, Math.random() * 10 - 5); scene.add(student); students.push(student); } // Spawn students for (let i = 0; i < 5; i++) { spawnStudent(); } // Player movement controls const keys = {}; document.addEventListener('keydown', (event) => { keys[event.code] = true; }); document.addEventListener('keyup', (event) => { keys[event.code] = false; }); function moveTeacher() { if (teacher) { if (keys['ArrowUp']) teacher.position.z -= 0.1; if (keys['ArrowDown']) teacher.position.z += 0.1; if (keys['ArrowLeft']) teacher.position.x -= 0.1; if (keys['ArrowRight']) teacher.position.x += 0.1; } } // Collision detection function checkCollisions() { students = students.filter(student => { if (teacher && student.position.distanceTo(teacher.position) < 1) { scene.remove(student); return false; // Remove student } return true; }); } // Animation loop function animate() { requestAnimationFrame(animate); moveTeacher(); checkCollisions(); renderer.render(scene, camera); } animate();