How to programmatically add a model in RealityKit
To programmatically add a model to a window, volume or space, use a RealityView, load the model and add it to the RealityView's content.
The code for the demonstration detailed on this post can be found at the tutorials/immersive-spaces/position-scale-and-rotation-with-animation branch within the repository below.
Specifically, the code that adds content to a window, volume or space is found within the body, where it loads an entity (i.e. scene) and then adds it the element using content.add(scene).
This content parameter is gathered from the RealityView's closure (i.e. { content in ... }).
If you run similar code in the simulator, you will see a result similar to the one above.
Looking to learn more about SwiftUI, Swift, RealityKit, Design and Technology?
Search our blog to learn more about Swift, SwiftUI, RealityKit, design and technology.