首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SceneKit -为什么SCNLight在SCNScene中自动创建?

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

Stack Overflow用户
提问于 2021-12-29 19:11:53
回答 3查看 130关注 0票数 3

这是我发现的一种奇怪的现象。有一个非常简单的例子,我有一个ARSCNView,它是空的,只有根节点和摄像头,所以它意味着相机是打开的,但是屏幕上什么也没有(只有相机)。

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

代码语言:javascript
复制
    private func printAllScene(node: SCNNode) {
        print("node: \(node), parent is: \(String(describing: node.parent))")
        
        for curNode in node.childNodes {
            printAllScene(node: curNode)
        }
    }

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

代码语言:javascript
复制
>>> 1
node: <SCNNode: 0x283313300 | 1 child>, parent is: nil
node: <SCNNode: 0x283318500 | camera=<SCNCamera: 0x1065261c0> | no child>, parent is: Optional(<SCNNode: 0x283313300 | 1 child>)
<<<

这里一切正常,但是在几秒钟内从按钮单击调用相同的print方法之后,我会得到另一个输出。

代码语言:javascript
复制
>>> 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>)
<<<

它已经有了三个孩子,而不是一个,怎么回事??然后再过几秒钟,我尝试再次单击并获得另一个输出。

代码语言:javascript
复制
>>> 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个孩子,有趣吧?

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

UPD

由于@mnuages,这个属性automaticallyUpdatesLighting看起来非常接近于正确的解决方案,我在viewDidLoad中设置了它,就像这个scnView.automaticallyUpdatesLighting = false,但是在我的例子中没有什么区别,我仍然看到轻节点正在添加。

UPD2

我现在的目标是-

代码语言:javascript
复制
...
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
...

但问题仍然是可再生的。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-01-04 09:42:48

最终,问题出现在ar配置中。

当启用环境纹理时,ARKit会自动添加光探针。可以通过将配置中的environmentTexturing属性值设置为.none来禁用此行为。

票数 0
EN

Stack Overflow用户

发布于 2021-12-29 22:13:06

视图上设置了automaticallyUpdatesLighting属性吗?

来自文档

如果此值为true (默认值),视图将自动创建一个或多个SCNLight对象,将其添加到场景中,并更新其属性以反映摄像机场景中的估计照明信息。如果要直接控制SceneKit场景中的所有照明,请将此值设置为SceneKit。

票数 1
EN

Stack Overflow用户

发布于 2022-01-02 13:26:08

我想你是在说SceneKit 程序天空。可以使用以下命令关闭它:

代码语言:javascript
复制
scnVue.scene?.lightingEnvironment.contents = .none      // Probe Light

scnVue.scene?.background.contents = .none               // Image

或者,您可以通过编程方式打开skybox

代码语言:javascript
复制
scnVue.scene?.background.contents = MDLSkyCubeTexture(name: "heaven",
                                           channelEncoding: .float32,
                                         textureDimensions: vector_int2(512, 
                                                                        512),
                                                 turbidity: 0.12,
                                              sunElevation: 1.00,
                                 upperAtmosphereScattering: 0.05,
                                              groundAlbedo: 0.32)

scnVue.scene?.lightingEnvironment.contents = scnVue.scene?.background.contents

scnVue.scene?.lightingEnvironment.intensity = 1.5

附注:

如果您使用的是ship.scn场景,您可能还记得那里的过程天空是打开的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70523927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档