Repository navigation
Conversation
ColorVisuals meshes export without a glTF material, so three.js renders them fully opaque. Convert semi-transparent meshes to texture visuals with a PBR BLEND material on a copy; opaque meshes keep the legacy path. Fixes viser-project#525.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #525.
Motivation
SceneApi.add_mesh_trimesh()silently drops transparency: a trimesh mesh with RGBA vertex/face colors (alpha < 255) renders fully opaque in the viewer. Maintainer diagnosis on the issue (root cause: trimesh's GLB exporter emits nomaterialsentry forColorVisuals, so the three.js loader falls back to an opaque standard material; upstream mikedh/trimesh#2436 still open) plus a multi-step manual workaround. This PR applies that workaround automatically, inside viser, so the repro from #525 just works.Changes
src/viser/_scene_api.py: new_trimesh_with_transparency()helper, wired into bothadd_mesh_trimesh()andadd_batched_meshes_trimesh()(same export path, same bug). When semi-transparent colors are present it exports a copy converted to texture visuals with a PBRBLENDmaterial; the caller's mesh is never mutated. Fully opaque meshes return as-is, keeping the export byte-identical. Graceful fallbacks (legacy opaque path) when the trimesh version lacks the PBR API or Pillow is missing for texture baking (with a warning pointing at Pillow).tests/test_trimesh_compatibility.py: 3 regression tests — wire-level test asserting the queued GLB payload carriesalphaMode: BLENDplus caller non-mutation; opaque mesh keeps the material-free export; unit test for the vertex-color path and opaque identity.Verification
materialsin export); post-fix the texture PNG carries the exact alpha (76) and material isBLEND.tests/test_trimesh_compatibility.py+tests/test_strict_copy_on_add.py: 6 passed;test_docs_coverage.py+test_scene_tree.py: 10 passed.ruff check,ruff format --check,pyright: all clean (0 errors).