【问题标题】:SCNScene load with textures from podSCNScene 从 pod 加载纹理
【发布时间】:2017-09-12 20:27:35
【问题描述】:

我正在尝试创建包含带有纹理的 SCNScene 的 pod,但出现错误:

SceneKit Error: Failed loading : C3DImage
src:file:///Users/.../Example.app/Templates.scnassets/grid.png

纹理和场景在同一个文件夹中。

我尝试使用 SCNSceneSource 加载

let sceneData = try Data(contentsOf: sceneUrl)
let options = [.overrideAssetURLs: true,
               .assetDirectoryURLs: MYPod.bundle().bundleURL
               ] as [SCNSceneSource.LoadingOption : Any]
let source = SCNSceneSource(data: sceneData, options:options)
scene = (source?.scene(options: options))!

但得到相同的结果(路径不变)

【问题讨论】:

  • 您找到解决此问题的方法了吗?
  • 非常原始。加载后,如果材质的内容是字符串(纹理名称),构建正确的路径并手动加载UIImage
  • @Андрей Первушин 你能解释更多细节吗
  • 您应该使用代码和 if(抱歉伪代码)浏览所有材料 If material.contents.type == String.type { material.contents = UIImage(named: /material.contents) }
  • @Андрей Первушин 谢谢老兄。最后它的作品

标签: cocoapods textures bundle scenekit scnscene


【解决方案1】:

您应该使用代码和(抱歉伪代码)浏览所有材料

If material.contents.type == String.type { 
material.contents = UIImage(named: <path tofolder>/material.contents) 
} 

【讨论】:

  • 我们是否需要遍历所有子节点并应用内容?如果我在一个子节点中有多个子节点怎么办?有没有其他方法可以做到这一点?
  • 在试用此代码时,我收到此错误“'Any 类型的值?'没有成员“类型””
  • 这是伪代码,您将拥有当前 swift 版本的解释逻辑
猜你喜欢
  • 1970-01-01
  • 2014-08-05
  • 2016-04-09
  • 2020-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-01
  • 1970-01-01
相关资源
最近更新 更多