简体   繁体   English

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

[英]How can I access SceneKit files downloaded from Firebase?

  • I have an ARKit app that uses image recognition to trigger SceneKit/3D Object files, specifically for art exhibitions.我有一个 ARKit 应用程序,它使用图像识别来触发 SceneKit/3D Object 文件,专门用于艺术展览。 I've recently began implementing Firebase Storage in order to reduce the overall download size and rather download the 3D files on demand, per which exhibition the user is using!我最近开始实施 Firebase 存储,以减少整体下载大小,而是按需下载 3D 文件,用户正在使用该文件!

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.

相关问题 SceneKit – 如何使用材质访问节点的变换? - SceneKit – How can I use materials to access node's transform? 如何从 Scenekit 场景中删除所有节点? - How can I remove all nodes from a scenekit scene? 如何从Scenekit场景中删除特定节点? - How can I remove specific nodes from a scenekit scene? 如何在SceneKit中反转动画? - How can I reverse an animation in SceneKit? 如何让实体不断查看 RealityKit 中的相机,类似于 SceneKit 中的 Billboard Constraint - How can I get an entity to constantly look at the camera in RealityKit similar to Billboard Constraint from SceneKit 当 State 发生变化时,如何防止 SceneKit 场景重新渲染不佳? - How can I keep a SceneKit scene from rerendering poorly when State changes? 如何从 SceneKit 中的 .dae 文件访问文本元素? - How to access text element from a .dae file in SceneKit? 如何让我的应用程序创建/下载的文件显示在文件应用程序中? - How can I make files created / downloaded by my app show up in the Files application? 我如何在firebase功能之外访问firebase变量 - How can i access firebase variable outside firebase function 如何将一个千兆像素的图像加载为SceneKit中的材质? - How can I load a Gigapixel image as a material in SceneKit?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM