/// <summary> /// Checks if the asset has the contents of the format to import, fetching them if need be; then imports /// the asset. /// </summary> /// <param name="asset">The asset who's format is being imported.</param> /// <param name="format">The format to import.</param> /// <param name="options">The import options for this asset.</param> /// <param name="callback">The callback to call when this is finished.</param> private void FetchAndImportFormat(PolyAsset asset, PolyFormat format, PolyImportOptions options, PolyApi.ImportCallback callback = null) { if (format.root.contents != null) { // If asset already has the gltf package, proceed directly to importing it. ImportFormat(asset, format, options, callback); } else { // Otherwise, first fetch the package and then import the model. FetchFormatFiles(asset, format.formatType, (PolyAsset resultAsset, PolyStatus status) => { PolyFormat fetchedFormat = resultAsset.GetFormatIfExists(format.formatType); if (fetchedFormat != null) { ImportFormat(asset, fetchedFormat, options, callback); } else { if (callback != null) { callback(asset, new PolyStatusOr <PolyImportResult>( PolyStatus.Error("Could not fetch format files for asset"))); } } }); } }
/// <summary> /// Imports the relevant format and corrects that the designated glTF format if need be. /// </summary> private void ImportFormat(PolyAsset asset, PolyFormat format, PolyImportOptions options, PolyApi.ImportCallback callback) { asyncImporter.ImportAsync(asset, format, options, (PolyStatus status, GameObject root, IEnumerable meshCreator) => { if (!status.ok) { // Failed. callback(asset, new PolyStatusOr <PolyImportResult>(status)); return; } PolyImportResult result = new PolyImportResult(root); result.mainThreadThrottler = meshCreator; callback(asset, new PolyStatusOr <PolyImportResult>(result)); }); }
public void Import(PolyAsset asset, PolyImportOptions options, PolyApi.ImportCallback callback = null) { PolyFormat gltfFormat = asset.GetFormatIfExists(PolyFormatType.GLTF); PolyFormat gltf2Format = asset.GetFormatIfExists(PolyFormatType.GLTF_2); if (gltf2Format != null && gltfFormat == null) { FetchAndImportFormat(asset, gltf2Format, options, callback); } else if (gltfFormat != null) { FetchAndImportFormat(asset, gltfFormat, options, callback); } else { callback(asset, new PolyStatusOr <PolyImportResult>( PolyStatus.Error("Neither glTF or glTF_2 format was present in asset"))); } }