// TODO: meshes for puzzle pieces import * as THREE from 'three'; import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; // Initialise scene const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); // Set up lights const ambientLight = new THREE.AmbientLight(0x404040); scene.add(ambientLight); const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5); directionalLight.position.set(1, 3, 2); scene.add(directionalLight); scene.add(directionalLight.target); // Position the camera camera.position.z = 5; const controls = new OrbitControls(camera, renderer.domElement); controls.enableDamping = true; controls.update(); // Make materials const redMaterial = new THREE.MeshLambertMaterial({ color: 0xff0000 }); const greenMaterial = new THREE.MeshLambertMaterial({ color: 0x00ff00 }); const blueMaterial = new THREE.MeshLambertMaterial({ color: 0x0000ff }); const materials = [redMaterial, greenMaterial, blueMaterial]; function makeCube(xCoord, material) { const geometry = new THREE.BoxGeometry(); const cube = new THREE.Mesh(geometry, material); cube.position.set(xCoord, 0, 0); scene.add(cube); return cube; } let cubes = []; for (let i = 0; i < 3; i++) { const cube = makeCube((i - 1)*2, materials[i]); cubes.push(cube); } // Animation loop function animate() { requestAnimationFrame(animate); for (let i = 0; i < cubes.length; i++) { const cube = cubes[i]; cube.rotation.x += 0.01; cube.rotation.y += 0.01; } controls.update(); renderer.render(scene, camera); } animate();