Previously we saw how to set up our Unity project for AR and Android deployment. If you haven’t checked it out already, then do it before continuing with this blog as it’s a prerequisite. In this blog, we’ll learn about plane detection, where we’ll be able to scan the environment using our phone’s camera to detect horizontal and vertical planes. We’ll also learn to create a custom plane and use it for visualizing the detected planes.
Let’s start by setting up our scene for plane detection
The component requires us to add a Plane Prefab. So, let’s see how to create and add a plane prefab.
We can create a Plane Prefab in just two steps:
With that, we have created a Plane Prefab. But the line renderer has a default line color (black) and the mesh renderer has a default material (orange). If you are not a fan of those colors then we can change them in just a few steps.
Before we build and test the application, there is one more step to do. That’s referencing the Plane Prefab. To do that, select the AR Session Origin GameObject from the Hierarchy window → drag and drop the AR Default Plane prefab into the Plane Prefab parameter of the AR Plane Manager component
Now, let’s build and test the application.
Once it’s built, the application will run on the device and we can test it. As we scan the environment, it should detect the horizontal and vertical planes and render the plane prefab on top of that.
What we saw in this blog was just the beginning, there are so many things that can be done after a plane has been detected. We can calculate its size, place an object on top of it, make an augmented object interact with it, etc. In the next article, we’ll be doing something similar. We’ll be creating a Tap To Place application where we’ll be able to spawn an object on the detected plane and move it to a different location on the plane based on the touch position.
If you've enjoyed the insights shared here, why not spread the word? Share the post with your friends and colleagues who might also find it valuable.
Your support means the world to us and helps us create more content you'll love.