0

我尝试对Apple ARKitInteraction进行更改 ,让用户将他的共享文件 (usdz) 添加到应用程序中,如下所示:

static let sharedObjects: [VirtualObject] = {

    let documents = URL(string: NSHomeDirectory() + "/Documents/")

    let fileEnumerator = FileManager().enumerator(at: documents!, includingPropertiesForKeys: [])!

    return fileEnumerator.compactMap { element in
        let url = element as! URL

        guard url.pathExtension == "usdz" else { return nil }

        return VirtualObject(url: url)
    }
}()

然后添加我的集成 Firebase 以将我的 3D 资产下载到路径 /Library(隐藏文件),以便将文件枚举为过去的代码:

static let downloadedObjects: [VirtualObject] = {

    let library = URL(string: NSHomeDirectory() + "/Library/")

    let fileEnumerator = FileManager().enumerator(at: library!, includingPropertiesForKeys: [])!

    return fileEnumerator.compactMap { element in
        let url = element as! URL

        guard url.pathExtension == "usdz" else { return nil }

        return VirtualObject(url: url)
    }
}()

我的问题:

奇怪的问题是,当尝试枚举(/Library & /Documents)中的所有数据并尝试放置对象时,有时会出现此消息("CANNOT PLACE OBJECT Try moving left or right.")

1 周后,我注意到如果我只是从 1 个路径枚举文件,它工作正常,没有任何问题,只是来自库或文档(即使将两个路径 URL 都保存在一个[VirtualObject]()

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    var current = 0

    let name = Model[indexPath.section].ModelItem[indexPath.item].name!.description
    let modelUrl = Model[indexPath.section].ModelItem[indexPath.item].model!
    let size = Model[indexPath.section].ModelItem[indexPath.item].size!
    Size = SCNVector3(size, size, size)


    if fileManager.fileExists(atPath: library + name + ".usdz") {

        if indexPath.section == 0 {
            for object in virtualObjects{
                if object.referenceURL.lastPathComponent == name + ".usdz" {
                    delegate?.virtualObjectSelectionViewController(self, didSelectObject: sharedObjects[current])
                    dismiss(animated: true, completion: nil)
                    current = 0
                }
                current += 1
            }
        } else {
            for object in virtualObjects{
                if object.referenceURL.lastPathComponent == name + ".usdz" {
                    delegate?.virtualObjectSelectionViewController(self, didSelectObject: downloadedObjects[current])
                    current = 0
                    dismiss(animated: true, completion: nil)
                }
                current += 1
            }

            self.downloadInProgress = true
            currentSelectedIndex = indexPath.row
            currentSection = indexPath.section
            self.downloadUsdzNDisplay(modelUrl, name: name)
        }
    }

}
4

0 回答 0