1

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.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
shahad
  • 43
  • 5

1 Answers1

1

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

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • Hi Andy, Thank you for your answer. In fact, I have many models and I will upload them via the server. Can this code be standard for all of these models? – shahad Apr 12 '20 at 17:25
  • Hi @shahad! What do you mean saying "standard"? – Andy Jazz Apr 12 '20 at 17:28
  • 1
    Hi Andy, I have about 60 glasses model, they will be downloaded from the server to the application. can this code be applied for all of them. (I mean the name of "glasses frame" and the color of glasses may changes from one to the other) – shahad Apr 13 '20 at 11:05
  • Yes, you can use these 2 shaders as prototypes for all models of your glasses (changing just a color). – Andy Jazz Apr 13 '20 at 11:15
  • How many questions do you have, and how much time you gonna spend on this consultation? – Andy Jazz Apr 14 '20 at 07:57