There are a lot of new features in realityKit as highlighted on this slide
RealityView attachments
- This allows you to attach SwiftUI content on a RealityKit scene
- By using a RealityView in your View Model, you add your various Entities and content, you need to add a new parameter in your closure for attachments, and add a view builder, where you add your SwiftUI elements. Also add a .tag(“”) or any hashable value. Then you use entity(for: ) with the same .tag to add it to the element.
- This creates a view.attachment entity that you can add like any other entity.
Video Playbacks
- VideoPlayerComponent is a new type to embed video inside of a scene.
- Load the file from bundle (or other location) , create a AVPlayer instance and then create the VideoPlayerComponent
- This will create a video mesh of the appropriate aspect ratio of the video
- You an handle both 3D and 2D video, and the player will also handle Captions
- By default the video will be 1Meter in height, but you can scale it to the size you’d like.
- This also supports passthrough tinting to match colors in the environment.
Portals
- Can render a view with different lighting and masked by its geometry.
- First create an entity that is a World Component. You can attach children to this entity, and they will only appear within this portal.
- You create a portal with a model a transform and a portal component which is targeted to the world component.
Particle Emitters
- Now that we have a world and a portal to it.. we can add a particle emitter to give it some excitement
- You can create particle emitters in code in RealityKit or design them in Reality Composer Pro
- Creating your Emitter in Reality Composer Pro, you can still modify it in code.
Anchors
- Now let’s attach the ports to a wall… this is the purpose of anchors.
- The are tracking modes, .once and .continuous – .once will not move once it is placed. .continuous will move with the anchor
- To use Anchors you must be in an ImmersiveSpace, because you will need to render things outside of the current space.
- The AnchorEntity will look for a vertical wall that is at least 1M by 1M – and that’s it!