Giter Club home page Giter Club logo

enva-xr's Introduction

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.
  • WebXR AR features supported by the framework

Getting Started

  • Download the repository from git gh repo clone tentone/enva-xr
  • Install Node and NPM.
  • 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.
const renderer = new ARRenderer({
  depthSensing: true,
  depthTexture: true,
  lightProbe: true
});

let material: any = new MeshPhysicalMaterial({color: (Math.random() * 0xFFFFFF)});
material = AugmentedMaterial.transform(material);

let box = new Mesh(new BoxGeometry(), material);
box.receiveShadow = true;
box.castShadow = true;
renderer.scene.add(box);

const probe = new LightProbe();
renderer.scene.add(probe);

const floor = new FloorPlane();
renderer.scene.add(floor);

renderer.onFrame = function(time: number, renderer: ARRenderer) {
  box.rotation.x += 0.01;
};

renderer.start();

Rendering

  • Depth data provided by WebXR can be used for occlusion in the 3D scene.
  • Occlusion is calculated in the shader code injected using the AugmentedMaterial.transform() method.
  • To enable realistic rendering of the scene the MeshPhysicalMaterial material should be used alonside PBR assets.

Physics

  • cannon.js can be used for physics interaction between objects.
  • The VoxelEnvironment provides a probabilistic voxel based model that maps the environment from depth data that is updated every frame.
  • Alternativelly physics can rely on plane detection using the FloorPlane or Planes objects.
  • Currently performance is limited might be improved using WebXR Real World Geometry API

License

  • The code from the project is MIT licensed. The license is available on the project repository,

enva-xr's People

Contributors

tentone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.