Place your Favorite Furniture using Augmented Reality
Make your vision entertain you by working with powerful technologies. Augmented Reality is one such incredibly useful technology, with which the entire world around you is in play.iOS introduced ARKit framework to remove the line between virtual and real world.
ARKit works with the iOS device’s camera, scanning images and objects in the environment, and positioning 3D models in real space and making them fit in. ARKit primarily does three essential things behind the scenes in AR apps: tracking, scene understanding, and rendering.The core of ARKit is about letting you drop objects into an environment, and manipulate them using the touchscreen.
At WWDC 2018 Apple announced a host of improvements that are coming to version 2.0 of ARKit. The first of these improvements is USDZ, a new file format developed by Apple and Disney’s Pixar for ARKit to make it easier to create and share augmented reality content. The new format will be supported natively by Adobe’s Creative Cloud suite of software to allow for compatibility with common programs like Photoshop.
ARKit 2 makes it easy to develop vivid augmented reality experiences and enable apps to interact with the real world in…developer.apple.com
There is a saying, the more you explore, the more you fall in love with it.This happened to me with Augmented Reality.I have been reading many articles and developer blogs of how to place a 3D object onto the plane using ARKit, inspired by IKEA furniture app.I made it through after few days.Thanks to Google!!!
This Furniture App is implemented based on the concept “Bring it home before you buy it”.You really like the furniture but you are not very sure if it fits in your living area.No problem, ARKit has the solution.Basically, the app determines the horizontal plane and once detected we will insert a furniture (chair) and we can scale the it by pinching and zooming.What is the use if the chair is not moving.Yes, we will use gestures to rotate the chair, move it and fits it in the environment.
Let’s see how the app works.
Before exploring more on ARKit framework, it is recommended to have knowledge on SceneKit.When Augmented app is selected in Xcode, the content technology by default is SceneKit.To know more,
objc.io publishes books on advanced techniques and practices for iOS and OS X developmentwww.objc.io
In Xcode, by default we will see ship.scn. If you are not very sure, how this works, run the app with the default code and you can see the space ship in your camera view.We don’t need ship.scn in our project.Just go ahead and delete it in your ViewController.Now, we need our furniture model, some sort of chair, table or sofa.
Find 3D models for your project in our vast online catalog of cars, people, textures, architectural models and more.www.turbosquid.com
TurboSquid has amazing 3D objects where you can download them for free.(I selected .dae collada format chair).Place the images into your project.
The project setup is done.Now, the fun part begins.Coding time !!!
Firstly, to place the object we need to detect the plane.In our case it should be horizontal.The plane detection is done using didAdd delegate method and ‘ARPlaneAnchor’.Register gesture recognizers like tap, pin, pan, long press and add it to the SceneView. Get the location of the touch recognizer.Search for the real world objects in the captured image corresponding to the SceneView using hitTest and add the chair model to the SCNScene.
If your chair in not placed properly onto the plane, try changing the perspective of the chair to front and transform the editor using Xcode node inspector.
That’s it !!! As simple as it looks.Run the project and you can now place the chair model onto the plane.Use progress indicators to let user’s know if the plane is detected.This is the basic part of adding 3D object models onto the horizontal plane using ARKit and SceneKit.Try using other gestures to add rotate, move, zoom in and zoom out.
Having great visual elements can give your App a unique personality. In this tutorial, we will look at 3D objects…www.appcoda.com