Create your first Virtual world 🌍

Yagnik Suthar
Simform Engineering
5 min readDec 7, 2022

Put your imagination into reality and make your own virtual world 🔭

Photo by Vinicius "amnx" Amano on Unsplash

RealityKit is a high-quality rendering technology that delivers realistic, physically-based graphics with simulation against the real world. It allows you to build pretty incredible experiences with very little code.

What is RealityKit?

  • Made for AR / VR projects, RealityKit has simplified settings for a multi-user experience and can be used on macOS / iOS that perform multithreaded rendering.
  • RealityKit easily blends virtual objects with real-world environments, is automatically scaled to perform properly on multiple Apple devices, and handles the networking demands of shared AR experience. It natively integrates with ARKit.

“RealityKit only supports swift, there’s no Objective-C legacy.”

Credits: Tenor

Relationship with ARKit 🤝

  • RealityKit uses the maximum advantages and information that the ARKit framework provides for the smooth integration of virtual objects into the real world.
  • RealityKit is a suite of technologies that allows developers to start building AR(Augmented Reality) experiences.

You can use the RealityKit framework to implement high-performance 3D simulation and rendering.

Pin Points 🖌

RealityKit works with UIKit storyboards or SwiftUI interfaces. It has a minimum of a boilerplate code. For instance, RealityKit has a simple setup for collision and gestures (pan, rotate, pinch). RealityKit fits perfectly with the Combine reactive paradigm, which helps to handle publishers, subscribers, and asynchronous events.

It mainly supports

Credits: Google

Amazing side for developers: It uses Swift’s rich language features to provide the full feature set automatically. The following are the key functionalities -

  • Import fully formed assets, including sophisticated compositions that you make with the Reality Composer app, or build them from materials and textures.
  • Place audio sources in the environment.
  • Animate objects, both manually and with physics simulations.
  • Synchronize across devices, enabling group AR experiences.

Prerequisite:

Before jumping into the tutorial and actual coding, you need to have the following:

  1. Apple’s macOS 10.14.5 or later (macOS Mojave)
  2. Xcode 11 or later
  3. A physical device with an A9 chip (namely Apple’s iPhone 6s and later will be fine), running iOS 13 or later. Note that you will need to have a physical device with you because you cannot run AR app on the simulator as it needs camera access.

Feature of RealityKit

Scalable performance:

Credits: Google

Shared AR experiences:

Credits: Google

Object Capture:

Credits: Google

Custom shaders:

Credits: Google

Dynamic assets:

Credits: Google

Character Controller:

Credits: Google

Custom Systems:

Credits: Google

Object Blocking:

Credits: Google

Video Texture:

Credits: Google

Let’s start the implementation.

Credit: Google

Before you start, let’s discuss the composer.

What is a Reality Composer?

Reality Composer for iOS, iPadOS, and macOS makes it simple to build, test, tune, and simulate Augmented Reality experiences for iPhone or iPad. With live linking, you can rapidly move between Mac and iPhone or Mac and iPad to create stunning AR experiences.

Reality composer for macOS is bundled with Xcode. It is also available for iOS and iPadOS, available on the App Store.

Let’s start with basic experiments 🧪

Credit: Tenor

Pre-requisite for demo

  • Apple’s macOS 10.14.5 or later (macOS Mojave)
  • Xcode 11 or later
  • A physical device with an A9 chip (namely Apple’s iPhone 6s and later will be fine), running iOS 13 or later.

Note: You will need to have a physical device because you cannot run AR app on the simulator as it needs camera access.

Use the RealityKit framework for implementation of high-performance 3D simulation and rendering. RealityKit leverages information given by the ARKit framework to seamlessly integrate virtual objects into the real world.

  • For the Reality Kit experiment, we need one 3D object to put on the surface area and see what it looks like
  • You’ll get built-in 3D models in the reality kit composer, which you can use and make your own model like the below image.
Built-in 3D Objects

I used the below built-in objects to make the custom 3D object.

Let’s put it all together and see what it looks like 😉

Example:

With the Circle, Star, Cone & Cylinder, we’re going to make a Christmas tree.

Christmas Tree (Custom 3D Object)

Let’s understand how it works 🤔

Overview of Pillers of the framework

Main Component of Reality Kit

ARView: It displays an augmented reality experience, a native view of RealityKit.

Entity: An element of the scene to which the user attaches components that provide appearance and behavior characteristics for the entity.

Anchor: It ties entities to the scene.

Scene: Container that holds the collection of entities rendered by an ARView.

Demo Time 👨🏻‍💻

If you want to skip ahead and see code examples without support material, take a look at this repository below.

Wrapping up 👏

I hope you’ve enjoyed putting your imagination into reality and making your own virtual world. Meanwhile, we shall talk briefly about Reality Composer soon, so stay tuned!

If these tips have helped you learn something new today and you enjoyed reading this article, be sure to throw me a couple of claps. 🖐

Let me know your thoughts too, and share your favorite Xcode shortcuts with us in the comments.

--

--

Yagnik Suthar
Simform Engineering

 Sr. Software Engineer @simform + gamer + blogger + Traveler