Spaces:
Running
on
Zero
Running
on
Zero
bluestyle97
commited on
Update freesplatter/utils/mesh_optim.py
Browse files
freesplatter/utils/mesh_optim.py
CHANGED
@@ -11,8 +11,6 @@ import cv2
|
|
11 |
from PIL import Image
|
12 |
import fast_simplification
|
13 |
|
14 |
-
from freesplatter.utils.mesh import Mesh
|
15 |
-
|
16 |
|
17 |
def parametrize_mesh(vertices: np.array, faces: np.array):
|
18 |
"""
|
@@ -153,7 +151,7 @@ def bake_texture(
|
|
153 |
|
154 |
|
155 |
def optimize_mesh(
|
156 |
-
mesh
|
157 |
images: torch.Tensor,
|
158 |
masks: torch.Tensor,
|
159 |
extrinsics: torch.Tensor,
|
@@ -165,16 +163,16 @@ def optimize_mesh(
|
|
165 |
"""
|
166 |
Convert a generated asset to a glb file.
|
167 |
Args:
|
168 |
-
mesh (
|
169 |
simplify (float): Ratio of faces to remove in simplification.
|
170 |
texture_size (int): Size of the texture.
|
171 |
verbose (bool): Whether to print progress.
|
172 |
"""
|
173 |
-
vertices = mesh.
|
174 |
-
faces = mesh.
|
175 |
|
176 |
# mesh simplification
|
177 |
-
max_faces =
|
178 |
mesh_reduction = max(1 - max_faces / faces.shape[0], simplify)
|
179 |
vertices, faces = fast_simplification.simplify(
|
180 |
vertices, faces, target_reduction=mesh_reduction)
|
|
|
11 |
from PIL import Image
|
12 |
import fast_simplification
|
13 |
|
|
|
|
|
14 |
|
15 |
def parametrize_mesh(vertices: np.array, faces: np.array):
|
16 |
"""
|
|
|
151 |
|
152 |
|
153 |
def optimize_mesh(
|
154 |
+
mesh,
|
155 |
images: torch.Tensor,
|
156 |
masks: torch.Tensor,
|
157 |
extrinsics: torch.Tensor,
|
|
|
163 |
"""
|
164 |
Convert a generated asset to a glb file.
|
165 |
Args:
|
166 |
+
mesh (trimesh.Trimesh): Extracted mesh.
|
167 |
simplify (float): Ratio of faces to remove in simplification.
|
168 |
texture_size (int): Size of the texture.
|
169 |
verbose (bool): Whether to print progress.
|
170 |
"""
|
171 |
+
vertices = np.array(mesh.vertices).astype(float)
|
172 |
+
faces = np.array(mesh.faces).astype(int)
|
173 |
|
174 |
# mesh simplification
|
175 |
+
max_faces = 30000
|
176 |
mesh_reduction = max(1 - max_faces / faces.shape[0], simplify)
|
177 |
vertices, faces = fast_simplification.simplify(
|
178 |
vertices, faces, target_reduction=mesh_reduction)
|