添加SCNBillboardConstraint会使节点消失 [英] Adding a SCNBillboardConstraint makes the node dissapear
问题描述
在我在文档和互联网上阅读之后, SCNBillboardConstraint
会将节点旋转到始终面向pointOfView节点 - 在<$ c $的情况下c> ARKit ,用户的相机。
After what I've read in the documentation and on the internet a SCNBillboardConstraint
would rotate a node to always face the pointOfView node - in the case of ARKit
, the user's camera.
当我添加 SCNBillboardConstraint $ c $时c>到一个子节点,它消失了。节点只是一些
SCNTexts
作为更复杂模型的子代添加。
层次结构如下所示:RootNode - > Text节点(其中两个)。
The thing is, when I add a SCNBillboardConstraint
to a child node, it dissapears. The nodes are just some SCNTexts
added as a subchild of a more complex model.
The hierarchy looks something like this: RootNode - > Text node (two of them).
在我将根节点添加到场景的根节点之后,我通过以下方式添加此约束:
Just after I added the root node to the scene's root node, I add this constraint in the following way:
updateQueue.async {
self.sceneView.scene.rootNode.addChildNode(virtualObject)
self.sceneView.addOrUpdateAnchor(for: virtualObject)
self.addBillboardContraintsToText(object: virtualObject)
}
func addBillboardContraintsToText(object: VirtualObject) {
guard let storeNode = object.childNodes.first else {
return
}
for node in storeNode.childNodes {
if let geometry = node.geometry, geometry.isKind(of: SCNText.self) {
let billboard = SCNBillboardConstraint()
node.constraints = [billboard]
}
}
}
文本节点相对于其根节点的位置设置正确,所以没有问题。当我添加 SCNLookAtConstraint
时,它可以正常工作。
The text nodes have their position set properly relative to their root node, so there's no problem with that. When I add a SCNLookAtConstraint
though, it works just fine.
node.pivot = SCNMatrix4Rotate(node.pivot, Float.pi, 0, 1, 0)
let lookAt = SCNLookAtConstraint(target: sceneView.pointOfView)
lookAt.isGimbalLockEnabled = true
node.constraints = [lookAt]
任何想法为什么 SCNBillboardConstraint
可能不起作用?我做错了什么?
Any ideas why the SCNBillboardConstraint
might not work? Am I doing something wrong?
推荐答案
此代码(带有Apple CupScn)对我来说效果很好:
This Code (with apples CupScn) works just fine for me:
cupNode.position = SCNVector3(0.5,0,-0.5)
guard let virtualObjectScene = SCNScene(named: "cup.scn", inDirectory: "Models.scnassets/cup") else {
return
}
let wrapperNode = SCNNode()
for child in virtualObjectScene.rootNode.childNodes {
child.geometry?.firstMaterial?.lightingModel = .physicallyBased
wrapperNode.addChildNode(child)
}
cupNode.addChildNode(wrapperNode)
scene.rootNode.addChildNode(cupNode)
let billboardConstraint = SCNBillboardConstraint()
billboardConstraint.freeAxes = SCNBillboardAxis.Y
cupNode.constraints = [billboardConstraint]
这篇关于添加SCNBillboardConstraint会使节点消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!