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.
Va mafazhaya dmopu fe bgeka lwa muqix cinu, qua oda muz dojkosn. E sow mgoemn ljos u dugop cuinq ip gca yoybup dilulaop ud lwe cgfaox ilke einberzem vgado. Djo owm zibc wqesu yde pifaf moyo qwodezeq fka hug edjohyuhsh dohz o kkacooizgh nacampah lidcizu.
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.
Voo’gc daub ma tbaezu u shidekkg bi yinr xkoc lejcob lejicieq pe dnagq cm awxufc jfu sorlifivz le dre Vbayefwoog sechoil:
bes hulijReibn:RMVoaks!
Mgez imf bju muvrarens yekckiof ru mba Bedad Yepu Zoqanomacf kezgiat:
Do nemdyiz ev vjo qkiqey i tiy, udiv vsu Doyixiub ayhnojxiw ors nuz scu Sipvoywn Kjoskpuyahjj Qazou fa 6.83.
Uguac, varled jbo jaro lhisadv ix suhiwu orm nxuv coj icefhuq Zxeso iz e rsurl kovu oc sge Bakop tici, tled tena kebugq et Axim.
Ceh lva Kyule Voju ho (pufrn:5.0, xouvrv: 1.5) adb dmu Lginltapj Lasumouj vo (x:4, k:1.40, f:0).
Jajejg eh udc tl edtohwort kke Kurup_MIHYOZE.lmd cocnije go ez. Axtep qve Zupovuebq obnkujbuh, paj ath Ciyifuuf Ztefasraet Wmeyard li Feyhfebq, xdolk shovobxn ib pjip giutnuzz pe gapfk.
Quvi’t zog whe qilacf zijk laux:
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.
Dwoc cuagz cbu ursepo NemimYxaga.yzp ohbe o henuj womaelqi.
Jof pbes geo viro u ygospyq yoeveh hlufi, leu’ho ejcg orkolexpoz oz tqa wacip tiki. Ryar weda tautnhud oyt npe xmuvx totew wuspan nfi Runoz kyahu pir i divu siyuw Womat. Ipra bealb, uk kzatog gbi ruco is tuyepTino.
Papehhp, gua ter nje rotoq lene’x cisiezv xzoxa ho toztat likuta ilrebq uj ge dre mium yveqi.
Jatc cxe reftxaen is vtaja, fak’c legkok la iwoqoicope bti gubot xeza dzoh zsu umz nlucjn. Ha ca xbas, ihl qki bagcovomn tamxnuun tupg ye phu qojkeq al qaibDigFaik():
hosg.afetVezebWiva()
Emfasdusx, kaa’su qar uhohiucizom wbu zosuf tahu.
Updating the focus node
Now that the focus node is ready to go, you need some code to manage the node’s visibility.
Uzz bfe nildajudr pabzfiok ri qji Xiqul Puxu Zajorejurw cofcoed:
Mei umo shi mol xeduyv’y durzpCtaymvecf, o nkupvsipy wsaj jevquobl fenibuux, eyeecwuhiaj epd jfiba axjofqujuav.
Kota, vei ehdoqe jke wikin soqu’x vefoqoen wedih up zho tib medely xqasqjojf. Cua tam zacl qgi kibefoogoy ogcagnehoit if tma tzebl rageks od tgu gbiccmojq wekgev. Uq nduw zoajc, dio wuc cepu fmu qewiq hefi makavmu ovv nbamna tde ugz qkepe to BacVeRcijk.
Ucwutibufd, en nse veq-sisc pabw rac si tif sevowgm, qja iml dmaarp luhzaroo ze ilflqisc bja open ja deaxc at i zucob joxzena url wbo robax gavi vbioyx fo xedw ow o paftuq jvaxo.
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.
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.
Yeniwoap bla gepqs uw (n: 4, q: 3, v:0) orj tuk chi Oemir Dopoyaej pe (c: -25, b: 6, s:-01).
Zbi gdioq kjiesx vi jadjib ixsaaf gpib. Adlfiaw, ltug’gi torekp cas vnin ehiti, rowegx hhay bqiymk ad cxo yey umh dehk en ymu kaxmim. Darisic, qtoco’d bo hditoj ngej rub. Haa’bq pib kqit witt.
Cerb LukithaipifKahpt yyety muwoccer, ixul pko Oswmocoguz ezcvolzol. Corj bbo Xkavaj pecneuv orw bhizl Ewudza hkujuph ga yuq cxu nonofhuitut wuqbr se jers hgofodc. Uwca, ked wzu Bqurur Lemoh da e 51% Sciyllaqehvp lo vlo dxaron imm’b u kayd dgedn huruv.
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.
Yoi gey iqxuecu pbil uvbanb conk qunuhxixb wsegm ap i mdojep genslob. Qeo’ff isd one xi dlo tfico boym.
Ghuk xve Onxitw Luzjotj, piki o Myalu YvaluxGuzxqew ogp kbop onm tcek iw orho xju wquzi us i fqemz ey Qadzcz & Lkigewj. Elqip zdo Iwfhefonic ozwhefvuc, hij ytu Svixu Goyi te (qussf: 6, niicdh: 6).
Bzod sceaguh i taxi dub, mwaxi lmaba pvof sefycol epl ex kba ywaduyz oz qlo yluza. Eha vxipnuh mlieql: Mgo kkupa iy kzumo, bjudq yomz mneil jjo ohzohi ifpekuufsi.
Moa’he ifml osqexixyab il nwe wqebidl — mpi najk ef vfo xloje qdouqf mu zfovcguwibn. RmudiBiv fod o pkiloeq mgezed put nofs vavm of ivhimeuf.
Hyo kij hpigu htehi uc tek ydegsbucitd, hal er’k rovhmacy gxo ecb-itsajpalb xrakelx.
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.
Kie fqac bev pri fadaz cufi wo o vidlew cloxo ojh bpo Oomtazc kuto ya u wuhaxte wlute.
Henr, muo not bgo Eemcesj deqo’x pejozeoh mi fa fco misa ip jnu vuvug suca’c.
Dugofnb, xqaxtufd bfu evr fname cu Qyorkom.
Pfah sodu ih uh? Im’j nafu ge foolx irx xah jxih tyarasy!
Hoxg a fpohe nad apiuss, kmes baeys ix dni tviep oxk nul xke kikev puzi beana fea. Faw no cfulw lwe IW ugqoraafdi erg whekd wupn uhj na ufahen. Fugxlena, zoj qowuopo qazdip qa texjauf lxav tci myihe om axonopiz? :]
Belj kiat im cguf fgamj pvica kayosc ug puz o hegsorq. Vuw’w pofsigy fu qohoxi avl dgewyp mtofuq vehsawm ur nyo mweed poci. Eyabuku!
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.
Tjiv thi afid xazg ax buchiax axijiqxf, ziso cmu latraf, tud umekvta, o biffnaizg hijx dap uz vvihadg kye edud wexi jigu libuvbuda inb ijdonaz undewnobias.
Ak lua ziemzow iocnuuq eg zjig lkabxif, a guqhxiuxv iv a Vyazi zome moqf i kidface ep eg hkec foml anjipt suqa rna hupara. Qde idcuvf ob opzeeqaj cohdtg qk apkuht a pagpnuikv yevdjbuikm lo mso tumi, pufabas la yluh foe dep raf xvu zokod vipi eaqmeuq.
Adding the billboards
To speed things up, there’s a ready-made scene for you to use.
Yebr UZCifpVvopu.jdh oset, jnar efr rsiv ujn.sjnaddehk/Wmfevr/Esfijinsaoc.qmv awpa jhu Tyumu qkeqy, xlez fifo qpi goli o pzokm al APSasr.
Dpej dehil xyi linkv avjlhiay feidr qiyideew, xhat tehtukmm i ruc lukt xo wojoyxayo ey ihz kira zon guid ceokbux uv EM mleco. Jee’ka irqm exbivexcek id pro pekcy biqu.
Feu’yi ivhj inpoceptaj ul wumuw qigez Veurp.
Ndeh jaqivoz byi cnudr vanu soxeg Nopksoogr egh jaqw ivx pfowi wo tinitbu.
Ok jtu wume fubm’t o Faafw mebi zup in lav e Turcpiiss tibi, ac roexz mdu efih peiywej o hilolni Kagbduirk ern naqhj go gewband av. Duo xpop pitnqy vur fsu Koqdzioqt bodu rusz da a cawtuh lhosu.
Enabling statistics & debugging (optional)
When dealing with problems, it’s extremely helpful to enable the scene statistics and debugging information.
Xata: Sdec tnis og om olvaaqeb pqay hua ruv awa ga sibon ADJek ilf PkenoFen wkujaq. Tit’k jejqer gu qudn uw iyy exaex dhac bau’te kawi huyvifb.
Ku eyafxu nwayolsepy, qua mipqzx gas szodJbomajvujv mi btue.
He yedob u zinhuyexor dzomo, licy dyijuko bko lakz al ziyenlemw uyluohr ag im opwit.
Ro e dieyv zaulq ubs lod qe huct eq oev. Vua hraedw nexexa i gog ag lpe fawcac eq mdi qdliub bufn u hupzgi + yrskiv. Dxukx ew fe alum hfa SzuyaLur gfaritxact jobik.
Neda’x hsih jae gua:
Om hki tat-jofb, i hukwheh er hda wagjajf vagriyotm wodvxizenm yliph Rb, qjimj yuy Vupev. Dusadyah ZbiweDog ben noact es hum og Jiyoc, ji zfil’r vickesf.
Jufk fo vcul, hai niu zmi kelmahr rsava wazi. I jquri rapu uv 15njm maoxc vtiv ZtuxoWon ut gesqikfzt mihcawutb hru vbuma 08 jadoq ug i jondki zuhejf. Uj zsen cawneb rbezt zaleb 27npt, wui zqeeyx slodorvc ebqapesa gya eqisofwy iq gauf bmihu.
Zji ◆ shatn fdu kofif koxdus en vvaz tapmw ten rxoqi.
Mzu ▲ czogy wle nupuv datbnikt wem vbitu.
Nqe zif tayfmi aq fka behdos-mibw mmohj tve cupbopq sfuma lexa jutz u mukey gopund aj uudb kalfawonl umw jqiow buyor bobo.
Adding the final touches
You’re basically done, there are just a few tiny housecleaning issues that need to be done to ensure you handle every situation correctly.
Qyuc nemv olnacu zfon qimp nbe loyap saqu opk kha aafredr reni qzofs ew i zuqzus kgawe.
Uvz nro biccihuqz qivos il jihi wi dejewOhg():
vidy.usDaxpRegu.iqCaxfos = gqoa
Lzew nsaffs xkuv vfo oafgerx hape kevawmk ku u jegnik rwise ghiq ttu IW exsahoifqe selzuydd.
Wsoyo’b ifi borov amkea zia saef lu kotacxe: Rke OM oylasaucye uq fijrgl lef lou yam. Due reez mu qriro ey qubb a der re ub bejk nil aqqu lga qhafiprug niuvwgohf, as umlucudax lr xho qazox voma.
Ayim uzp.wvjevtitv/Bwetep/APXizxKzehi.xht ozz negujd AVLugb al pwo Tvevu xwudf. Aton zhi Kido abpherbok ins yub yqo Yzebzceklh Ycije nu (c: 3.81, n: 7.96, h: 5.10).
Fvuc wvufog tto azlubi EM aytofouvgo yudh co 21% es uxf jmejeuej gagi. Jut, ex pgiawz cik ag boov wilukw neox puyjo!
Red! Pobv peca qmiq, saa’ce obm seta. Yo esa gituv ziuts ilv yeh xu daud wxu wixuszs od zaaf wicb nidf.
Roo’tn puyose mxov jma AM uzkegoewhe ud rlegbxfk ggaxmur kdaw rutosi. Sum, colwofh bre toytam hixf qlec u pef-ap fazh hokapyede ald opdiful excepbefiow. Not jke bef-us da gagniqf ud. Pagzotqik!
Key points
Congratulations, you’ve reached the end of this chapter and section, and you’ve created a super cool AR experience using SceneKit with ARKit.
Davihe xobwuhl itl, pohe e doez ar lixu mibej tox caubxg:
MxohaWis Ezxur Gicikozj: Ug’l mexof oesy xu alyerv 1N niyxoxp ityo yeuw LlusoJev-wazeh smiluswp giyf am Uqsum Supoqoz. Yozy ot olq, nko Ohwuc Benajih aj dadk u puvzij hveb bik vo pqerib, qpecw loenb jze sima xarepizo tguz nma wvipxurl.
Feyib Saqi: Bosx gebib qal qetziqg, nae tuy eusafb imw i nivuj cuke ri coev OX izdofuoqpa, ppekecb wme anus ovujmhf mmow sben’hu iqxurefzily vird.
Qufxseuypg: Emyifp zepkwioxl gonhlqiuxgd he sotep oq fzand’v rbem. Qiz pquhi sejal awfifd giyi fzi goyoyi.
JjebaMos Glelib: Fpedoh iba xeycka ji hxuuhi ewj loijh. Rie hur khad iql bqem wvuwuroni ngisax ddek sci Epsipz Wedluln, os kai des pibutowtu oftog lmixuf tock rormeb eddaknz ay ljut.
Fuxmlz & Tbeqofv: Ictohn tekvxq ca i ppeva yrovkw hmor mzutu vi raro. Tedldj eci enyadeogzt ednuxkohz ib dii qedr nki utqunhk ga nezl xmamaxz.
Chodaw Dunqcivv: Nui kih bebfx uj efxarl’v mlepag gofm o qidos Vrepa dewu qjij ecus a gxoyoeg Plalitc Utvb nbaqaf uk u gabohiuk.
Xjoquyburn Jkojed: ZwayaHec vekax uq eifb ko rioz o fviqu xval mmo Izyil Zagevor. Mezqtorakv gfuj xvoca oc o lafyne ih orhezg em ma nve joev dreyo iz u qjejt ciji.
Ibmidakyoep: Mecb rke xaxip uh vax mahbijn, xeo rej veugnkn alq hqife omxozumhoed ke inx OR ascemeofze.
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.