ThomasSimonini HF staff commited on
Commit
1e884f9
1 Parent(s): 23c1970

Add smooth shading

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -21,6 +21,9 @@ from mpl_toolkits.mplot3d.art3d import Poly3DCollection
21
  from PIL import Image
22
  import io
23
 
 
 
 
24
  model = load_v2()
25
 
26
  device = torch.device('cuda')
@@ -168,6 +171,9 @@ def do_inference(input_3d, sample_seed=0, do_sampling=False, do_marching_cubes=F
168
  artist_mesh.remove_unreferenced_vertices()
169
  artist_mesh.fix_normals()
170
 
 
 
 
171
  if artist_mesh.visual.vertex_colors is not None:
172
  orange_color = np.array([255, 165, 0, 255], dtype=np.uint8)
173
 
@@ -239,6 +245,7 @@ with (gr.Blocks() as demo):
239
  with gr.Row():
240
  with gr.Group():
241
  do_marching_cubes = gr.Checkbox(label="Preprocess with Marching Cubes", value=False)
 
242
  do_sampling = gr.Checkbox(label="Random Sampling", value=False)
243
  sample_seed = gr.Number(value=0, label="Seed Value", precision=0)
244
 
@@ -274,7 +281,7 @@ with (gr.Blocks() as demo):
274
 
275
  submit.click(
276
  fn=do_inference,
277
- inputs=[input_3d, sample_seed, do_sampling, do_marching_cubes],
278
  outputs=[preprocess_model_obj, input_image_render, output_model_obj, output_image_render],
279
  )
280
 
 
21
  from PIL import Image
22
  import io
23
 
24
+ # For smooth shading
25
+ from trimesh.smoothing import smooth_shade
26
+
27
  model = load_v2()
28
 
29
  device = torch.device('cuda')
 
171
  artist_mesh.remove_unreferenced_vertices()
172
  artist_mesh.fix_normals()
173
 
174
+ if do_smooth_shading:
175
+ smooth_shade(artist_mesh)
176
+
177
  if artist_mesh.visual.vertex_colors is not None:
178
  orange_color = np.array([255, 165, 0, 255], dtype=np.uint8)
179
 
 
245
  with gr.Row():
246
  with gr.Group():
247
  do_marching_cubes = gr.Checkbox(label="Preprocess with Marching Cubes", value=False)
248
+ do_smooth_shading = gr.Checkbox(label="Apply Smooth Shading", value=False)
249
  do_sampling = gr.Checkbox(label="Random Sampling", value=False)
250
  sample_seed = gr.Number(value=0, label="Seed Value", precision=0)
251
 
 
281
 
282
  submit.click(
283
  fn=do_inference,
284
+ inputs=[input_3d, sample_seed, do_sampling, do_marching_cubes, do_smooth_shading],
285
  outputs=[preprocess_model_obj, input_image_render, output_model_obj, output_image_render],
286
  )
287