如何在SceneKit中的3D对象的节点上应用带有金属阴影的颜色?

时间:2018-10-27 16:00:28

标签: swift 3d shader scenekit ios12

这是带有金属着色器的3d对象节点“黄色”的示例。

enter image description here

我想通过Swift将颜色应用于SceneKit中3d对象的metallic shader

我该怎么办?

1 个答案:

答案 0 :(得分:0)

要完成您需要的内容,只需使用以下代码:

override func viewDidLoad() {
    super.viewDidLoad()

    let scene = SCNScene(named: "art.scnassets/myScene.scn")!
    let sphereNode = SCNNode(geometry: SCNSphere(radius: 5))

    let goldenMaterial = SCNMaterial()
    goldenMaterial.lightingModel = .physicallyBased
    goldenMaterial.metalness.contents = 1.0
    goldenMaterial.roughness.contents = 0.0
    goldenMaterial.diffuse.contents = UIColor(red: 0.95, 
                                            green: 0.75, 
                                             blue: 0.2, 
                                            alpha: 1.0)

    sphereNode.geometry?.materials = [goldenMaterial]
    scene.rootNode.addChildNode(sphereNode)

    //......................................................

    let scnView = self.view as! SCNView
    scnView.scene = scene
    scnView.autoenablesDefaultLighting = true
}

enter image description here