AR.js

Image tracking, Location Based AR, Marker tracking. All on the Web.

README


AR.js - Augmented Reality on the Web


CI code style: prettier Gitter chat Twitter Follow Twitter Follow

You can now own the first commit of AR.js! 👉OpenSea

AR.js is a lightweight library for Augmented Reality on the Web, coming with features like Image Tracking, Location-based AR and Marker tracking.

30/12/21 Update: There is now also a brand new OSS Web AR JS library around, called [MindAR](https://github.com/hiukim/mind-ar-js).
If you need a great Image tracking feature (also multiple image tracking) and Face tracking, go check it out!
As for now, AR.js is still the only library providing Marker based and Location based AR features.

This project has been created by @jeromeetienne, previously managed by Nicolò Carpignoli and it is now maintained by the AR.js org.

🚀For frequent updates on AR.js you can follow @the official Twitter account and Watch this repo!

Logo is courtesy of Simon Poulter .



⚡️AR.js has now an official Documentation!⚡️


If you want to give a first look at AR.js potential, you can continue with this Readme.



⚡️ AR.js is coming in different builds. They are both maintained. They are exclusive.

Please import the one you need for your project, not both:

- AR.js with Image Tracking + Location Based AR (AFRAME):

  - https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js

- AR.js with Marker Tracking + Location Based AR (AFRAME):

  - https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar.js


- AR.js with Image Tracking + Marker Tracking (Threejs):

  - https://raw.githack.com/AR-js-org/AR.js/master/three.js/build/ar-threex.js

  if you need the ARjs namespace import ar.js:

  - https://raw.githack.com/AR-js-org/AR.js/master/three.js/build/ar.js

- AR.js with Location Based AR (Threejs):

  - https://raw.githack.com/AR-js-org/AR.js/master/three.js/build/ar-threex-location-only.js


You can also import a specific version replacing master keyword with version tag:

  1. ``` html
  2.   <script src="https://raw.githack.com/AR-js-org/AR.js/3.4.2/aframe/build/aframe-ar-nft.js">
  3. ```

Get started


🖼 Image Tracking


Please follow these simple steps:

- Create a new project with the code below (or open this live example and go directly to the last step)
- Run it on a server
- Open the website on your phone
- Scan this picture to see content through the camera.

  1. ``` html
  2. <script src="https://cdn.jsdelivr.net/gh/aframevr/aframe@1c2407b26c61958baa93967b5412487cd94b290b/dist/aframe-master.min.js"></script>
  3. <script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
  4. <style>
  5.   .arjs-loader {
  6.     height: 100%;
  7.     width: 100%;
  8.     position: absolute;
  9.     top: 0;
  10.     left: 0;
  11.     background-color: rgba(0, 0, 0, 0.8);
  12.     z-index: 9999;
  13.     display: flex;
  14.     justify-content: center;
  15.     align-items: center;
  16.   }
  17.   .arjs-loader div {
  18.     text-align: center;
  19.     font-size: 1.25em;
  20.     color: white;
  21.   }
  22. </style>
  23. <body style="margin : 0px; overflow: hidden;">
  24.   
  25.   <div class="arjs-loader">
  26.     <div>Loading, please wait...</div>
  27.   </div>
  28.   <a-scene
  29.     vr-mode-ui="enabled: false;"
  30.     renderer="logarithmicDepthBuffer: true; precision: medium;"
  31.     embedded
  32.     arjs="trackingMethod: best; sourceType: webcam;debugUIEnabled: false;"
  33.   >
  34.     
  35.     <a-nft
  36.       type="nft"
  37.       url="your-server/https://raw.githack.com/AR-js-org/AR.js/master/aframe/examples/image-tracking/nft/trex/trex-image/trex"
  38.       smooth="true"
  39.       smoothCount="10"
  40.       smoothTolerance=".01"
  41.       smoothThreshold="5"
  42.     >
  43.       <a-entity
  44.         gltf-model="your-server/https://raw.githack.com/AR-js-org/AR.js/master/aframe/examples/image-tracking/nft/trex/scene.gltf"
  45.         scale="5 5 5"
  46.         position="150 300 -100"
  47.       >
  48.       </a-entity>
  49.     </a-nft>
  50.     <a-entity camera></a-entity>
  51.   </a-scene>
  52. </body>
  53. ```

🌍Location Based Example


Please follow these simple steps:

- Create a new project with the following snippet, and change add-your-latitude and add-your-longitude with your latitude and longitude, without the <>.
- Run it on a server
- Activate GPS on your phone and navigate to the example URL
- Look around. You should see the text looking at you, appearing in the requested position, even if you look around and move.

  1. ``` html
  2. <!DOCTYPE html>
  3. <html>
  4.   <head>
  5.     <meta charset="utf-8" />
  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  7.     <title>GeoAR.js demo</title>
  8.     <script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
  9.     <script src="https://unpkg.com/aframe-look-at-component@0.8.0/dist/aframe-look-at-component.min.js"></script>
  10.     <script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
  11.   </head>
  12. <body>
  13.     <a-scene
  14.       vr-mode-ui="enabled: false"
  15.       arjs="sourceType: webcam; videoTexture: true; debugUIEnabled: false;"
  16.     >
  17.       <a-text
  18.         value="This content will always face you."
  19.         look-at="[gps-camera]"
  20.         scale="120 120 120"
  21.         gps-entity-place="latitude: <add-your-latitude>; longitude: <add-your-longitude>;"
  22.       </a-text>
  23.       <a-camera gps-camera rotation-reader> </a-camera>
  24.     </a-scene>
  25.   </body>
  26. </html>
  27. ```

🔲 Marker Based Example


Please follow this simple steps:

- Create a new project with the code below (or open this live example and go directly to the last step)
- Run it on a server
- Open the website on your phone
- Scan this picture to see content through the camera.

  1. ``` html
  2. <!DOCTYPE html>
  3. <html>
  4.     <script src="https://aframe.io/releases/1.0.0/aframe.min.js"></script>
  5.     
  6.     <script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar.js"></script>
  7.     <body style="margin : 0px; overflow: hidden;">
  8.         <a-scene embedded arjs>
  9.         <a-marker preset="hiro">
  10.             
  11.             <a-entity
  12.             position="0 0 0"
  13.             scale="0.05 0.05 0.05"
  14.             gltf-model="your-server/https://raw.githack.com/AR-js-org/AR.js/master/aframe/examples/image-tracking/nft/trex/scene.gltf"
  15.             </a-entity>
  16.         </a-marker>
  17.         <a-entity camera></a-entity>
  18.         </a-scene>
  19.     </body>
  20. </html>
  21. ```
Important! Be aware that if you are referring to external resources, in any app, especially those using NFT, you will encounter CORS problems if those resources are not in the same server of the code. If you can’t see the tracking, please open your Browser Dev Tools and check if you have CORS errors in the console. If so, you have to fix those errors in order to see your content. The correct fix is to place your resources on the same server of your code.

If you cannot do that, you can host a proxy anywhere server to solve that (https://github.com/Rob--W/cors-anywhere).
Please note that several hosting services have policies that does not permit to use such server. Always check hosting services policies before using them to avoid account suspensions

Learn more on the AR.js Official Documentation.

ES6 npm package


You can install AR.js with npm and use in any compatible project that support npm modules (React.js, Vue.js, Next.js or whatelse), to install it run:

  1. ```
  2. // Install with npm
  3. npm install @ar-js-org/ar.js
  4. ```
  1. ```
  2. // Install with yarn
  3. yarn add @ar-js-org/ar.js
  4. ```
For some examples read this issue.

Troubleshooting, feature requests, community


You can find a lot of help on the old AR.js repositories issues. Please search on open/closed issues, you may find interesting stuff.

Contributing


From opening a bug report to creating a pull request: every contribution is
appreciated and welcome. If you're planning to implement a new feature or change
the api please create an issue first. This way we can ensure that your precious
work is not in vain.

Issues


If you are having configuration or setup problems, please post
a question to StackOverflow.
You can also address the question to us in our Gitter chatroom

If you have discovered a bug or have a feature suggestion, feel free to create an issue on Github.

Submitting Changes


After getting some feedback, push to your fork and submit a pull request. We
may suggest some changes or improvements or alternatives, but for small changes
your pull request should be accepted quickly.

Some things that will increase the chance that your pull request is accepted:

Follow the existing coding style

Licenses


It is all open-source! artoolkit5-js is under LGPLv3 license and additional permission.
And all my code in the AR.js repository is under MIT license. :)

For legal details, be sure to check artoolkit5-js license

Full Changelog: AR.js changelog