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

标签 swift scenekit augmented-reality arkit realitykit

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实现的。

最佳答案

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 anchor 类型在开始时可供您使用。以下是 .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 this post.

附言

但是,目前,有一个令人不快的问题——如果您使用的是在 Reality Composer 中构建的场景,您一次只能使用一种类型的 anchor (水平 vertical, image, face, or object).因此,如果您需要将 ARWorldTrackingConfigARFaceTrackingConfig 一起使用,请不要使用 Reality Composer 场景。我相信这种情况会在不久的将来得到解决。

关于swift - 是否可以跟踪面部并在 RealityKit ARView 中渲染它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59684132/

相关文章:

ios - 当 imagePickerController 只返回 UIImagePickerControllerReferenceURL

ios - tabBarItem 图像质量差

ios - NSFetchRequest 没有参数重复

ios - Alpha map 在 scenekit swift ios 中不起作用

swift - RealityKit – 更改模型的颜色

ios - 将数据从 TableViewController 传递到容器中嵌入的另一个 TableViewController

ios - 用物理学控制一个物体

ios - SceneKit AVPlayer 仅播放音频

swift - 如何在 RealityKit 中仅围绕一个轴旋转对象?

unity-game-engine - 调试 IL2CPP 代码的最佳方法是什么?