在 SCNScene swift 中加载 glb 模型

问题描述 投票:0回答:2

我的文档文件夹中有一个 .glb 文件,如何获取图像并将其加载到 scnScene 中?就像我如何从文档文件夹加载 uiimage

let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
let nsUserDomainMask    = FileManager.SearchPathDomainMask.userDomainMask
let paths               = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory,     nsUserDomainMask, true)
if let dirPath          = paths.first
{
   let imageURL = URL(fileURLWithPath: dirPath).appendingPathComponent("Image2.png")
   let image    = UIImage(contentsOfFile: imageURL.path

是否可以在SCNScene中加载.glb?

   let scene = SCNScene(named: "latest.glb")
swift scenekit arkit
2个回答
1
投票

回答我自己的问题,我使用GLTFSceneKit

 let path = FileManager.default.urls(for: .documentDirectory,
                                                 in: .userDomainMask)[0]
                                       .appendingPathComponent("test.glb")
    
    var scene: SCNScene
            do {
                let sceneSource = try GLTFSceneSource(url: path)
                scene = try sceneSource.scene()
            } catch {
                print("\(error.localizedDescription)")
                return
            }

0
投票

您也可以加载该库 GLTFKit2

GLTFAsset.load(with: url, options: [:]) { (progress, status, maybeAsset, maybeError, _) in
    // Check for completion and/or error, use asset if complete, etc.
}
© www.soinside.com 2019 - 2024. All rights reserved.