【问题标题】:How to preserve behaviors from Reality Composer?如何保留 Reality Composer 的行为?
【发布时间】: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


    【解决方案1】:

    问题是:在 RealityKit 2.0 中,我们无法访问 Reality Composer 的行为(notification 除外)和锚类型 - 我们知道它是 AnchorEntity(.image) - 您在 Reality Composer 中分配的工作方式与 ARKit 在ARImageTrackingConfig 中的图像锚点的工作方式相同,即它使用本地跟踪而不是全局跟踪。换句话说,在当前的 Reality Composer 场景中,你很难得到这样的场景。

    尝试使用 ARKit 及其 ARWorldTrackingConfig 进行图像跟踪。所有“行为”都必须在 RealityKit 或 SceneKit 中重新创建。

    【讨论】:

    • 我已经锚定了整个体验而不是其中的实体,以保留行为。现在可以了
    猜你喜欢
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 2020-12-07
    • 1970-01-01
    • 2020-05-17
    • 2020-01-23
    相关资源
    最近更新 更多