예제 #1
0
 public ImportRequest(string gltfLocalPath, string ptAssetLocalPath, EditTimeImportOptions options, PolyAsset polyAsset)
 {
     this.gltfLocalPath    = gltfLocalPath;
     this.ptAssetLocalPath = ptAssetLocalPath;
     this.options          = options;
     this.polyAsset        = polyAsset;
 }
예제 #2
0
        /// <summary>
        /// Starts downloading and importing the given asset (in the background). When done, the asset will
        /// be saved to the user's Assets folder.
        /// </summary>
        /// <param name="asset">The asset to download and import.</param>
        /// <param name="ptAssetLocalPath">Path to the PtAsset that should be created (or replaced).</param>
        /// <param name="options">Import options.</param>
        public void StartDownloadAndImport(PolyAsset asset, string ptAssetLocalPath, EditTimeImportOptions options)
        {
            if (!assetsBeingDownloaded.Add(asset))
            {
                return;
            }
            PtDebug.LogFormat("ABM: starting to fetch asset {0} ({1}) -> {2}", asset.name, asset.displayName,
                              ptAssetLocalPath);

            // Prefer glTF1 to glTF2.
            // It used to be that no Poly assets had both formats, so the ordering did not matter.
            // Blocks assets now have both glTF1 and glTF2. PT does not understand the glTF2 version,
            // so the ordering matters a great deal.
            PolyFormat glTF2format = asset.GetFormatIfExists(PolyFormatType.GLTF_2);
            PolyFormat glTFformat  = asset.GetFormatIfExists(PolyFormatType.GLTF);

            PolyMainInternal.FetchProgressCallback progressCallback = (PolyAsset assetBeingFetched, float progress) => {
                EditorUtility.DisplayProgressBar(DOWNLOAD_PROGRESS_TITLE, DOWNLOAD_PROGRESS_TEXT, progress);
            };

            if (glTFformat != null)
            {
                EditorUtility.DisplayProgressBar(DOWNLOAD_PROGRESS_TITLE, DOWNLOAD_PROGRESS_TEXT, 0.0f);
                PolyMainInternal.Instance.FetchFormatFiles(asset, PolyFormatType.GLTF,
                                                           (PolyAsset resultAsset, PolyStatus status) => {
                    EditorUtility.ClearProgressBar();
                    OnFetchFinished(status, resultAsset, /*isGltf2*/ false, ptAssetLocalPath, options);
                }, progressCallback);
            }
            else if (glTF2format != null)
            {
                EditorUtility.DisplayProgressBar(DOWNLOAD_PROGRESS_TITLE, DOWNLOAD_PROGRESS_TEXT, 0.0f);
                PolyMainInternal.Instance.FetchFormatFiles(asset, PolyFormatType.GLTF_2,
                                                           (PolyAsset resultAsset, PolyStatus status) => {
                    EditorUtility.ClearProgressBar();
                    OnFetchFinished(status, resultAsset, /*isGltf2*/ true, ptAssetLocalPath, options);
                }, progressCallback);
            }
            else
            {
                Debug.LogError("Asset not in GLTF_2 or GLTF format. Can't import.");
                PtAnalytics.SendEvent(PtAnalytics.Action.IMPORT_FAILED, "Unsupported format");
            }
        }
예제 #3
0
        private void OnFetchFinished(PolyStatus status, PolyAsset asset, bool isGltf2,
                                     string ptAssetLocalPath, EditTimeImportOptions options)
        {
            if (!status.ok)
            {
                Debug.LogErrorFormat("Error fetching asset {0} ({1}): {2}", asset.name, asset.displayName, status);
                EditorUtility.DisplayDialog("Download Error",
                                            string.Format("*** Error downloading asset '{0}'. Try again later.", asset.displayName), "OK");
                PtAnalytics.SendEvent(PtAnalytics.Action.IMPORT_FAILED, "Asset fetch failed");
                return;
            }

            string baseName, downloadLocalPath;

            if (!PrepareDownload(asset, out baseName, out downloadLocalPath))
            {
                return;
            }

            string absPath = PtUtils.ToAbsolutePath(downloadLocalPath);

            string extension = isGltf2 ? ".gltf2" : ".gltf";
            string fileName  = baseName + extension;

            // We have to place an import request so that PolyImporter does the right thing when it sees the new file.
            PolyImporter.AddImportRequest(new PolyImporter.ImportRequest(
                                              downloadLocalPath + "/" + fileName, ptAssetLocalPath, options, asset));

            // Now unpackage it. GltfProcessor will pick it up automatically.
            UnpackPackageToFolder(isGltf2 ? asset.GetFormatIfExists(PolyFormatType.GLTF_2) :
                                  asset.GetFormatIfExists(PolyFormatType.GLTF), absPath, fileName);

            PtDebug.LogFormat("ABM: Successfully downloaded {0} to {1}", asset, absPath);
            AssetDatabase.Refresh();
            if (null != refreshCallback)
            {
                refreshCallback();
            }
        }