From f98e9687ba72ac0689e979da9dca62cda0a2a126 Mon Sep 17 00:00:00 2001 From: ashawkey Date: Mon, 11 Mar 2024 13:21:59 +0800 Subject: [PATCH] Mesh load glb: fix transform even the scene only has one geom --- docs/source/conf.py | 2 +- kiui/mesh.py | 24 +++++++++++------------- setup.py | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 667b51f..9e8dcd5 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -21,7 +21,7 @@ author = 'kiui' # The full version, including alpha/beta/rc tags -release = '0.2.4' +release = '0.2.5' # -- General configuration --------------------------------------------------- diff --git a/kiui/mesh.py b/kiui/mesh.py index 31b383e..5584889 100644 --- a/kiui/mesh.py +++ b/kiui/mesh.py @@ -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 diff --git a/setup.py b/setup.py index 8f8458f..e6e0373 100644 --- a/setup.py +++ b/setup.py @@ -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",