VisionOS programmatically toggle .showSceneUnderstanding

I was executing some code from Incorporating real-world surroundings in an immersive experience

    func processReconstructionUpdates() async {
        for await update in sceneReconstruction.anchorUpdates {
            let meshAnchor = update.anchor
            
            guard let shape = try? await ShapeResource.generateStaticMesh(from: meshAnchor) else { continue }
            switch update.event {
                case .added:
                    let entity = ModelEntity()
                    entity.transform = Transform(matrix: meshAnchor.originFromAnchorTransform)
                    entity.collision = CollisionComponent(shapes: [shape], isStatic: true)
                    entity.components.set(InputTargetComponent())
                    
                    entity.physicsBody = PhysicsBodyComponent(mode: .static)
                    
                    meshEntities[meshAnchor.id] = entity
                    contentEntity.addChild(entity)
                case .updated:
                    guard let entity = meshEntities[meshAnchor.id] else { continue }
                    entity.transform = Transform(matrix: meshAnchor.originFromAnchorTransform)
                    entity.collision?.shapes = [shape]
                case .removed:
                    meshEntities[meshAnchor.id]?.removeFromParent()
                    meshEntities.removeValue(forKey: meshAnchor.id)
            }
        }
    }

I would like to toggle the Occlusion mesh available on the dev tools below, but programmatically. I would like to have a button, that would activate and deactivate that.

I was checking .showSceneUnderstanding but it does not seem to work in visionOS. I get the following error 'ARView' is unavailable in visionOS when I try what is available Visualizing and Interacting with a Reconstructed Scene

Answered by Engineer in 786944022

The Example Code you linked is specific to iOS.

You may want to take a look at visionOS specific example code, e.g. this sample:

And also these samples in the ARKit section:

For a programatic mesh visualization you may need to create a RE MeshResource based on ARKit's MeshAnchor.geometry.

See the documentation for these types here:

Accepted Answer

The Example Code you linked is specific to iOS.

You may want to take a look at visionOS specific example code, e.g. this sample:

And also these samples in the ARKit section:

For a programatic mesh visualization you may need to create a RE MeshResource based on ARKit's MeshAnchor.geometry.

See the documentation for these types here:

VisionOS programmatically toggle .showSceneUnderstanding
 
 
Q