Joice George
Joice George

Reputation: 89

How to apply a shining to DAE model in SceneKit?

What I am trying to do is add shininess to a .dae model in SceneKit.

enter image description here

How can I add shininess to this model?

Upvotes: 1

Views: 115

Answers (1)

Andy Jazz
Andy Jazz

Reputation: 58563

At first select your .dae model and choose EditorConvert to SceneKit File Format (.scn) in main menu.

After that get through the hierarchy with .childNodes[0] to retrieve the model. Then apply a .blinn shader and setup specular.intensity and shininess parameters.

import SceneKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let sceneView = self.view as! SCNView
        sceneView.scene = SCNScene(named: "art.scnassets/ship.scn")!
        sceneView.allowsCameraControl = true
        sceneView.backgroundColor = .black
        sceneView.scene?.lightingEnvironment.contents = .none
        sceneView.scene?.background.contents = .none

        let sun = SCNNode()
        sun.light = SCNLight()
        sun.light?.type = .directional
        sun.light?.intensity = 500
        sun.eulerAngles.x = -.pi/2
        sceneView.scene?.rootNode.addChildNode(sun)

        let s = sceneView.scene!.rootNode.childNode(withName: "ship", 
                                                 recursively: true)!

        s.childNodes[0].geometry?.firstMaterial?.lightingModel = .blinn
        s.childNodes[0].geometry?.firstMaterial?.shininess = 100
        s.childNodes[0].geometry?.firstMaterial?.specular.intensity = 100
    }
}

enter image description here

Upvotes: 1

Related Questions