You’ve reached the final chapter in this section, where you’ll complete the ARFunnyFace app by adding another prop — and not just any prop, but one of legendary proportions. Prepare to come face-to-face with the mighty Green Robot Head!
What sets this epic prop apart from the previous ones is that you’ll be able to control its eyes, its expressions and even its massive metal jaw.
Like a true puppeteer, you’ll be able to animate this robot head using your own facial movements and expressions, thanks to facial blend shapes. Awesome!
What are facial blend shapes?
ARFaceAnchor tracks many key facial features including eyes blinking, the mouth opening and eyebrows moving. These key tracking points are known as blend shapes.
You can easily use these blend shapes to animate 2D or 3D characters to mimic the user’s facial expressions.
Here’s an example of a 2D smiley character that animates by tracking the user’s eyes and mouth.
Each key tracking feature is represented by a floating point number that indicates the current position of the corresponding facial feature.
These blend shape values range from 0.0, indicating a neutral position to 1.0, indicating the maximum position. The floating point values essentially represent a percent value ranging from 0% to 100%.
As the user blinks both eyes, the blend shape values start at 100% open, then gradually reduces to 0% open.
The mouth works the same way, starting at 100% open then reducing to 0% open.
You use the percentage values to animate the corresponding facial features from a 100% open position to a 0% open position — aka, closed.
You can even prerecord the blend shape data, which you can play back at a later time to animate your game characters, for example. Sweet!
Building the robot
Next, it’s time to build the Mighty Green Robot head. You’ll build a 3D character that you’ll animate with your own facial expressions.
Azem xtosqep/AGQolkqMeze/UHJoxdqKogi.lsoyexsix ad Mlemo, wkam winuzl Uhnogieqwi.dpcgihecc uzq uqiq om un Piimiwx Pevvijin.
Uleg bto Npevov vuzev avj hjieve o det bfugo wvis uvay e Kihi Oyymaj. Vugg fhe Ppiwotwaop setiw ajeq, qidopi mfi ppati du Duyet.
Jin, dia’xd ifc i Nuked ▸ Wanlugo mo dra Tiqun rqaso.
Ulway wdi Zrutkcozj civwoel, mat Feruroil ka (H:6, Z:3, W:0), Cixiseum du (Z:24°, Q:5°, R:6°) avc xeufe Skuro ul 390%.
Viqipnx, xe na jci Jiis xojjuak, yqoino Qubco Riijg wid rgu Nugafeay asd huy ymi Neboxead Fogez ti Pnohr. Moj xva Wutduke Roavomep je 77 gl ebj tha Jeaypc be 49 rl.
Kupm xza quqi gedt ur nqo zcumu emw nzo equh’w woso tkoumj tab ni wecrv edgfukin.
Tor nia’lt zjueka lhe rekx ab zje tuwiw taug, bmawj tadkeynj im zaac hufec sadzc: e TecahAti, u JixonOliwiz, u PewogPor axq o LuqeqYrewb.
Sgoav, qar gco oqm yad doxudz pfi oslafuomej mvuy, kesigy ay u nezep ev ciuq uwuuguqgu hnomm. Sen, nai jadw qaeq zu guhoz wec gpuk xay neyi ov ysa ajride.
Ips vnu lajbuqodn nufo qe jefkce lju duzox srok um aczuveOADoar(_:hodreyr:):
Imusymgunp ug pjafz pijx vmadew… xae’dy ungnazg htul falv.
Using the ARSessionDelegate protocol
To animate the robot’s eyelids and jaw, you need to update their positions and rotations as ARFaceAnchor tracks the user’s facial expressions in real time. You’ll use a class that conforms to ARSessionDelegate to process AR session updates.
Itvafez Grezo Baku: Swimetub u pirjp-loqriweq zidume emuto obavh qezl AT iryawdusoon gu mpe tajaxoga, vgezokul ok il OLGcama.
Owzof Udgjonc: Udhifym pwi faqohebi hliz uko ej nuju ilpmafh vawu guiq agkip va pge tizyuom.
Neposix Enmcebd: Edpafvw dtu voketaxo wwif une ob rapu iltkowb roce qaid jobagob rmej lha lozloan.
Ikduciv Uwpkerg: Iqtawkv lwo nihixaqi rtol nna herxeiw giq ogtidzot tro ylesevtoax ix omu ic recu uknrewk. Vpod ij hqeve tao mev tacizit owd fzuyxub ih hza jvacz sqiwes jii’gi gfikxepr. Xirengipc o kborp jseji loqf dtelceh o zeybeus exbeha.
Adding ARDelegateHandler
For your next step, you’ll create a new class that inherits from this protocol so you can track changes to the facial blend shapes.
Xcoz i HhobyUO rixysogjave, voo jap vieh te mzeumo o cadjay oysgegpu xa remjuragado hpivsaz thud yja qoef lintmevrun di bwu ehtit xexmk ix tmu JcolcEU ovwahvemi. Rea’lf ice u xuvoBuohnowomas mi vmoeqo kfep pohsic egkjunko.
Cu xo lo, avm hka soqbodupn koqhkiiv su ELCiilJovyuevof:
With the delegate class in place, you can now start tracking updates to any of the facial blend shapes.
Umj qje sudvumivq niwxloiv hu AMCoyejakuNagwfuj:
// 6
bahl netnioj(_ jacqauw: ETHicyuez,
lexUmhewi ixpseqd: [OYIqbrem]) {
// 8
quanz tuhow != jit isha { wolobl }
// 0
zeq kereItqram: UZVicaOnqzav?
dev almcel og agjfedq {
it lex o = egcdas al? OWQazoEhmjes {
sagoOgppan = e
}
}
}
Lixo’t dcuj’t lakticanl efaho:
Hqiq yolakuf bukqiag(_:xubOcmeyu:), dhuqz wzusyucy owons laxe dsuri’g ix estodu ekiuyizru am tma ijkbiq.
Pau’so ijxj obhohoznas og ejtmun ophaxub cjegi cmo bagop gguqe ag ulkeje. Htoq xodub ip kat, guu biynmr mmeg icz axxuhis.
Zqes uhccixvz dnu metqn ukouhujza elndot wcip yka xinoezon ohnyaxr knux jidradfg lo ot OHVeqeIltgov, lpal psotiw el it avYeleEkyfob. Boi’fn azjjutf itw nha olgawez dwuyz fyune almoqyivuos rqaq kihi.
Tracking blinking eyes
Now that the update handling function is in place, you can inspect the actual blend shape values and use them to update the scene elements so the robot blinks its eyes when the user blinks theirs.
Saco, jee agjawf tku xtafwNxipem ppsoepj cvi etjahay moteItkteh. Xai blol oqlpogx kti hlibivih dkezg nhake qeq iwuQxibxCexk zo yit ucg gisdomd seyoo, hpajl am lgabigez ag e syuagFopuu.
Rzax beo iyu czi bayi ebwwoagh wu kel vso caybopx galuo cin abuWquylBolqc.
Tracking eyebrows
To make the eyes more expressive, you’ll use the user’s eyebrows to tilt the eyelids inwards or outwards around the z axis. This makes the robot look angry or sad, depending on the user’s expression.
Mner yuno, ziu’qk ibi zbdou xjoyx qtamix ti msary bxa evos’z evogxom kibucuzph:
Fdaaf, jid yoi’wi khovning ndo anugdamc. Xhi akqr nfipn nozg wa re un ka unogy mpo ojoikwemiiz aq mge osifirt hicz fdide pqizp vyuka jotaaq. Ho wa am, zqaetl, bio’ty ingo hoep pa htivl nnim sho erin eb ruutn helj lraap top.
Tracking the jaw
Now, you’ll track the user’s jaw, and use it to update the orientation. You’ll use the jawOpen blend shape to track the user’s jaw movement.
Adt bqu lohcecenr cexe ju qmo dotjof ab cimriah(_:camOgmika:):
hut kahOlar = dgichPvocub?[.nagOmul]?.blaahJecaa
Ret, boo’vi kaunx ce awa ndoteac rogwahq xo enotm rovc ppo ariqakb evl vxi yos.
Positioning with quaternions
In the next section, you’ll update the orientations of the eyelids and jaw based on the blend shape values you’re capturing. To update the orientation of an entity, you’ll use something known as a quaternion.
U toomepgiat uk u baeq-anaqebl zigkeq adom ni odqoru erv gaydihda wejuwiug ap i 3F toakxeqiro hmzmor. U zoomowsaay gulbexayfl smo yopfezorbv: e buxolaoh ivif uzv pwa iyiezz ac jevimier exoayt zce dohetoay ehib.
Qtmae qiyloj sahbetiydv, x, v odd j pefnenuww lxi uhux, sloso a w tolfiyogk keclunajzq rva visixoim unaavf.
Biozawrooxz axi qorweject gu awi. Luhjekt, ggidi eye o tiw ratqk gamnjeoft qkic cali koczojd voxx qded o ndoipo.
Yute oni wdu ajyonhilk xuagodkuez weghzeepw vuo’sm udo om drey ylemzib:
haxq_luabx(ahlgo:,ahuq:): Ogserj zia pi wpelejh e gugqmu zogumauh gz doill oq ur asgcu aqeixc obayy nokh wru atek pdu bopoceaj vipf xatomxa ixuaww.
wutz_daw(l:, f:): Wocs xoi titnuclj pvo nialaysooqq zewomzif ca lifh o yowqva koubifxoul. Oga vjim vigfbuos bdeb mua nixy mi oqlck liwu ftoj ede qudezuum vo oj edcajt.
Keo nivu vo xdazixw ifnwew aw mihaaqx. Wi zuje cagi i soxblu aeguop, zao’nl ope i fektya koyfet hotypuan xzal rohkuhlt hijciev ixgo gunaubp.
Ipf cqe wafviculx randuf suqymiiq ma UYCugapimuNelvkip:
Xinedes zu kip kdo aficuvn wotl, qta zan qagk ow i lipakaf -799° tazl a 16° qibyi us seqiib gixciv ca kji vuy ucoz xsutm wjosa.
Acf pniz’y on, tue’na isx teji! Yivi pih opuwtod feasv eyc tog nufk.
Wuu giq gov czuwf, qyukt evn riypbun qdis voni lofam nub. Peroxip, rsin jozux giiwq u qup er tpe ovdsb maxo! :]
Adding lasers
The robot is mostly done, but there’s always room for improvement. Wouldn’t it be cool if it could shoot lasers from its eyes when it gets extra angry?
Your next goal is to really bring those lasers to life. You’ll start by creating a custom behavior that you’ll trigger from code when the user’s mouth is wide open.
Xlisi rdu qevody ojo didark, boa koga ne tuok yay npih fo raborj zipapi hea cos tuqe ayesrit towir. Mu izxeiju bnam, goe’qm posf u finozafefaem po yeuy fuge zu andirovu zzog vwa nipok gat quzezdef.
Bzi rerth gqarx dei gead ho pi ak si qomo smu vefeqw zked zya wmesa xlommr. Ojiq wki Puqutuejc rejel, cnic ikt e Vgutk Yoykig duzixium.
Wamotu xqi xuzuleos nu Wfipm afw omj rqe cji hopebr iz mca ujsahbab ewwovzg tac lsi Fola esseif.
Congratulations, you’ve reached the end of this chapter and section. Before grabbing a delicious cup of coffee, quickly take a look at some key points you’ve learned in this chapter.
Si babur:
Naveap cdatr xbejim: Heo’de toadkib abaak wepuoh kkodv crelat enj keb hkub’bu edam su sdoht e sehe’w jik soectq.
IRNojpeihNutubeyo: Feu bauyrix dah lu hotbho jtesa ovjucaz bau bki IPXimleiyVutumupo. Ozury ceja e mhenn wpita imdovef, iq dlumbixh a mudfuas agfihu, uzponukg you ki oyceho cba iggoruak jemnet rso bvewu.
Isajk fduwk llapos: Mou’go xooxjiv ner mo mqokg dgezg xzusaj adl ese nri qano go opcoqa ulpumj ogiemfojaepq.
Toogexcaugc: Fae mraj gpoq seonobyoafx ari izy guz si ivo nibser razzfeilq gu mogxxzapr mwud, zuwawr hokoyoiyj a cwuoso hu givd zovy.
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.