如何知道是否必须将USDZ模型放置在检测到的平面上?

发布于 2025-02-13 08:06:07 字数 213 浏览 0 评论 0原文

我正在开发iOS购物应用程序,并具有AR功能,用户可以使用Arkit&将对象放置在现实世界中。 RealityKit。 我一直在使用苹果的

我有不同种类的AR模型 - 有些应仅放置在水平面上,而有些则只能放置在垂直平面上。

我可以检测水平/垂直平面,但不确定如何知道该模型是否支持水平或垂直对齐。 任何答案都非常感谢。 谢谢

I am developing the iOS shopping app and it has the AR feature that users can place the object in the real world using the ARKit & RealityKit.
I have been using Apple's sample AR project for the AR feature and it's been working great with horizontal planes.

I have different kinds of AR models - some should be placed on the horizontal plane only, and some should be placed on the vertical plane only.

I can detect the horizontal/vertical planes but not sure how to know if the model supports the horizontal or vertical alignment.
Any answers are highly appreciated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

憧憬巴黎街头的黎明 2025-02-20 08:06:07

在RealityKit中,使用.isanchored找出是否将模型放置在检测到的平面上。

if usdzModel.isAnchored {

    print("Model is placed")
    print(anchor.anchoring.target)
}

在Arkit中,使用锚点(for:)实例方法,搜索场景层次结构与所提供的节点关联的锚点。

open func anchor(for node: SCNNode) -> ARAnchor?

内部ARSCNVIEW委托方法使用以下逻辑:

let nodeAnchor = sceneView.anchor(for: usdzModel) as? ARPlaneAnchor
    
guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
            
if nodeAnchor != nil {

    if planeAnchor.identifier == nodeAnchor?.identifier && 
       planeAnchor.alignment == .horizontal {

        print("Horizontal ARPlaneAnchor")
    }
}

In RealityKit, use .isAnchored to find out whether your model is placed on the detected plane.

if usdzModel.isAnchored {

    print("Model is placed")
    print(anchor.anchoring.target)
}

In ARKit, use anchor(for:) instance method that searches the scene hierarchy for an anchor associated with the provided node.

open func anchor(for node: SCNNode) -> ARAnchor?

Inside ARSCNView delegate method use the following logic:

let nodeAnchor = sceneView.anchor(for: usdzModel) as? ARPlaneAnchor
    
guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
            
if nodeAnchor != nil {

    if planeAnchor.identifier == nodeAnchor?.identifier && 
       planeAnchor.alignment == .horizontal {

        print("Horizontal ARPlaneAnchor")
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文