1
votes

I have trouble showing some textures in SceneKit, this is the model I would like to use:

Model in Sketchfab : https://skfb.ly/6QVTQ

The model should appear in these colors and textures in the AR environment using Scene Kit. But the golden tips appear black and the transparent lenses do not appear at all. Are there any suggestions to solve this problem?

The model is .scn format. here is the the model materials properties: https://drive.google.com/file/d/1HIHEsyONLXyL95dcSy9xWMGX89udMPND/view?usp=sharing

https://drive.google.com/file/d/1ndrZfcjqIQ4d2OfG6ZNvwyfDXnihJbnH/view?usp=sharing

If you need any additional information please let me know. Thank you in advance.

1

1 Answers

1
votes

There's no photorealistic glass with true index of refraction (IoR) in SceneKit but you can easily create a fake one using phong shader. Phong shader also has three important properties of a glass – specularity, reflectivity, and fresnelExponent.

For metallic material use physicallyBased shading model.

Here's a code:

import SceneKit

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let sceneView = self.view as! SCNView
        sceneView.scene = SCNScene(named: "glasses.scn")!
        sceneView.allowsCameraControl = true
        sceneView.pointOfView?.position.z = 20

        let glassesFrame = sceneView.scene?.rootNode.childNode(withName: "glassesFrame", 
                                                            recursively: true)

        glassesFrame?.geometry?.firstMaterial?.lightingModel = .physicallyBased
        glassesFrame?.geometry?.firstMaterial?.metalness.intensity = 1
        glassesFrame?.geometry?.firstMaterial?.diffuse.contents = NSColor.systemBrown

        let lens1 = sceneView.scene?.rootNode.childNode(withName: "rightLens", 
                                                     recursively: true)

        let lens2 = sceneView.scene?.rootNode.childNode(withName: "leftLens", 
                                                     recursively: true)

        let material = SCNMaterial()
        material.lightingModel = .phong
        material.diffuse.contents = NSColor(white: 0.2,
                                            alpha: 1)
        material.diffuse.intensity = 0.9
        material.specular.contents = NSColor(white: 1,
                                             alpha: 1)
        material.specular.intensity = 1.0
        material.reflective.contents = NSImage.Name("art.scnassets/texture.png")
        material.reflective.intensity = 2.0
        material.transparencyMode = .dualLayer
        material.fresnelExponent = 2.2
        material.isDoubleSided = true
        material.blendMode = .alpha
        material.shininess = 100
        material.transparency.native = 0.7
        material.cullMode = .back

        lens1?.geometry?.firstMaterial = material
        lens2?.geometry?.firstMaterial = material
    }
}

enter image description here

enter image description here