File size: 29,290 Bytes
317e664
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI 3D Model Generator</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .dropzone {
            border: 2px dashed #6366f1;
            border-radius: 0.75rem;
            transition: all 0.3s ease;
        }
        .dropzone.active {
            border-color: #4f46e5;
            background-color: rgba(99, 102, 241, 0.1);
        }
        .result-container {
            transition: all 0.5s ease;
            max-height: 0;
            overflow: hidden;
        }
        .result-container.show {
            max-height: 1000px;
        }
        .model-card {
            transition: all 0.3s ease;
        }
        .model-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .model-card.selected {
            border-color: #6366f1;
            background-color: rgba(99, 102, 241, 0.05);
        }
        .spinner {
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }
        canvas {
            max-width: 100%;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .model-badge {
            position: absolute;
            top: 10px;
            right: 10px;
            background-color: rgba(0, 0, 0, 0.7);
            color: white;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 12px;
        }
        .progress-text {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: white;
            font-weight: bold;
            text-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-12">
        <div class="text-center mb-12">
            <h1 class="text-4xl font-bold text-indigo-600 mb-3">AI 3D Model Generator</h1>
            <p class="text-lg text-gray-600 max-w-2xl mx-auto">Transform your 2D images into high-quality 3D models using cutting-edge AI models</p>
        </div>

        <div class="bg-white rounded-xl shadow-lg p-6 max-w-4xl mx-auto">
            <!-- Upload Section -->
            <div id="upload-section" class="mb-8">
                <h2 class="text-2xl font-semibold text-gray-800 mb-4">Upload Your Image</h2>
                <div id="dropzone" class="dropzone p-12 text-center cursor-pointer">
                    <div class="flex flex-col items-center justify-center">
                        <i class="fas fa-cloud-upload-alt text-5xl text-indigo-500 mb-4"></i>
                        <p class="text-lg text-gray-600 mb-2">Drag & drop your image here</p>
                        <p class="text-sm text-gray-500 mb-4">or</p>
                        <label for="file-upload" class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition cursor-pointer">
                            Browse Files
                        </label>
                        <input id="file-upload" type="file" accept="image/*" class="hidden">
                    </div>
                </div>
                <div id="preview-container" class="mt-6 hidden">
                    <h3 class="text-lg font-medium text-gray-700 mb-3">Image Preview</h3>
                    <div class="flex items-center">
                        <div class="relative">
                            <img id="image-preview" src="" alt="Preview" class="max-w-xs rounded-lg shadow">
                            <div id="model-badge" class="model-badge hidden">
                                <span id="selected-model-name">TripoSR</span>
                            </div>
                        </div>
                        <button id="change-image" class="ml-4 px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition">
                            <i class="fas fa-redo mr-2"></i>Change Image
                        </button>
                    </div>
                </div>
            </div>

            <!-- Model Selection -->
            <div id="model-selection" class="mb-8 hidden">
                <h2 class="text-2xl font-semibold text-gray-800 mb-4">Select AI Model</h2>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div class="model-card p-4 border-2 border-gray-200 rounded-xl cursor-pointer" data-model="triposr">
                        <div class="flex flex-col items-center text-center">
                            <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mb-3">
                                <i class="fas fa-cube text-2xl text-indigo-600"></i>
                            </div>
                            <h3 class="font-medium text-gray-800 mb-1">TripoSR</h3>
                            <p class="text-sm text-gray-500 mb-2">Fast feed-forward 3D object reconstruction</p>
                            <div class="text-xs text-indigo-600 bg-indigo-50 px-2 py-1 rounded">
                                <i class="fas fa-bolt mr-1"></i> Fast processing
                            </div>
                        </div>
                    </div>
                    <div class="model-card p-4 border-2 border-gray-200 rounded-xl cursor-pointer" data-model="real3d">
                        <div class="flex flex-col items-center text-center">
                            <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mb-3">
                                <i class="fas fa-user text-2xl text-indigo-600"></i>
                            </div>
                            <h3 class="font-medium text-gray-800 mb-1">Real3D</h3>
                            <p class="text-sm text-gray-500 mb-2">High-quality 3D face reconstruction</p>
                            <div class="text-xs text-indigo-600 bg-indigo-50 px-2 py-1 rounded">
                                <i class="fas fa-star mr-1"></i> High quality
                            </div>
                        </div>
                    </div>
                </div>
                <div class="mt-6">
                    <button id="generate-btn" class="w-full md:w-auto px-6 py-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition font-medium hidden">
                        <i class="fas fa-magic mr-2"></i> Generate 3D Model
                    </button>
                </div>
            </div>

            <!-- Processing Section -->
            <div id="processing-section" class="hidden">
                <div class="flex flex-col items-center justify-center py-8">
                    <div class="relative w-24 h-24 mb-4">
                        <div class="w-full h-full border-4 border-indigo-500 border-t-transparent rounded-full spinner"></div>
                        <div id="progress-text" class="progress-text">0%</div>
                    </div>
                    <h3 class="text-xl font-medium text-gray-800 mb-2">Processing Your Image</h3>
                    <p class="text-gray-600 text-center max-w-md" id="processing-message">Initializing the AI model...</p>
                    <div class="w-full bg-gray-200 rounded-full h-2.5 mt-4 max-w-md">
                        <div id="progress-bar" class="bg-indigo-600 h-2.5 rounded-full" style="width: 0%"></div>
                    </div>
                </div>
            </div>

            <!-- Results Section -->
            <div id="result-section" class="result-container">
                <div class="border-t border-gray-200 pt-6 mt-6">
                    <div class="flex justify-between items-center mb-4">
                        <h2 class="text-2xl font-semibold text-gray-800">Your 3D Model</h2>
                        <span id="model-used" class="text-sm bg-indigo-100 text-indigo-800 px-3 py-1 rounded-full"></span>
                    </div>
                    <div class="flex flex-col md:flex-row gap-8">
                        <div class="flex-1">
                            <div class="bg-gray-100 p-4 rounded-lg relative">
                                <canvas id="3d-viewer"></canvas>
                                <div id="viewer-controls" class="absolute bottom-4 left-4 flex gap-2">
                                    <button id="rotate-toggle" class="bg-white p-2 rounded-full shadow-md">
                                        <i class="fas fa-sync-alt"></i>
                                    </button>
                                    <button id="reset-view" class="bg-white p-2 rounded-full shadow-md">
                                        <i class="fas fa-expand"></i>
                                    </button>
                                </div>
                            </div>
                            <div class="mt-4 grid grid-cols-3 gap-2">
                                <button id="view-front" class="bg-gray-200 p-2 rounded text-sm">
                                    <i class="fas fa-arrow-up mr-1"></i> Front
                                </button>
                                <button id="view-side" class="bg-gray-200 p-2 rounded text-sm">
                                    <i class="fas fa-arrow-right mr-1"></i> Side
                                </button>
                                <button id="view-top" class="bg-gray-200 p-2 rounded text-sm">
                                    <i class="fas fa-arrow-down mr-1"></i> Top
                                </button>
                            </div>
                        </div>
                        <div class="flex-1">
                            <h3 class="text-lg font-medium text-gray-800 mb-3">Model Information</h3>
                            <div class="bg-white border border-gray-200 rounded-lg p-4 mb-4">
                                <div class="flex justify-between mb-2">
                                    <span class="text-gray-600">Model:</span>
                                    <span id="model-type" class="font-medium">TripoSR</span>
                                </div>
                                <div class="flex justify-between mb-2">
                                    <span class="text-gray-600">Vertices:</span>
                                    <span id="vertex-count" class="font-medium">12,456</span>
                                </div>
                                <div class="flex justify-between mb-2">
                                    <span class="text-gray-600">Faces:</span>
                                    <span id="face-count" class="font-medium">6,228</span>
                                </div>
                                <div class="flex justify-between">
                                    <span class="text-gray-600">Processing Time:</span>
                                    <span id="processing-time" class="font-medium">4.2s</span>
                                </div>
                            </div>
                            <div class="flex flex-wrap gap-3">
                                <button id="download-obj" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition flex items-center">
                                    <i class="fas fa-download mr-2"></i> Download OBJ
                                </button>
                                <button id="download-stl" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition flex items-center">
                                    <i class="fas fa-download mr-2"></i> Download STL
                                </button>
                                <button id="download-gltf" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition flex items-center">
                                    <i class="fas fa-download mr-2"></i> Download GLTF
                                </button>
                                <button id="new-conversion" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition flex items-center">
                                    <i class="fas fa-redo mr-2"></i> New Conversion
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="mt-12 text-center text-gray-500 text-sm">
            <p>Powered by <a href="https://huggingface.co./stabilityai/TripoSR" class="text-indigo-600 hover:underline" target="_blank">TripoSR</a> and <a href="https://huggingface.co./spaces/hwjiang/Real3D" class="text-indigo-600 hover:underline" target="_blank">Real3D</a> AI models</p>
        </div>
    </div>

    <!-- Three.js for 3D preview -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/GLTFLoader.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/OBJLoader.min.js"></script>

    <script>
        // DOM Elements
        const dropzone = document.getElementById('dropzone');
        const fileUpload = document.getElementById('file-upload');
        const previewContainer = document.getElementById('preview-container');
        const imagePreview = document.getElementById('image-preview');
        const changeImageBtn = document.getElementById('change-image');
        const modelSelection = document.getElementById('model-selection');
        const modelCards = document.querySelectorAll('.model-card');
        const generateBtn = document.getElementById('generate-btn');
        const processingSection = document.getElementById('processing-section');
        const progressBar = document.getElementById('progress-bar');
        const progressText = document.getElementById('progress-text');
        const processingMessage = document.getElementById('processing-message');
        const resultSection = document.getElementById('result-section');
        const newConversionBtn = document.getElementById('new-conversion');
        const modelBadge = document.getElementById('model-badge');
        const modelUsed = document.getElementById('model-used');
        
        // Variables
        let selectedFile = null;
        let selectedModel = null;
        let threeScene = null;
        let threeControls = null;
        let threeCamera = null;
        let threeRenderer = null;
        let threeModel = null;
        let autoRotate = true;
        
        // Event Listeners
        dropzone.addEventListener('click', () => fileUpload.click());
        
        fileUpload.addEventListener('change', (e) => {
            if (e.target.files.length) {
                handleFileUpload(e.target.files[0]);
            }
        });
        
        dropzone.addEventListener('dragover', (e) => {
            e.preventDefault();
            dropzone.classList.add('active');
        });
        
        dropzone.addEventListener('dragleave', () => {
            dropzone.classList.remove('active');
        });
        
        dropzone.addEventListener('drop', (e) => {
            e.preventDefault();
            dropzone.classList.remove('active');
            
            if (e.dataTransfer.files.length) {
                handleFileUpload(e.dataTransfer.files[0]);
            }
        });
        
        changeImageBtn.addEventListener('click', () => {
            selectedFile = null;
            previewContainer.classList.add('hidden');
            modelSelection.classList.add('hidden');
            generateBtn.classList.add('hidden');
            fileUpload.value = '';
            modelBadge.classList.add('hidden');
        });
        
        modelCards.forEach(card => {
            card.addEventListener('click', () => {
                modelCards.forEach(c => c.classList.remove('selected'));
                card.classList.add('selected');
                selectedModel = card.getAttribute('data-model');
                
                // Update model badge
                const modelName = card.querySelector('h3').textContent;
                document.getElementById('selected-model-name').textContent = modelName;
                modelBadge.classList.remove('hidden');
                
                // Show generate button
                generateBtn.classList.remove('hidden');
            });
        });
        
        generateBtn.addEventListener('click', () => {
            if (!selectedFile || !selectedModel) return;
            
            // Show processing section
            processingSection.classList.remove('hidden');
            
            // Set appropriate processing message
            processingMessage.textContent = selectedModel === 'triposr' 
                ? "Processing with TripoSR model (this may take 20-30 seconds)..." 
                : "Processing with Real3D model (this may take 1-2 minutes)...";
            
            // Start processing
            processImageWithModel(selectedModel, selectedFile);
        });
        
        newConversionBtn.addEventListener('click', resetForm);
        
        // 3D Viewer Controls
        document.getElementById('rotate-toggle').addEventListener('click', () => {
            autoRotate = !autoRotate;
            if (threeControls) threeControls.autoRotate = autoRotate;
        });
        
        document.getElementById('reset-view').addEventListener('click', () => {
            if (threeControls && threeCamera) {
                threeControls.reset();
                threeCamera.position.z = 5;
            }
        });
        
        document.getElementById('view-front').addEventListener('click', () => {
            if (threeControls && threeCamera) {
                threeControls.reset();
                threeCamera.position.set(0, 0, 5);
            }
        });
        
        document.getElementById('view-side').addEventListener('click', () => {
            if (threeControls && threeCamera) {
                threeControls.reset();
                threeCamera.position.set(5, 0, 0);
            }
        });
        
        document.getElementById('view-top').addEventListener('click', () => {
            if (threeControls && threeCamera) {
                threeControls.reset();
                threeCamera.position.set(0, 5, 0);
            }
        });
        
        // Functions
        function handleFileUpload(file) {
            if (!file.type.match('image.*')) {
                alert('Please upload an image file');
                return;
            }
            
            selectedFile = file;
            
            // Show preview
            const reader = new FileReader();
            reader.onload = (e) => {
                imagePreview.src = e.target.result;
                previewContainer.classList.remove('hidden');
                modelSelection.classList.remove('hidden');
            };
            reader.readAsDataURL(file);
        }
        
        async function processImageWithModel(modelType, file) {
            // Simulate progress for demo purposes
            let progress = 0;
            const interval = setInterval(() => {
                progress += Math.random() * 5;
                if (progress > 100) progress = 100;
                progressBar.style.width = `${progress}%`;
                progressText.textContent = `${Math.floor(progress)}%`;
                
                // Update messages based on progress
                if (progress < 30) {
                    processingMessage.textContent = modelType === 'triposr' 
                        ? "Uploading image to TripoSR model..." 
                        : "Uploading image to Real3D model...";
                } else if (progress < 70) {
                    processingMessage.textContent = modelType === 'triposr' 
                        ? "Generating 3D reconstruction..." 
                        : "Creating high-quality 3D face model...";
                } else {
                    processingMessage.textContent = "Finalizing and preparing your 3D model...";
                }
                
                if (progress === 100) {
                    clearInterval(interval);
                    setTimeout(() => {
                        processingSection.classList.add('hidden');
                        showResults(modelType);
                    }, 1000);
                }
            }, 500);
            
            // In a real implementation, you would call the Hugging Face API here
            // For example:
            /*
            try {
                const formData = new FormData();
                formData.append('image', file);
                
                const endpoint = modelType === 'triposr' 
                    ? 'https://api-inference.huggingface.co/models/stabilityai/TripoSR' 
                    : 'https://api-inference.huggingface.co/models/hwjiang/Real3D';
                
                const response = await fetch(endpoint, {
                    method: 'POST',
                    headers: {
                        'Authorization': 'Bearer YOUR_HUGGINGFACE_TOKEN',
                    },
                    body: formData
                });
                
                const result = await response.json();
                return result;
            } catch (error) {
                console.error('Error:', error);
                throw error;
            }
            */
        }
        
        function showResults(modelType) {
            // Update model info
            const modelName = modelType === 'triposr' ? 'TripoSR' : 'Real3D';
            document.getElementById('model-type').textContent = modelName;
            modelUsed.textContent = modelName;
            
            // Generate random stats for demo
            const vertices = modelType === 'triposr' 
                ? Math.floor(Math.random() * 15000 + 5000) 
                : Math.floor(Math.random() * 25000 + 10000);
            
            const faces = modelType === 'triposr' 
                ? Math.floor(Math.random() * 7500 + 2500) 
                : Math.floor(Math.random() * 12500 + 5000);
            
            const time = modelType === 'triposr' 
                ? (Math.random() * 10 + 20).toFixed(1) 
                : (Math.random() * 30 + 60).toFixed(1);
            
            document.getElementById('vertex-count').textContent = vertices.toLocaleString();
            document.getElementById('face-count').textContent = faces.toLocaleString();
            document.getElementById('processing-time').textContent = `${time}s`;
            
            // Initialize 3D viewer with appropriate model
            init3DViewer(modelType);
            
            // Show results
            resultSection.classList.add('show');
        }
        
        function init3DViewer(modelType) {
            const canvas = document.getElementById('3d-viewer');
            
            // Clear previous renderer if exists
            if (threeRenderer) {
                threeRenderer.dispose();
            }
            
            threeRenderer = new THREE.WebGLRenderer({ 
                canvas, 
                antialias: true,
                alpha: true
            });
            threeRenderer.setSize(canvas.clientWidth, canvas.clientHeight);
            threeRenderer.setClearColor(0xf0f0f0, 1);
            
            threeScene = new THREE.Scene();
            
            threeCamera = new THREE.PerspectiveCamera(45, canvas.clientWidth / canvas.clientHeight, 0.1, 1000);
            threeCamera.position.z = 5;
            
            threeControls = new THREE.OrbitControls(threeCamera, canvas);
            threeControls.enableDamping = true;
            threeControls.dampingFactor = 0.25;
            threeControls.autoRotate = autoRotate;
            
            // Add lights
            const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
            threeScene.add(ambientLight);
            
            const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
            directionalLight.position.set(1, 1, 1);
            threeScene.add(directionalLight);
            
            // Create different models based on selected type
            if (modelType === 'real3d') {
                // Create a face-like geometry for Real3D
                const geometry = new THREE.SphereGeometry(1, 64, 64);
                
                // Create texture from uploaded image
                const texture = new THREE.Texture(imagePreview);
                texture.needsUpdate = true;
                
                const material = new THREE.MeshPhongMaterial({
                    map: texture,
                    specular: 0x111111,
                    shininess: 30,
                    side: THREE.DoubleSide
                });
                
                threeModel = new THREE.Mesh(geometry, material);
            } else {
                // Create a more complex object for TripoSR
                const geometry = new THREE.TorusKnotGeometry(0.7, 0.2, 100, 16);
                
                // Create texture from uploaded image
                const texture = new THREE.Texture(imagePreview);
                texture.needsUpdate = true;
                
                const material = new THREE.MeshPhongMaterial({
                    map: texture,
                    specular: 0x111111,
                    shininess: 30
                });
                
                threeModel = new THREE.Mesh(geometry, material);
            }
            
            threeScene.add(threeModel);
            
            // Animation loop
            function animate() {
                requestAnimationFrame(animate);
                
                if (threeControls) {
                    threeControls.update();
                }
                
                threeRenderer.render(threeScene, threeCamera);
            }
            
            animate();
            
            // Handle resize
            window.addEventListener('resize', () => {
                threeCamera.aspect = canvas.clientWidth / canvas.clientHeight;
                threeCamera.updateProjectionMatrix();
                threeRenderer.setSize(canvas.clientWidth, canvas.clientHeight);
            });
        }
        
        function resetForm() {
            selectedFile = null;
            selectedModel = null;
            
            previewContainer.classList.add('hidden');
            modelSelection.classList.add('hidden');
            generateBtn.classList.add('hidden');
            processingSection.classList.add('hidden');
            resultSection.classList.remove('show');
            modelBadge.classList.add('hidden');
            
            fileUpload.value = '';
            modelCards.forEach(c => c.classList.remove('selected'));
            
            // Reset progress bar
            progressBar.style.width = '0%';
            progressText.textContent = '0%';
            
            // Clear 3D viewer if exists
            if (threeScene && threeModel) {
                threeScene.remove(threeModel);
                threeModel = null;
            }
        }
        
        // Download buttons functionality (simulated)
        document.getElementById('download-obj').addEventListener('click', () => {
            alert('In a real implementation, this would download the OBJ file generated by the model');
        });
        
        document.getElementById('download-stl').addEventListener('click', () => {
            alert('In a real implementation, this would download the STL file generated by the model');
        });
        
        document.getElementById('download-gltf').addEventListener('click', () => {
            alert('In a real implementation, this would download the GLTF file generated by the model');
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=vishnumeher/vhn-3d" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>