In-browser lightmap and ambient occlusion (AO map) baker for react-three-fiber and ThreeJS.
Example:
<Lightmap>
<mesh position={[0, 0, 0]} castShadow receiveShadow>
<boxBufferGeometry attach="geometry" args={[3, 3, 1]} />
<meshStandardMaterial attach="material" color="#ff6080" />
</mesh>
<mesh position={[0, 0, 1.8]} castShadow receiveShadow>
<boxBufferGeometry attach="geometry" args={[2, 2, 2]} />
<meshStandardMaterial attach="material" color="#4080ff" />
</mesh>
</Lightmap>
Try it in this editable sandbox.
NOTE: actual lightmap rendering is performed on a separate hidden canvas and WebGL context. If you are consuming any context in your lightmapped content, you will need to "bridge" that context.
To track when baking is complete, provide onComplete
callback to Lightmap
- it will be called with the resulting texture as the first argument. The library does automatically assign that texture as the lightmap on all the baked mesh materials too.
git clone git@github.com:pmndrs/react-three-lightmap.git
cd react-three-lightmap
yarn
yarn storybook
Based on original experimental implementation by @unframework.