【发布时间】:2018-08-21 23:16:57
【问题描述】:
我正在做这个简单的事情:
- 垂直平面检测
- 垂直平面上的图像识别
图像挂在检测到的平面上(在我的墙上)。在这两种情况下,我都从ARSCNViewDelegate 实现了renderer:didAddNode:forAnchor: 函数。我站在垂直平面检测和图像识别的地方。
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let shipScene = SCNScene(named: "ship.scn"), let shipNode = shipScene.rootNode.childNode(withName: "ship", recursively: false) else { return }
shipNode.position = SCNVector3(anchor.transform.columns.3.x, anchor.transform.columns.3.y, anchor.transform.columns.3.z)
sceneView.scene.rootNode.addChildNode(shipNode)
print(anchor.transform)
}
在垂直平面检测的情况下,anchor 将是ARPlaneAnchor。在图像识别的情况下,anchor 将是 ARImageAnchor。
为什么这两个锚的变换矩阵如此不同?我正在打印anchor.transform,我得到了这些结果:
1.
simd_float4x4([
[0.941312, 0.0, -0.337538, 0.0)],
[0.336284, -0.0861278, 0.937814, 0.0)],
[-0.0290714,-0.996284, -0.0810731, 0.0)],
[0.191099, 0.172432, -1.14543, 1.0)]
])
2.
simd_float4x4([
[0.361231, 0.10894, 0.926093, 0.0)],
[-0.919883, -0.121052, 0.373049, 0.0)],
[0.152743, -0.986651, 0.0564843, 0.0)],
[75.4418, 10.9618, -14.3788, 1.0)]
])
所以如果我想在检测到的垂直平面上放置一个 3D 对象,我可以简单地使用[x = 0.191099, y = 0.172432, z = -1.14543] 作为坐标来设置我的节点(myNode)的位置,然后使用@987654334 将此节点添加到场景中@ 但是如果我想在检测到的图像的锚点上放置一个 3D 对象,我不能使用[x = 75.4418, y = 10.9618, z = -14.3788]。
如何将 3D 对象放置在检测到的图像的锚点上?我真的不明白 ARImageAnchor 的变换矩阵。
【问题讨论】:
标签: ios swift augmented-reality arkit