예제 #1
0
 public ScreenSize GetScreenSize(FilmFormatData format, string screenSizeName)
 {
     if (format != null)
     {
         foreach (ScreenSize ss in format._screenSizes)
         {
             if (ss.name == screenSizeName)
             {
                 return(ss);
             }
         }
     }
     return(new ScreenSize());
 }
 public ScreenSize GetScreenSize(FilmFormatData format, string screenSizeName)
 {
     if (format != null)
     {
         foreach (ScreenSize ss in format._screenSizes)
         {
             if (ss.name == screenSizeName)
             {
                 return ss;
             }
         }
     }
     return new ScreenSize();
 }
예제 #3
0
    public void LoadLensData()
    {
        _filmFormats = new List <FilmFormatData>();

        // Load in the data from Resources/CinemaSuite_LensData.txt
        TextAsset textAsset = (TextAsset)(Resources.Load("CinemaSuite_LensData", typeof(TextAsset)));

        if (textAsset == null)
        {
            Debug.LogError("File 'CinemaSuite_LensData.txt' is not found in Resources folder. Unable to load lens data.");
            return;
        }

        FilmFormatData currentFormat = null;

        string[] lines    = textAsset.text.Split("\n"[0]);
        int      numLines = lines.Length;

        for (int i = 0; i < numLines; ++i)
        {
            //Debug.Log("Line: " + i + "= " + lines[i]);

            string line = lines[i].Trim();
            if (line.StartsWith("#"))
            {
                continue;
            }

            int length = line.Length;

            if (currentFormat == null)
            {
                // Look for "Name="
                if (line.StartsWith("Name="))
                {
                    // New section

                    int index = line.IndexOf("=") + 1;
                    if (index < length)
                    {
                        string name = line.Substring(index).Trim();
                        if (name.Length != 0)
                        {
                            // Create new film format with valid name
                            currentFormat             = new FilmFormatData();
                            currentFormat._formatName = name;
                        }
                    }
                }
                else if (length != 0)
                {
                    Debug.LogError("Invalid data at line: " + i);
                }
            }
            else
            {
                // Look for film format section entries

                if (length == 0)
                {
                    // End of section
                    _filmFormats.Add(currentFormat);
                    //Debug.Log ("Added film format " + currentFormat._formatName);
                    currentFormat = null;
                }
                else if (line.StartsWith("Aspect="))
                {
                    int index = line.IndexOf("=") + 1;
                    if (index < length)
                    {
                        string strAspect = line.Substring(index).Trim();
                        int    colon     = strAspect.IndexOf(":");
                        if (colon > 0 && colon < length)
                        {
                            string first  = strAspect.Substring(0, colon).Trim();
                            string second = strAspect.Substring(colon + 1).Trim();
                            float  w      = 0;
                            float  h      = 0;

                            if (!float.TryParse(first, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out w) || w <= 0)
                            {
                                Debug.LogError("Invalid number: " + first + " at line " + (i + 1));
                                return;
                            }
                            if (!float.TryParse(second, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out h) || h <= 0)
                            {
                                Debug.LogError("Invalid number: " + second + " at line " + (i + 1));
                                return;
                            }
                            currentFormat._aspect = w / h;
                            //Debug.Log ("Aspect: " + currentFormat._aspect);
                        }
                    }
                }
                else if (line.StartsWith("ScreenSize"))
                {
                    int index = line.IndexOf("=") + 1;
                    if (index < length)
                    {
                        // ScreenSize=DI,1024
                        string[] strSizes = line.Substring(index).Split(","[0]);
                        if (strSizes == null || strSizes.Length != 2)
                        {
                            Debug.LogError("Invalid screen size entry at line " + (i + 1));
                            return;
                        }

                        string sizeName  = strSizes[0].Trim();
                        int    sizeValue = 0;
                        if (!int.TryParse(strSizes[1].Trim(), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out sizeValue) || sizeValue <= 0)
                        {
                            Debug.LogError("Invalid screen size at line " + (i + 1));
                            return;
                        }
                        currentFormat._screenSizes.Add(new ScreenSize(sizeName, sizeValue));
                        //Debug.Log ("Screensize: " + sizeName + ", " + sizeValue);
                    }
                }
                else if (line.StartsWith("FocalLength"))
                {
                    int index = line.IndexOf("=") + 1;
                    if (index < length)
                    {
                        // FocalLength=Cooke S4/i - T2,12mm,4.980,00.000,00.000
                        string[] strData = line.Substring(index).Split(","[0]);
                        if (strData == null || strData.Length != 5)
                        {
                            Debug.LogError("Invalid data for focal length at line " + (i + 1));
                            return;
                        }

                        string lensKit = strData[0].Trim();
                        if (lensKit.Length == 0)
                        {
                            Debug.LogError("Invalid lens kit name at line " + (i + 1));
                            return;
                        }

                        int focal = 0;
                        if (!int.TryParse(strData[1].TrimEnd('m'), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out focal) || focal <= 0)
                        {
                            Debug.LogError("Invalid focal length at line " + (i + 1));
                            return;
                        }

                        float nodal = 0;
                        if (!float.TryParse(strData[2].Trim(), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out nodal) || nodal < 0)
                        {
                            Debug.LogError("Invalid nodal offset at line " + (i + 1));
                            return;
                        }

                        float realFOV = 0;
                        if (!float.TryParse(strData[3].Trim(), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out realFOV) || realFOV <= 0)
                        {
                            Debug.LogError("Invalid real FOV at line " + (i + 1));
                            return;
                        }

                        float unityFOV = 0;
                        if (!float.TryParse(strData[4].Trim(), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out unityFOV) || unityFOV <= 0)
                        {
                            Debug.LogError("Invalid Unity FOV at line " + (i + 1));
                            return;
                        }

                        currentFormat.AddFocalLengthData(lensKit, focal, nodal, realFOV, unityFOV);
                        //Debug.Log ("Focal Data: " + lensKit + ", " + focal + ", " + nodal + ", " + realFOV + ", " + unityFOV);
                    }
                }
            }
        }
    }
	public void LoadLensData()
	{
		_filmFormats = new List<FilmFormatData>();
		
		// Load in the data from Resources/CinemaSuite_LensData.txt
		TextAsset textAsset = (TextAsset)(Resources.Load("CinemaSuite_LensData", typeof(TextAsset)));
		if(textAsset == null)
		{
			Debug.LogError("File 'CinemaSuite_LensData.txt' is not found in Resources folder. Unable to load lens data.");
			return;
		}
		
		FilmFormatData currentFormat = null;
		
		string[] lines = textAsset.text.Split("\n"[0]);
		int numLines = lines.Length;
		for(int i = 0; i < numLines; ++i)
		{
			//Debug.Log("Line: " + i + "= " + lines[i]);
			
			string line = lines[i].Trim();
			if(line.StartsWith("#"))
			{
				continue;	
			}
			
			int length = line.Length;
			
			if(currentFormat == null)
			{
				// Look for "Name="
				if(line.StartsWith("Name="))
				{
					// New section

					int index = line.IndexOf("=") + 1;
					if(index < length)
					{
						string name = line.Substring(index).Trim();
						if(name.Length != 0)
						{
							// Create new film format with valid name
							currentFormat = new FilmFormatData();
							currentFormat._formatName = name;
						}
					}
				}
				else if(length != 0)
				{
					Debug.LogError("Invalid data at line: " + i);
				}
			}
			else
			{
				// Look for film format section entries
				
				if(length == 0)
				{
					// End of section
					_filmFormats.Add(currentFormat);
					//Debug.Log ("Added film format " + currentFormat._formatName);
					currentFormat = null;
				}
				else if(line.StartsWith("Aspect="))
				{
					int index = line.IndexOf("=") + 1;
					if(index < length)
					{
						string strAspect = line.Substring(index).Trim();
						int colon = strAspect.IndexOf(":");
						if(colon > 0 && colon < length)
						{
							string first = strAspect.Substring(0, colon).Trim();
							string second = strAspect.Substring(colon + 1).Trim();
							float w = 0;
							float h = 0;
							
							if(!float.TryParse(first, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out w) || w <= 0)
							{
								Debug.LogError("Invalid number: " + first + " at line " + (i + 1));
								return;
							}
							if(!float.TryParse(second, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out h) || h <= 0)
							{
								Debug.LogError("Invalid number: " + second + " at line " + (i + 1));
								return;
							}
							currentFormat._aspect = w / h;
							//Debug.Log ("Aspect: " + currentFormat._aspect);
						}
					}
				}
				else if(line.StartsWith("ScreenSize"))
				{
					int index = line.IndexOf("=") + 1;
					if(index < length)
					{
						// ScreenSize=DI,1024
						string[] strSizes = line.Substring(index).Split(","[0]);
						if(strSizes == null || strSizes.Length != 2)
						{
							Debug.LogError("Invalid screen size entry at line " + (i + 1));
							return;
						}
						
						string sizeName = strSizes[0].Trim();
						int sizeValue = 0;
						if(!int.TryParse(strSizes[1].Trim(), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out sizeValue) || sizeValue <= 0)
						{
							Debug.LogError("Invalid screen size at line " + (i + 1));
							return;
						}
						currentFormat._screenSizes.Add(new ScreenSize(sizeName, sizeValue));
						//Debug.Log ("Screensize: " + sizeName + ", " + sizeValue);
					}
				}
				else if(line.StartsWith("FocalLength"))
				{
					int index = line.IndexOf("=") + 1;
					if(index < length)
					{
						// FocalLength=Cooke S4/i - T2,12mm,4.980,00.000,00.000
						string[] strData = line.Substring(index).Split(","[0]);
						if(strData == null || strData.Length != 5)
						{
							Debug.LogError("Invalid data for focal length at line " + (i + 1));
							return;
						}
						
						string lensKit = strData[0].Trim();
						if(lensKit.Length == 0)
						{
							Debug.LogError("Invalid lens kit name at line " + (i + 1));
							return;
						}
						
						int focal = 0;
						if(!int.TryParse(strData[1].TrimEnd('m'), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out focal) || focal <= 0)
						{
							Debug.LogError("Invalid focal length at line " + (i + 1));
							return;
						}
						
						float nodal = 0;
						if(!float.TryParse(strData[2].Trim(), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out nodal) || nodal < 0)
						{
							Debug.LogError("Invalid nodal offset at line " + (i + 1));
							return;
						}
						
						float realFOV = 0;
						if(!float.TryParse(strData[3].Trim(), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out realFOV) || realFOV <= 0)
						{
							Debug.LogError("Invalid real FOV at line " + (i + 1));
							return;
						}
						
						float unityFOV = 0;
						if(!float.TryParse(strData[4].Trim(), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out unityFOV) || unityFOV <= 0)
						{
							Debug.LogError("Invalid Unity FOV at line " + (i + 1));
							return;
						}
						
						currentFormat.AddFocalLengthData(lensKit, focal, nodal, realFOV, unityFOV);
						//Debug.Log ("Focal Data: " + lensKit + ", " + focal + ", " + nodal + ", " + realFOV + ", " + unityFOV);
					}
				}
			}
		}
	}