-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
461 lines (407 loc) · 23.8 KB
/
Copy pathindex.html
File metadata and controls
461 lines (407 loc) · 23.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blender-Web Previewer | By Egret</title>
<!-- Google Fonts - Host Grotesk -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Host+Grotesk:ital,wght@0,300..800;1,300..800&display=swap" rel="stylesheet">
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Tailwind Styles with Host Grotesk font -->
<style type="text/tailwindcss">
@layer base {
body {
@apply bg-neutral-900 text-neutral-100 overflow-hidden;
font-family: "Host Grotesk", sans-serif;
font-weight: 400;
}
h1, h2, h3, h4, h5, h6 {
font-family: "Host Grotesk", sans-serif;
font-weight: 700;
}
button {
font-family: "Host Grotesk", sans-serif;
font-weight: 500;
}
input[type="range"] {
@apply w-full h-2 bg-neutral-700 rounded-lg appearance-none cursor-pointer;
}
input[type="range"]::-webkit-slider-thumb {
@apply appearance-none w-4 h-4 bg-neutral-500 rounded-full;
}
.controls-panel-mobile {
@apply fixed inset-0 z-20 bg-neutral-800 overflow-auto;
display: none;
}
.controls-panel-mobile.visible {
display: block;
}
.font-light {
font-weight: 300;
}
.font-regular {
font-weight: 400;
}
.font-medium {
font-weight: 500;
}
.font-semibold {
font-weight: 600;
}
.font-bold {
font-weight: 700;
}
.font-extrabold {
font-weight: 800;
}
}
</style>
</head>
<body>
<div class="relative h-screen flex flex-col md:flex-row">
<!-- Warning for file:// protocol -->
<div id="protocol-warning" class="hidden fixed top-0 left-0 w-full bg-red-600 text-white p-2 text-center z-50">
This 3D viewer may not work when opened directly from your computer.
<br>For best results:
<br>1) Use a web server (like VS Code Live Server) or
<br>2) Upload these files to a web hosting service.
</div>
<!-- Viewer Area -->
<div id="viewer" class="flex-1 bg-black relative">
<!-- Loading Overlay -->
<div class="loading-overlay absolute inset-0 bg-black bg-opacity-80 flex flex-col items-center justify-center z-50">
<div class="w-12 h-12 border-4 border-neutral-500 border-t-transparent rounded-full animate-spin"></div>
<div class="mt-4 text-neutral-300 text-sm font-medium" id="loading-percentage">Loading...</div>
</div>
</div>
<!-- Desktop Controls Panel -->
<div id="controls" class="hidden md:block w-full md:w-80 bg-neutral-950 border-l border-neutral-700 shadow-lg overflow-y-auto">
<div class="p-4 space-y-6">
<!-- Header Info -->
<div>
<!-- <span class="text-xs text-neutral-400">File Name</span> -->
<h2 id="scene-title" class="text-sm font-bold text-white flex items-center">
<i class="fa-solid fa-cube mr-2 text-neutral-400"></i>
<span>Blender Scene</span>
</h2>
<div id="scene-stats" class="text-sm text-neutral-400 mt-1"></div>
</div>
<!-- Camera Controls -->
<div class="space-y-3">
<h3 class="text-lg font-semibold text-neutral-300 flex items-center">
<i class="fa-solid fa-camera mr-2 text-neutral-400"></i>
Camera Controls
</h3>
<div>
<div class="grid grid-cols-3 gap-2">
<button id="btn-top-view" class="bg-neutral-900 rounded-md hover:bg-neutral-800 text-sm text-white py-2 px-3 rounded-md flex items-center justify-center">
<i class="fa-solid fa-arrow-up mr-1"></i>
Top
</button>
<button id="btn-front-view" class="bg-neutral-900 rounded-md hover:bg-neutral-800 text-sm text-white py-2 px-3 rounded-md flex items-center justify-center">
<i class="fa-solid fa-arrow-right mr-1"></i>
Front
</button>
<button id="btn-side-view" class="bg-neutral-900 rounded-md hover:bg-neutral-800 text-sm text-white py-2 px-3 rounded-md flex items-center justify-center">
<i class="fa-solid fa-arrow-left mr-1"></i>
Side
</button>
</div>
</div>
<button id="btn-reset-camera" class="w-full bg-neutral-900 rounded-md hover:bg-neutral-800 text-sm text-white py-2 px-4 rounded-md flex justify-center items-center mb-2">
<i class="fa-solid fa-rotate mr-2"></i>
Reset Camera
</button>
</div>
<!-- Display Controls -->
<div class="space-y-3">
<h3 class="text-lg font-semibold text-neutral-300 flex items-center">
<i class="fa-solid fa-display mr-2 text-neutral-400"></i>
Display Options
</h3>
<div class="space-y-2">
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" id="toggle-wireframe" class="h-4 w-4 rounded text-neutral-600 focus:ring-neutral-500 focus:ring-opacity-25">
<span class="flex items-center">
<i class="fa-solid fa-cubes-stacked mr-2 text-neutral-400"></i>
Wireframe
</span>
</label>
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" id="toggle-grid" checked class="h-4 w-4 rounded text-neutral-600 focus:ring-neutral-500 focus:ring-opacity-25">
<span class="flex items-center">
<i class="fa-solid fa-border-all mr-2 text-neutral-400"></i>
Grid
</span>
</label>
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" id="toggle-lights" checked class="h-4 w-4 rounded text-neutral-600 focus:ring-neutral-500 focus:ring-opacity-25">
<span class="flex items-center">
<i class="fa-solid fa-lightbulb mr-2 text-neutral-400"></i>
Lights
</span>
</label>
</div>
</div>
<!-- Animation Controls -->
<div id="animation-controls" class="space-y-3">
<h3 class="text-md font-semibold text-neutral-300 flex items-center">
<i class="fa-solid fa-play mr-2 text-neutral-400"></i>
Animation
</h3>
<div class="space-y-3">
<div class="flex space-x-2">
<button id="btn-play" class="flex-1 bg-orange-600 hover:bg-neutral-700 text-white py-2 px-2 rounded-md flex items-center justify-center">
<i class="fa-solid fa-play mr-1"></i>
Play
</button>
<button id="btn-pause" class="flex-1 bg-teal-600 hover:bg-neutral-700 text-white py-2 px-2 rounded-md flex items-center justify-center">
<i class="fa-solid fa-pause mr-1"></i>
Pause
</button>
<button id="btn-stop" class="flex-1 bg-rose-600 hover:bg-neutral-700 text-white py-2 px-2 rounded-md flex items-center justify-center">
<i class="fa-solid fa-stop mr-1"></i>
Stop
</button>
</div>
<div>
<input type="range" id="animation-slider" min="0" max="100" value="0" class="w-full">
</div>
<div id="animation-time" class="text-center text-sm text-neutral-400">
0:00 / 0:00
</div>
</div>
</div>
<!-- Attribution -->
<div class="pt-4 mt-4 border-t border-dashed border-neutral-700 text-xs text-neutral-500">
<div class="text-center mb-2">
Created with BlendXweb by
<a href="https://linktr.ee/egrettas" target="_blank" class="text-lime-400 font-bold hover:text-teal-400">Egret</a>
</div>
<div class="flex justify-center">
<a href="https://github.com/berloop/blender-web-viewer" target="_blank"
class="flex items-center bg-neutral-900 hover:bg-neutral-800 text-white py-2 px-3 rounded-md text-xs">
<i class="fa-brands fa-github mr-1"></i>
Star on GitHub
</a>
</div>
</div>
</div>
</div>
<!-- Mobile Controls Panel (clone) -->
<div id="mobile-controls" class="controls-panel-mobile bg-neutral-900">
<div class="p-4 space-y-6">
<!-- Close Button -->
<div class="flex justify-end">
<button id="close-mobile-controls" class="bg-neutral-700 hover:bg-neutral-600 text-white p-2 rounded-xl">
<i class="fa-solid fa-xmark"></i>
</button>
</div>
<!-- Header Info -->
<div>
<h2 id="mobile-scene-title" class="text-xl font-bold text-white flex items-center">
<i class="fa-solid fa-cube mr-2 text-neutral-400"></i>
<span>Blender Scene</span>
</h2>
<div id="mobile-scene-stats" class="text-sm text-neutral-400 mt-1"></div>
</div>
<!-- Camera Controls -->
<div class="space-y-3">
<h3 class="text-md font-semibold text-neutral-300 flex items-center">
<i class="fa-solid fa-camera mr-2 text-neutral-400"></i>
Camera Controls
</h3>
<div>
<div class="grid grid-cols-3 gap-2">
<button id="mobile-btn-top-view" class="bg-neutral-800 rounded-md hover:bg-neutral-700 text-sm text-white py-2 px-3 rounded-md flex items-center justify-center">
<i class="fa-solid fa-arrow-up mr-1"></i>
Top
</button>
<button id="mobile-btn-front-view" class="bg-neutral-800 rounded-md hover:bg-neutral-700 text-sm text-white py-2 px-3 rounded-md flex items-center justify-center">
<i class="fa-solid fa-arrow-right mr-1"></i>
Front
</button>
<button id="mobile-btn-side-view" class="bg-neutral-800 rounded-md hover:bg-neutral-700 text-sm text-white py-2 px-3 rounded-md flex items-center justify-center">
<i class="fa-solid fa-arrow-left mr-1"></i>
Side
</button>
</div>
</div>
<button id="mobile-btn-reset-camera" class="w-full bg-neutral-800 rounded-md hover:bg-neutral-700 text-sm text-white py-2 px-4 rounded-md flex justify-center items-center mb-2">
<i class="fa-solid fa-rotate mr-2"></i>
Reset Camera
</button>
</div>
<!-- Display Controls -->
<div class="space-y-3">
<h3 class="text-md font-semibold text-neutral-300 flex items-center">
<i class="fa-solid fa-display mr-2 text-neutral-400"></i>
Display Options
</h3>
<div class="space-y-2">
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" id="mobile-toggle-wireframe" class="h-4 w-4 rounded text-neutral-600 focus:ring-neutral-500 focus:ring-opacity-25">
<span class="flex items-center">
<i class="fa-solid fa-cubes-stacked mr-2 text-neutral-400"></i>
Wireframe
</span>
</label>
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" id="mobile-toggle-grid" checked class="h-4 w-4 rounded text-neutral-600 focus:ring-neutral-500 focus:ring-opacity-25">
<span class="flex items-center">
<i class="fa-solid fa-border-all mr-2 text-neutral-400"></i>
Grid
</span>
</label>
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" id="mobile-toggle-lights" checked class="h-4 w-4 rounded text-neutral-600 focus:ring-neutral-500 focus:ring-opacity-25">
<span class="flex items-center">
<i class="fa-solid fa-lightbulb mr-2 text-neutral-400"></i>
Lights
</span>
</label>
</div>
</div>
<!-- Animation Controls -->
<div id="mobile-animation-controls" class="space-y-3">
<h3 class="text-md font-semibold text-neutral-300 flex items-center">
<i class="fa-solid fa-play mr-2 text-neutral-400"></i>
Animation
</h3>
<div class="space-y-3">
<div class="flex space-x-2">
<button id="mobile-btn-play" class="flex-1 bg-teal-600 hover:bg-neutral-700 text-white py-2 px-2 rounded-md flex items-center justify-center">
<i class="fa-solid fa-play mr-1"></i>
Play
</button>
<button id="mobile-btn-pause" class="flex-1 bg-orange-600 hover:bg-neutral-700 text-white py-2 px-2 rounded-md flex items-center justify-center">
<i class="fa-solid fa-pause mr-1"></i>
Pause
</button>
<button id="mobile-btn-stop" class="flex-1 bg-rose-600 hover:bg-neutral-700 text-white py-2 px-2 rounded-md flex items-center justify-center">
<i class="fa-solid fa-stop mr-1"></i>
Stop
</button>
</div>
<div>
<input type="range" id="mobile-animation-slider" min="0" max="100" value="0" class="w-full">
</div>
<div id="mobile-animation-time" class="text-center text-sm text-neutral-400">
0:00 / 0:00
</div>
</div>
</div>
<!-- Attribution -->
<div class="pt-4 mt-4 border-t border-dashed border-neutral-700 text-xs text-neutral-500">
<div class="text-center mb-2">
Created with Blender Web Preview by
<a href="https://linktr.ee/egrettas" target="_blank" class="text-lime-400 font-bold hover:text-teal-400">Egret</a>
</div>
<div class="flex justify-center">
<a href="https://github.com/berloop/blender-web-viewer" target="_blank"
class="flex items-center bg-neutral-800 hover:bg-neutral-700 text-white py-2 px-3 rounded-md text-xs">
<i class="fa-brands fa-github mr-1"></i>
Star on GitHub
</a>
</div>
</div>
</div>
</div>
<!-- Mobile Controls Toggle -->
<button id="toggle-controls" class="md:hidden fixed bottom-4 right-4 bg-neutral-600 p-3 rounded-full shadow-lg z-10">
<i class="fa-solid fa-sliders text-white"></i>
</button>
</div>
<!-- Use a specific version known to work -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r124/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.7/dat.gui.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.124.0/examples/js/controls/OrbitControls.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.124.0/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.124.0/examples/js/loaders/DRACOLoader.js"></script>
<!-- Load viewer script -->
<script src="js/viewer.js"></script>
<!-- Initialize UI functionality -->
<script>
// Function to synchronize UI elements between desktop and mobile
function syncUIState() {
// Sync scene info
document.getElementById('mobile-scene-title').textContent = document.getElementById('scene-title').textContent;
document.getElementById('mobile-scene-stats').textContent = document.getElementById('scene-stats').textContent;
// Sync checkboxes
document.getElementById('mobile-toggle-wireframe').checked = document.getElementById('toggle-wireframe').checked;
document.getElementById('mobile-toggle-grid').checked = document.getElementById('toggle-grid').checked;
document.getElementById('mobile-toggle-lights').checked = document.getElementById('toggle-lights').checked;
// Sync animation slider
document.getElementById('mobile-animation-slider').value = document.getElementById('animation-slider').value;
document.getElementById('mobile-animation-time').textContent = document.getElementById('animation-time').textContent;
}
// Mobile controls toggle
document.getElementById('toggle-controls').addEventListener('click', function() {
const mobileControls = document.getElementById('mobile-controls');
mobileControls.classList.add('visible');
syncUIState();
});
// Close mobile controls
document.getElementById('close-mobile-controls').addEventListener('click', function() {
document.getElementById('mobile-controls').classList.remove('visible');
});
// Connect mobile controls to main functions
document.getElementById('mobile-btn-reset-camera').addEventListener('click', function() {
document.getElementById('btn-reset-camera').click();
});
document.getElementById('mobile-btn-top-view').addEventListener('click', function() {
document.getElementById('btn-top-view').click();
});
document.getElementById('mobile-btn-front-view').addEventListener('click', function() {
document.getElementById('btn-front-view').click();
});
document.getElementById('mobile-btn-side-view').addEventListener('click', function() {
document.getElementById('btn-side-view').click();
});
document.getElementById('mobile-toggle-wireframe').addEventListener('change', function(e) {
document.getElementById('toggle-wireframe').checked = e.target.checked;
document.getElementById('toggle-wireframe').dispatchEvent(new Event('change'));
});
document.getElementById('mobile-toggle-grid').addEventListener('change', function(e) {
document.getElementById('toggle-grid').checked = e.target.checked;
document.getElementById('toggle-grid').dispatchEvent(new Event('change'));
});
document.getElementById('mobile-toggle-lights').addEventListener('change', function(e) {
document.getElementById('toggle-lights').checked = e.target.checked;
document.getElementById('toggle-lights').dispatchEvent(new Event('change'));
});
document.getElementById('mobile-btn-play').addEventListener('click', function() {
document.getElementById('btn-play').click();
});
document.getElementById('mobile-btn-pause').addEventListener('click', function() {
document.getElementById('btn-pause').click();
});
document.getElementById('mobile-btn-stop').addEventListener('click', function() {
document.getElementById('btn-stop').click();
});
document.getElementById('mobile-animation-slider').addEventListener('input', function(e) {
document.getElementById('animation-slider').value = e.target.value;
document.getElementById('animation-slider').dispatchEvent(new Event('input'));
});
// Check for file protocol
if (window.location.protocol === 'file:') {
document.getElementById('protocol-warning').classList.remove('hidden');
}
// Update the original viewer.js loading progress function
window.updateLoadingProgress = function(percent) {
document.getElementById('loading-percentage').textContent =
percent < 100 ? `Loading: ${percent}%` : 'Processing...';
if (percent >= 100) {
setTimeout(() => {
document.querySelector('.loading-overlay').style.display = 'none';
}, 500);
}
};
</script>
</body>
</html>