Spaces:
Running

Reaperxxxx commited on
Commit
cb4742d
·
verified ·
1 Parent(s): 9d608f4

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +106 -116
index.html CHANGED
@@ -9,7 +9,6 @@
9
  margin: 0;
10
  overflow: hidden;
11
  background: #000;
12
- font-family: Arial, sans-serif;
13
  }
14
  canvas {
15
  display: block;
@@ -27,133 +26,124 @@
27
  border-radius: 8px;
28
  text-align: center;
29
  z-index: 100;
30
- font-size: 16px;
31
- }
32
- #error {
33
- position: fixed;
34
- top: 50%;
35
- left: 50%;
36
- transform: translate(-50%, -50%);
37
- background: rgba(200, 0, 0, 0.9);
38
- color: #fff;
39
- padding: 20px 40px;
40
- border-radius: 8px;
41
- text-align: center;
42
- z-index: 100;
43
- max-width: 80%;
44
  }
45
  </style>
46
  </head>
47
  <body>
48
- <div id="loading">Loading 3D Map...</div>
49
- <div id="error" style="display: none;"></div>
 
 
 
 
 
 
 
 
50
 
51
  <script type="module">
52
- import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js';
53
- import { GLTFLoader } from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/GLTFLoader.js';
54
- import { OrbitControls } from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/OrbitControls.js';
55
-
56
- const scene = new THREE.Scene();
57
- scene.background = new THREE.Color(0x111111);
58
-
59
- const camera = new THREE.PerspectiveCamera(
60
- 75,
61
- window.innerWidth / window.innerHeight,
62
- 0.1,
63
- 1000
64
- );
65
-
66
- const renderer = new THREE.WebGLRenderer({
67
- antialias: true,
68
- powerPreference: 'high-performance'
69
- });
70
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
71
- renderer.setSize(window.innerWidth, window.innerHeight);
72
- document.body.appendChild(renderer.domElement);
73
-
74
- // Lighting setup
75
- scene.add(new THREE.AmbientLight(0xffffff, 1.2));
76
- const dirLight = new THREE.DirectionalLight(0xffffff, 1);
77
- dirLight.position.set(10, 10, 10);
78
- scene.add(dirLight);
79
-
80
- const controls = new OrbitControls(camera, renderer.domElement);
81
- controls.enableDamping = true;
82
- controls.dampingFactor = 0.05;
83
- controls.autoRotate = false;
84
- controls.enableZoom = true;
85
-
86
- const loader = new GLTFLoader();
87
-
88
- let mapLoaded = false;
89
-
90
- function loadMap() {
91
- // Using a test model from GitHub
92
- const testModelUrl = 'https://github.com/mrdoob/three.js/raw/refs/heads/dev/examples/models/gltf/Parrot.glb';
93
-
94
- loader.load(
95
- testModelUrl,
96
- (gltf) => {
97
- const map = gltf.scene;
98
- scene.add(map);
99
- mapLoaded = true;
100
-
101
- // Auto-center and scale
102
- const box = new THREE.Box3().setFromObject(map);
103
- const center = box.getCenter(new THREE.Vector3());
104
- const size = box.getSize(new THREE.Vector3());
105
-
106
- map.position.x += map.position.x - center.x;
107
- map.position.y += map.position.y - center.y;
108
- map.position.z += map.position.z - center.z;
109
-
110
- const maxDim = Math.max(size.x, size.y, size.z);
111
- const fov = camera.fov * (Math.PI / 180);
112
- const cameraZ = Math.abs(maxDim / Math.sin(fov / 2));
113
-
114
- camera.position.set(center.x, center.y + maxDim / 4, cameraZ);
115
- camera.lookAt(center);
116
- controls.target.copy(center);
117
- controls.update();
118
-
119
- document.getElementById('loading').style.display = 'none';
120
- console.log('✅ Test model loaded successfully!');
121
- },
122
- (xhr) => {
123
- const progress = (xhr.loaded / xhr.total * 100).toFixed(0);
124
- document.getElementById('loading').textContent = `Loading 3D Map... ${progress}%`;
125
- },
126
- () => {
127
- showError('Failed to load test model. Check your internet connection.');
128
- }
129
  );
130
- }
131
 
132
- function showError(message) {
133
- document.getElementById('loading').style.display = 'none';
134
- const errorDiv = document.getElementById('error');
135
- errorDiv.textContent = message;
136
- errorDiv.style.display = 'block';
137
- console.error('❌', message);
138
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
- loadMap();
141
 
142
- function animate() {
143
- requestAnimationFrame(animate);
144
- if (mapLoaded) {
145
- controls.update();
146
- }
147
- renderer.render(scene, camera);
148
  }
149
 
150
- animate();
151
-
152
- window.addEventListener('resize', () => {
153
- camera.aspect = window.innerWidth / window.innerHeight;
154
- camera.updateProjectionMatrix();
155
- renderer.setSize(window.innerWidth, window.innerHeight);
156
- });
157
  </script>
158
  </body>
159
  </html>
 
9
  margin: 0;
10
  overflow: hidden;
11
  background: #000;
 
12
  }
13
  canvas {
14
  display: block;
 
26
  border-radius: 8px;
27
  text-align: center;
28
  z-index: 100;
29
+ font-size: 18px;
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
  </style>
32
  </head>
33
  <body>
34
+ <div id="loading">Loading...</div>
35
+
36
+ <script type="importmap">
37
+ {
38
+ "imports": {
39
+ "three": "https://cdn.jsdelivr.net/npm/three@0.128.0/build/three.module.js",
40
+ "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.128.0/examples/jsm/"
41
+ }
42
+ }
43
+ </script>
44
 
45
  <script type="module">
46
+ import * as THREE from 'three';
47
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
48
+
49
+ let scene, camera, renderer, modelLoaded = false;
50
+ let rotation = { x: 0, y: 0 };
51
+ let zoom = 5;
52
+
53
+ function init() {
54
+ scene = new THREE.Scene();
55
+ scene.background = new THREE.Color(0x111111);
56
+
57
+ camera = new THREE.PerspectiveCamera(
58
+ 75,
59
+ window.innerWidth / window.innerHeight,
60
+ 0.1,
61
+ 1000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  );
63
+ camera.position.z = zoom;
64
 
65
+ renderer = new THREE.WebGLRenderer({ antialias: true });
66
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
67
+ renderer.setSize(window.innerWidth, window.innerHeight);
68
+ document.body.appendChild(renderer.domElement);
69
+
70
+ // Lighting
71
+ scene.add(new THREE.AmbientLight(0xffffff, 1.2));
72
+ const dirLight = new THREE.DirectionalLight(0xffffff, 1);
73
+ dirLight.position.set(10, 10, 10);
74
+ scene.add(dirLight);
75
+
76
+ // Load map.glb
77
+ const loader = new GLTFLoader();
78
+ loader.load('./map.glb', (gltf) => {
79
+ const model = gltf.scene;
80
+ scene.add(model);
81
+ modelLoaded = true;
82
+ document.getElementById('loading').style.display = 'none';
83
+ console.log('✅ Map loaded!');
84
+ }, undefined, (error) => {
85
+ console.error('Error loading map:', error);
86
+ // Fallback: create test cube
87
+ const geometry = new THREE.BoxGeometry(2, 2, 2);
88
+ const material = new THREE.MeshPhongMaterial({ color: 0x00ff00 });
89
+ const cube = new THREE.Mesh(geometry, material);
90
+ scene.add(cube);
91
+ modelLoaded = true;
92
+ document.getElementById('loading').textContent = 'Test Cube (map.glb not found)';
93
+ });
94
+
95
+ // Mouse/touch controls
96
+ let isDragging = false;
97
+ let previousMousePosition = { x: 0, y: 0 };
98
+
99
+ renderer.domElement.addEventListener('mousedown', (e) => {
100
+ isDragging = true;
101
+ previousMousePosition = { x: e.clientX, y: e.clientY };
102
+ });
103
+
104
+ renderer.domElement.addEventListener('mousemove', (e) => {
105
+ if (isDragging && modelLoaded) {
106
+ const deltaX = e.clientX - previousMousePosition.x;
107
+ const deltaY = e.clientY - previousMousePosition.y;
108
+ rotation.y += deltaX * 0.01;
109
+ rotation.x += deltaY * 0.01;
110
+ previousMousePosition = { x: e.clientX, y: e.clientY };
111
+ }
112
+ });
113
+
114
+ renderer.domElement.addEventListener('mouseup', () => {
115
+ isDragging = false;
116
+ });
117
+
118
+ renderer.domElement.addEventListener('wheel', (e) => {
119
+ e.preventDefault();
120
+ zoom += e.deltaY * 0.01;
121
+ zoom = Math.max(1, Math.min(20, zoom));
122
+ });
123
+
124
+ function animate() {
125
+ requestAnimationFrame(animate);
126
+
127
+ if (modelLoaded) {
128
+ camera.position.x = zoom * Math.sin(rotation.y);
129
+ camera.position.y = zoom * Math.sin(rotation.x);
130
+ camera.position.z = zoom * Math.cos(rotation.y);
131
+ camera.lookAt(0, 0, 0);
132
+ }
133
+
134
+ renderer.render(scene, camera);
135
+ }
136
 
137
+ animate();
138
 
139
+ window.addEventListener('resize', () => {
140
+ camera.aspect = window.innerWidth / window.innerHeight;
141
+ camera.updateProjectionMatrix();
142
+ renderer.setSize(window.innerWidth, window.innerHeight);
143
+ });
 
144
  }
145
 
146
+ init();
 
 
 
 
 
 
147
  </script>
148
  </body>
149
  </html>