SceneKit避免在特定节点上点亮

问题描述 投票:3回答:2

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

cinema4D

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

my software

有没有办法阻止节点参与场景的照明,就像物理类别掩码一样?

在这种情况下,节点如何变亮以使其出现?

objective-c macos scenekit light
2个回答
7
投票

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
    }
}

enter image description here


4
投票

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

yourNode.geometry?.firstMaterial?.lightingModel = SCNMaterial.LightingModel.constant
© www.soinside.com 2019 - 2024. All rights reserved.