예제 #1
0
        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);
            }
        }
예제 #2
0
 private void GetIESConverterAndCubeSphere(out GameObject cubemapSphere, out IESConverter iesConverter)
 {
     UnityEngine.Object cubemapSpherePrefab = Resources.Load("IES cubemap sphere");
     cubemapSphere = (GameObject)Instantiate(cubemapSpherePrefab);
     iesConverter  = cubemapSphere.GetComponent <IESConverter>();
     iesConverter.NormalizationMode = LogarithmicNormalization ? NormalizationMode.Logarithmic : NormalizationMode.Linear;
     iesConverter.Resolution        = int.Parse(_resolutions[_resolutionIndex]);
 }
예제 #3
0
 private void GetIESConverterAndCubeSphere(out GameObject cubemapSphere, out IESConverter iesConverter)
 {
     UnityEngine.Object cubemapSpherePrefab = Resources.Load("IES cubemap sphere");
     cubemapSphere = (GameObject)Instantiate(cubemapSpherePrefab);
     iesConverter  = cubemapSphere.GetComponent <IESConverter>();
     iesConverter.SquashHistogram = EnhanceDetail;
     iesConverter.Resolution      = int.Parse(_resolutions[_resolutionIndex]);
 }
예제 #4
0
        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));
            }
        }
예제 #5
0
        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("[IES] 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
                {
                    ImportIES(file, relativePath, iesConverter);
                    successCount++;
                }
                catch (IESParseException ex)
                {
                    Debug.LogError(string.Format("[IES] Encountered invalid IES data in {0}. Error message: {1}", file, ex.Message));
                }
                catch (Exception ex)
                {
                    // If an error occurs while parsing, log it and continue with the remaining files.
                    Debug.LogError(string.Format("[IES] Error while parsing {0}. Please contact me through the forums or thomasmountainborn.com. Error message: {1}", file, ex.Message));
                }

                currentFileIndex++;
            }

            Debug.LogFormat("[IES] Successfully imported {0} IES file{1} to IES/Imports/{2}.", successCount, successCount == 1 ? "" : "s", Path.GetFileName(folder));
            EditorUtility.ClearProgressBar();
        }
예제 #6
0
 private static void GetIESConverterAndCubeSphere(bool logarithmicNormalization, int resolution, out GameObject cubemapSphere, out IESConverter iesConverter)
 {
     UnityEngine.Object original = Resources.Load("IES cubemap sphere");
     cubemapSphere = (GameObject)UnityEngine.Object.Instantiate(original);
     iesConverter  = cubemapSphere.GetComponent <IESConverter>();
     iesConverter.NormalizationMode = (logarithmicNormalization ? NormalizationMode.Logarithmic : NormalizationMode.Linear);
     iesConverter.Resolution        = resolution;
 }