r/iOSProgramming • • Jan 09 '21

Augmented Reality animated iPhone box made with SwiftUI, ARKit 4 and RealityKit (Github repo in comments)

923 Upvotes

43 comments sorted by

23

u/Tonqer Jan 09 '21

Here is my commented code for anyone who wants to experiment with it:

https://github.com/riccqi/ARImageTracking

My Twitter account where it went semi-viral:

https://twitter.com/riccqi

45

u/danen_ Jan 09 '21

Nice, it looks so smooth. In my beginnings of iOS dev I’ve used the image tracking that ARKit is offering but it wasn’t so smooth like on the video. Is it something that RealityKit offers? I was pretty much hyped for the ARKit at the beginning but later due to the work responsibilities I haven’t been reading about the new stuffs about it. Also another question, why are you using SwiftUI? As I can see there isn’t any UI element on your app

9

u/Tonqer Jan 09 '21

To my knowledge, the older SceneKit framework offers about the same tracking ability as RealityKit does. So it could be just general advancements to ARKit. I used SwiftUI because I wanted to try out working with SwiftUI's Coordinators and UIView wrappers; perhaps it can be adapted into a SwiftUI app someday

7

u/RadicalBond Jan 09 '21

Yeah I believe both SceneKit and RealityKit rely on ARKit to do the actual tracking (RK uses ARKit internally but for SK you have to explicitly import it.) SK and RK do the rendering.

It’s been my experience, and Apple has said as much at WWDC, that AR tracking has been improving a lot, especially on newer phones and in good lighting. The LIDAR sensor helps but not as much as you would think. It helps the most in low light (e.g. it makes testing a lot easier because you can just do it right at your desk instead of having to go outside or into a very brightly lit room.)

1

u/Tonqer Jan 10 '21

Yup, this was recorded on a regular iPhone 12 with no LIDAR

1

u/danen_ Jan 09 '21

Maybe it’s because of my device (8+). I remember when I was trying the image tracking if I moved it quickly the tracking was interrupted and it wasn’t nearly smooth as on the video of this post. Anyway AR was always interesting for me but now with the work responsibilities I don’t have that much energy and hype for trying something new, or maybe that’s some excuse from my side

1

u/Tonqer Jan 10 '21

Go for it man! The tracking still gets lost sometimes on the iPhone 12 I was screen recording this on, but only at odd angles and bad lighting.

3

u/javaHoosier Jan 10 '21

ARKit handles the session, ARAnchor tracking, and localization of the device. ARKit has configurations for different experiences for the world. This is an imagetrackingconfig. If you were to walk around it would suffer. worldtrackingconfig is the opposite in this case, it performs while walking around but detection and not tracking. So if the image moves it will suffer.

RealityKit is for renderer with stuff like occlusion, shadows, multiuser synchronization, lighting, sound and Entity Component System for Virtual Content to make things look more real, faster, and easier to work with built in.

There is an overlap with their functionality when it comes to anchors since RK has its own way of handling it which definitely will cause confusion.

ARkit itself is getting better with each version.

2

u/Tonqer Jan 10 '21

This is a really good summary of the differences, thank you!

8

u/iGoalie Objective-C / Swift Jan 09 '21

Well done! Does it track a y iPhone box or did you modify yours in someway for the phone to identify it?

2

u/Tonqer Jan 10 '21

Not at all, it will work with all iPhone Xs boxes, and sometimes even images of it. I just had to scan the image on my Xs box into the Xcode project

0

u/[deleted] Jan 09 '21

[deleted]

6

u/young_horhey Jan 09 '21

I don’t think the user even has to tap to set an anchor. From what I remember you can give the AR library an image that it uses as the anchor, and can automatically overlay the AR video when it detects that image in the camera view.

3

u/Tonqer Jan 10 '21

Thats exactly right

5

u/cform Jan 09 '21

That’s really awesome, and seems like something Apple marketing would love. Side note what keyboard is that?

2

u/Tonqer Jan 10 '21

It is a Keychron K1 V4!

3

u/themixtergames Jan 09 '21

Looks like a Keychron K1

3

u/MrGaloree Jan 09 '21

This is so wild. I'm just starting out as a developer, and cool things like this keep me going.

1

u/Tonqer Jan 10 '21

All the best man 🙌🏻

1

u/MrGaloree Jan 10 '21

Thanks man! Such a nice community.🤝

3

u/tapan666 Jan 10 '21

A small suggestion : you could’ve rounded the corners of the overlay so that it could’ve blended more with the iPhone image on the box.

2

u/Tonqer Jan 11 '21

I’m looking into whether thats possible!

1

u/tapan666 Jan 11 '21

In SceneKit, setting the corner radius of the plane Node, on which video is mounted as its materials, did the trick. Don’t know about the realitykit tho.

1

u/Tonqer Jan 11 '21

I just got the rounded corners to work in RealityKit through specifying a cornerRadius property when generating the plane! I’ll push a commit to my Github soon

2

u/hjam91 Jan 10 '21

This looks hella dope. Btw what keyboard are you using?

1

u/Tonqer Jan 10 '21

Thanks! It’s a Keychron K1 V4

7

u/[deleted] Jan 09 '21

That’s actually the coolest AR I’ve seen so far. So natural looking

5

u/Weabout Jan 09 '21

That's cool!!

4

u/archdanny Jan 09 '21

Really nice. The scene blending of ARKit has improved a lot.

1

u/PandaSmanda Jan 28 '21

Do you have to download an app to see or how did you get it to play?

Looks amazing btw

1

u/Tonqer Jan 31 '21

Thank you! You will have to download the project source file from my Github and launch it on your iPhone through Xcode.

3

u/[deleted] Jan 09 '21

Wow, AR is getting really good.

3

u/ronaldwreagan Jan 10 '21

That's awesome. There's no need to ever buy a new phone again. Just get a white box and run this app to get the latest features.

2

u/bobotwf Jan 10 '21

Yo dawg, I heard you like iPhone.

2

u/yyuuiko Jan 10 '21

iphone 13 box looking good, i see no notch

2

u/kkyl Jan 09 '21

Impressive, so trippy tho

2

u/jaegerpicker Jan 09 '21

This super well down!

2

u/orihpt NSObject Jan 09 '21

This is the most satisfying thing I saw in a while

2

u/Fizaraz Jan 10 '21

Ah I saw this on your Twitter the other day, super sick man! Really well done 👍🏻

1

u/a_la_commode Jan 23 '21

But.. does it run Doom?

1

u/ittrut Feb 23 '21

Shiiiiitttt this is NICE

1

u/[deleted] Apr 19 '21

Wow this is seriously impressive. I could think of 1000 reasons why companies would want this

0

u/[deleted] Jan 10 '21

[deleted]

1

u/Tonqer Jan 11 '21

Thank you! It’s the Keychron K1 V4