Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nerfstudio/exporter/exporter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple

import numpy as np
import pymeshlab
import torch
from jaxtyping import Float
from rich.progress import BarColumn, Progress, TaskProgressColumn, TextColumn, TimeRemainingColumn
Expand All @@ -41,6 +40,7 @@
# Importing open3d can take ~1 second, so only do it below if we actually
# need it.
import open3d as o3d
import pymeshlab


@dataclass
Expand Down Expand Up @@ -71,6 +71,8 @@ def get_mesh_from_pymeshlab_mesh(mesh: pymeshlab.Mesh) -> Mesh: # type: ignore

def get_mesh_from_filename(filename: str, target_num_faces: Optional[int] = None) -> Mesh:
"""Get a Mesh from a filename."""
import pymeshlab

ms = pymeshlab.MeshSet() # type: ignore
ms.load_new_mesh(filename)
if target_num_faces is not None:
Expand Down
5 changes: 3 additions & 2 deletions nerfstudio/exporter/tsdf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from typing import List, Optional, Tuple, Union

import numpy as np
import pymeshlab
import torch
import torch.nn.functional as F
from jaxtyping import Bool, Float
Expand All @@ -50,7 +49,7 @@ class TSDF:
weights: Float[Tensor, "xdim ydim zdim"]
"""TSDF weights for each voxel."""
colors: Float[Tensor, "xdim ydim zdim 3"]
"""TSDF colors for each voxel."""
"""TSDF colors of each voxel."""
voxel_size: Float[Tensor, "3"]
"""Size of each voxel in the TSDF. [x, y, z] size."""
origin: Float[Tensor, "3"]
Expand Down Expand Up @@ -147,6 +146,8 @@ def export_mesh(cls, mesh: Mesh, filename: str) -> None:
mesh: The mesh to export.
filename: The filename to export the mesh to.
"""
import pymeshlab

assert mesh.colors is not None
vertex_matrix = mesh.vertices.cpu().numpy().astype("float64")
face_matrix = mesh.faces.cpu().numpy().astype("int32")
Expand Down
21 changes: 21 additions & 0 deletions tests/test_exporter_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Tests for exporter dependency imports."""

import importlib
import sys


def test_exporter_modules_do_not_eagerly_import_pymeshlab(monkeypatch):
"""Exporter modules should import without initializing pymeshlab."""
monkeypatch.setitem(sys.modules, "pymeshlab", None)

modules = [
"nerfstudio.exporter.exporter_utils",
"nerfstudio.exporter.tsdf_utils",
]
for module in modules:
sys.modules.pop(module, None)

for module in modules:
importlib.import_module(module)

assert sys.modules["pymeshlab"] is None
Loading