private void ImportIES(string filePath, string targetPath, IESConverter iesConverter) { Cubemap cubemap = null; Texture2D spotlightCookie = null; EXRData exrData; string targetFilename = null; iesConverter.ConvertIES(filePath, targetPath, AllowSpotlightCookies, RawImport, ApplyVignette, out cubemap, out spotlightCookie, out exrData, out targetFilename); if (!RawImport) { if (cubemap != null) { AssetDatabase.CreateAsset(cubemap, targetFilename); } else { AssetDatabase.CreateAsset(spotlightCookie, targetFilename); } } else { if (exrData.Pixels == null) { return; } MiniEXR.MiniEXR.MiniEXRWrite(targetFilename, exrData.Width, exrData.Height, exrData.Pixels); } }
private static void ImportIES(string path, IESConverter iesConverter, bool allowSpotlightCookies, bool applyVignette, out Texture2D spotlightCookie, out Cubemap pointlightCookie) { string text = null; spotlightCookie = null; pointlightCookie = null; try { EXRData exrdata; iesConverter.ConvertIES(path, "", allowSpotlightCookies, false, applyVignette, out pointlightCookie, out spotlightCookie, out exrdata, out text); } catch (IESParseException ex) { Debug.LogError(string.Format("[IES] Encountered invalid IES data in {0}. Error message: {1}", path, ex.Message)); } catch (Exception ex2) { Debug.LogError(string.Format("[IES] Error while parsing {0}. Please contact me through the forums or thomasmountainborn.com. Error message: {1}", path, ex2.Message)); } }
private void ParseFolderHierarchy(string folder, IESConverter iesConverter) { EditorUtility.DisplayProgressBar("Finding .ies files...", "", 0); // Get all ies files in the folder (hierarchy). string[] iesFiles = Directory.GetFiles(folder, "*.ies", IncludeSubFolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); if (iesFiles.Length == 0) { Debug.Log("There are no .ies files in the selected folder."); EditorUtility.ClearProgressBar(); return; } Uri rootUri = new Uri(folder, UriKind.Absolute); int fileCount = iesFiles.Length; float currentFileIndex = 1; int successCount = 0; foreach (string file in iesFiles) { // Create the relative path, to be used in the IES/Imports folder. Uri fileUri = new Uri(Path.GetDirectoryName(file), UriKind.Absolute); string relativePath = ""; // If the file is in the root import folder, simply use that folder name. if (fileUri == rootUri) { relativePath = Path.GetFileName(folder); } // Else, create a relative path originating in the root import folder. else { relativePath = Uri.UnescapeDataString(rootUri.MakeRelativeUri(fileUri).OriginalString); } string currentFileName = string.Format("{0}/{1}", relativePath, Path.GetFileName(file)); // Display the progress, and allow cancelling. if (EditorUtility.DisplayCancelableProgressBar(string.Format("Parsing IES files... {0}/{1}", currentFileIndex, fileCount), currentFileName, currentFileIndex / fileCount)) { break; } try { Cubemap cubemap = null; Texture2D spotlightCookie = null; string targetFilename = null; iesConverter.ConvertIES(file, relativePath, AllowSpotlightCookies, out cubemap, out spotlightCookie, out targetFilename); if (cubemap != null) { AssetDatabase.CreateAsset(cubemap, targetFilename); } else { WriteSpotlightCookie(spotlightCookie, targetFilename); } successCount++; } catch (Exception ex) { // If an error occurs while parsing, log it and continue with the remaining files. Debug.LogError(string.Format("Error while parsing {0}. Please contact me through the forums or thomasmountainborn.com. Error message: {1}", file, ex.Message)); } currentFileIndex++; } Debug.LogFormat("Successfully imported {0} IES file{1} to IES/Imports/{2}.", successCount, successCount == 1 ? "" : "s", Path.GetFileName(folder)); EditorUtility.ClearProgressBar(); }