cronos3k commited on
Commit
f3eb6b9
·
verified ·
1 Parent(s): 498f1f8

Update app.py

Browse files

Filled Mesh: High-quality with hole filling

Files changed (1) hide show
  1. app.py +51 -11
app.py CHANGED
@@ -182,11 +182,37 @@ def extract_high_quality_mesh(
182
 
183
  # Create mesh and save
184
  simple_mesh = trimesh.Trimesh(vertices=rotated_vertices, faces=faces)
185
- glb_path = os.path.join(user_dir, f"{trial_id}_full.glb")
186
  simple_mesh.export(glb_path)
187
 
188
  return glb_path, glb_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
 
 
 
 
 
 
190
  @spaces.GPU
191
  def extract_reduced_glb(
192
  state: dict,
@@ -221,9 +247,10 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
221
  gr.Markdown("""
222
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
223
  * Upload an image and click "Generate" to create a 3D asset
224
- * After generation:
225
- * Click "Extract Full GLB" for maximum detail mesh (untextured)
226
- * Or use GLB Extraction Settings for a reduced textured version
 
227
  """)
228
 
229
  with gr.Row():
@@ -243,7 +270,8 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
243
  slat_sampling_steps = gr.Slider(1, 500, label="Sampling Steps", value=12, step=1)
244
 
245
  generate_btn = gr.Button("Generate")
246
- extract_full_btn = gr.Button("Extract Full GLB", interactive=False)
 
247
 
248
  with gr.Accordion(label="GLB Extraction Settings", open=False):
249
  mesh_simplify = gr.Slider(0.0, 0.98, label="Simplify", value=0.95, step=0.01)
@@ -256,7 +284,8 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
256
  model_output = LitModel3D(label="3D Model Preview", exposure=20.0, height=300)
257
  gr.Markdown("### Download Options")
258
  with gr.Row():
259
- download_full = gr.DownloadButton(label="Download Full-Quality GLB", interactive=False)
 
260
  download_reduced = gr.DownloadButton(label="Download Reduced GLB", interactive=False)
261
 
262
  output_buf = gr.State()
@@ -294,17 +323,28 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
294
  inputs=[image_prompt, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps],
295
  outputs=[output_buf, video_output],
296
  ).then(
297
- lambda: [gr.Button(interactive=True), gr.Button(interactive=True), gr.Button(interactive=False), gr.Button(interactive=False)],
298
- outputs=[extract_full_btn, extract_reduced_btn, download_full, download_reduced],
 
 
299
  )
300
 
301
- extract_full_btn.click(
302
  extract_high_quality_mesh,
303
  inputs=[output_buf],
304
- outputs=[model_output, download_full],
 
 
 
 
 
 
 
 
 
305
  ).then(
306
  lambda: gr.Button(interactive=True),
307
- outputs=[download_full],
308
  )
309
 
310
  extract_reduced_btn.click(
 
182
 
183
  # Create mesh and save
184
  simple_mesh = trimesh.Trimesh(vertices=rotated_vertices, faces=faces)
185
+ glb_path = os.path.join(user_dir, f"{trial_id}_raw.glb")
186
  simple_mesh.export(glb_path)
187
 
188
  return glb_path, glb_path
189
+
190
+ @spaces.GPU
191
+ def extract_high_quality_mesh_with_holes_filled(
192
+ state: dict,
193
+ req: gr.Request,
194
+ ) -> Tuple[str, str]:
195
+ """
196
+ Save mesh data with hole filling but no other processing.
197
+ """
198
+ user_dir = os.path.join(TMP_DIR, str(req.session_hash))
199
+ gs, mesh, trial_id = unpack_state(state)
200
+
201
+ # Use to_glb only for hole filling
202
+ raw_mesh = postprocessing_utils.to_glb(
203
+ gs,
204
+ mesh,
205
+ simplify=0.0, # No simplification
206
+ fill_holes=True, # Enable hole filling
207
+ fill_holes_max_size=0.04,
208
+ verbose=True
209
+ )
210
 
211
+ glb_path = os.path.join(user_dir, f"{trial_id}_filled.glb")
212
+ raw_mesh.export(glb_path)
213
+
214
+ return glb_path, glb_path
215
+
216
  @spaces.GPU
217
  def extract_reduced_glb(
218
  state: dict,
 
247
  gr.Markdown("""
248
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
249
  * Upload an image and click "Generate" to create a 3D asset
250
+ * After generation, choose from three export options:
251
+ * Raw Mesh: Maximum detail, untextured, may have holes
252
+ * Filled Mesh: Maximum detail, untextured, holes filled
253
+ * Reduced GLB: Reduced size with textures
254
  """)
255
 
256
  with gr.Row():
 
270
  slat_sampling_steps = gr.Slider(1, 500, label="Sampling Steps", value=12, step=1)
271
 
272
  generate_btn = gr.Button("Generate")
273
+ extract_raw_btn = gr.Button("Extract Raw Mesh", interactive=False)
274
+ extract_filled_btn = gr.Button("Extract Filled Mesh", interactive=False)
275
 
276
  with gr.Accordion(label="GLB Extraction Settings", open=False):
277
  mesh_simplify = gr.Slider(0.0, 0.98, label="Simplify", value=0.95, step=0.01)
 
284
  model_output = LitModel3D(label="3D Model Preview", exposure=20.0, height=300)
285
  gr.Markdown("### Download Options")
286
  with gr.Row():
287
+ download_raw = gr.DownloadButton(label="Download Raw Mesh", interactive=False)
288
+ download_filled = gr.DownloadButton(label="Download Filled Mesh", interactive=False)
289
  download_reduced = gr.DownloadButton(label="Download Reduced GLB", interactive=False)
290
 
291
  output_buf = gr.State()
 
323
  inputs=[image_prompt, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps],
324
  outputs=[output_buf, video_output],
325
  ).then(
326
+ lambda: [gr.Button(interactive=True), gr.Button(interactive=True), gr.Button(interactive=True),
327
+ gr.Button(interactive=False), gr.Button(interactive=False), gr.Button(interactive=False)],
328
+ outputs=[extract_raw_btn, extract_filled_btn, extract_reduced_btn,
329
+ download_raw, download_filled, download_reduced],
330
  )
331
 
332
+ extract_raw_btn.click(
333
  extract_high_quality_mesh,
334
  inputs=[output_buf],
335
+ outputs=[model_output, download_raw],
336
+ ).then(
337
+ lambda: gr.Button(interactive=True),
338
+ outputs=[download_raw],
339
+ )
340
+
341
+ extract_filled_btn.click(
342
+ extract_high_quality_mesh_with_holes_filled,
343
+ inputs=[output_buf],
344
+ outputs=[model_output, download_filled],
345
  ).then(
346
  lambda: gr.Button(interactive=True),
347
+ outputs=[download_filled],
348
  )
349
 
350
  extract_reduced_btn.click(