我正在使用以下方法将物体放置在平面上。它可以工作,但锚点的位置始终为 0,0,0,即使它是基于光线投射结果的。
let results = arView.raycast(from: tappedLocation,
allowing: .estimatedPlane,
alignment: .horizontal)
if let result = results.first {
print(result.worldTransform) // contains values
let anchor = AnchorEntity(raycastResult: result)
print(anchor.position) // why 0,0,0
}
有任何想法吗?
看起来position https://developer.apple.com/documentation/realitykit/hastransform/position变为零时anchor https://developer.apple.com/documentation/arkit/arraycastresult/3194593-anchor为零(转换 https://developer.apple.com/documentation/realitykit/hastransform/transform成为单位矩阵)。
如果我们打电话raycast https://developer.apple.com/documentation/realitykit/arview/raycast(from:allowing:alignment:) with .现有平面几何 https://developer.apple.com/documentation/arkit/arraycastquery/target/existingplanegeometry, anchor https://developer.apple.com/documentation/arkit/arraycastresult/3194593-anchor不会为零。
锚定实体 https://developer.apple.com/documentation/realitykit/anchorentity has 世界空间位置里面。
这不包括在转换 https://developer.apple.com/documentation/realitykit/entity/transform.
如果我们想知道世界空间位置,我们可以通过下面的代码来计算。 (好像没有什么属性可以获得……)
let anchorWorldTransform = anchorEntity.convert(transform: .identity, to: nil)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)