EnvironmentBlendingComponent
A component that controls how an entity blends visually with objects in the local environment.
Declaration
struct EnvironmentBlendingComponentOverview
Use this component in your visionOS apps to allow physical objects in the real world to occlude your virtual content.
To enable the surroundings to occlude an entity, you can set the preferredBlendingMode to occluded(by:), specifying the environment type as EnvironmentBlendingComponent.EnvironmentType.surroundings:
let blendingComponent = EnvironmentBlendingComponent(
preferredBlendingMode: .occluded(by: .surroundings)
)
let boxMesh = MeshResource.generateBox(width: 0.5, height: 0.5, depth: 0.5)
let boxModel = ModelComponent(mesh: boxMesh, materials: [PhysicallyBasedMaterial()])
let occludedBoxMesh = Entity(components: blendingComponent, boxModel)Alternatively, you can also disable the occlusion for the same entity by setting the preferredBlendingMode to default. If you deactivate and reactivate an Entity while it has an active EnvironmentBlendingComponent, it may take a few frames for visionOS to generate an occlusion map before it fades the entity in.
An entity with occlusion enabled behaves like a real-world passthrough object. It always renders behind other virtual contents that don’t have occlusion enabled. In addition, it doesn’t receive input events from the user if it’s behind a real-world object.
Occlusion only works in mixed or progressive immersive space. For progressive space, it works only for entities outside of the portal world. When the portal mask expands and overlaps with those entities by turning the Digital Crown, it fades those entities out gradually. Occlusion doesn’t work in full space, or in a window or volume in the Shared Space.
EnvironmentBlendingComponent applies occlusion recursively to the entity and its descendant entities. A sub-entity’s component set overrides the top-level component.