Create Lenskart like AR app using iOS RealityComposer and RealityKit with almost no coding

--

Have seen the Lenskart’s ‘Try in 3D’ feature? It’s amazing. You can try sunglasses in 3D before purchasing it. Using this medium story, you can create similar AR iOS app using Apple’s RealityKit and RealityComposer with almost no coding (very less code is required).

Prerequisite:

Before jumping into the tutorial and actual coding, you will need to have following things:

  1. Apple’s macOS 10.14.5 or later (macOS Mojave)
  2. Xcode 11 or later
  3. Physical device with A9 chip (namely Apple’s iPhone 6s and later will be fine), running iOS 13 or later. Note that you will need to have physical device with you, because you cannot run AR app on simulator as it needs camera access.

Let’s get started:

First, design some cool goggles, and it’s damm easy. You just have to import some cool 3D goggle objects from https://poly.google.com or https://usdzshare.com

Then, download some shades of your choice in ‘usdz’ format. (refer screenshot):

Now, open Xcode 11 and go to developers tools. From there, open ‘Reality composer’ . Select ‘Face’ template from the pop-up shown.

Trending AR VR Articles:

1. Ready Player One : How Close Are We?

2. Augmented Reality — with React-Native

3. Five Augmented Reality Uses That Solve Real-Life Problems

4. Virtual Reality Headsets: What are the Options? Which is Right For You?

Import sunglasses of your choice, and adjust according to the face. You can scale it and rotate.

Personality NFT | Get my Personality NFT

Now, select ‘Scenes’ from left hand side top and add some scenes, and repeat the procedure of importing different goggles 3d objects (usdz files) of your choice.

Then, after adding some cool shades, give names to your scenes. Then save your project (it will be saved in .rcproject format)

Coding (not much…):

Open Xcode 11 or later and select ‘Augmented reality app’ template.

Then, import (drag and drop) your .rcproject file in Xcode.

Import ARKit in your project, as we will be using some code to initialise the front camera and face tracking.

Then, in viewDidLoad() method, add swipe gesture to arView. Also, load the first goggle.

Then, write changeShade() func and loadShade() func, which handles changing the shades on swiping right.

Let’s Run the app:

Here is the screen recording(gif):

Your lenskart like AR app is ready!! 😎

Don’t forget to give us your 👏 !

--

--