[macOS] Fix Metal RHI 3D viewer crashes and enable qtAliceVision plugins#3030
[macOS] Fix Metal RHI 3D viewer crashes and enable qtAliceVision plugins#3030NeverGET wants to merge 10 commits intoalicevision:developfrom
Conversation
Metal RHI strictly validates that vertex shader inputs match the vertex descriptor provided by the geometry. The SphericalHarmonics shaders declared a vertexNormal input, but custom Qt3D geometries (Grid3D, BoundingBox, Locator3D) and some loaded meshes don't provide normal attributes, causing Metal pipeline creation to fail with a crash. Instead of requiring normals as a vertex attribute, compute flat face normals in the fragment shader using dFdx/dFdy screen-space derivatives of the world position. This produces correct lighting for flat-shaded geometry and works regardless of whether the mesh provides normals. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Built-in Qt3D materials (PhongMaterial, DiffuseSpecularMaterial) expect a vertexNormal attribute in the vertex descriptor. On Metal RHI, if a geometry lacks this attribute, the render pipeline state creation fails with a crash because Metal strictly validates that all shader inputs are satisfied by the vertex descriptor. Add default upward-facing (0, 1, 0) normal attributes to: - Grid3D.qml (dynamic count matching grid vertices) - BoundingBox.qml (24 vertices) - Locator3D.qml (6 vertices) These normals ensure Metal pipeline compatibility while maintaining correct visual appearance for these helper geometries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Meshes loaded via SceneLoader (OBJ, PLY, etc.) may lack normal attributes. When these meshes are rendered with built-in Qt3D materials that require vertexNormal, Metal RHI crashes due to missing vertex descriptor entries. Add Scene3DHelper.ensureNormals(entity) that traverses all QGeometry children of a loaded entity and adds default (0, 1, 0) normal attributes to any geometry missing them. Call this method in MediaLoader's sceneLoaderPostProcess before material setup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add OpenGL 3.2 Core Profile technique alternatives to the existing RHI techniques in WireframeEffect and SphericalHarmonicsEffect. This provides shader compatibility on platforms where Qt3D uses the OpenGL backend instead of RHI/Metal. New shader files: - SphericalHarmonics_gl.vert/frag: GLSL 330 versions using uniforms instead of UBO layout qualifiers - robustwireframe_gl.vert/geom/frag: GLSL 330 wireframe rendering with geometry shader for barycentric coordinate computation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Override the textured material's ambient, shininess, and specular properties with low fixed values instead of inheriting from the loaded mesh's MTL material properties. Many OBJ files include high ambient values that wash out textures when viewed in the 3D viewer. Using low ambient (alicevision#111), no specular (#000), and minimal shininess (1.0) ensures textures are displayed with proper diffuse-only lighting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add QML import paths for PySide6's bundled QML modules and the AliceVision bundle's PlugIns directory. This enables the QML engine to discover and load qtAliceVision, SfmDataEntity, and DepthMapEntity QML plugins that provide camera visualization, SfM data overlay, and depth map rendering in the 3D viewer. The PySide6 QML path ensures Qt3D and QtQuick.Scene3D modules are found, while the AV_BUNDLE/PlugIns path provides the AliceVision- specific visualization plugins. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Guard QT_PLUGIN_PATH and QML2_IMPORT_PATH setup behind directory existence checks. On macOS with PySide6, these directories may not exist in the standard locations and setting invalid paths causes plugin loading failures. - Add macOS-specific DYLD_FALLBACK_LIBRARY_PATH handling (analogous to LD_LIBRARY_PATH on Linux) so AliceVision framework libraries can be found at runtime. - Use Metal as the default RHI backend on macOS (QSG_RHI_BACKEND=metal) via setdefault so it can be overridden, while keeping OpenGL as the default on other platforms. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The cgroup CPU count detection reads /proc/self/cgroup which only exists on Linux. On macOS and Windows, this causes a crash when Meshroom tries to determine available CPU cores for task parallelism. Add an early return using os.cpu_count() on non-Linux platforms. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Some AliceVision node descriptors from the MTL-AliceVision bundle use the older 'groupDesc' parameter name instead of 'items' in GroupAttribute constructors. Add backward compatibility by accepting 'groupDesc' as a deprecated alias and defaulting positional params to allow keyword-only usage patterns. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
This is AWESOME! I ran into all these issues and did some very dirty hacking to get a bare minimum of it working 😅. |
|
You're welcome, BTW I bundled the app and using daily 😄. |
| ambient: root.ambient | ||
| shininess: root.shininess | ||
| specular: root.specular | ||
| ambient: "#111" | ||
| shininess: 1.0 | ||
| specular: "#000" |
There was a problem hiding this comment.
What's the reason to change that?
There was a problem hiding this comment.
Actually the mesh preview is looking a bit phased off, like whiteish. I tried to make it look like full saturated colour but it didn't worked either and I was feeling very happy about the app is working, I directly go into PR.
Tldr; it just a mess I forgot to revert
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (19.04%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #3030 +/- ##
===========================================
- Coverage 82.92% 82.78% -0.15%
===========================================
Files 71 71
Lines 9546 9565 +19
===========================================
+ Hits 7916 7918 +2
- Misses 1630 1647 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| @@ -196,12 +196,15 @@ def matchDescription(self, value, strict=True): | |||
| class GroupAttribute(Attribute): | |||
| """ A macro Attribute composed of several Attributes """ | |||
| @deprecated.depreciateParam("group", "Param 'group' on {name} should not be used anymore. Please use 'commandLineGroup' instead") | |||
There was a problem hiding this comment.
| @deprecated.depreciateParam("group", "Param 'group' on {name} should not be used anymore. Please use 'commandLineGroup' instead") | |
| @deprecated.depreciateParam("group", "Param argument 'group' on {name} should not be used anymore. Please use 'commandLineGroup' instead") | |
| @deprecated.depreciateParam("groupDesc", "GroupAttribute argument 'groupDesc' on {name} should not be used anymore. Please use 'items' instead") |
Summary
vertexNormalattributes in custom Qt3D geometriesdFdx/dFdyderivatives instead of requiring normals as vertex attributes in SphericalHarmonics shadersensureNormals()to dynamically patch loaded meshes (OBJ/PLY) that lack normalssetupEnvironment()(DYLD paths, Metal RHI backend, Qt plugin path guards)groupDescbackward compatibility for AliceVision node descriptorsAcknowledgments
Huge thanks to @music-dsp-collection for the incredible work on MTL-AliceVision (alicevision/AliceVision#2019) — bringing Metal GPU support and the complete macOS build pipeline to AliceVision is a massive achievement. And to the entire @alicevision team for building such an amazing open-source photogrammetry ecosystem. This PR is a small contribution building on top of their foundational work to help get the Meshroom 3D viewer running smoothly on macOS.
Context
While testing Meshroom on macOS 26.3 (Apple Silicon M4 Max, Mac15,6) with the MTL-AliceVision bundle from PR alicevision/AliceVision#2019, we found that the 3D viewer crashed due to Metal's strict vertex descriptor validation when geometries lacked normal attributes that built-in Qt3D materials expect.
Root cause: Metal RHI validates that all vertex shader inputs (
layout(location = N) in ...) are satisfied by the geometry's vertex descriptor. When a shader declaresvertexNormalbut the geometry only providesvertexPosition, Metal's pipeline state creation fails, crashing the application.Fixes applied:
vertexNormalinput entirely; compute flat normals fromdFdx/dFdyderivatives of world position in the fragment shader(0, 1, 0)normal attributesScene3DHelper.ensureNormals()dynamically adds normals to geometries missing themTest Plan
QT3D_RENDERERoverride needed)Tested on
🤖 Generated with Claude Code