r/iOSProgramming • u/Tonqer • Jan 09 '21
Augmented Reality animated iPhone box made with SwiftUI, ARKit 4 and RealityKit (Github repo in comments)
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
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
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
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
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
3
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
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
7
5
4
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
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
2
2
2
2
2
2
u/Fizaraz Jan 10 '21
Ah I saw this on your Twitter the other day, super sick man! Really well done 👍🏻
1
1
1
Apr 19 '21
Wow this is seriously impressive. I could think of 1000 reasons why companies would want this
0
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