WebXR AR occlusion, lighting, interaction and physics with three.js
JavaScriptMIT
Enva-XR - Environment Aware Augmented Reality
Web-based framework for environment-aware rendering and interaction in augmented reality based on WebXR using three.js
The framework handles geometry occlusions, matches the lighting of the environment, casts shadows, and provides physics interaction with real-world objects.
Material from three.js can be reused the shader code required for AR occlusion is injected into the existing shaders using the onBeforeCompile callback.
Capable of obtaining over 20 frames per second even on middle-range devices.
Ensure that your browser is compatible with WebXR and check features support (e.g. depth-estimation, hit-test, lighting).
Install dependencies from NPM by running npm install and start the code running npm run start
To allow easier debugging in mobile devices eruda can be used as a development tools alternative.
Usage Example
Bellow is a simple usage example of the library the ARRenderer is responsible for most of the work required to setup the AR scene.
The ARRenderer receives a configuration object that indicates wich WebXR features should be enabled.
To enable AR rendering on existing three.js materials the AugmentedMaterial.transform() method should be used to transform regular materials into AR materials.
The example bellow demonstrates how to create a simple AR scene with occlusion and lighting enabled.
LightProbe object replicates the envornment lighting and position main light source position and direction. Internaly contains a three.js LightProbe and DirectionalLight with shadow casting enabled by default.