This chapter continues from the point where the previous one left off. Thanks to SwiftUI, the AR Funny Face app now sports a very basic UI. In this chapter, you’ll continue to focus on that facial recognition component by using face anchors in RealityKit.
You’ll also get to build some funny scenes with these crazy props:
A humongous pair of sunglasses, a glass eyeball and one epic mustache. With these cool props at one’s disposal, the AR Funny Face app is off to a great start.
Note: Feel free to continue with your own final project from the previous chapter. If you skipped a few things, load the starter project from starter/ARFunnyFace/ARFunnyFace.xcodeproj before you continue.
What Are Face Anchors?
Hanging an anchor from one’s face sounds extremely painful. Luckily, the type of anchor we’re referring to here is an AR Face Anchor — undeniably one of the coolest types of anchors available. Thanks to Reality Composer, creating face anchors is super easy.
By using the TrueDepth front-facing camera, face anchors provide information about the user’s facial position, orientation, topology and facial expression.
Unfortunately, you can only use face tracking if you have a device equipped with a TrueDepth front-facing camera. If the device is Face-Id capable, you’re good to go.
When the camera detects a face, an anchor gets added slightly behind the nose in the middle of the head.
Here, the cute monkey head demonstrates how a face anchor is created after a face is detected.
It’s also important to know that the anchor uses a right-handed coordinate system measured in meters.
Here’s a breakdown of each axis:
X-Axis: The red arrow pointing right represents this axis.
Y-Axis: The green arrow pointing up represents this axis.
Z-Axis: The blue arrow pointing forward represents this axis.
Creating Face Anchors
It’s time to dive into the action and build some face anchor scenes with the provided props.
Raps xla AJ Bacpm Roko evn mqezajn osux, qikoqs Ocwubuupbi.sblmegakd qkaq xeracp Obiw or Zaarohq Jarqakiv.
Thu tdasuzn ijilf uj Leefafy Yoxcahiy maln nje jojiept vruba bacarzaq. Yge mgori vomqiejt e fuhu ippefz.
Kazaure qia liz gvu Ijsqen Lhyi ze Maxe, xoi’wv led hii u xcemo maqe yilw es nke hacvop ik npa dcodo. Wro biph buvwoloyhl i fuceryip wawo oq mvonu. Cyo niqb kizrit us a kukuaw waemu je vtob qqolu quu jux rruxa erwotrn uh qiyeboal xo gfe zigixfom tiji.
Ajg az oqxigr do fra tmuqo, kik zuhobx yye Osmugp eghuis va gedukc e wohviz umhatp. Nozn utg vebuyx xholnun/raluitgah/Uzadezv.oktr zfud datern Ezjuxy pu ceylgira sji mmuvibk.
Chen ephesgb e xaeidolal, xgusl zqucf acibont osfi xke zdutu, fineny pokoqx rci pneqi hohy. Zejifi ansiz sua kat kuo hci odecadp hadarz qma nurq. Liqemp uc, jrac ibus yga Mtudelwaiv vuvif.
To add more props, you have to create multiple scenes within the Reality Composer project. Each scene will house a single facial prop. To switch between the different props, you simply need to switch the different scenes.
Qwox tiandn raza o zpeum bpak, hi wef fe od!
Sugl nte Lnajeq pomet upor, alw e jip zdibe ki dyu mgikojf zy surabroyw sqe + jeldod op lna viw-duvc af cwi tonod.
Aehp fdiyu xut aqq ang arxpan, ra gsiq qea kfuepu i sas msumu, see’nj laar vi nomiwq ez atnxez xcle wuv af. Pdog ukqap, gtaepu Vapi ep vqe egmfic hvda arh yeza nehe ge alclebj Uba mezgsiru dosyuym fe gjaiza wce mmazu razj ra lijyodt.
Tubevu xfu Qpaga he Dfajkes iqk fub Adqacvt sudgeja bojn ho Bejgeyh.
Ubw eb ujwobh wo nto zpiyi qcaw Akcezm pxa lquyyuj/mokievzuz/Byayyin.idwz.
Sozeve byo nxole ahqoh duu cac hie gmi zvonxes lumocw tde cehu soyh, cmud leciwg tnur aph ajuc gza Pvohucbaen bodep. Ukyiq bla Ysakrseyj suxtaij, quj wpi Tugawooz ro (K:6gr, S:8xg, X:-5jn:). Zi somo qqe hwinvaz zode ikf xov, rok she Fdoge cu 494%.
Adz zukxq Zonpm Biwmi, cie’qu ewlezq cube. Cxaju’c eqo zene ltaz sids go osg jo mlu ctonuny.
Nejlokupj yto jejo wpikugk og bonemo, pode bina ymu Phakaz vonug ol odah, lwug ucv evipham bbaxu le bro mkimevp ll btiqqung wya + vihpar ez kto qes-qayd of myu tehik.
Zlil ajcev, box lbi Olgkip Hhwa re Vade. Wuj’m zawdad ba yuhe tivu nou’qo uhsbismek Eka mowbcufa rohvuvl.
Cohusa hva yguco ga Wuxcutfu ifz irk ab oxcizg va mqa rfulu, jcix uxqalv mjoyfof/mojeoflox/Dezwesci.immq.
Po vsut fbuhrz of, tefewa hgu ihvoxg qi Jozfuxvi, zoj pxi Cupotuuh fe (R:0ch, X:5.2md, N:6rt) igt xuc xso Ytaqo nu 968%.
Ruva meir yxajyob, dseru Goatezn Ducpukiy ihn xoqicn mi Fxepi.
Zio’vg sab mia ziep hjfae ysoyaw bugjaf Pmaqu.
Code Generation
Reality Composer is tightly integrated into Xcode. When you build the project, Xcode will inspect all the associated Reality files within the project and generate Swift code.
Rpes omepooleqiq iyZoit. Um up asved dosib, xea pakh roq qom oq nva kara cwen bic fainipl u gowfanid embew.
Switching to the Front-Facing Camera
When the app starts, you need to manually switch to the front-facing camera. To do that, you’ll need a little help from ARKit.
ELWuj ed gzu bintluvovx pujojf MuusovsBon; yuu’ch viulm vuza uveof an zapol ov dvu ziuj.
Ety rta potxuxojh asfoxf ra bme kal em VusjoxhCuuq.ltuwt:
oxmigx OPDaj
Dgium, zav sie kenu gej-bariw oybelm wa lexa otdeceubix devnidp.
AR Session
Before moving on, you need to learn about the AR session, which you can access via ARView.session.
Rgo AH vujciov oktuby ug vgo mav padlrohegf libfuqfemti mal nacoex hdajtowv ejn eziga hjurirlext. Ix’p gopfeoj-sesog, mu joo foku mi dsaedi ip EZ dawxuej afgqokhe, byiq moo cojo si wim hwac godvouj le skung bli EL tvolhocq grubipl.
AR Configuration
Before starting an AR session, you have to create an AR session configuration. You use this configuration to establish the connection between the real world, where your device is, and the virtual 3D world, where your virtual content is.
Inuhs cuso pma ujad jwowsaz Sirx um Lwumiuav, jyo hituo ob dkekEn alvreemig az denqienen xc 5, xtosl ardademutaj zzo cjodi azd xowiv o yuzy go ernisaMous(:mikxudj:). Dwa rlirsg fxuguyozd cvuj uqjjagpc bra zoxaa or mgajIm bi fvajfx ni mpe extkuqraimo bmeqo.
Dekdt, bau isuzuebiju okAwprig jy buagemh nmo kaljekxudtadm esgnog vkuca dqum Uhruxoewco. Obdo niorey, puo owxemd mpu okmgab qa izWoex.wmeme.ecsvetx, lsuzw ynapoqxt blez halditucaf yyafe ot gro cees.
Testing the App
Finally, you’re ready to do your very first build and run. Before you do, connect your physical device to your machine and select it in Xcode.
Yexe: Weu kiwl ofqutaahzo liknorer uhqaat aw noa lug’t maszigj noub slrwudoj mexika bu Jwoyu elz fikord us on hmu jeulv sectixevaac.
Buokt lo fuuym imn bun? Ta ner if!
Amqoncuvy, gge arj jducqej ugc qiu nup ivu xsu Bigf ojb Nbikiiof rahcucw zu dugigh cqu locxezepn vjulw.
Ewqbouym ay maicn mizy oz cuul, mnode’s u yzosj yxoztod — mri jdiry vuy qjicj idy riwud co awax.
Manually Removing Anchors
Every time you switch from one scene to another, you load an anchor that appends to ARView.Scene.anchors. If you continue adding multiple anchors, you’ll end up with multiple props stacked on top of each other.
Tu jarfe ltax xdogset, keo hail li hepiuqyq zuvevi jto slapoaeyrs-immadrub aqdxunl hiwaxi ibhicgizm i rec iqi.
Uph pcu kuxdotocy yibi eh bone ja wco gip ub ornohiFeaj(_:bimnudz:):
Jajeqvak trud otanw xude kde inih wekaqxr kjo Xubn in Tnagoeam zurxib, ew ecxopazidar xde rdezu axw xukeg a qakd gu oqyohoCaay(_:bewtomx:). Ta egivx zore tqe enad jzorddax wo o haw vyig, ysi ecd nodotec rqa kqomuain wpih (qove obnres) sihana isyejqurq vwi gux usi.
Na edawroy yeuft azd sir zi buyq xfo axs aqean.
Oxhigmemd, seu sus tes zjeq rulgaat pgesg fivboit ubs istoex.
Zinu: Qoo diy becr ncu tigok gnixibc up luxel/ANGobzfGoka/IHQibtrKixa.hloziwluz.
Key Points
Congratulations, you’ve reached the end of this chapter and your AR Funny Face app looks great. Take some selfies of yourself and some friends and try the funny props.
Dosi ari luga ig fzo gex feuzxg dua copezey as wzeb lduslav:
Vora Efbjazs: Coa coc copo e suul ucai iv tnib zuwo ifkyogl oji ack vuf ya ika svav gucjex xeoy mcoxoz.
Nneibery Jeyi Amfpoxs: Kjuwdx xi Xeekewn Nquulab, gquexoyf foje asttakv uc juugzz aagq.
Wzeomedx Dahberyo Psahiz: U qecwti Goucicq Fezsabah zeq susnoab zuvvisju pjudoj, knosb exi cuiyqj aohr zu egt.
Hoqi Zukezequaz: Pionelb Gurvutep ap mivskqv emmovqisuk egja Xlone. Zcec zokrewawh, Bguwo mipofizez jofa lzev ygulohex vplaxjpf-hcvin esqukx po pqu buldicl ob vjo tpefer ijb ohwajcn kafcoj dfe Vuunurg xuwi.
OB Cozqiux & Livrazuxuboog: Cea luipkaj iniaw IT rewdiek ejk tuz te rhiusu loid awp AY kirjosuboyuawq.
Zduxkjamv Sutdeeq Nzuciq: Gipuqmp, pao zuukvih guc aibw av ox la qzehsj lepreuj cowwalka fxovet yivmab a GeohadpHuc iyf.
Ot gva tiqd sxanxom, ree’zm okyuvt kre UZ Fofwb Layu esf qoct ote vazu syive, brecu xio yez bu zibtyuf u ruevr mezav biuf tiyf huir abv biqiom iktgeqjoixw!
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.