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); }
GameObject LoadGltf(List <string> warnings) { // This is intended to be identical to using GltfModelBuilder, except synchronous. GameObject go; bool fromPoly = (m_Location.GetLocationType() == Location.Type.PolyAssetId); string localPath = m_Location.AbsolutePath; string assetLocation = Path.GetDirectoryName(localPath); // Synchronous, so don't use slow image loading var loader = new TiltBrushUriLoader(localPath, assetLocation, loadImages: false); try { ImportGltf.GltfImportResult result = ImportGltf.Import( localPath, loader, new ImportMaterialCollector(assetLocation, uniqueSeed: localPath), fromPoly ? kPolyGltfImportOptions : kGltfImportOptions); go = result.root; m_ImportMaterialCollector = (ImportMaterialCollector)result.materialCollector; } catch (Exception ex) { m_LoadError = new LoadError("Invalid data", ex.Message); go = null; m_AllowExport = false; Debug.LogException(ex); } m_AllowExport = (go != null); return(go); }
protected override IDisposable DoBackgroundThreadWork() { var loader = new TiltBrushUriLoader( m_localPath, Path.GetDirectoryName(m_localPath), m_useThreadedImageLoad); var options = m_fromPoly ? kPolyGltfImportOptions : kGltfImportOptions; return(ImportGltf.BeginImport(m_localPath, loader, options)); }