【问题标题】:How to translate ARAnchor size to SpriteKit equivalent如何将 ARAnchor 大小转换为等效的 SpriteKit
【发布时间】:2019-01-09 15:47:29
【问题描述】:

问题:

如何创建一个与 ARObjectAnchor.referenceObject 高度和宽度相同的新 SKSpriteNode。

上下文:

我目前正在使用 ARKit 的新对象检测功能,并且有工作代码来检测我扫描的对象。当 ARKit 检测到对象时,它会提供一个类型为 ARObjectAnchor 的新 ARAnchor。

我知道 ARSCNView 提供了一个 projectPoint 方法,但我找不到任何与 ARSKView 等效的函数。如何将 ARObjectAnchor 尺寸映射到新的 Sprite?

这是我处理检测到的对象的方式:

func view(_ view: ARSKView, didAdd node: SKNode, for anchor: ARAnchor) {
    if let objectAnchor = anchor as? ARObjectAnchor {
        let width = objectAnchor.referenceObject.extent.x
        let height = objectAnchor.referenceObject.extent.y

        // How to translate above height/width to the below size? 

        let box = SKSpriteNode(color: .white, size: ???)
        node.addChild(box)
    }
} 

【问题讨论】:

    标签: ios swift sprite-kit scenekit arkit


    【解决方案1】:
    ...
    let size = CGSize(width: width, height: height)
    let box = SKSpriteNode(color: .white, size: size)
    ...
    

    【讨论】:

      【解决方案2】:

      当我在我的图像识别应用程序中将 SKScene 添加到我的 SCNPlane 时,我会按照我的 SCNPlane 的大小执行 * 10000(不要问我为什么它是 10000,我不知道),如下所示

      let toto = SCNNode(geometry: SCNPlane(width: 0.3, height: 0.1))
      let sk = SKScene(size: CGSize(width: 3000, height: 1000))
      

      对我来说大小相同,试试这个,告诉我它是否适合你!

      【讨论】:

      • 我尝试将其缩放 10,000,但结果太大了。 1,000 对我来说效果更好,但这并不能完全回答我的问题。我确信有一种正确的方法可以将 3d 坐标系转换为 2d,但我不知道该怎么做。
      • 也许是因为 3D 系统的尺寸以米为单位,而 2D 系统的尺寸以毫米为单位?,那么 x1000 是有意义的
      猜你喜欢
      • 2021-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      • 2018-12-07
      • 2014-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多