Har*_*ris 4 unity-game-engine swift arkit swiftui realitykit
在 Unity 中,我们可以使用环境深度来实现遮挡。它在幕后使用 ARKit。我如何在 iOS ARkit 中实现相同的行为。
我知道我们可以用深度配置帧语义,但我怀疑它真的与统一环境深度遮挡相同吗?
// Build the set of required frame semantics.
let semantics: ARConfiguration.FrameSemantics = [.sceneDepth]
configuration.frameSemantics = semantics
session.run(configuration)
Run Code Online (Sandbox Code Playgroud)
在 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) { }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1932 次 |
| 最近记录: |