Creating an iOS AR Portal App using Occlusion Materials

The AR Portal App uses Augmented Reality (AR) to provide the experience of entering a special space (inner space) through a portal, which can be achieved with a few lines of code using the iOS SDK’s ARKit and RealityKit.MechanismThe inner space is surr…


This content originally appeared on Level Up Coding - Medium and was authored by Yasuhito Nagatomo

The AR Portal App uses Augmented Reality (AR) to provide the experience of entering a special space (inner space) through a portal, which can be achieved with a few lines of code using the iOS SDK’s ARKit and RealityKit.

Mechanism

The inner space is surrounded by a large box or sphere, and the scenery of the world is pasted on its inner surface. When you enter the inner space, the outside camera image is blocked, which gives you an immersive feeling. The Occlusion Material of RealityKit can be used to make the inner space invisible to the outside world.

Create an inner space

The virtual objects in the inner space can be created freely. In this article, we will create a sphere with a radius of 1.5m and paste HDRI texture on its inner surface using a DCC (Digital Content Creation) tool such as Blender.

Load your 3D model into Reality Composer, where you can use its behavioral features to create interactions such as playing music or displaying text when the user enters the inner space. We’ll keep it simple and just set the location of the inner space to the appropriate location. Since the inner space is surrounded by a sphere with a radius of 1.5m, set the center of the sphere to be (0.0, 1.5, 0.0) and save the rcproject file.

Create an AR app

Create an AR Portal application.
- iOS Deployment Target: iOS 14.0
- Xcode 13.2
The inner space is loaded from the rcproject file and displayed. The box that hides the inner space (called Occlusion Box) is created programmatically, and its Material is set to OcclusionMaterial. This makes the Occlusion Box and the virtual object inside it invisible from the outside.

If you adjust the position of the Occlusion Box to intersect with the inner space, the area will look like a cutout door, and you will be able to see the outside from the inside.
Virtual Objects outside the Occlusion Box are visible, so the Objects representing the portal entrance are placed outside the Occlusion Box.

In this example, the ARView is wrapped with a UIViewRepresentable for use with SwiftUI. innerSpaceSize sets the size of the inner space. innerSpaceMargin is used to calculate the size of the Occlusion Box. The innerSpaceOcclusion is used to shift the OcclusionBox in the z-direction so that part of it intersects with the inner space to create a door. 0.0 means no door.

Conclusion

RealityKit’s Occlusion Material allows you to hide your virtual space from the external AR space. If you enter the virtual space, you can see it. This can be implemented with fewer lines of code in ARKit and RealityKit SDK.

The Swift Code described in this article is available on GitHub, and includes rcproject samples (day, indoor, and night), so you can try it out right away.

- GitHub: ARSimplePortal

You can create your own AR portal app by creating an inner space and replacing the rcproject, and you can add animations, sounds with Reality Composer.


Creating an iOS AR Portal App using Occlusion Materials was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Yasuhito Nagatomo


Print Share Comment Cite Upload Translate Updates
APA

Yasuhito Nagatomo | Sciencx (2022-01-20T12:04:46+00:00) Creating an iOS AR Portal App using Occlusion Materials. Retrieved from https://www.scien.cx/2022/01/20/creating-an-ios-ar-portal-app-using-occlusion-materials/

MLA
" » Creating an iOS AR Portal App using Occlusion Materials." Yasuhito Nagatomo | Sciencx - Thursday January 20, 2022, https://www.scien.cx/2022/01/20/creating-an-ios-ar-portal-app-using-occlusion-materials/
HARVARD
Yasuhito Nagatomo | Sciencx Thursday January 20, 2022 » Creating an iOS AR Portal App using Occlusion Materials., viewed ,<https://www.scien.cx/2022/01/20/creating-an-ios-ar-portal-app-using-occlusion-materials/>
VANCOUVER
Yasuhito Nagatomo | Sciencx - » Creating an iOS AR Portal App using Occlusion Materials. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/20/creating-an-ios-ar-portal-app-using-occlusion-materials/
CHICAGO
" » Creating an iOS AR Portal App using Occlusion Materials." Yasuhito Nagatomo | Sciencx - Accessed . https://www.scien.cx/2022/01/20/creating-an-ios-ar-portal-app-using-occlusion-materials/
IEEE
" » Creating an iOS AR Portal App using Occlusion Materials." Yasuhito Nagatomo | Sciencx [Online]. Available: https://www.scien.cx/2022/01/20/creating-an-ios-ar-portal-app-using-occlusion-materials/. [Accessed: ]
rf:citation
» Creating an iOS AR Portal App using Occlusion Materials | Yasuhito Nagatomo | Sciencx | https://www.scien.cx/2022/01/20/creating-an-ios-ar-portal-app-using-occlusion-materials/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.