gpt4 book ai didi

ios - 调用 setWorldOrigin 时子节点不可见?

转载 作者:行者123 更新时间:2023-11-28 07:34:50 29 4
gpt4 key购买 nike

所以我有一个像下面这样的函数,它将世界原点设置为扫描图像后放置在图像所在位置的节点。我从数据库中加载已保存的节点,该数据库使用单独的函数将它们添加到场景中。

出于某种原因,当我运行应用程序时,节点不会显示。它在 setWorldOrigin 被注释掉时起作用。

我希望节点相对于图像显示为原点。

我错过了什么吗? setWorldOrigin 会改变 session 吗?

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let imageAnchor = anchor as? ARImageAnchor else { return }
let referenceImage = imageAnchor.referenceImage

let nodeGeometry = SCNText(string: "Welcome!", extrusionDepth: 1)
nodeGeometry.font = UIFont(name: "Helvetica", size: 30)
nodeGeometry.firstMaterial?.diffuse.contents = UIColor.black

anchorNode.geometry = nodeGeometry
anchorNode.scale = SCNVector3(0.1, 0.1, 0.1)
anchorNode.constraints = [SCNBillboardConstraint()]
anchorNode.position = SCNVector3(imageAnchor.transform.columns.3.x, imageAnchor.transform.columns.3.y, imageAnchor.transform.columns.3.z)
imageAnchor.transform.columns.3.y, imageAnchor.transform.columns.3.z)

// Create a plane to visualize the initial position of the detected image.
let plane = SCNPlane(width: referenceImage.physicalSize.width, height: referenceImage.physicalSize.height)

let planeNode = SCNNode(geometry: plane)
planeNode.opacity = 0.25

/*
* Plane is rotated to match the picture location
*/
planeNode.eulerAngles.x = -.pi / 2

/*
* Scan runs as an action for a set amount of time
*/
planeNode.runAction(self.imageHighlightAction)

// Add the plane visualization to the scene.
node.addChildNode(planeNode)

sceneView.session.setWorldOrigin(relativeTransform: imageAnchor.transform)
sceneView.scene.rootNode.addChildNode(node)

/*
* Populates the scene
*/
handleData()
} // renderer

最佳答案

我想通了。我的图像尺寸不正确。我使用的图像是 512x512 像素。我通过右键单击图像并选择“获取信息”并查看尺寸得到了它。

我也有以米为单位的测量值。我将其更改为厘米并使用了 pixel to centimeters converter

关于ios - 调用 setWorldOrigin 时子节点不可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53504393/

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