Spaces:
Sleeping
Sleeping
Commit
·
487fffe
1
Parent(s):
951bb28
fix smoothing and texture
Browse files- .gitignore +11 -0
- app.py +12 -9
.gitignore
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore Python bytecode files
|
| 2 |
+
*.pyc
|
| 3 |
+
*.pyo
|
| 4 |
+
__pycache__/
|
| 5 |
+
|
| 6 |
+
# Ignore virtual environment directory
|
| 7 |
+
venv/
|
| 8 |
+
|
| 9 |
+
/3D_stage/outputs/
|
| 10 |
+
input_3D.png
|
| 11 |
+
input.png
|
app.py
CHANGED
|
@@ -279,20 +279,23 @@ class Inference2D_API:
|
|
| 279 |
|
| 280 |
|
| 281 |
def traverse(path, back_proj, smooth_iter):
|
| 282 |
-
mesh = trimesh.load(f"{path}/model-00.obj", process=False, maintain_order=True)
|
| 283 |
-
mesh.apply_transform(trimesh.transformations.rotation_matrix(np.radians(90.0), [-1, 0, 0]))
|
| 284 |
-
mesh.apply_transform(trimesh.transformations.rotation_matrix(np.radians(180.0), [0, 1, 0]))
|
| 285 |
-
|
| 286 |
-
cmesh = pymeshlab.Mesh(mesh.vertices, mesh.faces)
|
| 287 |
ms = pymeshlab.MeshSet()
|
| 288 |
-
ms.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
ms.meshing_merge_close_vertices()
|
| 290 |
ms.apply_coord_laplacian_smoothing(stepsmoothnum=smooth_iter)
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
mesh.export(f'{path}/output.glb', file_type='glb')
|
| 294 |
|
| 295 |
-
image = Image.open(f"{path}/{'refined_texture_kd.
|
| 296 |
texture = np.array(image)
|
| 297 |
vertex_colors = np.zeros((mesh.vertices.shape[0], 4), dtype=np.uint8)
|
| 298 |
|
|
@@ -303,7 +306,7 @@ def traverse(path, back_proj, smooth_iter):
|
|
| 303 |
|
| 304 |
color = texture[y, x, :3]
|
| 305 |
vertex_colors[vertex_index] = [color[0], color[1], color[2], 255]
|
| 306 |
-
return trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces, vertex_colors=vertex_colors)
|
| 307 |
|
| 308 |
class Inference3D_API:
|
| 309 |
|
|
|
|
| 279 |
|
| 280 |
|
| 281 |
def traverse(path, back_proj, smooth_iter):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
ms = pymeshlab.MeshSet()
|
| 283 |
+
ms.load_new_mesh(f"{path}/model-00.obj")
|
| 284 |
+
image = Image.open(f"{path}/{'refined_texture_kd.jpg' if back_proj else 'texture_kd.jpg'}")
|
| 285 |
+
out_image_path = f"{path}/{'refined_texture_kd.png' if back_proj else 'texture_kd.png'}"
|
| 286 |
+
image.save(out_image_path, 'PNG')
|
| 287 |
+
ms.set_texture_per_mesh(textname=f"{path}/{'refined_texture_kd.png' if back_proj else 'texture_kd.png'}")
|
| 288 |
ms.meshing_merge_close_vertices()
|
| 289 |
ms.apply_coord_laplacian_smoothing(stepsmoothnum=smooth_iter)
|
| 290 |
+
ms.save_current_mesh(f"{path}/temp-00.obj", save_vertex_normal=False, save_wedge_normal=False, save_vertex_color=False)
|
| 291 |
+
|
| 292 |
+
mesh = trimesh.load(f"{path}/temp-00.obj", process=False)
|
| 293 |
+
mesh.apply_transform(trimesh.transformations.rotation_matrix(np.radians(90.0), [-1, 0, 0]))
|
| 294 |
+
mesh.apply_transform(trimesh.transformations.rotation_matrix(np.radians(180.0), [0, 1, 0]))
|
| 295 |
|
| 296 |
mesh.export(f'{path}/output.glb', file_type='glb')
|
| 297 |
|
| 298 |
+
image = Image.open(f"{path}/{'refined_texture_kd.png' if back_proj else 'texture_kd.png'}")
|
| 299 |
texture = np.array(image)
|
| 300 |
vertex_colors = np.zeros((mesh.vertices.shape[0], 4), dtype=np.uint8)
|
| 301 |
|
|
|
|
| 306 |
|
| 307 |
color = texture[y, x, :3]
|
| 308 |
vertex_colors[vertex_index] = [color[0], color[1], color[2], 255]
|
| 309 |
+
return trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces, vertex_colors=vertex_colors, process=False)
|
| 310 |
|
| 311 |
class Inference3D_API:
|
| 312 |
|