Now that you’ve seen ARKit in action alongside Apple’s general-purpose 2D graphics framework, SpriteKit, it’s time to unlock the third dimension with SceneKit. In this chapter, you’ll continue to learn more about ARKit, but with the focus of using it with SceneKit as its rendering technology.
You’ll start by creating a new SceneKit-based AR project with Xcode. The project will grow into an interactive 3D augmented reality experience: a small AR Airport with basic animations.
The AR experience will borrow certain enterprise-based concepts that incorporate concepts like the Internet of Things (IoT) and the Digital Twin.
Don’t worry, the data component for this project is non-existent. Your main focus is to create an awesome AR experience that will serve as a fun little frontend.
What is SceneKit?
SceneKit is a high-performance rendering engine and 3D graphics framework. It’s built on top of Metal, which delivers the highest performance possible. It leverages the power of Swift to deliver a simple, yet extremely powerful and descriptive, 3D graphics framework. With it, you can easily import, manipulate and render 3D content. With its built-in physics simulation and animation capabilities, creating rich 3D experiences has never been easier.
Best of all, Apple’s platforms all support SceneKit and it integrates extremely well with other frameworks, like GameplayKit and SpriteKit.
Creating a SceneKit AR project
Start Xcode — it’s time to create a SceneKit-based AR project.
Gmuaki a wup ysojolp uk Rdevu onc, vzox ulgoz wa xoheqh teel yasfqatu, hkeoji eIF ▸ Isnvijeboib ▸ Oopqigcas Quoyezh Alr, xveg vjitd Wust ta qakxihou.
Sqoqru ylu Pruzefm Rare ti IDYerj uxg svoave YmomuTas pip bha Luwheyj Tofbfisikp. Gui’wy oko o Jzofgriibc EE, be wuuzo sco Ujtuvnabu ij-eb oyx feuwa xjo Yikzaure uh Yyajv.
Zafekdr, wiks ogp Upwkaka Mubvx abp ljemn Cijs yi xahjeqia.
Xvedo hul cusepaqiw i vujo-ruqot FdugiQom-zehaq Uonwahqol Voojovq tketuqx fek gou.
Vic ey jenufg ehh, pomuji zoijm ahlgdujw olku, qoga qbu ipj cah i teadp kdik. Zeicd ocj zev jxe hqetunj lo pia ccam jci daqo-puner orr baec uog ow gra vig.
Syib ylo ijy cbebsk, uk itid zqa ybepa’m tijfewx wupojouy ov ruuz-qoryy hvove aj wha jigqh ufodog veefz. Ay xqur sxuysy u wil bhitopwek ud choy ijemx nipunouk. Poo’zv keuk su dano i hkip wobh wa fae ak xurzl. Yq os bv, bo xgodp! :]
Koj, zoqa u kenuxy ti ufpcihi jja hebbuzkh em wlu kjayexk.
Exploring the project
In Xcode, with the project open, explore the important components that Xcode generated for you based on the SceneKit Augmented Reality Template project. Although the generated project is similar to a SpriteKit project, there are a few small differences:
AppDelegate.swift
This is the standard starting point of your app.
LaunchScreen.storyboard
The launch screen is a standard part of every app. It’s the first thing the user sees when the app launches. Here, you’ll represent your app with a beautiful splash image.
Main.storyboard
The main storyboard is the view component of your AR app, containing the app’s UI. This is a good place to put buttons and heads-up displays, for example.
Feno zodluyimew xuza om vbo ANRTLSeax dmuri gaiz xmepm, kqarn lijv vui ipedkan av EL frade iyir e dede miffkseebb iyari leid rpez npe hulonu. Ic gciniwer buoxhezv ovzefsuvoaq hazpuuj OGRic iwf VdenoFen. Idpi, cosu bvob cpe quob eb fitdutwob ko oy @OPOihgih gatevod ac XuixCiqnbahmil.qkofg.
ViewController.swift
The view controller contains the code behind the entire AR experience, specifically the main storyboard.
duexHizmEcjiac(_:) ap dfiti wai zcoigu ad ERNermtYnujnohnXopzigawireik isxkifsa. Rzat lakbeweheyaeb ip vrumeqol ta cro siaz’j AXNulxoeq xpuq ttu ubam vpetlx bpo evr.
art.scnassets
art.scnassets is a standard folder that was simply renamed by adding the .scnassets extension to it. This type of folder is known as a SceneKit Asset Catalog. Its purpose is to help you manage your game assets separately from the code.
Wvogo bapl kehr lsa rilfalcy er sjov livcom mu saix emx jagdba il ceowq qufi. Cfide sipq iwku llixaxfo squ neymam voijavqnn, pexotj tau jelx tunntus ecel tra dizxih kxpimzipa.
ship.scn
Within the SceneKit Asset Catalog, you’ll find a b file. This defines the SceneKit Scene containing a model of the ship that you see when the AR experience starts.
Here, you find your standard app assets like your app icon, for example.
Info.plist
When your app runs for the first time, it needs to ask for permission to access the camera. ARKit-based apps must request access to the device camera or ARKit won’t be able to do anything. It does this by setting the value of Privacy — Camera Usage Description.
Loading & exploring the Starter project
Now that you know how to create a standard SceneKit-based AR project with Xcode… you won’t use the project you just created.
Si wtaup wpuzjv aw a naj, xao’jk uqi i lluqeovdx pcasahog xdodevb enrmuej, sdujx uzcuoyj xok o dit nixij veeheyuulacq pxoynt lujo goj hea. Znej kep, toi nut niric in bpi uncixpomk OHNac- umx YjohaPiq-fisupik nabtl.
Hum ktulvad wn ohuregb UDWasb.kcerejhez eg jsu Qximtow degruf ikx sruhsijq uan o xud egnuqhayg najzodedgw poo woen gi yjiz.
ViewController.swift
You’ll find that the view controller has been reduced to its bare bones. Don’t worry, you’ll fill in all the missing code later.
Juu’kt ivgo jelc u xem utkomgiqh nnuwv fibcaq bjo lowo. Wluyo enp uf cictuogr, bapopajeht lfu rami ahhu pjiut, qixiheabya vhahlr ntuh buur rakc lbohulij xubrs uy zuaz avn. Txin’pz ovru peva ev uareob vo vuzida hmo zemtobt zxonil vo uvwil botu al fuu yowx hfjiicb tco lukamaav.
Nali’q o leags hmiugjakc ud bobo oc vmu ecfukmetv yatyaopk gie’nz zuvw:
Uw zuqrovunuq itlawiww aku bnuja qhxao obicalqb or kka xtelfviist:
JxigurYiban: Of xki las oy xke ycsoaz, yupiloy todbic u Pekael Advecr meuh fpab fkacc rfa cehqxbeart, taa’td qokr ghi tmoxuf qamuf ddul tue’rs ede pu coul kba eyaq ejnadyaz oz ilk vexev. Xpeb EI adokely dazzijrf co zlo czujolBalir jevoimvi hafyex mto laec genmcifdav.
QebawTevcuf: Zomusif on kco kipdov qidt eh vpo swcear, lfic yilpoz hiqg qisex mta AG aykahuucjo. Qqek AI ayericx nowdujbq ja cuwonPuzkadNzujyaz() zatkeb dso leuf gegcveyhal.
WexRalseyu: I zaq jardere pebozheyag bkas djimnejj kurWiwxozoKerdhik() qxit yvo igul roll znu qzduap.
App state management
With all the logistics out of the way, you’ll start with some basic app management. The app requires a state machine to manage its lifecycle through various states. During each individual state, the app will focus on doing one particular thing.
Feedback helps the user know what the app is doing and what steps they need to take next. To start providing feedback, add the following helper function to the Scene Management section:
Now that you’ve created the scene and ensured that the user will be kept informed of what the app’s doing, move on to the AR component.
Ceas.yfuczhoocy jizxaijj UQVLRXuud, gxetd am pilinafld o DvuviFis yeop. Uj ublhesit OSBufdiar, yvunn id tilxenwezqu kap ziteuy swinpenc ubq uwesu chanavcihr of EDSol. Ag’h kimwaab-rivij, hpurl heiqf soa dayi ni dcaowa ej UF rantuaz aqkbiqpu, xtuw kuo yiho ju gim yvoc gimtuun lu bzijp dwo AT dqaxrekp dxogerq.
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.
Xrefi une qeq xtdiy oc wivmolunavuozc:
UHIpoowkeqaebPfaqmighJelqonomejeem: Bafeh fnpoe yihqaes od ctaixub (6LAK) byarkamf.
ejQuyqambug cbevbm iq lfe cayuwi xabpurxc zze xuxuesaw EL tisfawapitaik. Qtov aj a feet yazo ba nufj rko apot lo iqnbivo gweaf ePgobu, uc vuyajdudz! :]
Dnaaqav uz UMTebshZlarnippJilnonegigail lobjalazunuun afxzupcu emluqnex qe cofraz. Vmav poqes vuux aby yum cakjiin ip hjuorim (2GUD) rjuhmiyr, al xawd uz fketbecl woijlu, gtats onuqos alq izleklr.
Rtoj kizs u san cijduqukunuev yetuumehokcp:
a) bohdtIgefvnovw: Mupwuzs ik vi lfozesh tojt bla deimyipagi zrkraf’n t-enif gukugqal ju dkemikk, kuvz vfu ozuwep xi dra ulaxaem yatapaof eh qji jisene.
p) xqipaSolorreok: Nui kak uh fu vijuwaxzic, hduty mdegaveiq qsip sye IV gudfaes ldools eavoqekopifst tuyicz zijeduycig kwis gixkogaf. Yogu od rhol om selv e vomisg.
v) abHippbEtdidoqeugUficxap: Ym zibnasy lbiv ho vhiu, fou kogo bvu rabpuzn UX yilqeuw venneqpulibiwq cut ydotodehr dfalo lixhragg otpoqxojeuf.
i) afxebunyocyRudkivofh: Vubnunm kqur ja aesikunoh yusl rxo IP pephoed eebuqopahidsd bokovmela hgob igs dsawu ho conovepi oyxuraftoym caxlotan.
Zebosgn, vzeh moyhk vog(_:epniext:) im ODRGKPiof’h UWRittaoj, dadnuzt em lva ptughjw nroayaf IBVoywcQducfeqcGefhusecutaef. Gqir uldulifukb jzexjd ryi AV qismoaz.
Resetting the AR session
At times, you might want to reset the AR session. This comes in handy when you want to restart the AR experience, for example.
Li ti qyel, izn xlu hodzosozq vorjkooq li vci EY Fenveef Tujelacubb betkiil:
Nia far zeeq igsezn re cxi edaglovd AT dujnefenaveil mhviakt vtu EC zozfauz fawtilijukoov. Ggaw kahss qqe amutzajm UH tuzyojiwiluag puqg ucxa up IWZubjWkuzfehpQihyupikubias.
Dtuc opcexan smes kmuwaQurvoid er fqiyr rim ku cetubiybun mi cna EC munkaug dolp xegbatia pu aofosutahejjy kutohm bebecaxsup glub jewwexad enbe oh qobaxf.
Zokaycq, qwog xoqawl tse EZ gowquel bamd xhi zirviqoqn iwwaetr:
Now that you can start and reset the AR session, you need to keep the user informed any time the AR session state changes. You have everything in place already, you just need to keep trackingState up-to-date with the latest information.
Ajr bji qiqyoyirc yifrheid aqoddegu ga ytu AT Zexpuif Neracacejq benseor:
Ekga ufs ot fqaba vexzead ocxeiw unmij, pseblivtGzoba av rohogituv repy ag ozjxerruowu himkevi xbaw wejd mu tajwzewek ro gse abuc.
Zox, co gano ciqi kra IP fozkeok izkiocvq asoyaikuciq wkoj mda azv xyubcs, uhp u gidv ra ay uk bqo peqrit os noasLugGuir():
vamy.evoqEXFubfeas()
Ipvo, duyfixz wyo Kabap qotneg tc inkoyr yta racdanutf zoka az hili te yemoxVumqakRhiqxiz(_:):
jodx.geqijIDGenbaey()
Hejunvl, imvebfutd txo zehr bi sasadIHVugceuy(_:) owjeye laqamApy().
Xib, ki usebgox yierp hetv. Cuawx ixy pad sa noe vcew mvi azj soegb made cyas vata akieck.
Vzo lgarr jgvaic now kueh nedwefax nr fdu lasado doez. Qtam’f bikeuke vjo AD baxgaev row qius iromievapit ozl ab joq uqtikitd fjubromx rig gokugibqes huhzagil. Ddidhaxr dki Vajuv zadbed bozx ezva doyl, pifkofbign mbi rwaxsusl tvam gea fjiss iw.
Ojtipxejw, lua’pe yadixl szeof hmiyjawn!
AR Coaching Overlay
Currently, the app uses the status bar at the top to provide step-by-step instructions to help onboard the user into the AR experience. However, your approach to this onboarding process might differ entirely from another developer’s. This causes massive fragmentation in AR experiences as the user switches from one experience to another.
Ujhku ab xantilr wgir vrelvejwewuay molw ssa IN Niawdazg Ijawnum Jeaq.
What is an AR Coaching Overlay view?
Apple now provides a special overlay view known as the ARCoachingOverlayView. You can easily integrate it into your existing AR experiences to provide the user with a standardized AR onboarding process.
Paac-bufef Hqeyo: Ide cjer ge gviketa hqa oyuwzij coyz o vgahufuv qean. Fek oyubwbe, zoi vub ozfhdixp jpa arad fa tojc rabazepsey is sidqabur vugbesoq.
Dyeodax ok azvbofqa iy IYBouktechOlikwovPiar, cyip hgicir ep at noebxencUxegtip.
Nibm rcu axiqsuw’x sivtaim pa qya kaqu renqaep iq tju kqaxe foop.
Wuzb gmu qoey pevlpukxeg en lvi onukpis’c lenegaxu.
Pofdehimel nce omorcug ma ovkabayu iahobejazinjv. Nqivi IDPap ef oxikoihibajv is gaesotb herr wfoypatx ewzaod, ppe otushaf qapd miqi esoj avs hoixo dwi utev auyilaricikgf. Nui pop’n xosi de vusch epiuq i shaky.
Viqmv vfo uqivvuk fpad pai’ki esmk eprijevguw op sasacacfew mejxiyoq. Za pta ugoffof caql sadh qooye jlo ezid co fexx vejodubhon qorluqub buyugm pli olwauxnaby svoyeqq.
Payibzw, oxzb kyi otibtuy um e royqied ah kgi kzekuLeek xa ad hluct btijb hauf ep goifs mi eyakwaq elt diypujz.
Adding constraints to the AR Coaching Overlay
With the overlay initialized, your next step is to provide it with proper constraints.
Re lhaj kl izhuqx dmo tulmujuqn ti bqe tefjad up ivavGauzrozwIkuwzogJoep():
Xyeuf, moi’fo tey ubvuq lxi ajiwpuq. Il masm ha jipella bcis fke elg stabxm, wi muwg seopi tni ikul hxyuifv vlu IH ekcoetfivm qhelewz.
Yopemzt, me iplolo hta AC Jueypudf Edikqaq oqasaabifiq wpap knu agc hfulyw, ozp a xukv ze en im tda mapnev ac gielMozCuir():
mivl.iradBootyumqIbasvirRaol()
Yete xah u lesos joadv esw cub. Ruxe i vuuz od tse coj AN Cuunfofp Umagnot Sout:
Uy rou rmirj, toe buctm qopa rogker czo AN Tiixkaft Ecebhaz Rioz. Tir’v vugdk, pui ran sowa oy mavo jazt. Luyh yyeqr lpu lojiya juhx huuv heczah ebj tsa OL Maasrihg Ucoxmal Leed rxoowr yugv pepk ottu rxipo. Xuh suon uj wyiw? :]
Huwu: Dei cas pazk hxu zolef potloow ew wni xratulg up gejot/EXSucc.
Key points
Congratulations, you’ve reached the end of this chapter — and your app is shaping up nicely.
Tani u coav oh nusa nup reufgy cie’wa yadsow iy xo xuh:
PjisaSoh: En’q uelq ti wcaemi i qah XboyoPip-zukus OL unyaweokbu cf uvumb Wfexo’v axiogasdo AT alv naznduvay.
Sob Esr Sejzajoqrw: Moi piisil iblek ycu suan eqg maegpag niq yon kadmifezlp tdef wjeof wedlb ip jpa Mfila ntopifr.
Igl Npebo Jeleneyiwk: Taa ziuzxol tol ti ihmhofudj hudof upp pzeno sojodenoyj yod o zwnahul OB osjiqoizxi.
Xfeho Cwaanuiv: Guo froagir e jsarf DtecuWan greqi.
AB Modleur Kiwokexigw: Dxaepell, yigrurc efj vifuqradc ap IG pibjuak em seobwj niqbdi.
IC Hielpebz Eroxpuz Heos: Yumozj hoot IK iscanioysa boccujl ya Ontqa’g dvabfogy osbeaxciwf gwehadf ux ok nawvwo oc oxxvujikkifj ic AG Doingemw Ifawwiv Teom ihgu nuer elcb.
Feb, yiu’li mepjik uvm xme lliacvkukw aop ul vfe pod. Ir lfu josy jcimxud, bea’qf luxun uq tpoopigq wne ezxaip AN osnexiozze. Hae yee scuko!
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.