How To Apply .MTL File on .OBJ 3d Model via SceneKit & Model I/O : <p>I am trying to apply an .mtl file texture on .obj 3d model via SceneKit &amp; Model I/0.</p>

<p>My code below works fine when I try to apply .jpg of a texture on it:</p>

<pre><code>       let url = NSBundle.mainBundle().URLForResource("chair", withExtension: "obj")            
       let asset = MDLAsset(URL: NSURL(string:url)!)
        guard let object = asset.objectAtIndex(0) as? MDLMesh else {
            //fatalError("Failed to get mesh from asset.")
            return
        }

        if shouldApplyTexture == true {
            var textureFileName = "chair.mtl"

            // Create a material from the various textures
            let scatteringFunction = MDLScatteringFunction()
            let material = MDLMaterial(name: "baseMaterial", scatteringFunction: scatteringFunction)

            material.setTextureProperties(textures: [
                                            .BaseColor:textureFileName])

            // Apply the texture to every submesh of the asset
            for  submesh in object.submeshes!  {
                if let submesh = submesh as? MDLSubmesh {
                    submesh.material = material
                }
            }

        }

        // Wrap the ModelIO object in a SceneKit object
        let node = SCNNode(MDLObject: object)

        if (scene.rootNode.childNodes.count &gt; 0){
            scene.rootNode.enumerateChildNodesUsingBlock { (node, stop) -&gt; Void in
                node.removeFromParentNode()
            }
        }
        scene.rootNode.addChildNode(node)
</code></pre>

<p>I am using the following MDMaterial extension for setTextureProperties:</p>

<pre><code>extension MDLMaterial {
func setTextureProperties([MDLMaterialSemantic:String]) -&gt; Void {

    for (key,value) in textures {
        var finalURL = NSBundle.mainBundle().URLForResource(value, withExtension: "")
       guard let url = finalURL else {
           // fatalError("Failed to find URL for resource \(value).")
            return
        }

        let property = MDLMaterialProperty(name:fileName!, semantic: key, URL: url)
        self.setProperty(property)
    }
  }
}
</code></pre>

<p>How should I load an .mtl file and apply it on my model to have texture on it?
What properties of SCNMaterial should I declare for getting texture data from a .mtl file?</p>
