private static void SetVerticalAndHorizontalType(IESData iesData) { if ((iesData.VerticalAngles[0] == 0f && iesData.VerticalAngles[iesData.VerticalAngles.Count - 1] == 90f) || (iesData.VerticalAngles[0] == -90f && iesData.VerticalAngles[iesData.VerticalAngles.Count - 1] == 0f)) { iesData.VerticalType = VerticalType.Bottom; } else if (iesData.VerticalAngles[iesData.VerticalAngles.Count - 1] == 180f && iesData.VerticalAngles[0] == 90f) { iesData.VerticalType = VerticalType.Top; } else { iesData.VerticalType = VerticalType.Full; } if (iesData.HorizontalAngles.Count == 1) { iesData.HorizontalType = HorizontalType.None; return; } if (iesData.HorizontalAngles[iesData.HorizontalAngles.Count - 1] - iesData.HorizontalAngles[0] == 90f) { iesData.HorizontalType = HorizontalType.Quadrant; return; } if (iesData.HorizontalAngles[iesData.HorizontalAngles.Count - 1] - iesData.HorizontalAngles[0] == 180f) { iesData.HorizontalType = HorizontalType.Half; return; } iesData.HorizontalType = HorizontalType.Full; if (iesData.HorizontalAngles[iesData.HorizontalAngles.Count - 1] != 360f) { ParseIES.StitchHorizontalAssymetry(iesData); } }
/// <summary> /// Converts an IES file to either a point or spot light cookie. /// </summary> public void ConvertIES(string filePath, string targetPath, bool createSpotlightCookies, bool rawImport, bool applyVignette, out Cubemap pointLightCookie, out Texture2D spotlightCookie, out EXRData exrData, out string targetFilename) { // Parse the ies data. IESData iesData = ParseIES.Parse(filePath, rawImport ? NormalizationMode.Linear : NormalizationMode); // Create a texture from the normalized IES data. _iesTexture = IESToTexture.ConvertIesData(iesData); // Regular import - creates cookies that are directly usable within Unity. if (!rawImport) { exrData = default(EXRData); RegularImport(filePath, targetPath, createSpotlightCookies, applyVignette, out pointLightCookie, out spotlightCookie, out targetFilename, iesData); } // Raw import - creates a .exr import of the IES data instead, to give the user full control. else { pointLightCookie = null; spotlightCookie = null; RawImport(iesData, filePath, targetPath, createSpotlightCookies, out exrData, out targetFilename); } // Clean up. if (_iesTexture != null) { #if UNITY_EDITOR DestroyImmediate(_iesTexture); #else Destroy(_iesTexture); #endif } }
private static void ReadProperties(string[] lines, ref int lineNumber, out int numberOfVerticalAngles, out int numberOfHorizontalAngles, out PhotometricType photometricType) { List <float> list = ParseIES.ReadValues(lines, 13, ref lineNumber); numberOfVerticalAngles = (int)list[3]; numberOfHorizontalAngles = (int)list[4]; photometricType = (PhotometricType)list[5]; }
private static float CalculateHalfSpotFov(IESData iesData) { if (iesData.VerticalType == VerticalType.Bottom && iesData.VerticalAngles[0] == 0f) { return(ParseIES.CalculateHalfSpotlightFovForBottomHalf(iesData)); } if (iesData.VerticalType == VerticalType.Top || (iesData.VerticalType == VerticalType.Bottom && iesData.VerticalAngles[0] == -90f)) { return(ParseIES.CalculateHalfSpotlightFovForTopHalf(iesData)); } return(-1f); }
private static void DiscardBottomHalf(IESData iesData) { int num = 0; int num2 = 0; while (num2 < iesData.VerticalAngles.Count && iesData.VerticalAngles[num2] != 90f) { num++; num2++; } ParseIES.DiscardHalf(iesData, 0, num); }
private static void PadToSquare(IESData iesData) { if (Mathf.Abs(iesData.HorizontalAngles.Count - iesData.VerticalAngles.Count) <= 1) { return; } int num = Mathf.Max(iesData.HorizontalAngles.Count, iesData.VerticalAngles.Count); if (iesData.HorizontalAngles.Count < num) { ParseIES.PadHorizontal(iesData, num); return; } ParseIES.PadVertical(iesData, num); }
public static IESData Parse(string path, NormalizationMode normalizationMode) { string[] array = File.ReadAllLines(path); int num = 0; ParseIES.FindNumberOfAnglesLine(array, ref num); if (num == array.Length - 1) { throw new IESParseException("No line containing number of angles found."); } int numberOfValuesToFind; int num2; PhotometricType photometricType; ParseIES.ReadProperties(array, ref num, out numberOfValuesToFind, out num2, out photometricType); List <float> verticalAngles = ParseIES.ReadValues(array, numberOfValuesToFind, ref num); List <float> horizontalAngles = ParseIES.ReadValues(array, num2, ref num); List <List <float> > list = new List <List <float> >(); for (int i = 0; i < num2; i++) { list.Add(ParseIES.ReadValues(array, numberOfValuesToFind, ref num)); } IESData iesdata = new IESData { VerticalAngles = verticalAngles, HorizontalAngles = horizontalAngles, CandelaValues = list, PhotometricType = photometricType }; ParseIES.NormalizeValues(iesdata, normalizationMode == NormalizationMode.Logarithmic); if (normalizationMode == NormalizationMode.EqualizeHistogram) { ParseIES.EqualizeHistogram(iesdata); } if (photometricType != PhotometricType.TypeA) { ParseIES.DiscardUnusedVerticalHalf(iesdata); ParseIES.SetVerticalAndHorizontalType(iesdata); iesdata.HalfSpotlightFov = ParseIES.CalculateHalfSpotFov(iesdata); } else { ParseIES.PadToSquare(iesdata); } return(iesdata); }
private static void DiscardTopHalf(IESData iesData) { int num = 0; for (int i = 0; i < iesData.VerticalAngles.Count; i++) { if (iesData.VerticalAngles[i] == 90f) { num = i + 1; break; } } int range = iesData.VerticalAngles.Count - num; ParseIES.DiscardHalf(iesData, num, range); }
private static void DiscardUnusedVerticalHalf(IESData iesData) { if (iesData.VerticalAngles[0] != 0f || iesData.VerticalAngles[iesData.VerticalAngles.Count - 1] != 180f) { return; } int k = 0; while (k < iesData.VerticalAngles.Count && !iesData.NormalizedValues.Any((List <float> slice) => slice[k] > 0.1f)) { if (iesData.VerticalAngles[k] == 90f) { ParseIES.DiscardBottomHalf(iesData); return; } if (iesData.VerticalAngles[k] > 90f) { iesData.VerticalAngles[k] = 90f; ParseIES.DiscardBottomHalf(iesData); return; } int j = k; k = j + 1; } int i = iesData.VerticalAngles.Count - 1; while (i >= 0 && !iesData.NormalizedValues.Any((List <float> slice) => slice[i] > 0.1f)) { if (iesData.VerticalAngles[i] == 90f) { ParseIES.DiscardTopHalf(iesData); return; } if (iesData.VerticalAngles[i] < 90f) { iesData.VerticalAngles[i] = 90f; ParseIES.DiscardTopHalf(iesData); return; } int j = i; i = j - 1; } }
public void ConvertIES(string filePath, string targetPath, bool createSpotlightCookies, bool rawImport, bool applyVignette, out Cubemap pointLightCookie, out Texture2D spotlightCookie, out EXRData exrData, out string targetFilename) { IESData iesdata = ParseIES.Parse(filePath, rawImport ? NormalizationMode.Linear : this.NormalizationMode); this._iesTexture = IESToTexture.ConvertIesData(iesdata); if (!rawImport) { exrData = default(EXRData); this.RegularImport(filePath, targetPath, createSpotlightCookies, applyVignette, out pointLightCookie, out spotlightCookie, out targetFilename, iesdata); } else { pointLightCookie = null; spotlightCookie = null; this.RawImport(iesdata, filePath, targetPath, createSpotlightCookies, out exrData, out targetFilename); } if (this._iesTexture != null) { UnityEngine.Object.Destroy(this._iesTexture); } }
/// <summary> /// Converts an IES file to either a point or spot light cookie. /// </summary> public void ConvertIES(string filePath, string targetPath, bool createSpotlightCookies, out Cubemap pointLightCookie, out Texture2D spotlightCookie, out string targetFilename) { // Parse the ies data. IESData iesData = ParseIES.Parse(filePath, SquashHistogram); IesTexture = IESToTexture.ConvertIesData(iesData, Resolution); // If spot light cookie creation is enabled, check if the ies data can be projected into a spot light cookie. // Only half the sphere may be provided if the ies data is to fit inside a spot light cookie. if (createSpotlightCookies && iesData.VerticalType != VerticalType.Full) { pointLightCookie = null; GetComponent <IESToSpotlightCookie>().CreateSpotlightCookie(IesTexture, iesData, Resolution, out spotlightCookie); } // Create a point light cookie cubemap in all other cases. else { spotlightCookie = null; GetComponent <IESToCubemap>().CreateCubemap(IesTexture, iesData, Resolution, out pointLightCookie); } // Create the target file name and required folders. BuildTargetFilename(Path.GetFileNameWithoutExtension(filePath), targetPath, pointLightCookie != null, SquashHistogram, out targetFilename); }