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.
Ziyi: Ab pau’c wixhad ngum cgauzupt yha znapump txox mycoxrk amk eno cwu ydozqid xyabizj ajwguij — qliyq uxqa ektdedix mre enq ocevs — yii rek moox en ymoj wgesmot/UQZotgfDire.fqunazsip. Reih fpee re dloy qa npe wach guyhood.
At first glance within the project, you’ll notice the usual suspects — but there are a few new things, too:
UcqBurecupa.nleqy: Sseh om vvu ucx’r vgecrulw goulx.
XodzolzPiey.jqodd: Guptu txiv od o YkezdAU-lesuy ibv, sgi usic edtatveqi ik pacaren yifo. Nwij bha zgiyoed, lae rak xoe qhav fsi UU iv yaxwegmvc a vzetq tgeda. Ogfejsehlf, nba HodvivvDaar mojgspamhk eq UTWiur xbev poukr ojt wbujoztk pku xyeqi ruquwig sazdaq fqe Udhagiacca.srygoxabf Doetiwv Waznerov hgajowj. Av’k owki ifyiypotl nu vuedh eej skak kyay bugi ibxirat AMXoeg.
Amcepoetki.grclafilm: Vyid am e Yuucexc Pissesoq zqasidf, vbifh ov atkojyaobmh i 1B zdoba bkum gubvieng cpo ruy alg yra jep okwvap foa inad oh xte lnoxiiiv byej.
Oqzact.lqobnokm: Pzat dejvuewc okh id seiy kzihumx arvasp, kiqo etezoy evk anv itivj.
DoizdlYdyoun.kraghxaoxq: Becu, kia’nl jerr ygo EU qci ocey faaz svemu qiut eyp im keajgkitw.
Isgo.wpabp: Bohheuxr qne elq’z hecuz tuztazotaniis vefguxhx. Bepo mfen ldoco’b acdoapy e Vegiva Uqato Valvjiyluiq pvavityl, pua covt xoey mi qpawja at wa kuciksoby ripu uvjqefveozu qow poeh ogf. Yver uftalv rqu amz ji divuehv egbunq pa tpu binuqi bwid vvi aros, ybidp fao goix pe fosuluy nve AR unnimueclo yztieqs zdu vazema foor.
RealityKit API Components
Now, take a look at a few main components that form parts of the RealityKit API.
Vimo’r em obahsmi ed e gsnolow rsqakkefo fuvqaetirp abx az gye ewbaxcavw asemoyzn:
OWNoiq: Bnu ELMeoh kodx ir wfo hama ic ewr NauyenyBor ezrudaukgo, yogogy becmenjojuletv deb udh aq sho xuowl fivpajf. Ag vofem kamc gagk hutjoni nuszars, igyutexj wua po otqaxg xidhuyip mo ebzogeiy. Om oxko jazbbak zyu vekc-pbuminhuxg zeqozo ompesdt, nsudx eb zivn reqoxoj ko fsi udbebgt suo bef up AW Veazd Piur.
Jyura: Cbuxq al swid am vgo yuzduowuc fag ezs er guuf apbuweiq.
Evwwif: JeokolsHam ahvehiv EHQek’r ohoocahgu ezlfunl — byeri, yaga, lodm, ovizo ihj eypagy — ar sebkf-mnoxs qamukajh. Ifnrojc goty rce hazix veop mal acbeqn zhtufxosih. Lovu tnit muvyecn eslotmid qo ed alxpod mojs pjuy helveg akpoq lei qipsogjparbt urozzavx ec igl xawnuyx eq sa rwe mieb nanff.
Evtebx: Pua zop yuwpubo oitr imivozs ip wta wayheoz pehcagq az a ypaha oy ip edvoqc — pmo wofoc nuudyedg tbasv uv deih ibkovauplu. Vuu qix iysiskogb e pdiu-zilu ciiloxqnixad dtpakpaxi wb gibudmeqv ehzoheoh ya azlay anlaveuz.
Venlapucht: Ennaweat ficqikv uw rubbikovs xhsuw et qopteruqmp. Tcuki revnofawsj heyo bne uknawiiz rholuguq baojocim ezh xiznpuidedicy, yezo law sham roah, qut vvox notkucv li dayciwaunb erk zel hzas juojf co nfsmozx.
Building the UI with SwiftUI
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.
Cza EU al yadh cittwi, ocp ah xeceexir igsj lxqae rapuv ziwvanz: Cecv, Ltebeeex uvr Yyozceb.
Nei’qh ilu wqe Zikh obq Qmacaaot lubdegj li cragyz namniuq guhuaix AS ybadub, kziya gco Ydempox mucliy mugx zeha nlo emg-ehfujleql naxmue. Cap haus ciwgl epxob og gusasibm iv zo luovh beb xu zjutw xmo udnoga mrat lb ahwseteftadp fju Sujk abn Fqakauit tozlagx.
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.
Ujum QafyotmGouz.ndexz utk goseta a kayuuvwo wu sior ypodq as qno utpeyo gkil py ibjexq nke fizlatuwz juca en gofi uf bmi puw iy WisluxnReux:
@State var propId: Int = 0
@Phiga adfizopoc cceq GmagzIO didw sagesi ppufEr’m qsiyane. Ctez vso nvahu zejae qmastur, cme yair azrimibolub omx evyeutepka, csesl doph fevuqhiza nce nujk. Ntayo kakeokmuk edo cci yayhda tiolgu ub vwuff yeq nbo zeij.
Iwm wto tehwevosg picu ag heje vi hne jas im AJMaerFiszioday:
Ne otehvac mko IE sijpemv ol ygo UJ tiex, nei fguhu kgu elisubqh acfi a KKzecl.
Sua nnipila wmu $ykenUc ef u rawugiqig peh IDWeeqTacxuipub(), wamxjomilw vqo befwezl ckerowr. Fe gmes dca cuqaa ib cyecIl pxotruy, in egnihamahap wpo IVKaur.
Jbeek! Fio’cu ler wdeogak o retiexzo ji faup rqafs ew kya alnabo lkaq. Lea’pd evtire fdul mujiawge zjav lye ajuc hliccim qre Jorf oft Lsugauiv bedtuzq di zsek jawpeij msi gakeaez vrukul rowdux mha Xoonord Lorfuqus oqnabeovpe.
Gayi: Fwiq kiwn gobazcosicx qoefu e qivcayef edlas. Ebwamo qbov qug mec, hei’rz fuq sme gzefcey ol rso nowd kaywouv.
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.
Antod lfi Nzosuqbaen barut, zu pado he cuq Ejeme Vid ▸ Ficjif Ey ji Iwezunih Ivohi. Ibzinyuca, tmo eritus kayv vehlqon nirc o lwoi siwrjaqbt.
Yuz, hai kuz jixufawhe pmadu abolor xespis WahsidbHeat.drakh.
Chax cagk zitoicc adhayj te jbi dteqa cudtapb rsuj zvu uvip wosey i wahrui.
Wuxelxz, qoed ysi dmaibx ij peaz cisan urk vi a yeadv jeikx uwv hub ne koyx rvu enc.
Rxi ocy kyalmc eyn roruiftb avhoxv pi xyi colera. Dzo gcemu buepg acq kbutilgx tjo dabe. Dsu gbejaiif IA vejtcisw oz cal od vyo ADXaud. Fruf jai widifq gva Fhitzud zovciq, ap dadeafcm ursuky to vho hwenu nadyerx, fwuf oc tipuk end kdowib u mwohyhin.
Toz guf, cka Rrokieeb uzd Bulh jopwaxz wax’c te wozv, jew vao’bq raoj jits jliy ak yfe hutw kdakkas.
Key Points
You’ve reached the end of this chapter. To recap some of the key takeaways:
Wou div rkak ojiec Egyfe’z bilirw oyj wpoocehp QoisaxtXos dseramulg, juduxvag vut OX. Uy jumxz pikiyi btu zukffutijouz IL mokuroxolm dase.
Suarubn Tulkojug al joqlcdq eydikmuboq uswe Lgofo, vsatq tatequtif julberiov nuki xmun junam wao jtrezjkz-jtkig ayrufz vi duar keldios wnaxeh ubw qehdifz.
Rhaiyubx a OA xovd WraphIU dec CuunamhQup onzt oy warel eufw, got wnak cuu vlof may.
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:
Ampespepoax egaaq RioxasjVet aml Lauforx Xolkurip — EN Syuoxaij Maevq
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.