Spaces:
Running
Running
cool it's working but we need to generate model with https://huggingface.co/spaces/ilcve21/Sparc3D. model - Initial Deployment
Browse files- README.md +6 -4
- index.html +487 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
title: 3dgen
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: 3dgen
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: red
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,487 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Model Generator with Sparc3D</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
.model-container {
|
| 11 |
+
width: 100%;
|
| 12 |
+
height: 400px;
|
| 13 |
+
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
| 14 |
+
border-radius: 12px;
|
| 15 |
+
display: flex;
|
| 16 |
+
justify-content: center;
|
| 17 |
+
align-items: center;
|
| 18 |
+
position: relative;
|
| 19 |
+
overflow: hidden;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.model-placeholder {
|
| 23 |
+
animation: pulse 2s infinite;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
@keyframes pulse {
|
| 27 |
+
0% { opacity: 0.5; }
|
| 28 |
+
50% { opacity: 0.8; }
|
| 29 |
+
100% { opacity: 0.5; }
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.loading-spinner {
|
| 33 |
+
width: 50px;
|
| 34 |
+
height: 50px;
|
| 35 |
+
border: 5px solid rgba(255,255,255,0.3);
|
| 36 |
+
border-radius: 50%;
|
| 37 |
+
border-top-color: #4f46e5;
|
| 38 |
+
animation: spin 1s ease-in-out infinite;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
@keyframes spin {
|
| 42 |
+
to { transform: rotate(360deg); }
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.model-view {
|
| 46 |
+
width: 100%;
|
| 47 |
+
height: 100%;
|
| 48 |
+
object-fit: contain;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.history-item {
|
| 52 |
+
transition: all 0.3s ease;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.history-item:hover {
|
| 56 |
+
transform: scale(1.02);
|
| 57 |
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body class="bg-gray-50 min-h-screen">
|
| 62 |
+
<div class="container mx-auto px-4 py-8">
|
| 63 |
+
<!-- Header -->
|
| 64 |
+
<header class="mb-10 text-center">
|
| 65 |
+
<h1 class="text-4xl md:text-5xl font-bold text-indigo-800 mb-3">3D Model Generator</h1>
|
| 66 |
+
<p class="text-lg text-gray-600 max-w-2xl mx-auto">
|
| 67 |
+
Create stunning 3D models from text prompts using the power of Sparc3D's AI technology
|
| 68 |
+
</p>
|
| 69 |
+
</header>
|
| 70 |
+
|
| 71 |
+
<!-- Main Content -->
|
| 72 |
+
<div class="flex flex-col lg:flex-row gap-8">
|
| 73 |
+
<!-- Generation Panel -->
|
| 74 |
+
<div class="lg:w-2/3">
|
| 75 |
+
<div class="bg-white rounded-xl shadow-lg p-6">
|
| 76 |
+
<h2 class="text-2xl font-semibold text-gray-800 mb-6">Generate New Model</h2>
|
| 77 |
+
|
| 78 |
+
<!-- Prompt Input -->
|
| 79 |
+
<div class="mb-6">
|
| 80 |
+
<label for="prompt" class="block text-sm font-medium text-gray-700 mb-2">Describe your 3D model</label>
|
| 81 |
+
<div class="flex gap-2">
|
| 82 |
+
<input
|
| 83 |
+
type="text"
|
| 84 |
+
id="prompt"
|
| 85 |
+
placeholder="e.g. A futuristic spaceship with glowing engines"
|
| 86 |
+
class="flex-1 px-4 py-3 rounded-lg border border-gray-300 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 outline-none transition"
|
| 87 |
+
>
|
| 88 |
+
<button id="generate-btn" class="px-6 py-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition flex items-center gap-2">
|
| 89 |
+
<i class="fas fa-magic"></i> Generate
|
| 90 |
+
</button>
|
| 91 |
+
</div>
|
| 92 |
+
</div>
|
| 93 |
+
|
| 94 |
+
<!-- Advanced Options (Collapsible) -->
|
| 95 |
+
<div class="mb-6">
|
| 96 |
+
<button id="advanced-toggle" class="flex items-center text-indigo-600 hover:text-indigo-800 transition mb-3">
|
| 97 |
+
<i class="fas fa-cog mr-2"></i>
|
| 98 |
+
Advanced Options
|
| 99 |
+
<i class="fas fa-chevron-down ml-2 text-sm transition-transform" id="advanced-arrow"></i>
|
| 100 |
+
</button>
|
| 101 |
+
|
| 102 |
+
<div id="advanced-options" class="hidden bg-gray-50 p-4 rounded-lg space-y-4">
|
| 103 |
+
<div>
|
| 104 |
+
<label for="style" class="block text-sm font-medium text-gray-700 mb-1">Style</label>
|
| 105 |
+
<select id="style" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
|
| 106 |
+
<option value="realistic">Realistic</option>
|
| 107 |
+
<option value="cartoon">Cartoon</option>
|
| 108 |
+
<option value="low-poly">Low Poly</option>
|
| 109 |
+
<option value="scifi">Sci-Fi</option>
|
| 110 |
+
</select>
|
| 111 |
+
</div>
|
| 112 |
+
|
| 113 |
+
<div>
|
| 114 |
+
<label for="quality" class="block text-sm font-medium text-gray-700 mb-1">Quality</label>
|
| 115 |
+
<select id="quality" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
|
| 116 |
+
<option value="low">Low (Faster)</option>
|
| 117 |
+
<option value="medium" selected>Medium</option>
|
| 118 |
+
<option value="high">High (Slower)</option>
|
| 119 |
+
</select>
|
| 120 |
+
</div>
|
| 121 |
+
|
| 122 |
+
<div>
|
| 123 |
+
<label for="color" class="block text-sm font-medium text-gray-700 mb-1">Primary Color</label>
|
| 124 |
+
<input type="color" id="color" value="#4f46e5" class="h-10 w-10 cursor-pointer">
|
| 125 |
+
</div>
|
| 126 |
+
</div>
|
| 127 |
+
</div>
|
| 128 |
+
|
| 129 |
+
<!-- Model Display -->
|
| 130 |
+
<div class="model-container mb-6">
|
| 131 |
+
<div id="model-placeholder" class="model-placeholder text-center p-6">
|
| 132 |
+
<i class="fas fa-cube text-6xl text-gray-400 mb-4"></i>
|
| 133 |
+
<p class="text-gray-500">Enter a prompt and click Generate to create your 3D model</p>
|
| 134 |
+
</div>
|
| 135 |
+
<div id="loading-indicator" class="hidden absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center">
|
| 136 |
+
<div class="loading-spinner"></div>
|
| 137 |
+
<p class="ml-3 text-white font-medium">Generating your 3D model...</p>
|
| 138 |
+
</div>
|
| 139 |
+
<iframe id="model-view" class="model-view hidden" frameborder="0"></iframe>
|
| 140 |
+
<iframe id="sparc3d-iframe" src="https://ilcve21-sparc3d.hf.space" class="hidden w-full h-full"></iframe>
|
| 141 |
+
</div>
|
| 142 |
+
|
| 143 |
+
<!-- Action Buttons -->
|
| 144 |
+
<div class="flex flex-wrap gap-3">
|
| 145 |
+
<button id="download-btn" class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition flex items-center gap-2 disabled:opacity-50" disabled>
|
| 146 |
+
<i class="fas fa-download"></i> Download
|
| 147 |
+
</button>
|
| 148 |
+
<button id="share-btn" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition flex items-center gap-2 disabled:opacity-50" disabled>
|
| 149 |
+
<i class="fas fa-share-alt"></i> Share
|
| 150 |
+
</button>
|
| 151 |
+
<button id="regenerate-btn" class="px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition flex items-center gap-2">
|
| 152 |
+
<i class="fas fa-sync-alt"></i> Regenerate
|
| 153 |
+
</button>
|
| 154 |
+
</div>
|
| 155 |
+
</div>
|
| 156 |
+
</div>
|
| 157 |
+
|
| 158 |
+
<!-- History Panel -->
|
| 159 |
+
<div class="lg:w-1/3">
|
| 160 |
+
<div class="bg-white rounded-xl shadow-lg p-6 h-full">
|
| 161 |
+
<div class="flex justify-between items-center mb-6">
|
| 162 |
+
<h2 class="text-2xl font-semibold text-gray-800">Your History</h2>
|
| 163 |
+
<button id="clear-history" class="text-sm text-red-500 hover:text-red-700 flex items-center gap-1">
|
| 164 |
+
<i class="fas fa-trash"></i> Clear
|
| 165 |
+
</button>
|
| 166 |
+
</div>
|
| 167 |
+
|
| 168 |
+
<div id="history-list" class="space-y-3 max-h-[600px] overflow-y-auto pr-2">
|
| 169 |
+
<!-- History items will be added here -->
|
| 170 |
+
<div class="text-center py-10 text-gray-400" id="empty-history-message">
|
| 171 |
+
<i class="fas fa-history text-4xl mb-3"></i>
|
| 172 |
+
<p>Your generated models will appear here</p>
|
| 173 |
+
</div>
|
| 174 |
+
</div>
|
| 175 |
+
</div>
|
| 176 |
+
</div>
|
| 177 |
+
</div>
|
| 178 |
+
|
| 179 |
+
<!-- Info Section -->
|
| 180 |
+
<div class="mt-12 bg-indigo-50 rounded-xl p-6">
|
| 181 |
+
<h3 class="text-xl font-semibold text-indigo-800 mb-3">About Sparc3D</h3>
|
| 182 |
+
<p class="text-gray-700 mb-4">
|
| 183 |
+
This app uses <a href="https://lizhihao6.github.io/Sparc3D/" target="_blank" class="text-indigo-600 hover:underline">Sparc3D</a>, a free AI-powered 3D model generator that creates high-quality 3D assets from text descriptions.
|
| 184 |
+
</p>
|
| 185 |
+
<div class="grid md:grid-cols-3 gap-4">
|
| 186 |
+
<div class="bg-white p-4 rounded-lg shadow">
|
| 187 |
+
<i class="fas fa-bolt text-indigo-500 text-2xl mb-2"></i>
|
| 188 |
+
<h4 class="font-medium text-gray-800">Fast Generation</h4>
|
| 189 |
+
<p class="text-sm text-gray-600">Create 3D models in minutes instead of hours</p>
|
| 190 |
+
</div>
|
| 191 |
+
<div class="bg-white p-4 rounded-lg shadow">
|
| 192 |
+
<i class="fas fa-paint-brush text-indigo-500 text-2xl mb-2"></i>
|
| 193 |
+
<h4 class="font-medium text-gray-800">Customizable</h4>
|
| 194 |
+
<p class="text-sm text-gray-600">Control style, quality and colors of your models</p>
|
| 195 |
+
</div>
|
| 196 |
+
<div class="bg-white p-4 rounded-lg shadow">
|
| 197 |
+
<i class="fas fa-download text-indigo-500 text-2xl mb-2"></i>
|
| 198 |
+
<h4 class="font-medium text-gray-800">Free to Use</h4>
|
| 199 |
+
<p class="text-sm text-gray-600">Download your creations without any cost</p>
|
| 200 |
+
</div>
|
| 201 |
+
</div>
|
| 202 |
+
</div>
|
| 203 |
+
</div>
|
| 204 |
+
|
| 205 |
+
<script>
|
| 206 |
+
// Listen for messages from the Sparc3D iframe
|
| 207 |
+
window.addEventListener('message', (event) => {
|
| 208 |
+
if (event.origin !== 'https://ilcve21-sparc3d.hf.space') return;
|
| 209 |
+
|
| 210 |
+
if (event.data.type === 'model-ready') {
|
| 211 |
+
const modelUrl = event.data.url;
|
| 212 |
+
document.getElementById('model-view').src = modelUrl;
|
| 213 |
+
document.getElementById('sparc3d-iframe').classList.add('hidden');
|
| 214 |
+
document.getElementById('model-view').classList.remove('hidden');
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
if (event.data.type === 'generation-error') {
|
| 218 |
+
console.error('Generation error:', event.data.error);
|
| 219 |
+
// Show error message to user
|
| 220 |
+
}
|
| 221 |
+
});
|
| 222 |
+
|
| 223 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 224 |
+
// DOM Elements
|
| 225 |
+
const promptInput = document.getElementById('prompt');
|
| 226 |
+
const generateBtn = document.getElementById('generate-btn');
|
| 227 |
+
const regenerateBtn = document.getElementById('regenerate-btn');
|
| 228 |
+
const downloadBtn = document.getElementById('download-btn');
|
| 229 |
+
const shareBtn = document.getElementById('share-btn');
|
| 230 |
+
const advancedToggle = document.getElementById('advanced-toggle');
|
| 231 |
+
const advancedOptions = document.getElementById('advanced-options');
|
| 232 |
+
const advancedArrow = document.getElementById('advanced-arrow');
|
| 233 |
+
const modelPlaceholder = document.getElementById('model-placeholder');
|
| 234 |
+
const loadingIndicator = document.getElementById('loading-indicator');
|
| 235 |
+
const modelView = document.getElementById('model-view');
|
| 236 |
+
const historyList = document.getElementById('history-list');
|
| 237 |
+
const emptyHistoryMessage = document.getElementById('empty-history-message');
|
| 238 |
+
const clearHistoryBtn = document.getElementById('clear-history');
|
| 239 |
+
|
| 240 |
+
// Toggle advanced options
|
| 241 |
+
advancedToggle.addEventListener('click', function() {
|
| 242 |
+
advancedOptions.classList.toggle('hidden');
|
| 243 |
+
advancedArrow.classList.toggle('rotate-180');
|
| 244 |
+
});
|
| 245 |
+
|
| 246 |
+
// Generate model function using Sparc3D Hugging Face Space
|
| 247 |
+
async function generateModel(prompt, style = 'realistic', quality = 'medium', color = '#4f46e5') {
|
| 248 |
+
if (!prompt.trim()) {
|
| 249 |
+
alert('Please enter a description for your 3D model');
|
| 250 |
+
return;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
// Show loading state
|
| 254 |
+
modelPlaceholder.classList.add('hidden');
|
| 255 |
+
loadingIndicator.classList.remove('hidden');
|
| 256 |
+
modelView.classList.add('hidden');
|
| 257 |
+
|
| 258 |
+
try {
|
| 259 |
+
// Show the Sparc3D iframe
|
| 260 |
+
const sparc3dIframe = document.getElementById('sparc3d-iframe');
|
| 261 |
+
sparc3dIframe.classList.remove('hidden');
|
| 262 |
+
|
| 263 |
+
// Wait for iframe to load
|
| 264 |
+
await new Promise(resolve => {
|
| 265 |
+
sparc3dIframe.onload = resolve;
|
| 266 |
+
});
|
| 267 |
+
|
| 268 |
+
// Send message to iframe with prompt
|
| 269 |
+
sparc3dIframe.contentWindow.postMessage({
|
| 270 |
+
type: 'generate',
|
| 271 |
+
prompt: prompt,
|
| 272 |
+
style: style,
|
| 273 |
+
quality: quality,
|
| 274 |
+
color: color
|
| 275 |
+
}, 'https://ilcve21-sparc3d.hf.space');
|
| 276 |
+
|
| 277 |
+
// Hide loading indicator
|
| 278 |
+
loadingIndicator.classList.add('hidden');
|
| 279 |
+
|
| 280 |
+
// Enable download and share buttons
|
| 281 |
+
downloadBtn.disabled = false;
|
| 282 |
+
shareBtn.disabled = false;
|
| 283 |
+
|
| 284 |
+
// Add to history
|
| 285 |
+
addToHistory(prompt, 'https://ilcve21-sparc3d.hf.space');
|
| 286 |
+
|
| 287 |
+
} catch (error) {
|
| 288 |
+
console.error('Error generating model:', error);
|
| 289 |
+
loadingIndicator.classList.add('hidden');
|
| 290 |
+
modelPlaceholder.classList.remove('hidden');
|
| 291 |
+
|
| 292 |
+
// Create and show error message
|
| 293 |
+
const errorElement = document.createElement('div');
|
| 294 |
+
errorElement.className = 'bg-red-50 border-l-4 border-red-500 p-4 mb-4';
|
| 295 |
+
errorElement.innerHTML = `
|
| 296 |
+
<div class="flex">
|
| 297 |
+
<div class="flex-shrink-0">
|
| 298 |
+
<i class="fas fa-exclamation-circle text-red-500"></i>
|
| 299 |
+
</div>
|
| 300 |
+
<div class="ml-3">
|
| 301 |
+
<p class="text-sm text-red-700">
|
| 302 |
+
Failed to generate model. Please try again later.
|
| 303 |
+
</p>
|
| 304 |
+
</div>
|
| 305 |
+
</div>
|
| 306 |
+
`;
|
| 307 |
+
|
| 308 |
+
// Insert error message above the model container
|
| 309 |
+
modelContainer.insertAdjacentElement('beforebegin', errorElement);
|
| 310 |
+
|
| 311 |
+
// Remove error after 5 seconds
|
| 312 |
+
setTimeout(() => {
|
| 313 |
+
errorElement.remove();
|
| 314 |
+
}, 5000);
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
// Add generated model to history
|
| 319 |
+
function addToHistory(prompt, modelUrl) {
|
| 320 |
+
// Remove empty message if it's the first item
|
| 321 |
+
if (emptyHistoryMessage) {
|
| 322 |
+
emptyHistoryMessage.remove();
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
const historyItem = document.createElement('div');
|
| 326 |
+
historyItem.className = 'history-item bg-gray-50 rounded-lg p-4 cursor-pointer hover:bg-indigo-50 border border-gray-200';
|
| 327 |
+
historyItem.innerHTML = `
|
| 328 |
+
<div class="flex items-start gap-3">
|
| 329 |
+
<div class="bg-indigo-100 p-2 rounded-lg">
|
| 330 |
+
<i class="fas fa-cube text-indigo-600"></i>
|
| 331 |
+
</div>
|
| 332 |
+
<div class="flex-1">
|
| 333 |
+
<h4 class="font-medium text-gray-800 line-clamp-1">${prompt}</h4>
|
| 334 |
+
<p class="text-xs text-gray-500 mb-2">Just now</p>
|
| 335 |
+
<div class="flex gap-2">
|
| 336 |
+
<button class="view-btn text-xs px-3 py-1 bg-indigo-100 text-indigo-700 rounded hover:bg-indigo-200 transition">
|
| 337 |
+
<i class="fas fa-eye mr-1"></i> View
|
| 338 |
+
</button>
|
| 339 |
+
<button class="download-btn text-xs px-3 py-1 bg-green-100 text-green-700 rounded hover:bg-green-200 transition">
|
| 340 |
+
<i class="fas fa-download mr-1"></i> Download
|
| 341 |
+
</button>
|
| 342 |
+
</div>
|
| 343 |
+
</div>
|
| 344 |
+
</div>
|
| 345 |
+
`;
|
| 346 |
+
|
| 347 |
+
// Add click handlers
|
| 348 |
+
const viewBtn = historyItem.querySelector('.view-btn');
|
| 349 |
+
const downloadBtn = historyItem.querySelector('.download-btn');
|
| 350 |
+
|
| 351 |
+
viewBtn.addEventListener('click', (e) => {
|
| 352 |
+
e.stopPropagation();
|
| 353 |
+
modelPlaceholder.classList.add('hidden');
|
| 354 |
+
modelView.classList.remove('hidden');
|
| 355 |
+
modelView.src = modelUrl;
|
| 356 |
+
});
|
| 357 |
+
|
| 358 |
+
downloadBtn.addEventListener('click', (e) => {
|
| 359 |
+
e.stopPropagation();
|
| 360 |
+
downloadModel(modelUrl, prompt);
|
| 361 |
+
});
|
| 362 |
+
|
| 363 |
+
historyItem.addEventListener('click', () => {
|
| 364 |
+
modelPlaceholder.classList.add('hidden');
|
| 365 |
+
modelView.classList.remove('hidden');
|
| 366 |
+
modelView.src = modelUrl;
|
| 367 |
+
});
|
| 368 |
+
|
| 369 |
+
// Add to top of history
|
| 370 |
+
historyList.insertBefore(historyItem, historyList.firstChild);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
// Download model function
|
| 374 |
+
async function downloadModel(url, prompt) {
|
| 375 |
+
try {
|
| 376 |
+
const response = await fetch(url);
|
| 377 |
+
if (!response.ok) {
|
| 378 |
+
throw new Error('Failed to download model');
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
const blob = await response.blob();
|
| 382 |
+
const downloadUrl = window.URL.createObjectURL(blob);
|
| 383 |
+
|
| 384 |
+
const link = document.createElement('a');
|
| 385 |
+
link.href = downloadUrl;
|
| 386 |
+
link.download = `3d-model-${prompt.substring(0, 20).toLowerCase().replace(/\s+/g, '-')}.glb`;
|
| 387 |
+
document.body.appendChild(link);
|
| 388 |
+
link.click();
|
| 389 |
+
|
| 390 |
+
// Clean up
|
| 391 |
+
setTimeout(() => {
|
| 392 |
+
document.body.removeChild(link);
|
| 393 |
+
window.URL.revokeObjectURL(downloadUrl);
|
| 394 |
+
}, 100);
|
| 395 |
+
|
| 396 |
+
} catch (error) {
|
| 397 |
+
console.error('Error downloading model:', error);
|
| 398 |
+
alert('Failed to download model. Please try again.');
|
| 399 |
+
}
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
// Share model function
|
| 403 |
+
function shareModel() {
|
| 404 |
+
if (navigator.share) {
|
| 405 |
+
navigator.share({
|
| 406 |
+
title: 'Check out this 3D model I created',
|
| 407 |
+
text: `I created a 3D model of "${promptInput.value}" using Sparc3D`,
|
| 408 |
+
url: window.location.href,
|
| 409 |
+
})
|
| 410 |
+
.catch(err => {
|
| 411 |
+
console.error('Error sharing:', err);
|
| 412 |
+
});
|
| 413 |
+
} else {
|
| 414 |
+
// Fallback for browsers that don't support Web Share API
|
| 415 |
+
alert('Web Share API not supported in your browser. Copy this link to share: ' + window.location.href);
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
// Get model container element
|
| 420 |
+
const modelContainer = document.querySelector('.model-container');
|
| 421 |
+
|
| 422 |
+
// Event listeners
|
| 423 |
+
generateBtn.addEventListener('click', function() {
|
| 424 |
+
// Clear any previous errors
|
| 425 |
+
const existingError = document.querySelector('.bg-red-50');
|
| 426 |
+
if (existingError) {
|
| 427 |
+
existingError.remove();
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
const prompt = promptInput.value;
|
| 431 |
+
const style = document.getElementById('style').value;
|
| 432 |
+
const quality = document.getElementById('quality').value;
|
| 433 |
+
const color = document.getElementById('color').value;
|
| 434 |
+
generateModel(prompt, style, quality, color);
|
| 435 |
+
});
|
| 436 |
+
|
| 437 |
+
regenerateBtn.addEventListener('click', function() {
|
| 438 |
+
if (!promptInput.value.trim()) {
|
| 439 |
+
alert('Please enter a description first');
|
| 440 |
+
return;
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
const prompt = promptInput.value;
|
| 444 |
+
const style = document.getElementById('style').value;
|
| 445 |
+
const quality = document.getElementById('quality').value;
|
| 446 |
+
const color = document.getElementById('color').value;
|
| 447 |
+
generateModel(prompt, style, quality, color);
|
| 448 |
+
});
|
| 449 |
+
|
| 450 |
+
downloadBtn.addEventListener('click', function() {
|
| 451 |
+
if (modelView.src) {
|
| 452 |
+
const prompt = promptInput.value || 'my-3d-model';
|
| 453 |
+
downloadModel(modelView.src, prompt);
|
| 454 |
+
}
|
| 455 |
+
});
|
| 456 |
+
|
| 457 |
+
shareBtn.addEventListener('click', shareModel);
|
| 458 |
+
|
| 459 |
+
clearHistoryBtn.addEventListener('click', function() {
|
| 460 |
+
if (confirm('Are you sure you want to clear your generation history?')) {
|
| 461 |
+
historyList.innerHTML = `
|
| 462 |
+
<div class="text-center py-10 text-gray-400" id="empty-history-message">
|
| 463 |
+
<i class="fas fa-history text-4xl mb-3"></i>
|
| 464 |
+
<p>Your generated models will appear here</p>
|
| 465 |
+
</div>
|
| 466 |
+
`;
|
| 467 |
+
}
|
| 468 |
+
});
|
| 469 |
+
|
| 470 |
+
// Load any saved history from localStorage
|
| 471 |
+
function loadHistory() {
|
| 472 |
+
// In a real app, you would load from localStorage or a backend
|
| 473 |
+
// This is just a placeholder
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
loadHistory();
|
| 477 |
+
|
| 478 |
+
// Allow pressing Enter in the prompt input to generate
|
| 479 |
+
promptInput.addEventListener('keypress', function(e) {
|
| 480 |
+
if (e.key === 'Enter') {
|
| 481 |
+
generateBtn.click();
|
| 482 |
+
}
|
| 483 |
+
});
|
| 484 |
+
});
|
| 485 |
+
</script>
|
| 486 |
+
<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=blacksiders/3dgen" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 487 |
+
</html>
|