Create index.html
Browse files- index.html +78 -19
index.html
CHANGED
|
@@ -1,19 +1,78 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>3D Map Viewer</title>
|
| 7 |
+
<style>
|
| 8 |
+
body { margin: 0; overflow: hidden; background: #000; }
|
| 9 |
+
canvas { display: block; }
|
| 10 |
+
</style>
|
| 11 |
+
</head>
|
| 12 |
+
<body>
|
| 13 |
+
<script type="module">
|
| 14 |
+
import * as THREE from 'https://unpkg.com/three@0.165.0/build/three.module.js';
|
| 15 |
+
import { GLTFLoader } from 'https://unpkg.com/three@0.165.0/examples/jsm/loaders/GLTFLoader.js';
|
| 16 |
+
import { OrbitControls } from 'https://unpkg.com/three@0.165.0/examples/jsm/controls/OrbitControls.js';
|
| 17 |
+
|
| 18 |
+
// Scene setup
|
| 19 |
+
const scene = new THREE.Scene();
|
| 20 |
+
scene.background = new THREE.Color(0x222222);
|
| 21 |
+
|
| 22 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 23 |
+
camera.position.set(0, 2, 5);
|
| 24 |
+
|
| 25 |
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 26 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 27 |
+
document.body.appendChild(renderer.domElement);
|
| 28 |
+
|
| 29 |
+
// Lights
|
| 30 |
+
const hemiLight = new THREE.HemisphereLight(0xffffff, 0x444444, 1);
|
| 31 |
+
hemiLight.position.set(0, 20, 0);
|
| 32 |
+
scene.add(hemiLight);
|
| 33 |
+
|
| 34 |
+
const dirLight = new THREE.DirectionalLight(0xffffff, 1);
|
| 35 |
+
dirLight.position.set(5, 10, 7.5);
|
| 36 |
+
scene.add(dirLight);
|
| 37 |
+
|
| 38 |
+
// Controls
|
| 39 |
+
const controls = new OrbitControls(camera, renderer.domElement);
|
| 40 |
+
controls.enableDamping = true;
|
| 41 |
+
controls.dampingFactor = 0.05;
|
| 42 |
+
controls.target.set(0, 1, 0);
|
| 43 |
+
|
| 44 |
+
// Load GLB map
|
| 45 |
+
const loader = new GLTFLoader();
|
| 46 |
+
loader.load(
|
| 47 |
+
'./map.glb', // make sure your map.glb is in the same folder
|
| 48 |
+
(gltf) => {
|
| 49 |
+
const map = gltf.scene;
|
| 50 |
+
map.position.set(0, 0, 0);
|
| 51 |
+
scene.add(map);
|
| 52 |
+
console.log('Map loaded ✅');
|
| 53 |
+
},
|
| 54 |
+
(xhr) => {
|
| 55 |
+
console.log(`Loading map: ${(xhr.loaded / xhr.total * 100).toFixed(2)}%`);
|
| 56 |
+
},
|
| 57 |
+
(error) => {
|
| 58 |
+
console.error('Error loading GLB:', error);
|
| 59 |
+
}
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
// Animation loop
|
| 63 |
+
function animate() {
|
| 64 |
+
requestAnimationFrame(animate);
|
| 65 |
+
controls.update();
|
| 66 |
+
renderer.render(scene, camera);
|
| 67 |
+
}
|
| 68 |
+
animate();
|
| 69 |
+
|
| 70 |
+
// Responsive resize
|
| 71 |
+
window.addEventListener('resize', () => {
|
| 72 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 73 |
+
camera.updateProjectionMatrix();
|
| 74 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 75 |
+
});
|
| 76 |
+
</script>
|
| 77 |
+
</body>
|
| 78 |
+
</html>
|