gpt4 book ai didi

swift - 如何访问从 Firebase 下载的 SceneKit 文件?

转载 作者:行者123 更新时间:2023-11-30 10:34:05 27 4
gpt4 key购买 nike

  • 我有一个 ARKit 应用程序,它使用图像识别来触发 SceneKit/3D 对象文件,专门用于艺术展览。我最近开始实现 Firebase Storage,以减少总体下载大小,而是根据用户正在使用的展览按需下载 3D 文件!

我已成功设置应用程序将 SceneKit 文件下载到移动存储,但我现在陷入困境的是弄清楚如何从特定下载位置读取文件并继续在图像识别/AR 中工作进行相应处理。

之前,当 Scenekit 文件包含在通过应用程序文件夹中的 Scenekit Catalog 进行初始下载时,我会像这样读取它们:

   let ShipScene = SCNScene(named: "art.scnassets/ship.scn")

现在,我已将其更新为读取与下载 URL 相同的字符串,但图像识别不起作用。

我认为我的问题是它没有读取正确的位置,或者我可能使用了错误的函数。我已通过 TestFlight 将应用程序连接到我的手机,但仍然没有成功。

// Downloading from firebase to device URL

let shipURL = documentsURL.appendingPathComponent("file:///var/mobile/Containers/Data/Application/QZ_Gallery/SceneKitFiles/ship.scn", isDirectory: true)


let shipDownload = shipRef.write(toFile: shipURL)

// Attempting to pull the file from the downloaded location

let ShipScene = SCNScene(named:"file:///var/mobile/Containers/Data/Application/QZ_Gallery/SceneKitFiles/ship.scn" )

*** 我的问题在我包含的最后一行代码中。我试图确保我在正确的位置搜索以检索已下载的文件,或者我正在使用的功能是否适合检索移动设备上本地存储的文件。

最佳答案

通过首先添加一个函数来查找包含我的所有场景的容器的场景路径,然后在获取单个 .scn 文件时使用场景路径来解决。从 Firebase 存储下载场景(不使用实时数据库)并与图像识别正确集成。

      let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

let scenePath = documentsURL.appendingPathComponent("Scenes")
if(!FileManager.default.fileExists(atPath: scenePath.absoluteString)) {
do {
try FileManager.default.createDirectory(atPath: scenePath.absoluteString, withIntermediateDirectories: true, attributes: nil)
} catch {
print(error.localizedDescription);
}
}

// Start Download, writing to a file




let sceneURL = scenePath.appendingPathComponent("Ship.scn", isDirectory: true)

关于swift - 如何访问从 Firebase 下载的 SceneKit 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58459127/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com