2

In Unity we can implement occlusion with Environment Depth. Which uses ARKit behind the scene. How can I achieve same behaviour in iOS ARkit.

I know we can configure frame semantics with depth, but I doubt it is really same as unity environment depth occlusion?

// Build the set of required frame semantics.
let semantics: ARConfiguration.FrameSemantics = [.sceneDepth]
configuration.frameSemantics = semantics

session.run(configuration)
4

1 回答 1

2

在 ARKit 中实现sceneReconstruction选项,在 RealityKit 中打开.occlusion.

唯一的缺点是一个丑陋的面具,在现实世界的物体周围有柔软的扩张边缘......

import RealityKit
import SwiftUI
import ARKit

struct ContentView: View {
    var body: some View {
        return ARContainer().ignoresSafeArea()
    }
}

struct ARContainer: UIViewRepresentable {

    func makeUIView(context: Context) -> ARView {  
        let arView = ARView(frame: .zero)
        arView.cameraMode = .ar
                
        arView.automaticallyConfigureSession = false
        let config = ARWorldTrackingConfiguration()
        config.sceneReconstruction = .mesh
        arView.session.run(config)

        arView.environment.sceneUnderstanding.options = .occlusion

        let box: MeshResource = .generateBox(size: 0.5)
        let material = SimpleMaterial(color: .green, isMetallic: true)
        let entity = ModelEntity(mesh: box, materials: [material])
        let anchor = AnchorEntity(world: [0,0,-1.5])
        anchor.addChild(entity)
        arView.scene.anchors.append(anchor)            
        return arView
    }       
    func updateUIView(_ uiView: ARView, context: Context) { }
}
于 2021-12-24T13:15:39.007 回答