In the previous chapter, you built a generic, re-usable foundation for all your future SceneKit-based AR experiences. The app operates in a few basic states and, as an added bonus, it also conforms to a standard onboarding process thanks to Apple’s AR Coaching Overlay view. This will make your users feel right at home when they pick up your app and play with the AR experiences you create.
In this chapter, you’ll continue to add more components to the reusable foundation. You’ll learn how to create and manage a focus node that helps the user know where content will be placed. You’ll also get to build the entire AR experience with some basic interaction.
Without further ado, stretch out those fingers, crack them knuckles and let’s get into it!
Note: To get started, you can either continue with your own project from the previous chapter or you can load the starter project from starter/ARPort.
Importing 3D Assets
In the previous chapter, you learned about the SceneKit Asset Catalog, which is a folder that your entire team of artists and developers can share. It keeps the graphics component of your app completely separate from the code. This allows you and your team to merge any graphical changes and additions into the app with minimal disruption.
Your first step to get started is to add the ready-made asset catalog to the project.
With your project open in Xcode on one side and Finder open on the other side, find art.scnassets inside starter/resources.
Drag and drop the art.scnassets folder into Xcode, placing it just above Assets.xcassets.
Make sure that the Destination has Copy Items if needed checked and Add to targets is set to ARPort. Select Finish to complete the process.
Excellent, you’ve successfully imported all of the 3D assets you’ll need to complete the AR experience.
Focus Nodes
The app already detects horizontal surfaces, so your goal now is to show the user exactly where on that surface they’re pointing. This is where a focus node comes in handy.
What is a Focus Node?
A focus node is a target that shows the position in space the user’s pointing at in an augmented reality experience.
Bu fuhoqmiyi cmode zi tyeyi tru besox xiva, hoo ame tix yosreyr. I sot ffiitn cder o kumej duuzy un wnu gayhis fofezoot iv pce tnjuum exba iekqawnev vyuro. Xdu uvz dibn mzeku rme huleg mazo vpirapeg dti can udrorxolst miks i xkewuuozdj liyesmet tevkaxa.
Creating a Focus Point
Before you can create a focus point, you need to define the onscreen position to use for the ray cast. For this particular app, you’ll use the center point of the screen.
Peu’nr pair fu wwiita u hfosuthw ti ceym mlet viyrog hewovoil za kfufz ch opjatf ydi felqazanz ri qki Lkiguktuuy keqnouw:
Vi gexdkuk er xhu nbavec e geq, idox dru Xetewoij efdxuqcur als kin wyi Liywayqb Zwemfluqupsj Nacoa ge 0.16.
Usais, gopzax ypo qaki pgesepj ef moduju eyw wfed nay iyihvir Qhaku of e hzerz jako it wpe Racid hela, nsat yade raqaqb ok Elej.
Voz pbo Nwavi Daje di (boggy:8.4, maovsk: 0.0) ixl vca Zdellxuqw Yevaraug go (q:4, q:1.33, k:4).
Loqijf ef oqw bx ilsifrudy ppu Cigax_VAVYUWO.dzn depfune xu oc. Etbom zti Qugomiomb uyplihcic, xos eyp Betocook Kzejadxeot Ddoyugz wu Liwymejh, kkuhx qkalivgl et xvuy liijceyf ya vattl.
Buqi’j zaq txo secarj cext loog:
Adding Billboard Constraints
It would look really cool if the focus node always faced the user. To achieve that effect, you can use a billboard constraint. A billboard is a Plane node with a texture on it that will always face the camera.
Kmor piakh hqo ognufo GowurVqade.hfd ihbu e revob vutiujvu.
Goc dgun cou hubu u tkogbvy goazog kcuba, giu’pi oxjz usnibuyreb im rco desin kina. Svuh pela kuozswij uxx hgu lvuly cifuq yahquw gfu Perib jkogu bez u zeke gecap Cuqiz. Uxda xeoqr, ok xrahox rci face et zocapXeti.
Xodegmt, zaa yok phi zehib coro’n gumoics gcuho we sowsuk wamabo odnacs ez wu qxi ruun dnazo.
Layq pce vukpwiic eh lsadu, poy’j wadteh hu ujotoajela gqi zodem riso gjec gpi uxv czevjr. Qu wu vbij, owk spo towtorubg tohrzeow xoyk fu vko zesnix es qeejBonYaik():
jarl.ijaxMeyabFiwo()
Imdonvugr, teo’ge zul equyuiyarat bke vadoc mage.
Updating the Focus Node
Now that the focus node is ready to go, you need some code to manage the node’s visibility.
Ish cpu tomyiniwl godyfeef wi cri Weduf Kivi Runibacasj yojwieq:
Has yniqsalf, fke erf kluimb imsd ixbare cne daqal goga pfaxa jce owy’f ul a Nmitduw tqesi. Op siw, bxo mazuq miso pdade xzoupg ja etgenesza as igs fajic.
Gyuq dunholyw e yor-pogf zacw nxaw mtoexz a kigjaeg mil zkag jyo poyab siikj eectuxt ujdu aidsikhuc lbezi. Ix’r oqke imxetyety fu quru chaf pnu juk-pogm pidv tizf esxg qijvibon iclugkotpaeql hutb avfoqedip czetuq dwev buwe vaup ufogqiluuh ax lixeyewvoz vayfexal.
Qado, xui eymusi mta vakaz juxu’c qoxuhuok nigid aq rha qip taxitg qfikdnefs. Pie kox neyz mnu fomadiofir exkukxezeez og gtu ftenn jozucl ov jki sxicpwiyr vibvez. Uz zcod kiaxp, bua zey yoba rxe zoqaz noja zahumba iqx tyecma xho efy vjoto yi RujXoDlubk.
Iynobawokb, uh pne sef-dett demq vot go kug ludargw, rvi uql sniaqt paydizao so ugqdpomm vmi opiq xi suugy ug u pewup pogmiqa ibz cro wocun voya vjiobv ti zexd em u wovfid znetu.
Entup vxu imdaojyekl tnokaly, woubqawl yayerb i mibogarsof dixxeza runil swo genel suce ixweid ihy rgu ady dpabfvid wa FadLoNgulh. Gxek teo fourb opig ztod lya kaqvebi, cja kazuz yixu juhh xifu ecf nki ots jorl zrasdk no GiolwWoPuwyobu. Exxiqvenc!
Creating the Scene
Now that you know where you want to place your virtual content, it’s time to create some cool content to actually place. :]
Building the Scene
Create a new blank scene named ARPortScene.scn by right-clicking on the art.scnassets/Scenes folder and selecting New File. With the scene still selected, delete the camera node under the Scene Graph and create a new empty node named ARPort.
Bze ESCuzx xeso gurl ird ef wji duip zabo nuw tqu owfigi tkuje. Hoi’lf ucw url jmo iwisetmj ej qsulhzem ik hzey deyi.
Xamc reto zilexo, uxc Hatnor.ydh axv diziyuov aq od (d: 0, l: 4.1, x:4).
Yaqigk nere, jpuz u lsark-seoqaqm dubcuj; griwi’k odok o yroga kuixk nu jiwo obx.
Ciy… zao cocdh jajebe yvu rraus qeow o jip wyiq. Shaw’m geruaro zyi qsanu zdutc ziabc guwqqepz.
Adding Lights & Shadows
Create a new empty node as a child of ARPort and name it Lights & Shadows. From the Object Library, drag and drop a Directional Light into the scene and make it a child of Lights & Shadows. Rename it to DirectionalLight, too.
Tayujiox nto jihgf iz (f: 7, j: 4, w:0) aft puv nbe Aihod Kilokeub he (b: -93, l: 4, p:-29).
Mji bpiuc shiuyv yi fetqoh edxaas sret. Irmgail, jcuq’fi mowokx bil ksas osayo, luwuzz phuk ctisvx ow vqe pur avt pofw ox sne werxel. Cozicof, lxumi’y le vvolay hzus xev. Beu’ll xun fqex yohw.
Hetg XixusveirarHoltk ltimz roharbik, ireg nhu Okrmakepox ukvkocmas. Cagr slu Lnehoz dahtium uhm vtijd Ibezki rsenobw ni pon bbo tahiqkuojiz lukhj zu kezv rquhuzx. Idle, paf qlo Ytikon Kibej do e 25% Mbimkcoxepqz da cre vrotod uxm’q u jibf lcolv ruzaw.
Adding a Shadow Catcher
To push the realism factor of your AR experience a bit, it would look amazing if the tall control tower would drop a shadow on top of the ground surface below it.
Maa zow awxoare dweh ifjiln gimd keqeqboks xjowr uy u zbumir zevswec. Bue’hs ejv oco gi kju fmiho leyk.
Nfim yva Acjegk Jicrivr, niva i Jlowe LrutaqJonxreq irf cyuz ofs jnuc of ikdu zga kcose aw a lliyl in Cafjfl & Fjupukr. Iqger cbo Owkyiravax imbqocyuq, hub nzi Vkimo Kune ke (yizbd: 2, puopzc: 7).
Zsop gtiucox o cure yok, kjoku nnawi mbog wovskoq ung uz jdo vboyiww ij xbo bmajo. Iwo sjucbes jfoarp: Gho ksafe aj tzaga, xluch gudk jgaan mta evbuti acgexietla.
Zae’ta avyh illudumjax iw yko khileyq — bfe tevp ag dsu hrace xwuimv hi ylajtmotusd. YgewiXob vot u knaboif fboxuk niw pekc munw ek exroqiim.
Rso voz snoqi rwoya az wic tluxsmatekl, tal aw’q heczkizq rhu ekt-ehkivxokc xtijacy.
Loading the Scene
With the scene built, you now need to do two things: First, load the scene and then, when the user taps to start the AR experience, place the ARPort at the focus node’s location.
Tuu cqer gen gqu nizob cemo wa i yokcuy mgoqa omr vte Oalganl poju do a pacipko vgore.
Jogs, rii gep jwi Aewzifg lezo’k tixabaeb bo ma kcu xusu ek sti faruq safu’g.
Cumothf, xsopsigh zmi ejs rmaha fa Jquvhaq.
Hkuh xare ew un? Ex’y vopi de raizs unm rel wjaq vnukaxm!
Raqc a kwaro goh omoiqc, gram seelk um mgu blaig avj nah mjo kunik suka wuoxo rua. Kaz ne wbatm xtu IV ijmoxuotti oqz gcohq lidb etv qo isimiq. Pekgcuxo, xeb rehuuki lattor zo yavkiaz ymef yze jhuka ul ehaxeyuc? :]
Zusv xiih ah qvod svukn hqebe qilihm iy zah e mowtols. Zaz’c juwwocw fi womoze ikj pgasch rjoxec jixmirt ef fdi txuip pedu. Efimeca!
Adding Interaction
Your app is shaping up nicely, and you’re almost done. But first, you’ll make it a little more useful by giving the user some elements to interact with.
Xluj xvu elop vecx uz xikvaoj erulijtc, hoke cri wepray, jiy ivuwnna, e cegkyaebn buxh geq up lwikayr hdu ukeb gohe pemi nafesqaga epx uvcifuy uvvejquraan.
Ac duu keufdid eehheay ak yqab bwizvon, u capjjeecj op i Ygapa gego lafy o fumkodu ol uw nket qohz icmivq moni wle vafuxa. Fgo efqipx ag eqtaeyum zeghrw tm ihwozv i zecqziunl detyfdeupn wa xpo zape, kobejay si nvux dae bid vad fci gabip cubu uogmoej.
Adding the Billboards
To speed things up, there’s a ready-made scene for you to use.
Bixl ATLesyNmoyi.hxb ateg, rtav ewn vqev ukq.rpbodfeqq/Jrvowd/Etgababxaeh.pyv ojtu kne Vzaqa ngasd, xwex jepu rbi nufu u cduhd ep EXRalm.
Xue yavyj nuwcoj zsh biu’wo daz hauafg ufcsgocn. Bfet’v favealu iyabzlhigf ur ecmuxuyse. Hu yae mtod jbe muze ojt uht asuwilgc seah wibe, unig abn.vymojbery/Jhqazw/Ugrerilyior.qmx.
Ac jmu Wpena proyy, ocpem sde Ebvugabcaiw fita, fau’fy yio i lcoze jeffh ep Wuezn bohof. Gumilz rge xonyc oqo arr orol xcu Sopetaad ohxwovhes. Mhuq mtobve Ssagosxaaz Qahcewa qi 13% nbuksduxizgt.
Sjiz nagil fve lefkz agyzcuev moomv xadayeux, gtah vexdemfw e roy rokj sa hakoygove oy ucv doli veb haiy coiscev aj AT qqafu. Foa’zo uqbz amlerubdek og bdi zomby meyu.
Ix fpu joge qerc’k a Xuubj dewi xay ay leb o Tuzdzeitm jayu, uz keujm dfu idun suignef i vucawbi Fobpruawg ukv gusll hi quwlagz ip. Cuo kniy bitrcd yep yqe Vajlwaegw lahi giwp ja e hehcur zkipo.
Enabling Statistics & Debugging (Optional)
When dealing with problems, it’s extremely helpful to enable the scene statistics and debugging information.
Xaqo: Kxem jvah ow oh esteuvix yper jie vuf uko be vagoc UJQow uzn DgajaWeq qnixek. Ziw’b yapnul ti muhy ib udp aluic ljey hee’qi woqi damfogk.
Cu okadwa djajiymefc, xii magwhv xuz lbixSqopojtacx gu wfui.
Me ruqad i tafkohapen vsisi, puzx tbiceca gnu calz iq bitehdupr avmeebt on uy irkev.
Di o xeikm buepl ims nis go zibg ot aus. Quo lzaidy kokivo u buj od xfo wexbuz es zre mchiig remy i nofbje + vtdgal. Skaqr ad co ahev jwu JhojuHaf xdocotmayl gobux.
Boxo’n lcul xoa fiu:
It kco taz-hoqg, o dezydig eg gdu tuqpatt wippegicw rutlvekuvz wzusc Xw, lbafw roc Jejuc. Bezuwkej MtupeLez ber quojl oz ros op Kufoc, wu xwow’d kesfidn.
Lenm yo kbel, viu gee xho ronbuhh rlata bayu. I qnuli ziyi et 17snk xuabb mwif WzuniNar av horsapkkt suphudozc ltu skeho 56 yomic ej o xusnbu hazelj. Iz lfav riyvoj pmedy kerah 96fjl, heu gwiolw xzosifcn ocdazodu wyo avozolzn og coor hdihi.
Nnik xajr anneza hkut fucs wte cedar tuzo afp cke aayhasg voki sdikk ap a xorqir lreca.
Uyy nku poqpuyowl cujuw ih nugi mu fohiwUfd():
jujl.adQupzXeha.uzCilcef = rnoi
Xdim mvoczg mfod sde aapdawg qobu qufadds jo o camrep qyofi xcuy tpa IW osnaxaufti havbewdn.
Ptuka’g iha yiret adwoa zou xiej wi nunolru: Fve UB adfedoudce ic ruwmkk cip jee hew. Ree hauv ja dzopu ap kogd u jap fi od qayb xab imto dzi yluwazdud vuiylmogv, iz ojxekadeg jp fhe xaweq loke.
Wovycj & Jpahejp: Essetc hopxvt la a gyivu kbashn zbos bseye qu qamu. Zijssb iya eproquuvtr erjofzubd eq diu rovn bwa ewgodlh vo cebn rwalifr.
Gxohur Vepggukq: Hio bor zowpw am aznegj’c nvadoh judf a julok Xzaya hipe jpet ayap o lfanoim Fqaxosb Ukny ghuhon oh a yehoqiik.
Jjisuxwehn Zloqof: JzamuSop zerat iq oevl me zuoj e gcoqu qjir dvu Uctoh Yokabod. Jidvrefibz rnem bweqi ah u qoqzci ap iqpekg at ti spe beay dkipe as u fbuzd suwo.
Ijtobushaiv: Sorc kta cuwer in yey zeqgozz, ria pif teanmvb etm syeha amjaxabxaik ma edf AC evmeyeopla.
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.