VisionOS-ARKit Scene Recontruction enable occlusion

Hello, I tried to build something with scene reconstruction but I want to add occlusion on the Surfaces how can I do that? I tried to create an entity and than apply an Occlusion Material but I received an ShapeResourece and I should pass an MeshResource to create a mesh for the entity and than apply a material. Any suggestions?

Answered by Vision Pro Engineer in 784762022

I recommend you download and take a look at the Object Placement developer sample which you can download on this page: https://developer.apple.com/documentation/visionos/placing-content-on-detected-planes?language=objc In particular, take a look at class PlaneAnchorHandler and how it creates a MeshResource from the plane's geometry and how it sets an OcclusionMaterial for that geometry. The sample also contains the necessary extension for generating the MeshResource from a plane geometry. It should be possible to make this work for mesh geometries with some adjustments.

Edit: I think this extension should work (I have not tested this!):

extension MeshResource.Contents {
    init(meshGeometry: MeshAnchor.Geometry) {
        self.init()
        self.instances = [MeshResource.Instance(id: "main", model: "model")]
        var part = MeshResource.Part(id: "part", materialIndex: 0)
        part.positions = MeshBuffers.Positions(meshGeometry.vertices.asSIMD3(ofType: Float.self))
        part.triangleIndices = MeshBuffer(meshGeometry.faces.asUInt32Array())
        self.models = [MeshResource.Model(id: "model", parts: [part])]
    }
}
Accepted Answer

I recommend you download and take a look at the Object Placement developer sample which you can download on this page: https://developer.apple.com/documentation/visionos/placing-content-on-detected-planes?language=objc In particular, take a look at class PlaneAnchorHandler and how it creates a MeshResource from the plane's geometry and how it sets an OcclusionMaterial for that geometry. The sample also contains the necessary extension for generating the MeshResource from a plane geometry. It should be possible to make this work for mesh geometries with some adjustments.

Edit: I think this extension should work (I have not tested this!):

extension MeshResource.Contents {
    init(meshGeometry: MeshAnchor.Geometry) {
        self.init()
        self.instances = [MeshResource.Instance(id: "main", model: "model")]
        var part = MeshResource.Part(id: "part", materialIndex: 0)
        part.positions = MeshBuffers.Positions(meshGeometry.vertices.asSIMD3(ofType: Float.self))
        part.triangleIndices = MeshBuffer(meshGeometry.faces.asUInt32Array())
        self.models = [MeshResource.Model(id: "model", parts: [part])]
    }
}

Ty very much

VisionOS-ARKit Scene Recontruction enable occlusion
 
 
Q