import * as THREE from "three"; import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"; const scene = new THREE.Scene(); scene.background = new THREE.Color("white"); const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ); camera.position.z = 5; const renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); const geometry = new THREE.TorusKnotGeometry(1.5, 0.5, 100, 16); const materials = { black: new THREE.MeshStandardMaterial({ color: "black", roughness: 1, metalness: 0, }), silver: new THREE.MeshStandardMaterial({ color: "#C0C0C0", roughness: 0.3, metalness: 1, }), gold: new THREE.MeshStandardMaterial({ color: "#FFD700", roughness: 0.4, metalness: 1, }), }; const sphere = new THREE.Mesh(geometry, materials.black); scene.add(sphere); const ambientLight = new THREE.AmbientLight(0xffffff, 0.6); scene.add(ambientLight); const pointLight = new THREE.PointLight(0xffffff, 1); pointLight.position.set(5, 5, 5); scene.add(pointLight); const controls = new OrbitControls(camera, renderer.domElement); controls.enableDamping = true; const buttons = document.querySelectorAll("button"); buttons.forEach((btn) => { btn.addEventListener("click", () => { const variant = btn.getAttribute("data-variant"); sphere.material = materials[variant]; buttons.forEach((b) => b.classList.remove("active")); btn.classList.add("active"); }); }); function animate() { requestAnimationFrame(animate); controls.update(); sphere.rotation.y += 0.01; renderer.render(scene, camera); } animate(); window.addEventListener("resize", () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); });