是否可以跟踪面部并在 RealityKit ARView 中渲染它?

Is it possible to track a face and render it in RealityKit ARView?

Apple 文档说您可以将 userFaceTrackingEnabled 设置为同步前置和后置摄像头。添加 ARView 并正确设置配置后,我可以确认 ARSessionDelegate 函数将正常调用,如下所示:

func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
    for anchor in anchors where anchor is ARFaceAnchor {
        // triggerd
    }
}

func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
    for anchor in anchors where anchor is ARFaceAnchor {
        // triggerd
    }
}

所以现在我有 ARFaceAnchor 对象,接下来我应该做什么?是否可以使用 RealityKit 渲染此 ARFaceAnchor?还是只能由SceneKit渲染?因为网上的例子都是用SceneKit实现的

我相信,这不能通过 Reality Kit 完成,当我阅读面部跟踪文档时,我找不到任何关于使用 Reality Kit 进行跟踪的信息。但是你可以使用 SceneKit 和 SpriteKit。请检查此文档。

https://developer.apple.com/documentation/arkit/tracking_and_visualizing_faces

这句话也引起了我的注意

This sample uses ARSCNView to display 3D content with SceneKit, but you can also use SpriteKit or build your own renderer using Metal (see ARSKView and Displaying an AR Experience with Metal).

If you wanna use RealityKit rendering technology you should use its own anchors.

因此,对于 RealityKit 面部跟踪体验,您只需要:

AnchorEntity(AnchoringComponent.Target.face)

如果您使用的是 Reality Composer 场景,您甚至不需要 session(_:didAdd:)session(_:didUpdate:) 实例方法。

如果您在 Reality Composer 中准备场景 .face 开始时可以使用锚点类型。 .reality 文件中不可编辑的隐藏 Swift 代码如下所示:

public static func loadFace() throws -> Facial.Face {

    guard let realityFileURL = Foundation.Bundle(for: Facial.Face.self).url(forResource: "Facial", 
                                                                          withExtension: "reality") 
    else {
        throw Facial.LoadRealityFileError.fileNotFound("Facial.reality")
    }

    let realityFileSceneURL = realityFileURL.appendingPathComponent("face", isDirectory: false)
    let anchorEntity = try Facial.Face.loadAnchor(contentsOf: realityFileSceneURL)
    return createFace(from: anchorEntity)
}

If you need a more detailed info about anchors, please read .

P.S.

但是,目前有一个令人不快的问题 – 如果您使用的是 Reality Composer 内置的场景,您一次只能使用一种类型的锚点 (horizontal, verticalimagefaceobject)。因此,如果您需要将 ARWorldTrackingConfigARFaceTrackingConfig 一起使用,请不要使用 Reality Composer 场景。我相信这种情况会在不久的将来得到解决。