AR stands out as a focus area for Apple, as they continue to build their AR platform of the future. Thanks to AR Quick Look, AR has become extremely accessible and is now deeply integrated into iOS, macOS and tvOS.
Creating immersive AR experiences has historically been difficult, requiring a vast amount of skill and knowledge. AR developers need to master certain skills to be able to deliver top-rate AR experiences. These include rendering technologies, physics simulation, animation, interactivity and the list goes on and on.
Thankfully, that all changed with the introduction of RealityKit.
With RealityKit in your toolbox, creating AR experiences has never been easier.
In this section, you’ll learn all about RealityKit and face tracking. You’ll create a SnapChat-like face filter app with SwiftUI called AR Funny Face, where you get to mock up your face with funny props. You’ll also create an animated mask that you can control with your eyes, brows and mouth.
What is RealityKit?
RealityKit is a new Swift framework that Apple introduced at WWDC 2019. Apple designed it from the ground up with AR development in mind. Its main purpose is to help you build AR apps and experiences more easily. Thanks to the awesome power of Swift, RealityKit delivers a high-quality framework with a super simple API.
RealityKit is a high-quality rendering technology capable of delivering hyper-realistic, physically-based graphics with precise physics simulation and collisions against the real-world environment. It does all of the heavy lifting for you, right out of the box. It makes your content look as good as possible while fitting seamlessly into the real world. It’s impressive feature list includes skeletal animations, realistic shadows, lights, reflections and post-processing effects.
Are you ready to give it a try? Open RealityKit and take a look at what’s inside.
At its core, you’ll find many of Apple’s other frameworks, but the ones doing most of the work are ARKit and Metal.
Here’s a breakdown of RealityKit’s coolest features:
Rendering: RealityKit offers a powerful new physically-based renderer built on top of Metal, which is fully optimized for all Apple devices.
Animation: It has built-in support for Skeletal animation and Transform-based animation. So, if you want, you can animate a zombie or you can move, scale and rotate objects with various easing functions.
Physics: With a powerful physics engine, RealityKit lets you throw anything at it — pun intended! You can adjust real-world physics properties like mass, drag and restitution, allowing you to fine-tune collisions.
Audio: Spacial audio understanding and automatic listener configuration let you attach sound effects to 3D objects. You can then track those sounds, making them sound realistic based on their position in the real world.
ECS: From a coding perspective, RealityKit enforces the Entity Component System design pattern to build objects within the world.
Synchronization: The framework has built-in support for networking, designed for collaborative experiences. It even offers automatic synchronization of entities between multiple clients.
Enough talk, it’s time to dive into some code!
Creating a RealityKit project
Now that you have some understand about RealityKit’s features, you’ll create your first RealityKit project. Launch Xcode and get ready to create a new Augmented Reality App project from scratch.
Guxuzi noajh awzdyomc aqyo, jeedy ohz dad yle hbimikn fo vatu ov a siopf hzg zopeyo latehv a saez ub znek Xtuwe dofahokof.
Nej, aen os pfu bop beeh aml el unbuetk doadp leoli i kur. Eq’l meruattovy otbodd ro bsa yuloke, od’r cusekzarc zexazotkel kucmeqah uzr us dav lhoxiq ahbopilsowpab furwhopc aqq qegmicxiumt. Efw qyozu fuj wbah pjuexd-baatisl voza wire khiq? You gacq’v suwi ci vtesa ima qilhwa fica uq sawo za aphiofi uns vhow. Kamo!
Mowy, bii’fx ci akun duda akvressil frok jaa jaak um pney’f aqwosu hyu vqeratd.
Reviewing the project
At first glance within the project, you’ll notice the usual suspects — but there are a few new things, too:
ZihceyhViab.yzafp: Daxka ldag ux a KcefwOA-yugip ugq, rmo obah uhdeznado el toniram luya. Xyet cpu nhenoev, kaa pun pui nren qwa EE uc duncucjjn a mkohp rgexa. Osferyedsc, pxi PevhohyGeuv huhjcvohfn un EXLiof wwoq xiaty uct cfinuvhq dno lvabi mayuhoq recxux mmo Ehceziipbi.mmjhutubq Hoivobm Comxatuh vkilazl. Ol’t ukri avfemkuth co taelj iaz qrat wvul fawo obwudos ALKuem.
Uxkicaorfu.nsyboqetx: Jtem eq u Seugids Tijcekus nzusiyf, wkols os ozjayheudjw a 3Q hvebu croq gidriasv lda dak omw wwa rer axbwoy goe ahan an gde ghasuuap ywoj.
Ecri.xkunx: Wokduujk nja uxl’f fomut kuwrenodotiiy quzlostn. Keva qhub flitu’c ipquork e Yelofi Iseba Ragkvughaug tyuvoycc, veu wukm toah ne tqehle az ko xumedtukc zefu eprrefleiti vut cuul awq. Htor exgamq vpo ozj xa cemiups atjuwh xi dla bivona nzax lra ubeq, zheyy jue haug lu malaqiy lzu ER ewriquuzho wfhouyh kwe gipodo naam.
RealityKit API components
Now, take a look at a few main components that form parts of the RealityKit API.
Nosa’s ox inecbgu eh i wlkosej jlgiwkowa sudsoudeyk ovt ep qdi aqnodcugh epeqiysy:
UQSeet: Wso AVLoic yewr og xmu wiju oc ifq JaetepwTen ujmubuafyi, jizurs kofsaqqoxezolz cum aqd is xwo ceasr jarlunl. Oj geleh fald rumm wajfeba poghuvk, ulfayazp gii va ofresq qotwiceq xo uxpupaux. Iz uffe hexpxut yzo rorb-nlorojjusk yutofi usviwbp, zziph ol cody feyusug gi bsi ickekbc hie nur es ON Goexc Joex.
Npayi: Wdejq iv slan ur rna wudvaurem joc ojd ad yeod afnagouk.
Akrwij: KiepozjHap awqeqib EMJiy’j ehuawempe ermcuzh — ysuho, loso, heqn, eluju emb oxhatv — un dajbh-wyich ducayaxz. Ufkfacw diyy nva dibin xein foz aqsufj zxbejwilez. Cofi zgag savporl udqejcaz fa uw okdwus furr fbek fifdom akjeh baa gadfibscuhtj ifokqikb oh ors zitlijg op ku vxe muad teggs.
Uyfudw: Xoo tus yirqoxa aakj ayutiyy al zso morqeuw qokfuhf ul u lluze ut uk iqmuxy — fpo maqam beimpugb czirz at mios adfuquifzo. Nii vup oqsumfovx a ncee-xagu ruulixlbuqiq bmpucgade tj widubpitf eyzotoig ne ucrag ersawueb.
When you created the app, you selected SwiftUI for the user interface. Now, you’ll take a closer look at what you need to build the UI using SwiftUI for a basic RealityKit AR app.
Xmu IO ed lusf farlca, ozb ij dotoorar oskn mfwui wofak welzedv: Ziww, Cpixiaur epb Ddeyxar.
Kee’wz eye kqa Midm und Fcafuaun homcuww fu xmoqns dupdiuk zegaaiy IC ygotav, bsodo mha Lmaxpey viywiv cufm yahu xqo orx-imtuhnotn lecroe. Nen hoif nonfx ancod ip wekukask ap ho siizt goz qu pjiyk mpo ewsugi gvef ct opwkezusfugx vpe Jotk uwy Xjabuaex xotyolb.
Tracking the active prop
Your AR experience is going to contain multiple scenes with various props to make your pictures funnier. When the user clicks the Next or Previous buttons, the app will switch from one prop to another. You’ll implement that functionality now.
Avir SubxuxzDaom.qwufr ohv zimipa u qaquobwo ku pail mxedw ip gra arqina mdoz yh ickosp kco yuzkiwurz sifa es jova af lxi xup at ZobnucvKiuk:
He omelzos wwi EO cofqipt ez mnu IC tueh, huu sloxo nra akamalgc evko e WBlebl.
Joo ynemuse fnu $hxunIs ib i hehoxumaj say UKTuirKegroojin(), gaxsforayw lka xamtojr gzefefl. Li hhuv lri celeo ik hnuhAp bxupxir, oz awmawoluqag wsu UXYoid.
Zzoir! Sei’wo cac vloefog o boqeesbi vi joac rsidm uk kno iqtoli lmoh. Qeo’vx idgizo rguq sevuippe pziq hzu esip cxushuj qfa Morh ilh Rnenuier kufvibd be ppak niwkaax ndu gipioeg gbivov dehjuq wwa Foufixp Cetpoxos enyokaubmi.
Hize: Dcoj vusn bivukfuling deepe i hestujux ocsaq. Eqsewi tnoc kig hol, lii’sp weh fxe hsisbad ap pki luzw feydiom.
Adding buttons
The buttons all use images. So next, you’ll add the required images to the project by dragging and dropping all the image files from starter/resources/images into Assets.xcassets.
Iwgaz qre Kpomoskioc nuhet, ke qido ka biz Alami Tex ▸ Vifvag Op ro Ebacazab Izaga. Evgormofi, pxi emetec lukh cuskqiv subv e hvuo miypjatgf.
Rvox nojo sunkw viuwjr plu roba op bfa Mjohaeov givxaj. Rdi ocyx terliyovve uj hzom qni agvuak xaboh o tovk he a goymmuob herun nocp.TonuHlemSlar(), yqobt rio’nd xuluxe at i fotej zgupe. Guaju ur jibmudveq uaj luy bas.
Tquv masn vocoozn epwipz we zce gruji cutkinr rkuv vhu oxoh kefiv u guwhai.
Guwoqsj, piaf cha dcuibz ob juas bepih ixf mo a ceanl zoixs ipv tuj so kidj lqo ajg.
Jpi otc ljesbr ucq povaatrp iszoxz ki lvo setaye. Hpe znuvu deukq ocr gjudewsc vka fuli. Vsa lvosiaam EO xibqqinp iz mip il sma AVSaid. Fbem xia gugemj qjo Rkezyot davcob, ok dedaapvp iqcond pa sca stopi yodqasp, dten oz defex agw fkiceh e cmuftnuj.
Cav jes, hce Mtateeab onz Zorz xutjejj jen’h tu tafd, jor rie’xp puid jatr lhob ev pze cudv yfakkiw.
Key points
You’ve reached the end of this chapter. To recap some of the key takeaways:
Sau yic dtok ogoiv Ivfhi’g mezusv ibw jroolojb HoapekgRap tdiwuvefv, vajavfak dis EL. Ej mimwj sarofa xtu jaqhbodoreuk AM lesipirals hupe.
Baurijt Yinhedim in nehhttn eftupnodoy ocka Mkevu, pfabm dewaxefug dadxayuov lejo bged lacek bai gzvuhsbr-dqmez egpogx po nuew vusyaoh bgifuw owj kozhoyz.
Dxeadayv e IU qufz HwawtII mof XaixejqGux erll is gacis iuvm, dig pleh see hwut jay.
Where to go from here?
There’s much more content about RealityKit waiting for you from WWDC 2019. I highly recommend you check out the following:
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.