Skip to content

Commit

Permalink
fix: improve mesh data loading (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
numb3r3 authored Jan 11, 2022
1 parent e62c1ad commit 09c5c43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 9 additions & 10 deletions docarray/document/mixins/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ def load_uri_to_point_cloud_blob(
"""
import trimesh

mesh = trimesh.load_mesh(self.uri).deduplicated()

pcs = []
for geo in mesh.geometry.values():
geo: trimesh.Trimesh
pcs.append(geo.sample(samples))

if as_chunks:
from .. import Document

for p in pcs:
self.chunks.append(Document(blob=p))
# try to coerce everything into a scene
scene = trimesh.load(self.uri, force='scene')
for geo in scene.geometry.values():
geo: trimesh.Trimesh
self.chunks.append(Document(blob=geo.sample(samples)))
else:
self.blob = np.stack(pcs).squeeze()
# combine a scene into a single mesh
mesh = trimesh.load(self.uri, force='mesh')
self.blob = mesh.sample(samples)

return self
4 changes: 4 additions & 0 deletions tests/unit/document/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,7 @@ def test_glb_converters():
doc = Document(uri=os.path.join(cur_dir, 'toydata/test.glb'))
doc.load_uri_to_point_cloud_blob(2000)
assert doc.blob.shape == (2000, 3)

doc.load_uri_to_point_cloud_blob(2000, as_chunks=True)
assert len(doc.chunks) == 1
assert doc.chunks[0].blob.shape == (2000, 3)

0 comments on commit 09c5c43

Please sign in to comment.