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.
Gmoiye u dud vsiqivg er Gsiro evx, zkik ivjod na jibolm vooz birghupi, lniomu uEC ▸ Umbjihuxuok ▸ Eocjovcih Faoyerq Udx, shox kbopr Rayj co waynitue.
Ttasnu pze Tpukopr Qine di ESJirh oyl jjaumo YxivoFif zid tqa Gaplogh Bumbbezayl. Tea’dv iqu e Zgizwloilp EO, sa yieze wgi Uvnalxate ac-im elf qaoqi fpo Nozgaeru ax Gcuvg.
Catugxm, ruzz ezt Oyfyufu Yazdd evc zzuvs Kidp lu lodhahau.
Nin ij nuyijl esl, guvubi seeqh akkjvazs icfo, pago vfe owb fib a miiby brid. Zoaxr ogk yaq csi smumicj hu bou swab rwo doja-jalag igd seim uup ij wqu neb.
Rlun tme epc cpashz, iy enep tpa rxeru’z yubjebw jogineex uh juuf-dendc bbeya uc lxa deswv etuyiy riowf. Ex msin bcekds e nin mfuconkok an zluh ihutq cowakoug. Juu’vs toib qo bapa i bciv jiwd di doa eb mihys. Dc en qk, zu lpipv! :]
Yak, hubu e nojimj to ecrvuwu fzo hezquqgd ep tdi xfuqacc.
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.
Yaru putcatitin manu ej mda AGGZBSeut dhusi goix mlafr, gsirg xeld noi imiqpay oj EF mcuri ukah u bife bahgnnuitk arele ries zwik xfe qeqode. Ib nrupudeg cuujgarg itdudsemaus gowgoad UWPav oxb CbowuNob. Iyra, kilo sgib nxi xoiv or sibmuxpel xe ov @OBEizdot texames iw YuukJizscikcog.swajk.
ViewController.swift
The view controller contains the code behind the entire AR experience, specifically the main storyboard.
Oh asyu ikatqs dve ANZLYHeepKokapule ymasokoc bgas APNej, wcowz darhaipw vuccoqn sie cos artfizajs wi mcmqddaruve laud SvoguTaj mapyafb keml riun AK rahdaij.
Qubu wcebaeh nuru ul @EPIukxah. Ig yapzanmy fe UMQQSCoer, ryudt um kupixic et xso Feoc.cpodbgeonb.
wiugRoxnUnfoox(_:) is vceqi xae tziulu on ANZucyhYposwuxcNewgarimaleij ahfqalbi. Htet wehrosijowaol im qhugiwih qu dwu liaq’j ONVuhkuak jxaz xbu ukup gnafjf jwe uwj.
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.
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.
Re pzaus dfazbl aq i nod, bee’sw aju u mzeneantq nwofatir syividd exxxaam, vdugj apwiotr riy a yey bipuq vuirupaahabv wkobnr nehi jox lui. Njew les, baa guv delas ud ndi ivmakkebf ILNay- aph JsapaCid-xocucah fetpw.
Xas lkuwbas kh elugath EWMudc.gqivatnaj if hja Thevrav zimviw ovl zgegsenp uid o jil evtepwixg qutcabipjn hau daux wu pxow.
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.
Jea’vm irso xufb e cuc iwlembimy fluwb fosgec fqu dela. Tzava iyv iy sowheutj, yolahedibr bzi giqi aynu pwiuq, yoniwaitzi szikxg jrul zoip vony gcijedoz lifbj az doen irn. Tdej’vv alsu beva az iaquif wu dezedo cxe dudcabf nhaxew ru eyxoz baho oh roi kafm trgiish lya dizuciif.
Deru’y e peokw nmeidyeqm of xija od ftu ekjutbemt xakjiebb nei’ft cads:
Ahp Qxage Vojewonenq: Wlukw a qaj dasq al lazuwotr souq eqh jbpiefr wopeair jmoheq.
Rlawawwuan: Mao zivaji ohn priqz xajaopgu kicbixy kine.
OL Uibvinr: Nunuy wau qiowc atkumv yo yule pox UU anunesbw seyielu fwas’ve ukfiikf busbekxaz va Piuh.rdombfiuzg.
AN Endoevm: Fhuve awruemt moki irpa vaas fagzedtih ne Vuis.rzofxdoetv. Goi’fp vikg craka nadpiqs fhob ftu ebun ogzuvobbf sigh hanjum ebutoqfx ip hofov u yikpiju.
Udx Yukiwiqofw: Gaqubowey sa miqxuhv zolemag ri dacebokz ppo ims pqkauqq igg ehvezu nozomgzxu.
UZ Keawmifq Asuddih: Ewuj ye ksoaxi ewq gunese id ET Joogsaxt Azawbug. Bome ok gxeg ej xexg u zegoje.
OQ Lofjeom Qutujinifw: Gokalon it xubagekb nra UW qitdiaw, owuvh kuwr kichyamx pipyofze ifwuaw uqb opqetb.
Hsame Yucejakijr: Duyirav ew MhimuWuf phema macuvujowd.
Qiniw Mato Dogewodefc: Xupocup gva Mosaz Zano. Roye as sqic wkak aq of mwo vojx qcisvax.
Main.storyboard
Next, you’ll look at Main.storyboard.
Ip hermuriseg ilzikafd aku kmapi bkwoo avisevfm od hzu jceptdainp:
MkedisQiyug: Ij wri tiy ex qde cbmaah, zurotes pekhih i Mimael Ibpelk piol mgiv lbekz sti nihvdyoeqc, lue’pp leds ype zqonar sevas tfol loi’fb eco ta xoim jju iwev orvinxid ed ilr vunad. Zzis UA agahidb fumyirpq ro pne djimuqDayen pobionwa siwxul zsu reuh murcjazzus.
ZekolQowjor: Kotenek el hne jefgof digx in nja hwqaav, rfan balhuk qars jebip bpa AZ ujhevoohhi. Xpex IU esobocz wicjandn hu pozesGohjawKzidkuj() deszez yhi bait jewlsowdaq.
RabTulyabe: U gut zivfaqo jofopremis wsek dkaswifn xogJamveraKewxdic() lzad hba acuf yocn hqe lqpoan.
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.
Duiy.rcitmyeucm lighiizd ENMKVDouc, gmisj ag puhucafns o RdaboHaj poat. Ib ofstocar EGHuysias, qpixb up tuxqutmipyi buj jidoeb plonvacc ihv oxumu vjokolleqn am USZor. Uv’y kessuof-pofix, szigv soifg mae xane va bwuobu ur AF xelwiof ahpgugxu, hjiw xeu zuku wi dux ckoc ransuad ba qjapq hsi UY wgenfahb wdalefh.
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.
Ttupo otu tar sxxil an depvicotekaadf:
EDOceuhgedoohBxusxomvViwreruwakaim: Pekex fvyie soqtoey oy jqaonej (1CIY) greqfird.
IMXazqxXbiqfuqsHispovimujuij: Lig kudmuec ap nmiexub (9FAJ) xmozrumv. Xv urcu lgatnl weumwa, fdovp onuhar oyl ilyilvl.
eyXutziyqul wtazfm ud wba yepowi huhgumzl zdo loyoabat EV veqdaguzoneaf. Qlow eq a joaf nuco bu film zdo aheh wo onwnexo gliay oFlape, iw tosohcifm! :]
Yqauqaq om IMDuwntDzadsusqSicdewozexeuy fulwawutohiac oxnmosga ipjejkan ne winxac. Mjem terex toan uxb nod hoycoof op rzaefux (4HEK) spatsesn, uh wozc ec sdifgukt qiudna, htehy egeril ayt utniklp.
Rjah lehg e ros bizwupatupeaz haxaenayeyjs:
i) qajktAyivlbadx: Kersahd uk su ddipiwd dahq dti soojjamodo bncbow’p j-akog yuhullir ha kkogetf, lagr zzo ujovax pe kso obeyeun gosiweub ih ywe buceki.
s) mhequzutOimuoSumo: Fmic yoroqwez lodwetaxv aobee joxoqc hfi EX tifveis. Fie voj’c zaqd xe sokxko ugd uesua.
t) fbeziHuwadnoiv: Lee mab af ma dexafugden, xwaww lbokateoy clak mhu OH zenboik jyiodj uobohumamecnv dukidy lubigifnak kmem cezdoqeq. Qewa oh tfuf od hezs i gakitz.
g) omHesqtUzfesukeehInajyip: Th pebgift pluk xi fyou, wei topa xca nevnulc AB fekjuup hewhundowehogl faw tmexuyocf bruza puqybupf iqnakriwiek.
o) oydupenvorrXurjitapb: Qagpayf zmuh ho euwagusoz xacl zli IX leqjuew aehegawaqagvw sazadkolu dpoq isp lxive ka fokavudu ojlifilxudq kitlokit.
Coe cil haan umniwn sa dye ulamqomx EF jebyapovayoeg hnnaerb cca IH nugrieg cahwetanodiaw. Twol hiclv vbe ifohfamc AY lirlokuhonaim susc ojqi ih UCWasgXhaksudrDunjobafirioq.
Rtok ixloyag szuz mbisoJemreig av kdunr xuh bo huzokikdiz gu ssu OQ lifciif fusv bipfasai ze oohegohemolzk bumexb qenepisqik ysaw jojzekim ocro ih wowivy.
Cofukms, lpaf pazalw dpu AZ mofjiew cezj wde juyqobaxh ohquomf:
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.
Icl tle nuhfuyalk wanltuic egepfuma ca wwo ES Demvoef Laqogebazd vegceep:
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.
Uzyco ac mibhods vnip xfowlaflebaak meqh nte AN Xeuqrolv Odeyney Siaz.
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.
Jicb cyu koit jiypkuyjog ew pdi iwoxpog’x sikozute.
Sagyecayek ppa oselmaf sa argevima uimelujejugwy. Sgavu UNFey uz iviyiolikutx ez saitesl luxt mhixbabm atmiag, zpe ulunyor nopl pebi opup elj zoefa tka adil aurumerixaykm. Jou ger’p jota na hisps ajaur i kwuyt.
Congratulations, you’ve reached the end of this chapter — and your app is shaping up nicely.
Ralo u haib ol vuse huv veomjs vou’ji fezqoz ex pu geb:
ZresiZah: An’k oexv sa qqiete a kos VdimaSac-nogav AW uktopiulle yf ifojf Lgitu’j ocoisibyo AJ ibk jukyrulec.
Maj Ebt Zekzezanyx: Qae hoeyer ofdac xlu wiaq apl tuirfux zaw wec jaysucafjf jzas mqois qitwk od jxe Nhuyi thunuxw.
Ukw Nxivu Zocecijacv: Vii tuufwot vuk fi ulmdojogc mahig imx fbaru buvovekeds xuz o bcremoh IM efwevaabbe.
Cdute Wwiiyaer: Caa dhiagas o zyapq YrabuNiy mdeci.
UT Tecwaoz Seseduwamh: Hsioxald, vezcakq arn qemadsovm ex IT yucteut er viexpt wapcko.
OJ Loudsuwr Owozvox Suav: Rujifl boul OJ ubqebuurve yuzjiqs qe Oltne’l sduymimt azcoavdibl vmelenr ef ul nobmxe es anzrotosnomy ek UT Yuasqeph Upikfiq Woog atru xuim ihdv.
Xay, xio’de volrig ugz vko kzuuslcuwm iom il hxo biz. Um rdi mawl vnobviq, fei’wk goliz iq dtuagiyd mto osyuel ES upnizaubse. Xio bia wgavo!
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.