Hi Alex here from rebeloper.com and today you are going to learn about
Vertical Plane Detection in ARKit 1.5 so without further ado let's get started!
(MUSIC PLAYING)
Okay you most probably heard that as of iOS 11.3 we are able to
have vertical plane detection because in ARKit 1.0 we only had horizontal
plane detection and I was talking about that earlier in the previous episodes!
And if you already haven't subscribe to the channel go ahead and subscribe and
take a look at the previous videos of our ARKit playlist. Now in ARKit
1.5 as of iOS 11.3 we have finally vertical plane detection and we
are going to talk about that today. So let me show you what we are going to
build out today. Now first of before we get started and we get into the code
part I have to tell you that you will need of course a device supporting iOS
11.3 or higher of course. And you will need Xcode 9.3
I believe let me show you. Yes Xcode version 9.3 or above.
Now that supports ARKit 1.5. Okay, that is the minimum
requirement from Xcode. Now let me just build and run and show you what we are
going to build out today. So I have my project and after the demo I
will just show you what I have pre-built for you. It's basic stuff that I have
already showed you in the previous lessons.
So let me just drag that out. Okay, here we are and we are detecting our surfaces
and horizontal surface has been found. Good, now let's go over my screen here
and let the magic begin that's it just wait for a little bit.
And here we are it took a while maybe because it's a screen and not real wall
but there you have it we have a wall on our screen and let me just go even
deeper there you can see... there it is on my screen and new horizontal plane has
been detected too. So let me just stop this and this is what we are going to
build out today. Now because this is a pre-made project I have managed to do
this with the knowledge that I have already taught you in the previous
lesson so go ahead and take a look at those episodes too. But I am going to
demo you what I have written here. So first of all I got rid of the Main.storyboard
and here we are in the app delegate and we are creating the window
and with the game view controller manually here. And I already do have a
juicy part in the view controller but we are going to create it with our game
view controller so you know what you actually need to build out. So one last
thing that I have added this extension at degrees to radians go ahead
and take a look at the previous videos if you don't know what I'm talking about
here. So here we are in the game view controller we have our ARView our
configuration and we have added our ARView to our view as a sub view we
have constrained it and of course we have added our configuration as a plane
detection as horizontal as usual we have started our session and we have added
some debug options. Now because we already have implemented our ARSceneViewsDelegate
protocols we need to add our delegate to our ARView here. And
here are our three delegate methods. Well this is in the previous videos we
are basically adding node our plane to our... well our node when a horizontal
plane has been detected so that is how we add our floor here and we update it
if it has been updated. Well we replace it with another node. I have gone into
deep explanation in the previous videos. And of course we remove it and next up
is that we have our create function here and our remove node with our name
because when we update our node well our claim we remove the existing node and we
add a new plane instead of it. So here we have our name so we may run through each
node and remove the node with that name. And here we have our Euler angles
because we need to... well move it as with 90 degrees and here we have our 90
degrees radians because the SCNVector free requires radians and that is where
our extension comes into play. Here we create a geometry plane. We give a first
material and here we have our materials. Let me just go to our assets. Here we
have our floor and of course our wall that we are going to build out to today.
And we are making it double sided while this is a tricky one go ahead and take a
look at the previous videos why this needs to be true. And we are positioning
it to the anchors center XY and Z values. Now that is old for this well demo
pre-prepared Xcode project and that basically does is
adds us a floor. Now I won't go on and show you that because you have already seen
that what we are going to do now is we are going to add a wall. So let's get
right into it and first of all let's change this plane detection from
horizontal to vertical. So go ahead and type in "." and here you have again a
new vertical plane detection option so let's do that and now we can have a
vertical plane detection. Now what we want to do now is add a floor. And what
we need to do here is just delete the contents of our first material and add
it as a wall. Okay, and that is pretty much it so let's build and run and see how
this looks like. Let's wait for it and let me just show you in my QuickTime
Player here so let us wait for it to familiarize itself and let you just show
my computer here and we should get a plane detection really soon. And there
you have it vertical plane detection it best! Okay
but if we just want to have one vertical plane detection that is okay. But as a
bonus I will show you how you can add vertical and horizontal plane detection
and that is pretty simple too so let us just change our vertical plane detection
here and let us add an array so ".vertical" and ".horizontal" and now you
have both of the plane detections enabled. Next up is that I want to
fix this create anchor and this floor because now we need to remove the floor
and the walls too. So I will just edit this create function to named and we
will pass on here a string. And let me just go here and give the nodes name: named.
So I will just create a named floor or wall. Now according to the name of this
function we will add our wall or our floor image. Then we are going to
add our wall here otherwise we are going to add our floor. So this is a ternary
operator go ahead and find out more about it. Okay pretty a good stuff and
now we need to add this double equal sign because we are checking. Okay, now we
have our first material set up correctly. Next up is that we want to
check so let us just add in here our missing parameter and this will be at
this moment let's say a wall. Okay and let's add here to our missing
parameter and this will be our wall. But of course we want to add floors too so
what we are going to do here is create a variable and that is our name. And it
will be of type string so I will just name this wall. Let it be with capital W.
But I want to change this because... oh not with capital W with
a simple w is ok. And the let us just add this to the create named with anchor
function. So now whatever I pass in for the name it will be created
currently we are passing in the wall. So now I wanted to check for the well the
line detection orientation. And for that we need to check the anchor planes alignment.
So if anchorPlane.alignment == ARPlaneAnchor.Aligment.vertical
here we have our let's say vertical. And and if it is vertical then the name
should remain a wall. So let's add here our wall. Else it is
horizontal so let's add our name here floor. Great, now we need to do this with
the update method and the remove method so I will fast forward this...
Great! Now we have our delegate methods set up and I believe this will fix
everything. We should be able to have vertical and horizontal plane detection.
So let's build and run and see if we got everything correctly set up. Let's build
and run and now let's wait for it to configure. Okay! And let's first check our
work horizontal plane detection and there it is pretty good and now let's
check the vertical one. This is my screen so it will take a little longer and
there it is great! Now you know how you can add both vertical and horizontal
plane detection to your ARKit games of course with the help of ARKit 1.5 and
that is it for this tutorial. Hope you enjoyed it! And let me know in the
comments below what is your favorite type of plane detection: is it vertical
or is it horizontal? So go ahead and type into the comments. And if you did like
this video go ahead and give it a thumbs up subscribe to the channel hit that
notification bear and as usual I will see you in the next one!