【问题标题】:SceneKit avoid lighting on specific nodeSceneKit 避免在特定节点上照明
【发布时间】:2017-08-22 23:55:33
【问题描述】:

在 SceneKit 中,我正在构建一个由线条组成的节点,以在场景中心绘制 XYZ 轴,就像在 Cinema4D 中一样。

我希望这 3 个节点不参与全局光照,即使光线很暗/不存在/太强也可以看到。在下图中可以看到Z轴显得太亮了,看不到。

有没有办法阻止节点参与到场景的光照中,比如物理的类别掩码?

在这种情况下,如何使节点变亮才能让它出现?

【问题讨论】:

    标签: objective-c macos scenekit light


    【解决方案1】:

    SCNLight 有一个 categoryBitMask 属性。这使您可以选择受光影响的节点(尽管环境光会忽略这一点)。您可以有 2 种光源类别,一种用于您的主要场景,另一种只影响您的线条。

    这是一个简单的例子,有 2 个节点,每个节点都用不同颜色的光点亮:

    struct LightType {
        static let light1:Int = 0x1 << 1
        static let light2:Int = 0x1 << 2
    }
    
    class GameViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            let scene = SCNScene(named: "art.scnassets/scene.scn")!
    
            let lightNode1 = SCNNode()
            lightNode1.light = SCNLight()
            lightNode1.light!.type = .omni
            lightNode1.light!.color = UIColor.yellow
            lightNode1.position = SCNVector3(x: 0, y: 10, z: 10)
            lightNode1.light!.categoryBitMask = LightType.light1
            scene.rootNode.addChildNode(lightNode1)
    
            let lightNode2 = SCNNode()
            lightNode2.light = SCNLight()
            lightNode2.light!.type = .omni
            lightNode2.light!.color = UIColor.red
            lightNode2.position = SCNVector3(x: 0, y: 10, z: 10)
            lightNode2.light!.categoryBitMask = LightType.light2
            scene.rootNode.addChildNode(lightNode2)
    
            let sphere1 = scene.rootNode.childNode(withName: "sphere1", recursively: true)!
            sphere1.categoryBitMask = LightType.light1
            let sphere2 = scene.rootNode.childNode(withName: "sphere2", recursively: true)!
            sphere2.categoryBitMask = LightType.light2
    
            let scnView = self.view as! SCNView
            scnView.scene = scene
        }
    }
    

    【讨论】:

    • 谢谢,我现在就去研究它!你要一段代码吗? :-)
    • @BenoîtLahoz 我添加了一个简单的示例。
    • 非常感谢!这正是我想要的!
    • categoryBitMask 不适用于 iOS 14.4。 Apple 开发者论坛上有帖子称它在 iOS 12 中已被破坏。
    【解决方案2】:

    我认为将材质的闪电模型设置为常数会容易得多。

    yourNode.geometry?.firstMaterial?.lightingModel = SCNMaterial.LightingModel.constant
    

    【讨论】:

      猜你喜欢
      • 2017-02-07
      • 2019-06-27
      • 2020-04-01
      • 1970-01-01
      • 2015-10-04
      • 2021-11-13
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      相关资源
      最近更新 更多