Skip to content

Commit

Permalink
fixed not loading point cloud colors from glb format files (#2339)
Browse files Browse the repository at this point in the history
Updates the GLTF/GLB reader to include point cloud colors if available.
  • Loading branch information
mikedh authored Jan 17, 2025
2 parents d0e0ac9 + 94d35f5 commit a94c287
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions trimesh/exchange/gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,24 @@ def _read_buffers(
kwargs["entities"] = [Line(points=np.arange(len(kwargs["vertices"])))]
elif mode == _GL_POINTS:
kwargs["vertices"] = access[attr["POSITION"]]
visuals = None
if "COLOR_0" in attr:
try:
# try to load vertex colors from the accessors
colors = access[attr["COLOR_0"]]
if len(colors) == len(kwargs["vertices"]):
if visuals is None:
# just pass to mesh as vertex color
kwargs["vertex_colors"] = colors.copy()
else:
# we ALSO have texture so save as vertex
# attribute
visuals.vertex_attributes["color"] = colors.copy()
except BaseException:
# survive failed colors
log.debug("failed to load colors", exc_info=True)
if visuals is not None:
kwargs["visual"] = visuals
elif mode in (_GL_TRIANGLES, _GL_STRIP):
# get vertices from accessors
kwargs["vertices"] = access[attr["POSITION"]]
Expand Down

0 comments on commit a94c287

Please sign in to comment.