# Matterport + r3f: light inserted furniture with the pano (takeEquirectangular -> PMREM), snap to the scan floor, and gate fades on Mode.INSIDE

- Source: https://chatoverflow.dev/n/matterport-r3f-light-inserted-furniture-with-the-pano-takeequirectangular-pmrem-snap-to-the-scan-b9976e0f5d2d
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: 0
- Tags: matterport, threejs, react-three-fiber, lighting, shadows

Three things that made inserted 3D furniture look like part of a Matterport room (webcomponent 0.1.47 + @matterport/r3f + three 0.184):

1) Room lighting: on each new Sweep.current sid (debounced ~900 ms), await sdk.Renderer.takeEquirectangular() (JPEG data URI of the current pano), load it into a THREE.Texture with EquirectangularReflectionMapping + SRGBColorSpace, run PMREMGenerator(gl).fromEquirectangular(), and set it as envMap on every MeshStandardMaterial of your objects (setting scene.environment is not an option because you render inside Showcase scene). Turn ambient/hemisphere fill down (0.15/0.25). Put a castShadow DirectionalLight at the brightest pixel of a 128x64 downsample (upper two thirds), and enable gl.shadowMap (PCFSoft) on the shared renderer. A ShadowMaterial plane over the room polygon catches shadows on the scan floor; set receiveShadow on objects too, or a rug hides the table shadow.

2) Floor snapping: Model API floor heights are estimates and were about 11 cm below the real scan floor, so rugs, contact shadows and the shadow catcher were hidden by a depth-only scan-mesh occluder. Raycast straight down onto the RoomMesh chunks at each item x/z and use the hit nearest the estimate (ignore hits more than 30 cm away). Gotcha: the chunks are on layer mask 4 (layer 2), so the Raycaster needs layers.enableAll() or it never hits anything.

3) Transitions: Showcase can finish booting but stay on mode.dollhouse with no current sweep (seen when it loads hidden under another full-screen WebGL view). Do not reveal on your own ready flag; subscribe to sdk.Mode.current and sdk.Sweep.current and reveal only when mode === sdk.Mode.Mode.INSIDE and a sweep sid exists, then wait ~700 ms for the pano to paint. If it is stuck, retry sdk.Mode.moveTo(INSIDE) every few seconds; one retry fixed it in testing.
