我使用下面的代码在scenekit中呈现场景,当dae文件从art.scnassests文件夹加载时,它完美地工作。
let scene = SCNScene(named: "art.scnassets/idle.dae")但是,我想下载该资产并应用它,但我得到了一个错误。
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let scene = SCNScene(named: documentsURL.absoluteString+"idle.dae")文件夹中存在一个名为idle.dae的文件。
我得到了错误:fatal error: unexpectedly found nil while unwrapping an Optional value
如何加载下载的资产并动态应用?我做错了什么?有什么建议吗?我是iOS编程的新手。
发布于 2017-07-03 20:26:41
除非对iOS 11做了一些更改,否则您将无法在运行时在iOS上下载和实例化DAE文件。它们在构建时使用名为scntool的实用程序进行压缩/编译。
您能使用I/O模型所支持的文件格式之一吗?请参阅https://developer.apple.com/videos/play/wwdc2015/602/?time=320的原始列表(Alembic .abc、Polygon .ply三角.stl、WaveFront .obj)和https://developer.apple.com/videos/play/wwdc2017/610/,以快速讨论Pixar的美元(通用场景描述)。
如果你被DAE文件困住了,弗雷德里克·雅克在https://the-nerd.be/2014/11/07/dynamically-load-collada-files-in-scenekit-at-runtime/有一篇文章,概述了他在DAE处理管道逆向工程的经验。他的技术允许从服务器上的DAE文件中下载SCN文件。还请参阅Load uncompressed collada file using iOS Scene Kit (有权威来源的评论)和https://forums.developer.apple.com/thread/38010。
https://stackoverflow.com/questions/44890596
复制相似问题