[英]How can I access SceneKit files downloaded from Firebase?
I've successfully set up the app to download the SceneKit files to the mobile storage, but where I am stuck now is figuring out how to read the file from the specific downloaded location and continue working it in the image recognition/AR process accordingly.我已成功设置应用程序以将 SceneKit 文件下载到移动存储,但我现在卡住的地方是弄清楚如何从特定下载位置读取文件并继续在图像识别/AR 过程中相应地工作。
Before, when the Scenekit files were included in the initial download via Scenekit Catalog in the app folder, I would read them like so:之前,当 Scenekit 文件通过应用文件夹中的 Scenekit 目录包含在初始下载中时,我会这样阅读它们:
let ShipScene = SCNScene(named: "art.scnassets/ship.scn")
Now, I've updated it to read the same string as the download URL, but the image recognition is not working.现在,我已经更新它以读取与下载 URL 相同的字符串,但图像识别不起作用。
I assume my problem is that it is not reading the right location, or I may be using the wrong function.我认为我的问题是它没有读取正确的位置,或者我可能使用了错误的 function。 I've put the app through to my phone through TestFlight and still no luck.我已经通过 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" )
*** My question is in the final line of code I included. *** 我的问题在我包含的最后一行代码中。 I am trying to make sure I am searching in the right place to retrieve the files that were downloaded, or if the function I am using is even proper for retrieving files stored locally on a mobile device.我试图确保我在正确的位置搜索以检索已下载的文件,或者我使用的 function 是否适合检索本地存储在移动设备上的文件。
Solved by first adding a function to find the scenepath of the container which has all my scenes, and then using the scene path in the fetching of the individual.scn file.解决方法是先添加一个 function 找到包含我所有场景的容器的场景路径,然后在获取 individual.scn 文件时使用场景路径。 Scene downloads from Firebase Storage (No use of Realtime Database) and integrates properly with the image recognition.场景从 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.