【发布时间】:2022-02-19 22:09:06
【问题描述】:
我想在图像上显示 Reality Composer 体验,但是我不希望 AR 对象在我丢失图像时隐藏,因此我创建了一个 AnchorEntity 并从 didAdd 锚点委托中获取 ImageAnchor 的翻译方法如下:
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
// If we already added the content to render, ignore
if rootAnchor != nil {
return
}
// Make sure we are adding to an image anchor. Assuming only
// one image anchor in the scene for brevity.
guard anchors[0] is ARImageAnchor else {
return
}
// Create the entity to render, could load from your experience file here
// this will render at the center of the matched image
rootAnchor = AnchorEntity(world: [0,0,0])
guard let boxAnchor = boxAnchor else { return }
rootAnchor!.addChild(boxAnchor.tap!)
arView.scene.addAnchor(rootAnchor!)
}
正如您在此处看到的,我从 Reality Composer 文件中获取 tap 实体,以便将其重新插入 Anchor 实体。
我现在的问题是我丢失了 Reality Composer 文件中的行为,这个实体有一些行为,比如当你点击它时它会翻转或靠近相机。通过失去行为,我失去了 Reality Composer 的全部意义。
现在我的问题是,如何从现实文件中检索行为?我想过锚定整个体验而不是实体,所以不是rootAnchor!.addChild(boxAnchor.tap!) 而是rootAnchor!.addChild(boxAnchor) ,但是更新delagate方法不会更新场景中实体的位置,这里是代码:
func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
guard let rootAnchor = rootAnchor else {
return
}
// Code is assuming you only have one image anchor for brevity
guard let imageAnchor = anchors[0] as? ARImageAnchor else {
return
}
if !imageAnchor.isTracked {
return
}
rootAnchor.transform = Transform(matrix: imageAnchor.transform)
}
如果根锚点是整个场景,基本上rootAnchor.transform = Transform(matrix: imageAnchor.transform) 不起作用。
那么如何在根据图像更新锚点的同时保留行为呢?
谢谢
【问题讨论】:
标签: swift arkit realitykit reality-composer