MindAR is a web-based augmented reality library that integrates with Three.js and A-frame. This library supports both marker-based AR and face-tracking. In this Answer, we’ll focus on creating a React application using Three.js with MindAR. Currently, incorporating augmented reality into websites, particularly e-commerce sites, is popular. There are many libraries and frameworks available to assist with this task.
In this demo, we want a 3D educative logo to overlay over an image that has been placed inside the scope of the camera.
We can download the “target” image from below and compile the image to be used in the application.
Alternatively, we can simple download the “.mind” file below.
The overlay image could be a 3D asset or any image. In our case we’ll be overlaying educative logo over the target image. We can download the 3D logo asset from below.
We can use the commands given below to set up the project quickly.
npx create-react-app <Project_Name>
cd <Project_Name>
Now, it’s time to add the necessary packages (mind-ar
and three
) to our application.
npm i mind-ar --save
npm install --save three
We’ll create a few more folders for better project structuring. The final project structure would look like the following:
The Components
folder contains the component related to the MindAR.
The threeDAssets
folder contains the three assets, like the target and overlay models.
In the code sample below, we have used “.glb” models and “.mind” links instead of the components folder. While it’s preferable to upload the models to a CDN and fetch them from there, in small applications, we can create a folder like “threeDAsset.” We can then use the relative path within the application.
Press the “Run” button below and click on the link.