Spaces:
Running
on
Zero
Running
on
Zero
Update trellis/pipelines/trellis_image_to_3d.py
Browse files
trellis/pipelines/trellis_image_to_3d.py
CHANGED
@@ -8,7 +8,6 @@ from PIL import Image
|
|
8 |
import trimesh
|
9 |
import os
|
10 |
import random
|
11 |
-
import open3d as o3d
|
12 |
import trellis.modules.sparse as sp
|
13 |
from trellis.models.sparse_structure_vae import *
|
14 |
from contextlib import contextmanager
|
@@ -657,32 +656,7 @@ class TrellisImageTo3DPipeline(Pipeline):
|
|
657 |
sparse_cond = slat_cond = self.get_cond([image])
|
658 |
|
659 |
torch.manual_seed(seed)
|
660 |
-
if
|
661 |
-
mesh_o3d = o3d.geometry.TriangleMesh()
|
662 |
-
mesh_o3d.vertices = o3d.utility.Vector3dVector(init_mesh.vertices)
|
663 |
-
mesh_o3d.triangles = o3d.utility.Vector3iVector(init_mesh.faces)
|
664 |
-
if normalize_init_mesh:
|
665 |
-
vertices = np.asarray(mesh_o3d.vertices)
|
666 |
-
init_mesh = normalize_trimesh(init_mesh)
|
667 |
-
center = (vertices.max(axis=0) + vertices.min(axis=0)) / 2
|
668 |
-
vertices = vertices - center
|
669 |
-
diag = np.linalg.norm(vertices.max(axis=0) - vertices.min(axis=0))
|
670 |
-
vertices = vertices / diag
|
671 |
-
mesh_o3d.vertices = o3d.utility.Vector3dVector(vertices)
|
672 |
-
|
673 |
-
vertices = np.clip(np.asarray(mesh_o3d.vertices), -0.5 + 1e-6, 0.5 - 1e-6)
|
674 |
-
mesh_o3d.vertices = o3d.utility.Vector3dVector(vertices)
|
675 |
-
|
676 |
-
voxel_grid = o3d.geometry.VoxelGrid.create_from_triangle_mesh_within_bounds(
|
677 |
-
mesh_o3d,
|
678 |
-
voxel_size=1/64,
|
679 |
-
min_bound=(-0.5, -0.5, -0.5),
|
680 |
-
max_bound=(0.5, 0.5, 0.5)
|
681 |
-
)
|
682 |
-
|
683 |
-
voxel_indices = np.array([voxel.grid_index for voxel in voxel_grid.get_voxels()])
|
684 |
-
coords = torch.cat([torch.zeros(len(voxel_indices), 1), torch.tensor(voxel_indices)], dim=1).int().to(self.device)
|
685 |
-
elif coords is not None:
|
686 |
coords = coords
|
687 |
else:
|
688 |
coords = self.sample_sparse_structure(sparse_cond, num_samples, sparse_structure_sampler_params)
|
|
|
8 |
import trimesh
|
9 |
import os
|
10 |
import random
|
|
|
11 |
import trellis.modules.sparse as sp
|
12 |
from trellis.models.sparse_structure_vae import *
|
13 |
from contextlib import contextmanager
|
|
|
656 |
sparse_cond = slat_cond = self.get_cond([image])
|
657 |
|
658 |
torch.manual_seed(seed)
|
659 |
+
if coords is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
660 |
coords = coords
|
661 |
else:
|
662 |
coords = self.sample_sparse_structure(sparse_cond, num_samples, sparse_structure_sampler_params)
|