gpt4 book ai didi

ios - ARKit:将 3D 对象放置在图像之上

转载 作者:搜寻专家 更新时间:2023-10-30 23:07:52 25 4
gpt4 key购买 nike

我正在尝试在引用图像上正确添加 3D 对象。为了在现实世界中的图像上添加 3D 对象,我使用了 imageAnchor.transform 属性,如下所示。

    func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {

guard let imageAnchor = anchor as? ARImageAnchor else { return }

let referenceImage = imageAnchor.referenceImage

updateQueue.async {
// Add a virtual cup at the position of the found image
self.virtualObject.addVirtualObjectWith(sceneName: "cup.dae",
childNodeName: nil,
position: SCNVector3(x: imageAnchor.transform.columns.3.x,
y: imageAnchor.transform.columns.3.y,
z: imageAnchor.transform.columns.3.z),
recursively: true,
imageAnchor: imageAnchor)

}

}

The cup when just added to the scene

问题是当我移动设备方向时,杯子不会很好地停留在图像的中间。即使我删除图像,我也希望将杯子放在同一个位置。我不明白这个问题,因为当您使用平面检测和 HitTest 添加对象时,还有一个用于平面的 ARAnchor。

The cup when device is moved

2018 年 5 月 14 日更新

 func addVirtualObjectWith(sceneName: String, childNodeName: String, objectName: String, position: SCNVector3, recursively: Bool, node: SCNNode?){
print("VirtualObject: Added virtual object with scene name: \(sceneName)")

let scene = SCNScene(named: "art.scnassets/\(sceneName)")!
var sceneNode = scene.rootNode.childNode(withName: childNodeName, recursively: recursively)!
sceneNode.name = objectName
sceneNode.position = position

add(object: sceneNode, toNode: node)

}

func add(object: SCNNode, toNode: SCNNode?){
if toNode != nil {
toNode?.addChildNode(object)
}
else {
sceneView.scene.rootNode.addChildNode(object)
}
}

最佳答案

我终于找到了解决方案,结果是属性检查器中的 AR 引用图像的大小设置不正确。当尺寸不正确时,图像的 anchor 会摇晃。

attributes inspector

关于ios - ARKit:将 3D 对象放置在图像之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49425383/

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