相关疑难解决方法(0)

如何通过SceneKit和Model I/O在.OBJ 3d模型上应用.MTL文件

我试图通过SceneKit和Model I/0在.obj 3d模型上应用.mtl文件纹理.

当我尝试在其上应用纹理的.jpg时,我的代码工作正常:

       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 …
Run Code Online (Sandbox Code Playgroud)

3d ios scenekit modelio swift

14
推荐指数
1
解决办法
4097
查看次数

标签 统计

3d ×1

ios ×1

modelio ×1

scenekit ×1

swift ×1