gpt4 book ai didi

ios - 在 ARImageTrackingConfiguration 中转换坐标

转载 作者:行者123 更新时间:2023-11-28 14:33:33 25 4
gpt4 key购买 nike

ARKit 2 添加了一个新配置:ARImageTrackingConfiguration,根据 SDK可以有更好的性能和一些新的用例。

在 Xcode 10b2 上对其进行试验(请参阅 https://forums.developer.apple.com/thread/103894 如何修复 Assets 加载)我的代码现在正确地调用了跟踪图像的委托(delegate),此后添加了一个节点,但我找不到坐标系所在的任何文档位于,因此有人知道如何将节点放入场景中以覆盖检测到的图像:

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
DispatchQueue.main.async {
if let imageAnchor = anchor as? ARImageAnchor {
let imageNode = SCNNode.createImage(size: imageAnchor.referenceImage.physicalSize)
imageNode.transform = // ... ???
node.addChildNode(imageNode)
}
}
}

ps:与 ARWorldTrackingConfiguration 相比,原点似乎不断移动(很可能将相机置于 0,0,0)。

pps: SCNNode.createImage 是一个没有任何坐标计算的辅助函数。

最佳答案

假设我已正确阅读您的问题,您可以执行以下操作:

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {

let nodeToReturn = SCNNode()

//1. Check We Have Detected Our Image
if let validImageAnchor = anchor as? ARImageAnchor {

//2. Log The Information About The Anchor & Our Reference Image
print("""
ARImageAnchor Transform = \(validImageAnchor.transform)
Name Of Detected Image = \(validImageAnchor.referenceImage.name)
Width Of Detected Image = \(validImageAnchor.referenceImage.physicalSize.width)
Height Of Detected Image = \(validImageAnchor.referenceImage.physicalSize.height)
""")

//3. Create An SCNPlane To Cover The Detected Image
let planeNode = SCNNode()

let planeGeometry = SCNPlane(width: validImageAnchor.referenceImage.physicalSize.width,
height: validImageAnchor.referenceImage.physicalSize.height)

planeGeometry.firstMaterial?.diffuse.contents = UIColor.white

planeNode.geometry = planeGeometry

//a. Set The Opacity To Less Than 1 So We Can See The RealWorld Image
planeNode.opacity = 0.5

//b. Rotate The PlaneNode So It Matches The Rotation Of The Anchor
planeNode.eulerAngles.x = -.pi / 2

//4. Add It To The Node
nodeToReturn.addChildNode(planeNode)

//5. Add Something Such As An SCNScene To The Plane
if let modelScene = SCNScene(named: "art.scnassets/model.scn"), let modelNode = modelScene.rootNode.childNodes.first{

//a. Set The Model At The Center Of The Plane & Move It Forward A Tad
modelNode.position = SCNVector3Zero
modeNode.position.z = 0.15

//b. Add It To The PlaneNode
planeNode.addChildNode(modelNode)
}
}

return nodeToReturn

}

希望这会为您指明正确的方向...

关于ios - 在 ARImageTrackingConfiguration 中转换坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51065239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com