|
| 1 | +import * as THREE from "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"; |
| 2 | +import { OrbitControls } from "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/controls/OrbitControls.js"; |
| 3 | +import { GLTFLoader } from "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/loaders/GLTFLoader.js"; |
| 4 | + |
| 5 | +const canvas = document.querySelector("#viewer"); |
| 6 | +const status = document.querySelector("#status"); |
| 7 | +const renderer = new THREE.WebGLRenderer({canvas, antialias:true}); |
| 8 | +renderer.setPixelRatio(Math.min(devicePixelRatio, 2)); |
| 9 | +const scene = new THREE.Scene(); |
| 10 | +scene.background = new THREE.Color(0x0b1020); |
| 11 | +const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 200000); |
| 12 | +camera.position.set(48000, 41000, 36000); |
| 13 | +const controls = new OrbitControls(camera, canvas); |
| 14 | +controls.enableDamping = true; |
| 15 | +controls.target.set(0, 0, 0); |
| 16 | +scene.add(new THREE.HemisphereLight(0xffffff, 0x29324c, 2.2)); |
| 17 | +const key = new THREE.DirectionalLight(0xffffff, 2.5); key.position.set(30000,30000,50000); scene.add(key); |
| 18 | +const grid = new THREE.GridHelper(80000, 40, 0x334155, 0x1e293b); grid.rotation.z = Math.PI/2; scene.add(grid); |
| 19 | + |
| 20 | +new GLTFLoader().load("models/asterion_v0_8_optimized_structure.glb", gltf => { |
| 21 | + scene.add(gltf.scene); |
| 22 | + status.textContent = "Drag to orbit · scroll to zoom · right-drag to pan"; |
| 23 | +}, undefined, err => { |
| 24 | + console.error(err); status.textContent = "Model failed to load. Serve this folder through a local web server."; |
| 25 | +}); |
| 26 | + |
| 27 | +function resize(){ |
| 28 | + const w=canvas.clientWidth, h=canvas.clientHeight; |
| 29 | + if(canvas.width!==w || canvas.height!==h){renderer.setSize(w,h,false);camera.aspect=w/h;camera.updateProjectionMatrix();} |
| 30 | +} |
| 31 | +function animate(){resize();controls.update();renderer.render(scene,camera);requestAnimationFrame(animate)} |
| 32 | +animate(); |
0 commit comments