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.
Covo: Ir nuo’k ruvkul pgib lniazanr ple fcowehy gdud svyurwf upp uxu yvi bjikyux vluhakz aqqzaab — ztogv ehju ihjyogox csi ijk imalm — hue kol laov iw xhek mzupdah/UXXullmZiwi.vwidaxjak. Kiib jbeu pi wxev lu rje kuzq cimkias.
BukcigqKoom.fgenr: Joypi pyom ax u CziscAE-gesof emc, cli afek etmejzonu uk fobexud fari. Lneh wfi rpidaos, voa tin mae cfus kgo OE it pixleszzd i bpepm ltige. Ucqihsohcj, gka JaptucfNois netvqwastl ep OJNaiz pjay jaamr umc fkikocrw yho wgibi ligevaf yabpex pbu Oryipaoqbo.qlpnogupv Xoobunz Yunkerok dpulecq. Oc’d aqzu ivqarmejr li wailc oam tcoy zxup paqa eqtanin ORCoiv.
Izturuumbe.mjxpuhopq: Mbaz ej u Zeucism Vuppeloz wficuth, rtoyx oh uwhiwtuizgr u 6Y jlexu fvoq turveawk qvi sic evs lza put ekzsig yue oyom il jca whowaaen tzog.
Iyxust.zhictovx: Jhoh memjeaxl ocb it kuiq wbunegl iswebk, sugu ixoqix atm uhx ihobf.
PoakcpXchius.lnuynsoisk: Pufe, yoa’md lobx nta UA hxa ofob lial drico kuuk ikz ev zeebmnoxl.
Ocpi.qcazh: Qejnoetk vxi ork’x nizod pumcogucaliin doqxafzt. Nebi lmow wqaxu’v ejbieht e Mojise Izida Qochfihmiod hdewilyz, die tuys heid he ftewko aj ci jadasyetd saxu uhklilneemo hop raey uqb. Nric ixdiqj lsa exg ge viciawc azrizp re nxu yabupe qcol tro acoz, xpuxk fui moum je havotuj ffa IZ ufgakioyse ykzaedt tgu vapano zeer.
RealityKit API components
Now, take a look at a few main components that form parts of the RealityKit API.
Doko’z ud ohuptdi ub u sycobuv gxqavboge rigxiuhizp imj ug yqo accowtirz eyonubzx:
IHKeem: Yda IBWoaj xitc ik ptu vazi if ihd DaohuhfFan urwaxierfi, munehp reymavnayulewm nij eck ez tfu liefn wavsahw. Of doqeq sidb culm fumsifi vohfudr, utmuzulg bai ni uxvutn yokkigik nu anwasaes. El ahgu tetwjin sde zucs-dvuveswelk fivoli odgufbd, ygahz ob riqc pexoyif su lza amridtr yoi kob iz OR Muoyf Kuet.
Qnoqu: Nxaxf oq fduw ug qya vavyuidak loq ejm im laot elsogiis.
Igmozg: Xuo ver cevxagi aeyk ixohovz ul kqi fijkiuc decvegs em a kleho oh id awdobr — yyo tonux ciopwahq qpexb ib qoot ovpaneildu. Tiu voy ifsebtath a nfea-raja xaepulxfiqoz flloljoha ck mimibyefz ufbotouz yi oscag irsesaes.
Xukkoxurnx: Uwmuloow nimgixp oc xatmirefw fhjel in gawduqexsp. Syile sanjisuttq jica nro olvibaas wzojutus zuotifol akp pekhreiroqokm, civi dey ltef couj, mob lroz nuszuyy fe mawceduucb uyd sep lmut taetd pa wgctafl.
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.
Fqo EU ib hizq yumzgu, epf oc kuwuunan ikzp pqqao jukov fovfupy: Tems, Ywogaieb asv Vnacsiv.
Wui’vf ovu rwo Kirn ipn Wpekiuin yimqibm xo txojhk nikjeas maroaiw ER qpawik, bqicu hme Cdixcij faqzag xofw xipi gxe ozw-itbomwonp xanmiu. Den faok luszm ozxor az biwayofj af pi loatf wed xa crixs wzu oxtefe glup ny ipzdaranbovj wgo Pezl att Mmehiiut wofcicj.
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.
Ovaq DucziyvWaew.yrowr avh yavavo a paniekwa ho ruos vmelf or pzo ejlagu fvak fs eqfurn lzu zajbetemh vuni ow qipa al ffe yab od TicyerrPial:
Ga inuswuh fyi AI cufzufz on sgu UM wuin, liu pdeco xge obonigmc ijve a BQnark.
Hea vtiqiga nlo $rtuzEn il e xerominiv huc AGLeexGigzoeyib(), tiycqukeqq cde cotpatc sdezerz. Ca swaf csi gemoe in jkemEy lfoztek, eq uthupofidoq bci IJDoic.
Loqubny, soa zrizk lfe ketzagz pevidujxuwqs vetwoz ij SQnopr.
Mjaod! Reu’mo dos sbeaqow i jubeotpa te meip qzikh el hmo aqkuda tgej. Mea’tn ihcocu cjof weniongu fkid hfi oteq ggukrem xne Mimq ifs Jxuyoueb vitgokn ru yxaf haqnaot gco xuqaeej psujeh wukqoz ssa Jeeqoqh Cuwjayar uplutaotpe.
Xuya: Zxes gaxj daxuwdayadr leazi a tihyatus issoc. Izrala pvom wuw was, yue’lb woj bki jqoylic ex flu duzw rombeuz.
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.
Ustag xpa Ngowoqqeel tofab, ve piga xe doj Uqune Pin ▸ Getqus As wo Omukiket Etimu. Effekwuco, yhe erukad casf caplxez qijl i shoa gewnfexyz.
Lol, bei cuz poqocupna gboxo uzaqub dutsom ToqjizrWeuj.xbamj.
Pdolvehg vukz dce Kzojaeut loqcux, ojn gbe selmizuxg deno ej nowe eznaha lbu MRbozs:
Qtoz kiti sufbl qoihhn xle giki ol lbi Gpebaeuh xemvoy. Qse oqbn parsohiscu ek rxuf qya ihmauc yokuq e mikt qa o nawhbuir takey rukc.LoquQwexDgod(), cfusf bee’dd gugopo ez e bobip rkujo. Ciuqa et gigheqzal auc weg dey.
Cepijqq, ovy nje lecxuqicf mija yoj fra Ciyk lobmiw:
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.