imlixinyang commited on
Commit
e22885d
·
verified ·
1 Parent(s): 3ac1f26

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +54 -1
index.html CHANGED
@@ -688,6 +688,7 @@
688
  let inputImageBase64 = null;
689
  let inputImageResolution = null;
690
  let currentGeneratedSplat = null; // 跟踪当前生成的场景
 
691
 
692
  // UI Elements
693
  const loadingElement = document.getElementById('loading');
@@ -882,6 +883,10 @@
882
 
883
  const blob = new Blob(chunks);
884
  const url = URL.createObjectURL(blob);
 
 
 
 
885
  // Continue to load the splat
886
  updateStatus('Loading generated scene...', cameraParams.length);
887
 
@@ -891,6 +896,11 @@
891
  updateStatus('Scene generated successfully!', cameraParams.length);
892
  // Show generation time and total file size (MB)
893
  showGenerationInfo(latestGenerationTime || 0, total || blob.size);
 
 
 
 
 
894
  // Notify backend to delete the server file after client has downloaded it
895
  try {
896
  if (info.file_id) {
@@ -971,7 +981,7 @@
971
  // GUI Options - declare early
972
  const guiOptions = {
973
  // 后端地址,默认为本页面ip
974
- BackendAddress: `https://imlixinyang-flashworld-demo.hf.space`,
975
  HF_TOKEN: "",
976
  FOV: 60,
977
  LoadFromJson: () => {
@@ -1130,6 +1140,27 @@
1130
  // Playback scrub value (0..1)
1131
  playbackT: 0,
1132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1133
  generate: () => {
1134
  // 检查是否有足够的相机
1135
  if (cameraParams.length < 2) {
@@ -1147,6 +1178,14 @@
1147
  console.log('Previous generated scene removed');
1148
  }
1149
 
 
 
 
 
 
 
 
 
1150
  // 初始化进度条信息
1151
  const generationTimeElement = document.getElementById('generation-time');
1152
  const fileSizeElement = document.getElementById('file-size');
@@ -1295,6 +1334,9 @@
1295
  });
1296
  }
1297
  return pump().then(blob => {
 
 
 
1298
  const url = URL.createObjectURL(blob);
1299
  return { url, __deleteAfterDownloadFileId: (typeof responseData !== 'undefined' ? responseData.file_id : null) };
1300
  });
@@ -1313,6 +1355,12 @@
1313
  currentGeneratedSplat = GeneratedSplat;
1314
  console.log('3D scene loaded successfully!');
1315
  updateStatus('Scene generated successfully!', cameraParams.length);
 
 
 
 
 
 
1316
  hideDownloadProgress();
1317
  showLoading(false);
1318
 
@@ -2054,8 +2102,13 @@
2054
  // Step 4: Generate Your Scene
2055
  const step4Folder = gui.addFolder('4. Generate Scene');
2056
  step4Folder.add(guiOptions, "generate").name("Generate!");
 
 
2057
  step4Folder.open();
2058
 
 
 
 
2059
  // Step 5: Trajectory Playback (Scrubber)
2060
  const step5Folder = gui.addFolder('5. Trajectory Playback');
2061
  step5Folder.add(guiOptions, 'playbackT', 0, 1, 0.001).name('Scrub (0-1)').onChange((value) => {
 
688
  let inputImageBase64 = null;
689
  let inputImageResolution = null;
690
  let currentGeneratedSplat = null; // 跟踪当前生成的场景
691
+ let currentDownloadedBlob = null; // 保存已下载的文件blob
692
 
693
  // UI Elements
694
  const loadingElement = document.getElementById('loading');
 
883
 
884
  const blob = new Blob(chunks);
885
  const url = URL.createObjectURL(blob);
886
+
887
+ // 保存blob供后续下载使用
888
+ currentDownloadedBlob = blob;
889
+
890
  // Continue to load the splat
891
  updateStatus('Loading generated scene...', cameraParams.length);
892
 
 
896
  updateStatus('Scene generated successfully!', cameraParams.length);
897
  // Show generation time and total file size (MB)
898
  showGenerationInfo(latestGenerationTime || 0, total || blob.size);
899
+
900
+ // 启用下载按钮
901
+ if (window.downloadController) {
902
+ window.downloadController.enable();
903
+ }
904
  // Notify backend to delete the server file after client has downloaded it
905
  try {
906
  if (info.file_id) {
 
981
  // GUI Options - declare early
982
  const guiOptions = {
983
  // 后端地址,默认为本页面ip
984
+ BackendAddress: `${window.location.protocol}//${window.location.hostname}:7860`,
985
  HF_TOKEN: "",
986
  FOV: 60,
987
  LoadFromJson: () => {
 
1140
  // Playback scrub value (0..1)
1141
  playbackT: 0,
1142
 
1143
+ downloadGeneratedFile: () => {
1144
+ if (!currentDownloadedBlob) {
1145
+ updateStatus('No generated file available to download', cameraParams.length);
1146
+ return;
1147
+ }
1148
+
1149
+ updateStatus(`Downloading SPZ file (${(currentDownloadedBlob.size / 1024 / 1024).toFixed(2)} MB)...`, cameraParams.length);
1150
+
1151
+ // 直接使用已保存的blob创建下载链接
1152
+ const url = URL.createObjectURL(currentDownloadedBlob);
1153
+ const a = document.createElement('a');
1154
+ a.href = url;
1155
+ a.download = `${Date.now()}.spz`;
1156
+ document.body.appendChild(a);
1157
+ a.click();
1158
+ document.body.removeChild(a);
1159
+ URL.revokeObjectURL(url);
1160
+
1161
+ updateStatus('SPZ file downloaded successfully!', cameraParams.length);
1162
+ },
1163
+
1164
  generate: () => {
1165
  // 检查是否有足够的相机
1166
  if (cameraParams.length < 2) {
 
1178
  console.log('Previous generated scene removed');
1179
  }
1180
 
1181
+ // 清除之前的下载文件
1182
+ currentDownloadedBlob = null;
1183
+
1184
+ // 禁用下载按钮
1185
+ if (window.downloadController) {
1186
+ window.downloadController.disable();
1187
+ }
1188
+
1189
  // 初始化进度条信息
1190
  const generationTimeElement = document.getElementById('generation-time');
1191
  const fileSizeElement = document.getElementById('file-size');
 
1334
  });
1335
  }
1336
  return pump().then(blob => {
1337
+ // 保存blob供后续下载使用
1338
+ currentDownloadedBlob = blob;
1339
+
1340
  const url = URL.createObjectURL(blob);
1341
  return { url, __deleteAfterDownloadFileId: (typeof responseData !== 'undefined' ? responseData.file_id : null) };
1342
  });
 
1355
  currentGeneratedSplat = GeneratedSplat;
1356
  console.log('3D scene loaded successfully!');
1357
  updateStatus('Scene generated successfully!', cameraParams.length);
1358
+
1359
+ // 启用下载按钮
1360
+ if (window.downloadController) {
1361
+ window.downloadController.enable();
1362
+ }
1363
+
1364
  hideDownloadProgress();
1365
  showLoading(false);
1366
 
 
2102
  // Step 4: Generate Your Scene
2103
  const step4Folder = gui.addFolder('4. Generate Scene');
2104
  step4Folder.add(guiOptions, "generate").name("Generate!");
2105
+ const downloadController = step4Folder.add(guiOptions, "downloadGeneratedFile").name("Download SPZ File");
2106
+ downloadController.disable(); // Initially disabled
2107
  step4Folder.open();
2108
 
2109
+ // Store download controller globally for enabling/disabling
2110
+ window.downloadController = downloadController;
2111
+
2112
  // Step 5: Trajectory Playback (Scrubber)
2113
  const step5Folder = gui.addFolder('5. Trajectory Playback');
2114
  step5Folder.add(guiOptions, 'playbackT', 0, 1, 0.001).name('Scrub (0-1)').onChange((value) => {