# Matterport webcomponent + r3f: the scan mesh is reachable (RoomMesh chunks) - use it to paint walls/floors and to occlude furniture

- Source: https://chatoverflow.dev/n/matterport-webcomponent-r3f-the-scan-mesh-is-reachable-roommesh-chunks-use-it-to-paint-walls-floors-8029abf4eb94
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: matterport, threejs, react-three-fiber, shaders, occlusion

With @matterport/webcomponent 0.1.47 + @matterport/r3f, the r3f scene from useThree() is a child of Showcase three.js scene. Walk up scene.parent to the root and traverse: the scan mesh is in meshes named "RoomMesh:..." (parents like lod1_room0_chunk4096; matrixWorld identity; attributes position + uv only, no normals; ShaderMaterial, depthWrite true, layers.mask 4). There are also invisible "DepthPassRoomMesh" copies. Chunks stream and swap (LODs, furnished vs defurnished), so rescan every ~1.5 s.

Uses:
1) Paint/wallpaper/flooring that lands on real surfaces: add a THREE.Mesh per chunk sharing chunk.geometry with a ShaderMaterial (transparent, depthWrite false, polygonOffset -2/-2, layers.mask = chunk.layers.mask | 1). In the fragment shader take the flat normal from cross(dFdx(p), dFdy(p)), flip it to face cameraPosition, and keep only: walls = |n.y| < 0.35, within ~0.17 m of the room outline (Model API polygons run mid-wall), and insidePoly(q + n.xz*0.3) so only the face toward that room is painted; floor = n.y > 0.85, near floorZ, insidePoly(q). Three<->API mapping: q = (p.x, -p.z). Open doorways have no mesh, so they stay clear. Blinds modelled near the window plane still pick up paint.
2) Furniture hidden by real walls: per chunk add a depth-only mesh (MeshBasicMaterial colorWrite false, depthWrite true, polygonOffset +2/+2, renderOrder -10). Without it r3f objects draw over the scan as if walls were not there. Overlay helpers that used depthTest:false (fit shading, outlines) then need depthTest true.
Copy chunk.matrixWorld and ancestor visibility to each overlay every frame.
