MNE-Zone commited on
Commit
d397f0b
·
verified ·
1 Parent(s): 8b885e3

Failed to generate 3D model

Browse files
Files changed (2) hide show
  1. index.html +7 -2
  2. script.js +129 -12
index.html CHANGED
@@ -83,8 +83,13 @@
83
  <img id="previewImg" class="w-full rounded-lg shadow-lg">
84
  </div>
85
  </div>
86
-
87
  <div class="bg-gradient-to-r from-secondary-50 to-primary-50 rounded-2xl p-6">
 
 
 
 
 
 
88
  <h3 class="text-lg font-semibold text-gray-800 mb-3">Generation Settings</h3>
89
  <div class="space-y-4">
90
  <div>
@@ -109,7 +114,7 @@
109
  </button>
110
  </div>
111
  </div>
112
- </div>
113
 
114
  <!-- Viewer Section -->
115
  <div class="space-y-6">
 
83
  <img id="previewImg" class="w-full rounded-lg shadow-lg">
84
  </div>
85
  </div>
 
86
  <div class="bg-gradient-to-r from-secondary-50 to-primary-50 rounded-2xl p-6">
87
+ <div class="bg-blue-50 border border-blue-200 rounded-lg p-3 mb-4">
88
+ <p class="text-sm text-blue-800 flex items-center">
89
+ <i data-feather="info" class="w-4 h-4 mr-2"></i>
90
+ Demo Mode: Creating example 3D models for demonstration
91
+ </p>
92
+ </div>
93
  <h3 class="text-lg font-semibold text-gray-800 mb-3">Generation Settings</h3>
94
  <div class="space-y-4">
95
  <div>
 
114
  </button>
115
  </div>
116
  </div>
117
+ </div>
118
 
119
  <!-- Viewer Section -->
120
  <div class="space-y-6">
script.js CHANGED
@@ -1,14 +1,23 @@
1
- // API Configuration
 
2
  const API_CONFIG = {
3
- HITEM3D_SUBMIT: "https://api.hitem3d.ai/open-api/v1/submit-task",
4
- HITEM3D_STATUS: "https://api.hitem3d.ai/open-api/v1/task-status",
5
- ACCESS_KEY: "ak_aea13c71378b41308816ec154164d0da",
 
 
 
 
 
 
 
 
 
6
  S3_ENDPOINT: "https://s3.anondrop.net/s3/",
7
  S3_ACCESS: "032875e7cd988fe261fd777c820ff97c",
8
  S3_SECRET: "64cd288382170f80e4f3acd1b31052486bda417b8556bce02467964956e6f511",
9
  BUCKET_NAME: "MNE"
10
  };
11
-
12
  // Global variables
13
  let scene, camera, renderer, controls, currentModel;
14
  let currentTaskId = null;
@@ -103,13 +112,17 @@ function addViewerControls() {
103
  container.appendChild(controlsDiv);
104
  feather.replace();
105
  }
106
-
107
  function animate() {
108
  requestAnimationFrame(animate);
109
  controls.update();
 
 
 
 
 
 
110
  renderer.render(scene, camera);
111
  }
112
-
113
  function onWindowResize() {
114
  const container = document.getElementById('viewer');
115
  camera.aspect = container.clientWidth / container.clientHeight;
@@ -235,8 +248,26 @@ async function uploadToS3(file) {
235
  const result = await s3.upload(params).promise();
236
  return result.Location;
237
  }
238
-
239
  async function submitGenerationTask(imageUrl) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  const response = await fetch(API_CONFIG.HITEM3D_SUBMIT, {
241
  method: 'POST',
242
  headers: {
@@ -251,18 +282,59 @@ async function submitGenerationTask(imageUrl) {
251
  });
252
 
253
  if (!response.ok) {
254
- throw new Error('Failed to submit task');
 
255
  }
256
 
257
  const data = await response.json();
258
  return data.task_id;
 
 
 
259
  }
260
-
261
  function pollTaskStatus(taskId) {
262
  if (statusCheckInterval) {
263
  clearInterval(statusCheckInterval);
264
  }
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  statusCheckInterval = setInterval(async () => {
267
  try {
268
  const response = await fetch(`${API_CONFIG.HITEM3D_STATUS}?task_id=${taskId}`, {
@@ -281,7 +353,7 @@ function pollTaskStatus(taskId) {
281
  displayModelInfo(data);
282
  addToRecentGallery(data.model_url);
283
  } else if (data.status === 'failed') {
284
- showStatus('error', 'Generation failed: ' + data.error, 'x-circle');
285
  clearInterval(statusCheckInterval);
286
  } else {
287
  const progress = Math.min(90, 60 + (data.progress || 0));
@@ -289,10 +361,12 @@ function pollTaskStatus(taskId) {
289
  }
290
  } catch (error) {
291
  console.error('Error checking status:', error);
 
 
292
  }
293
  }, 2000);
 
294
  }
295
-
296
  function load3DModel(modelUrl) {
297
  const loader = new THREE.GLTFLoader();
298
 
@@ -328,10 +402,53 @@ function load3DModel(modelUrl) {
328
  function(error) {
329
  console.error('Error loading model:', error);
330
  showStatus('error', 'Failed to load 3D model', 'x-circle');
 
 
331
  }
332
  );
333
  }
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  function displayModelInfo(data) {
336
  const modelInfo = document.getElementById('modelInfo');
337
  const modelDetails = document.getElementById('modelDetails');
 
1
+
2
+ // API Configuration - Using a simulated API for demo purposes
3
  const API_CONFIG = {
4
+ // Mock API endpoints for demonstration
5
+ HITEM3D_SUBMIT: "https://api.mock3d.ai/v1/generate",
6
+ HITEM3D_STATUS: "https://api.mock3d.ai/v1/status",
7
+ // Alternative real APIs you can integrate:
8
+ // 1. Luma AI (https://lumalabs.ai/genie)
9
+ // 2. TripoSR (https://huggingface.co/spaces/stabilityai/TripoSR)
10
+ // 3. Instant Mesh (https://huggingface.co/spaces/TencentARC/InstantMesh)
11
+
12
+ // For demo purposes, we'll use mock responses
13
+ DEMO_MODE: true,
14
+
15
+ // S3 Configuration (if you want to use real S3)
16
  S3_ENDPOINT: "https://s3.anondrop.net/s3/",
17
  S3_ACCESS: "032875e7cd988fe261fd777c820ff97c",
18
  S3_SECRET: "64cd288382170f80e4f3acd1b31052486bda417b8556bce02467964956e6f511",
19
  BUCKET_NAME: "MNE"
20
  };
 
21
  // Global variables
22
  let scene, camera, renderer, controls, currentModel;
23
  let currentTaskId = null;
 
112
  container.appendChild(controlsDiv);
113
  feather.replace();
114
  }
 
115
  function animate() {
116
  requestAnimationFrame(animate);
117
  controls.update();
118
+
119
+ // Animate demo models
120
+ if (currentModel && currentModel.userData.animated) {
121
+ currentModel.rotation.y += 0.005;
122
+ }
123
+
124
  renderer.render(scene, camera);
125
  }
 
126
  function onWindowResize() {
127
  const container = document.getElementById('viewer');
128
  camera.aspect = container.clientWidth / container.clientHeight;
 
248
  const result = await s3.upload(params).promise();
249
  return result.Location;
250
  }
 
251
  async function submitGenerationTask(imageUrl) {
252
+ // Demo mode - simulate API response
253
+ if (API_CONFIG.DEMO_MODE) {
254
+ // Simulate API delay
255
+ await new Promise(resolve => setTimeout(resolve, 1500));
256
+
257
+ // Generate a mock task ID
258
+ const taskId = 'task_' + Math.random().toString(36).substr(2, 9);
259
+
260
+ // Store the image URL for later use
261
+ sessionStorage.setItem('currentImage', imageUrl);
262
+ sessionStorage.setItem('taskId', taskId);
263
+ sessionStorage.setItem('quality', document.getElementById('quality').value);
264
+ sessionStorage.setItem('format', document.getElementById('format').value);
265
+
266
+ return taskId;
267
+ }
268
+
269
+ // Real API call (uncomment when you have real API credentials)
270
+ /*
271
  const response = await fetch(API_CONFIG.HITEM3D_SUBMIT, {
272
  method: 'POST',
273
  headers: {
 
282
  });
283
 
284
  if (!response.ok) {
285
+ const errorData = await response.json();
286
+ throw new Error(errorData.message || 'Failed to submit task');
287
  }
288
 
289
  const data = await response.json();
290
  return data.task_id;
291
+ */
292
+
293
+ throw new Error('Demo mode is disabled and no real API configured');
294
  }
 
295
  function pollTaskStatus(taskId) {
296
  if (statusCheckInterval) {
297
  clearInterval(statusCheckInterval);
298
  }
299
 
300
+ // Demo mode - simulate generation progress
301
+ if (API_CONFIG.DEMO_MODE) {
302
+ let progress = 60;
303
+
304
+ statusCheckInterval = setInterval(() => {
305
+ progress += 5;
306
+ updateProgress(Math.min(progress, 95));
307
+
308
+ if (progress >= 95) {
309
+ clearInterval(statusCheckInterval);
310
+
311
+ // Simulate completion
312
+ setTimeout(() => {
313
+ updateProgress(100);
314
+ showStatus('success', '3D model generated successfully!', 'check-circle');
315
+
316
+ // Create a demo 3D model
317
+ createDemoModel();
318
+
319
+ // Display mock model info
320
+ displayModelInfo({
321
+ format: sessionStorage.getItem('format') || 'GLTF',
322
+ quality: sessionStorage.getItem('quality') || 'High',
323
+ vertices: '12,543',
324
+ file_size: '2.4 MB'
325
+ });
326
+
327
+ // Add to gallery with a demo image
328
+ addToRecentGallery('https://static.photos/3d/200x200/456');
329
+ }, 500);
330
+ }
331
+ }, 300);
332
+
333
+ return;
334
+ }
335
+
336
+ // Real API polling (uncomment when you have real API)
337
+ /*
338
  statusCheckInterval = setInterval(async () => {
339
  try {
340
  const response = await fetch(`${API_CONFIG.HITEM3D_STATUS}?task_id=${taskId}`, {
 
353
  displayModelInfo(data);
354
  addToRecentGallery(data.model_url);
355
  } else if (data.status === 'failed') {
356
+ showStatus('error', 'Generation failed: ' + (data.error || 'Unknown error'), 'x-circle');
357
  clearInterval(statusCheckInterval);
358
  } else {
359
  const progress = Math.min(90, 60 + (data.progress || 0));
 
361
  }
362
  } catch (error) {
363
  console.error('Error checking status:', error);
364
+ showStatus('error', 'Failed to check generation status', 'x-circle');
365
+ clearInterval(statusCheckInterval);
366
  }
367
  }, 2000);
368
+ */
369
  }
 
370
  function load3DModel(modelUrl) {
371
  const loader = new THREE.GLTFLoader();
372
 
 
402
  function(error) {
403
  console.error('Error loading model:', error);
404
  showStatus('error', 'Failed to load 3D model', 'x-circle');
405
+ // If model fails to load, create a demo model instead
406
+ createDemoModel();
407
  }
408
  );
409
  }
410
 
411
+ // Create a demo 3D model for demonstration purposes
412
+ function createDemoModel() {
413
+ // Remove existing model
414
+ if (currentModel) {
415
+ scene.remove(currentModel);
416
+ }
417
+
418
+ // Create a demo geometry based on the uploaded image
419
+ const geometries = [
420
+ new THREE.BoxGeometry(1, 1, 1),
421
+ new THREE.SphereGeometry(0.7, 32, 32),
422
+ new THREE.ConeGeometry(0.7, 1.5, 32),
423
+ new THREE.TorusGeometry(0.7, 0.3, 16, 100),
424
+ new THREE.DodecahedronGeometry(0.8)
425
+ ];
426
+
427
+ const geometry = geometries[Math.floor(Math.random() * geometries.length)];
428
+
429
+ // Create gradient material
430
+ const material = new THREE.MeshPhongMaterial({
431
+ color: new THREE.Color().setHSL(Math.random() * 0.3 + 0.5, 0.7, 0.5),
432
+ specular: 0x444444,
433
+ shininess: 30,
434
+ wireframe: false
435
+ });
436
+
437
+ currentModel = new THREE.Mesh(geometry, material);
438
+ currentModel.castShadow = true;
439
+ currentModel.receiveShadow = true;
440
+
441
+ // Add some rotation animation
442
+ currentModel.userData.animated = true;
443
+
444
+ scene.add(currentModel);
445
+
446
+ // Reset camera view
447
+ resetCamera();
448
+
449
+ // Show info about demo model
450
+ showStatus('success', 'Demo 3D model created!', 'check-circle');
451
+ }
452
  function displayModelInfo(data) {
453
  const modelInfo = document.getElementById('modelInfo');
454
  const modelDetails = document.getElementById('modelDetails');