protected override GameObject DoUnityThreadWork(IDisposable state__, out IEnumerable <Null> meshEnumerable, out ImportMaterialCollector importMaterialCollector) { meshEnumerable = null; importMaterialCollector = null; GameObject rootObject = null; using (IDisposable state_ = state__) { var state = state_ as ImportGltf.ImportState; if (state != null) { string assetLocation = Path.GetDirectoryName(m_localPath); // EndImport doesn't try to use the loadImages functionality of UriLoader anyway. // It knows it's on the main thread, so chooses to use Unity's fast loading. var loader = new TiltBrushUriLoader(m_localPath, assetLocation, loadImages: false); ImportGltf.GltfImportResult result = ImportGltf.EndImport( state, loader, new ImportMaterialCollector(assetLocation, uniqueSeed: m_localPath), out meshEnumerable); if (result != null) { rootObject = result.root; importMaterialCollector = (ImportMaterialCollector)result.materialCollector; } } } IsValid = (rootObject != null); return(rootObject); }
public void Update() { // We process at most one import result per frame, to avoid doing too much work // in the main thread. ImportOperation operation; lock (finishedOperationsLock) { if (finishedOperations.Count == 0) { return; } operation = finishedOperations.Dequeue(); } if (!operation.status.ok) { // Import failed. operation.callback(operation.status, root: null, meshCreator: null); return; } try { IEnumerable meshCreator; ImportGltf.GltfImportResult result = ImportGltf.EndImport(operation.importState, operation.loader, out meshCreator); if (!operation.options.clientThrottledMainThread) { // If we're not in throttled mode, create all the meshes immediately by exhausting // the meshCreator enumeration. Otherwise, it's the caller's responsibility to // do this. foreach (var unused in meshCreator) /* empty */ } { meshCreator = null; } // Success. operation.callback(PolyStatus.Success(), result.root, meshCreator); } catch (Exception ex) { // Import failed. Debug.LogException(ex); operation.callback(PolyStatus.Error("Failed to convert import to Unity objects.", ex), root: null, meshCreator: null); } }