Skip to content

Commit

Permalink
Mesh load glb: fix transform even the scene only has one geom
Browse files Browse the repository at this point in the history
  • Loading branch information
ashawkey committed Mar 11, 2024
1 parent e02c97c commit f98e968
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
author = 'kiui'

# The full version, including alpha/beta/rc tags
release = '0.2.4'
release = '0.2.5'


# -- General configuration ---------------------------------------------------
Expand Down
24 changes: 11 additions & 13 deletions kiui/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,18 @@ def load_trimesh(cls, path, device=None):

# use trimesh to load ply/glb
_data = trimesh.load(path)
# always convert scene to mesh, and apply all transforms...
if isinstance(_data, trimesh.Scene):
if len(_data.geometry) == 1:
_mesh = list(_data.geometry.values())[0]
else:
print(f"[INFO] load trimesh: concatenating {len(_data.geometry)} meshes.")
_concat = []
# loop the scene graph and apply transform to each mesh
scene_graph = _data.graph.to_flattened() # dict {name: {transform: 4x4 mat, geometry: str}}
for k, v in scene_graph.items():
name = v['geometry']
if name in _data.geometry and isinstance(_data.geometry[name], trimesh.Trimesh):
transform = v['transform']
_concat.append(_data.geometry[name].apply_transform(transform))
_mesh = trimesh.util.concatenate(_concat)
print(f"[INFO] load trimesh: concatenating {len(_data.geometry)} meshes.")
_concat = []
# loop the scene graph and apply transform to each mesh
scene_graph = _data.graph.to_flattened() # dict {name: {transform: 4x4 mat, geometry: str}}
for k, v in scene_graph.items():
name = v['geometry']
if name in _data.geometry and isinstance(_data.geometry[name], trimesh.Trimesh):
transform = v['transform']
_concat.append(_data.geometry[name].apply_transform(transform))
_mesh = trimesh.util.concatenate(_concat)
else:
_mesh = _data

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if __name__ == "__main__":
setup(
name="kiui",
version="0.2.4",
version="0.2.5",
description="A toolkit for 3D vision",
long_description=open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit f98e968

Please sign in to comment.