问题描述
我已经在Reality Composer中的人脸锚中添加了内容,稍后,在加载我在Reality Composer中创建的Experience
之后,我创建了一个人脸跟踪会话,如下所示:
I have added content to the face anchor in Reality Composer, later on, after loading the Experience
that i created on Reality Composer, i create a face tracking session like this:
guard ARFaceTrackingConfiguration.isSupported else { return }
let configuration = ARFaceTrackingConfiguration()
configuration.maximumNumberOfTrackedFaces = ARFaceTrackingConfiguration.supportedNumberOfTrackedFaces
configuration.isLightEstimationEnabled = true
arView.session.delegate = self
arView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
它不是将内容添加到正在检测的所有面孔上,并且我知道它正在检测一个以上的面孔,因为其他面孔遮挡了粘附到另一张面孔的内容,这是对RealityKit
的限制还是我在作曲家中缺少一些东西?实际上,由于它是如此简单和简单,所以很难错过.
It is not adding the content to all the faces that is detecting, and i know it is detecting more than one face because the other faces occlude the content that is stick to the other face, is this a limitation on RealityKit
or i am missing something in the composer? actually is pretty hard to miss somehting since it is so basic and simple.
谢谢.
推荐答案
如果您使用带有嵌入式Face Anchor的模型(即来自Reality Composer的Face Tracking的模型),则无法在RealityKit中成功进行多面跟踪预设(您只能使用带有.face
锚点的一个模型,而不是三个).或者,您可以使用此类模型,但是您需要删除这些嵌入式AnchorEntity(.face)
锚点.尽管有更好的方法–只需加载.usdz
格式的模型即可.
You can't succeed in multi-face tracking in RealityKit in case you use models with embedded Face Anchor, i.e. the models that came from Reality Composer' Face Tracking preset (you can use just one model with .face
anchor, not three). Or you MAY USE such models but you need to delete these embedded AnchorEntity(.face)
anchors. Although there's a better approach – simply load models in .usdz
format.
Reality Composer支持5种锚点类型:Horizontal
,Vertical
,Image
,Face
& Object
.它针对每种锚点类型显示一组不同的指南,以帮助您放置内容.如果选择了错误的选项,或者稍后改变主意如何锚定场景,则可以稍后更改锚点类型.
Reality Composer supports 5 anchor types: Horizontal
, Vertical
, Image
, Face
& Object
. It displays a different set of guides for each anchor type to help you place your content. You can change the anchor type later if you choose the wrong option or change your mind about how to anchor your scene.
有两种选择:
-
在新的Reality Composer项目中,取消选择启动时看到的操作表左下方的
Create with default content
复选框.
在RealityKit代码中,删除现有的Face Anchor
并分配一个新的Face Anchor
.后一种选择不是很好,因为您需要从头开始重新创建对象位置:
In RealityKit code, delete existing Face Anchor
and assign a new one. The latter option is not great because you need to recreate objects positions from scratch:
boxAnchor.removeFromParent()
尽管如此,我还是使用AnchorEntity()
和session(:didUpdate:)
实例方法中的ARAnchor
初始化器实现了多面跟踪(就像SceneKit的renderer()
实例方法一样).
Nevertheless, I've achieved a multi-face tracking using AnchorEntity()
with ARAnchor
intializer inside session(:didUpdate:)
instance method (just like SceneKit's renderer()
instance method).
这是我的代码:
import ARKit
import RealityKit
extension ViewController: ARSessionDelegate {
func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
guard let faceAnchor = anchors.first as? ARFaceAnchor
else { return }
let anchor1 = AnchorEntity(anchor: faceAnchor)
let anchor2 = AnchorEntity(anchor: faceAnchor)
anchor1.addChild(model01)
anchor2.addChild(model02)
arView.scene.anchors.append(anchor1)
arView.scene.anchors.append(anchor2)
}
}
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
let model01 = try! Entity.load(named: "angryFace") // USDZ file
let model02 = try! FacialExpression.loadSmilingFace() // RC scene
override func viewDidLoad() {
super.viewDidLoad()
arView.session.delegate = self
guard ARFaceTrackingConfiguration.isSupported else {
fatalError("Alas, Face Tracking isn't supported")
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let config = ARFaceTrackingConfiguration()
config.maximumNumberOfTrackedFaces = 2
arView.session.run(config)
}
}
这篇关于RealityKit中的多人脸检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!