public void ImportOBJFromNetwork() { // This function downloads and imports an obj file named onion.obj from the url below // This also loads the associated textures and materials given by the absolute URLs GameObject importedObject; isImportingFromNetwork = true; OBJImportOptions importOptions = new OBJImportOptions(); importOptions.zUp = false; importOptions.localPosition = new Vector3(0.87815f, 1.4417f, -4.4708f); importOptions.localScale = new Vector3(0.0042f, 0.0042f, 0.0042f); string objURL = "https://dl.dropbox.com/s/v09bh0hiivja10e/onion.obj?dl=1"; string objName = "onion"; string diffuseTexURL = "https://dl.dropbox.com/s/0u4ij6sddi7a3gc/onion.jpg?dl=1"; string bumpTexURL = ""; string specularTexURL = ""; string opacityTexURL = ""; string materialURL = "https://dl.dropbox.com/s/fuzryqigs4gxwvv/onion.mtl?dl=1"; progressSlider.value = 0; uninteractivePanel.SetActive(true); downloadProgress = new ReferencedNumeric <float>(0); StartCoroutine(UpdateProgress()); PolyfewRuntime.ImportOBJFromNetwork(objURL, objName, diffuseTexURL, bumpTexURL, specularTexURL, opacityTexURL, materialURL, downloadProgress, (GameObject imp) => { AssignMeshesFromPairs(); isImportingFromNetwork = false; importedObject = imp; barabarianRef.SetActive(false); targetObject = importedObject; ResetSettings(); objectMeshPairs = PolyfewRuntime.GetObjectMeshPairs(targetObject, true); trianglesCount.text = PolyfewRuntime.CountTriangles(true, targetObject) + ""; exportButton.interactable = true; uninteractivePanel.SetActive(false); importFromWeb.interactable = false; importFromFileSystem.interactable = false; preserveFace.interactable = false; preservationStrength.interactable = false; disableTemporary = true; preservationSphere.gameObject.SetActive(false); disableTemporary = false; }, (Exception ex) => { uninteractivePanel.SetActive(false); isImportingFromNetwork = false; Debug.LogError("Failed to download and import OBJ file. " + ex.Message); }, importOptions); }
public ObjectImporter() { isException = false; downloadProgress = new ReferencedNumeric <float>(0); objDownloadProgress = 0; textureDownloadProgress = 0; materialDownloadProgress = 0; activeDownloads = 6; }
public async Task <GameObject> ImportModelFromNetwork(string objURL, string objName, string diffuseTexURL, string bumpTexURL, string specularTexURL, string opacityTexURL, string materialURL, ReferencedNumeric <float> downloadProgress, ImportOptions options) { if (loaderList == null) { loaderList = new List <Loader>(); } if (loaderList.Count == 0) { numTotalImports = 0;// files.Length; ImportingStart?.Invoke(); } Loader loader = CreateLoader("", true); if (loader == null) { throw new SystemException("Failed to import obj."); //return null; } numTotalImports++; loaderList.Add(loader); loader.buildOptions = options; allLoaded = false; if (string.IsNullOrWhiteSpace(objName)) { objName = ""; } ObjectImporter.downloadProgress = downloadProgress; //string objURL, string objName, string textureURL, string materialURL, ReferencedNumeric< float > downloadProgress, ImportOptions options GameObject loaded; try { loaded = await loader.LoadFromNetwork(objURL, diffuseTexURL, bumpTexURL, specularTexURL, opacityTexURL, materialURL, objName); } catch (Exception ex) { throw ex; } return(loaded); }
public void ImportModelFromNetworkWebGL(string objURL, string objName, string diffuseTexURL, string bumpTexURL, string specularTexURL, string opacityTexURL, string materialURL, ReferencedNumeric <float> downloadProgress, ImportOptions options, Action <GameObject> OnSuccess, Action <Exception> OnError) { if (loaderList == null) { loaderList = new List <Loader>(); } if (loaderList.Count == 0) { numTotalImports = 0;// files.Length; ImportingStart?.Invoke(); } Loader loader = CreateLoader("", true); if (loader == null) { OnError(new SystemException("Loader initialization failed due to unknown reasons.")); } numTotalImports++; loaderList.Add(loader); loader.buildOptions = options; allLoaded = false; if (string.IsNullOrWhiteSpace(objName)) { objName = ""; } ObjectImporter.downloadProgress = downloadProgress; StartCoroutine(loader.LoadFromNetworkWebGL(objURL, diffuseTexURL, bumpTexURL, specularTexURL, opacityTexURL, materialURL, objName, OnSuccess, OnError)); }
public async void ImportFromNetworkWebGL(string objURL, string objName, string diffuseTexURL, string bumpTexURL, string specularTexURL, string opacityTexURL, string materialURL, ReferencedNumeric <float> downloadProgress, Action <GameObject> OnSuccess, Action <Exception> OnError, OBJImportOptions importOptions = null) { if (String.IsNullOrWhiteSpace(objURL)) { OnError(new InvalidOperationException("Cannot download from empty URL. Please provide a direct URL to the obj file")); return; } if (String.IsNullOrWhiteSpace(diffuseTexURL)) { Debug.LogWarning("Cannot download from empty URL. Please provide a direct URL to the accompanying texture file."); } if (String.IsNullOrWhiteSpace(materialURL)) { Debug.LogWarning("Cannot download from empty URL. Please provide a direct URL to the accompanying material file."); } if (downloadProgress == null) { OnError(new ArgumentNullException("downloadProgress", "You must pass a reference to the Download Progress object.")); return; } GameObject objectToPopulate = new GameObject(); objectToPopulate.AddComponent <ObjectImporter>(); ObjectImporter objImporter = objectToPopulate.GetComponent <ObjectImporter>(); if (importOptions == null) { importOptions = new OBJImportOptions(); } objImporter.ImportModelFromNetworkWebGL(objURL, objName, diffuseTexURL, bumpTexURL, specularTexURL, opacityTexURL, materialURL, downloadProgress, importOptions, (GameObject imported) => { Destroy(objImporter); OnSuccess(imported); }, (exception) => { DestroyImmediate(objectToPopulate); OnError(exception); }); }