gpt4 book ai didi

ios - ARKit 中节点函数的渲染器 didUpdate 未被执​​行

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

我试图在 XCode 中运行以下代码:

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
// Checking if the planeAnchor exists
guard let planeAnchor = anchor as? ARPlaneAnchor else { return }

// Declaring some variables for future use
let width = CGFloat(planeAnchor.extent.x)
let height = CGFloat(planeAnchor.extent.z)
//The plane(geometry) for the node
let plane = SCNPlane(width: width, height: height)

// The planeNode for the plane anchor
let planeNode = SCNNode(geometry: plane)
//Setting up the plane node
planeNode.geometry?.firstMaterial?.diffuse.contents = UIColor.init(red: 0, green: 0, blue: 1, alpha: 0.4)
planeNode.geometry?.firstMaterial?.isDoubleSided = true

// Some variables for future use
let x = CGFloat(planeAnchor.center.x)
let y = CGFloat(planeAnchor.center.y)
let z = CGFloat(planeAnchor.center.z)
// The plane node's position
planeNode.position = SCNVector3(x,y,z)
// This is done so that the plane node is horizontal
planeNode.eulerAngles.x = -.pi / 2

// Adding the planeNode to the rootNode??
node.addChildNode(planeNode)

// Informing the user that a plane anchor has been found
mainLabel.text = "Found a plane anchor!"

}

这是 viewDidLoad 函数的代码:

override public func viewDidLoad() {
sceneView.session.run(configuration)
sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]
view.addSubview(sceneView)
sceneView.delegate = self
sceneView.session.delegate = self
configuration.planeDetection = .horizontal
//Setup constraints
setupConstraints()
}

由于某种原因,渲染器 didUpdate 节点的 anchor 函数没有被执行。 mainLabel 的文本根本没有改变,平面也从未添加到 View 中。类(class)是公开的。可能是什么原因呢?我该如何解决?请帮忙。

谢谢。

最佳答案

这里的问题是您在完全设置配置之前运行了 session 。任何 session 配置代码都应在运行 session 之前完成。试试这个:

override public func viewDidLoad() {

sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]

view.addSubview(sceneView)

sceneView.delegate = self
sceneView.session.delegate = self

// setup the plane detection FIRST
configuration.planeDetection = .horizontal

// then run the session
sceneView.session.run(configuration)

//Setup constraints
setupConstraints()
}

关于ios - ARKit 中节点函数的渲染器 didUpdate 未被执​​行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55025273/

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