gpt4 book ai didi

swift - SceneKit – 为什么 SCNLight 在 SCNScene 中自动创建?

转载 作者:行者123 更新时间:2023-12-05 04:38:46 25 4
gpt4 key购买 nike

这是我发现的一种奇怪的现象。有一个非常简单的例子,我有一个空的 ARSCNView,只有 rootnode 和 camera,所以这意味着相机是打开的,但屏幕上没有任何东西(只有相机)。

我从 viewDidLoad() { printAllScene(node: scnView.scene.rootNode) } 调用了一个方法来打印场景中的所有节点

    private func printAllScene(node: SCNNode) {
print("node: \(node), parent is: \(String(describing: node.parent))")

for curNode in node.childNodes {
printAllScene(node: curNode)
}
}

这个递归方法打印场景中的所有节点,所以在我在 viewDidLoad() 中调用它之后我得到了这样的输出

>>> 1
node: <SCNNode: 0x283313300 | 1 child>, parent is: nil
node: <SCNNode: 0x283318500 | camera=<SCNCamera: 0x1065261c0> | no child>, parent is: Optional(<SCNNode: 0x283313300 | 1 child>)
<<<

这里一切正常,但是在我从按钮调用相同的打印方法后,几秒钟后我得到了另一个输出

>>> 3
node: <SCNNode: 0x283313300 | 3 children>, parent is: nil
node: <SCNNode: 0x283318500 pos(-0.002828 0.016848 0.034329) rot(0.229921 0.895326 -0.381477 0.336716) scale(1.000000 1.000000 1.000000) | camera=<SCNCamera: 0x1065261c0> | no child>, parent is: Optional(<SCNNode: 0x283313300 | 3 children>)
node: <SCNNode: 0x283336d00 | light=<SCNLight: 0x103973dd0 | type=probe> | no child>, parent is: Optional(<SCNNode: 0x283313300 | 3 children>)
node: <SCNNode: 0x283324800 pos(-0.007079 -0.074922 0.031407) rot(0.000000 -1.000000 0.000000 1.474911) | light=<SCNLight: 0x103985120 | type=probe> | no child>, parent is: Optional(<SCNNode: 0x283313300 | 3 children>)
<<<

它已经有了 3 个 child ,而不是一个,怎么办??几秒钟后,我尝试再次点击并获得另一个输出

>>> 3
node: <SCNNode: 0x283313300 | 4 children>, parent is: nil
node: <SCNNode: 0x283318500 pos(0.000974 0.011970 0.039510) rot(0.231398 0.878019 -0.418974 0.304382) scale(1.000000 1.000000 1.000000) | camera=<SCNCamera: 0x1065261c0> | no child>, parent is: Optional(<SCNNode: 0x283313300 | 4 children>)
node: <SCNNode: 0x283336d00 | light=<SCNLight: 0x103973dd0 | type=probe> | no child>, parent is: Optional(<SCNNode: 0x283313300 | 4 children>)
node: <SCNNode: 0x283324800 pos(-0.007079 -0.074922 0.031407) rot(0.000000 -1.000000 0.000000 1.474911) | light=<SCNLight: 0x11aceec70 | type=probe> | no child>, parent is: Optional(<SCNNode: 0x283313300 | 4 children>)
node: <SCNNode: 0x28332ac00 pos(-0.007079 -0.074922 0.031407) rot(0.000000 -1.000000 0.000000 1.474911) | light=<SCNLight: 0x11b908130 | type=probe> | no child>, parent is: Optional(<SCNNode: 0x283313300 | 4 children>)
<<<

它有 4 个 child ,很有趣吧?

会不会跟配置有关?就像 ARKit 试图创建与真实光环境相关的光节点,以便在场景中模拟它或类似的东西?

UPD

感谢@mnuages,真的这个属性 automaticallyUpdatesLighting 似乎非常接近正确的解决方案,我在 viewDidLoad 中设置它像这样 scnView.automaticallyUpdatesLighting = false ,但这对我的情况没有影响,我仍然看到轻节点正在添加。

UPD2

我目前的实现是-

...
override func viewWillAppear(_ animated: Bool) {
let config = ARWorldTrackingConfiguration()
config.environmentTexturing = .automatic
scnView.session.run(config)
}

override func viewDidLoad() {
super.viewDidLoad()

scnView.scene = SCNScene()
scnView.scene.lightingEnvironment.contents = .none
scnView.scene.background.contents = .none
scnView.automaticallyUpdatesLighting = false

scnView.delegate = self
scnView.showsStatistics = true
...

但问题仍然可以重现。

最佳答案

您是否在 View 上设置了 automaticallyUpdatesLighting 属性?

来自documentation :

If this value is true (the default), the view automatically creates one or more SCNLight objects, adds them to the scene, and updates their properties to reflect estimated lighting information from the camera scene. Set this value to false if you want to directly control all lighting in the SceneKit scene.

关于swift - SceneKit – 为什么 SCNLight 在 SCNScene 中自动创建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70523927/

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