Exemple #1
0
 public Light_(Light_ copy)
 {
     this.name    = copy.name;
     this.type    = copy.type;
     this.enabled = copy.enabled;
     colorR       = copy.colorR;
     colorG       = copy.colorG;
     colorB       = copy.colorB;
     this.power   = copy.power;
     position     = new Vector3(copy.position.X, copy.position.Y, copy.position.Z);
     direction    = new Vector3(copy.direction.X, copy.direction.Y, copy.direction.Z);
     innerAngle   = copy.innerAngle;
     outerAngle   = copy.outerAngle;
     goniometric  = copy.goniometric;
 }
 public Light_(Light_ copy)
 {
     this.name = copy.name;
     this.type = copy.type;
     this.enabled = copy.enabled;
     colorR = copy.colorR;
     colorG = copy.colorG;
     colorB = copy.colorB;
     this.power = copy.power;
     position = new Vector3(copy.position.X, copy.position.Y, copy.position.Z);
     direction = new Vector3(copy.direction.X, copy.direction.Y, copy.direction.Z);
     innerAngle = copy.innerAngle;
     outerAngle = copy.outerAngle;
     goniometric = copy.goniometric;
 }
 public Light_()
 {
     name = "default";
     type = Light_Type.Point;
     enabled = true;
     colorR = 1;
     colorG = 1;
     colorB = 1;
     power = 20;
     position = new Vector3(0, 0, 0);
     direction = new Vector3(1, 0, 0);
     innerAngle = 30;
     outerAngle = 60;
     goniometric = new SortedList<float, float>{{0, 1}, {180, 1}};
 }
 public Light_(String name, Light_Type type, bool enabled, float r,
     float g, float b, float power, Vector3 position)
 {
     this.name = name;
     this.type = type;
     this.enabled = enabled;
     colorR = r;
     colorG = g;
     colorB = b;
     this.power = power;
     this.position = position;
     direction = new Vector3(1, 0, 0);
     innerAngle = -1;
     outerAngle = -1;
     goniometric = new SortedList<float, float> {{0, 1}, {180, 1}};
 }
 public Light_(String name, Light_Type type, bool enabled, float r,
     float g, float b, float power, float x, float y, float z)
 {
     this.name = name;
     this.type = type;
     this.enabled = enabled;
     colorR = r;
     colorG = g;
     colorB = b;
     this.power = power;
     position = new Vector3(x, y, z);
     direction = new Vector3();
     innerAngle = -1;
     outerAngle = -1;
     goniometric = null;
 }
 public Light_(String name, Light_Type type, bool enabled, float r,
               float g, float b, float power, float x, float y, float z)
 {
     this.name    = name;
     this.type    = type;
     this.enabled = enabled;
     colorR       = r;
     colorG       = g;
     colorB       = b;
     this.power   = power;
     position     = new Vector3(x, y, z);
     direction    = new Vector3();
     innerAngle   = -1;
     outerAngle   = -1;
     goniometric  = null;
 }
Exemple #7
0
 public Light_()
 {
     name        = "default";
     type        = Light_Type.Point;
     enabled     = true;
     colorR      = 1;
     colorG      = 1;
     colorB      = 1;
     power       = 20;
     position    = new Vector3(0, 0, 0);
     direction   = new Vector3(1, 0, 0);
     innerAngle  = 30;
     outerAngle  = 60;
     goniometric = new SortedList <float, float> {
         { 0, 1 }, { 180, 1 }
     };
 }
Exemple #8
0
 public Light_(String name, Light_Type type, bool enabled, float r,
               float g, float b, float power, Vector3 position,
               Vector3 direction, float innerAngle, float outerAngle,
               SortedList <float, float> goniometric)
 {
     this.name        = name;
     this.type        = type;
     this.enabled     = enabled;
     colorR           = r;
     colorG           = g;
     colorB           = b;
     this.power       = power;
     this.position    = position;
     this.direction   = direction;
     this.innerAngle  = innerAngle;
     this.outerAngle  = outerAngle;
     this.goniometric = goniometric;
 }
Exemple #9
0
 public Light_(String name, Light_Type type, bool enabled, float r,
               float g, float b, float power, Vector3 position)
 {
     this.name     = name;
     this.type     = type;
     this.enabled  = enabled;
     colorR        = r;
     colorG        = g;
     colorB        = b;
     this.power    = power;
     this.position = position;
     direction     = new Vector3(1, 0, 0);
     innerAngle    = -1;
     outerAngle    = -1;
     goniometric   = new SortedList <float, float> {
         { 0, 1 }, { 180, 1 }
     };
 }
 public Light_(String name, Light_Type type, bool enabled, float r,
     float g, float b, float power, Vector3 position,
     Vector3 direction, float innerAngle, float outerAngle,
     SortedList<float, float> goniometric)
 {
     this.name = name;
     this.type = type;
     this.enabled = enabled;
     colorR = r;
     colorG = g;
     colorB = b;
     this.power = power;
     this.position = position;
     this.direction = direction;
     this.innerAngle = innerAngle;
     this.outerAngle = outerAngle;
     this.goniometric = goniometric;
 }
Exemple #11
0
        public static List <Light_> LoadLights(string file)
        {
            List <Light_> lights = new List <Light_>();

            try
            {
                List <string> text    = File.ReadFileLines(file);
                int           pointer = 0;

                string lightsLabel = File.GetAttribute(text[pointer], 0);
                if (lightsLabel != "lights_count")
                {
                    return(null);
                }
                uint lightsNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                for (int i = 0; i < lightsNum; ++i)
                {
                    string[] lightName = File.GetAttributes(text[pointer]);
                    if (lightName[0] != "light_name")
                    {
                        return(null);
                    }
                    string name = name = File.CutFirstString(text[pointer]);
                    ++pointer;

                    string enabledLabel = File.GetAttribute(text[pointer], 0);
                    if (enabledLabel != "enabled")
                    {
                        return(null);
                    }
                    bool enabled = int.Parse(File.GetAttribute(text[pointer++], 1)) == 1 ? true : false;

                    string typeLabel = File.GetAttribute(text[pointer], 0);
                    if (typeLabel != "light_type")
                    {
                        return(null);
                    }
                    Light_Type type = Light_Type.Point;
                    switch (File.GetAttribute(text[pointer++], 1))
                    {
                    case "point":
                        type = Light_Type.Point;
                        break;

                    case "spot":
                        type = Light_Type.Spot;
                        break;

                    case "goniometric":
                        type = Light_Type.Goniometric;
                        break;
                    }

                    string colorLabel = File.GetAttribute(text[pointer], 0);
                    if (colorLabel != "rgb")
                    {
                        return(null);
                    }
                    float colorR = float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture);
                    float colorG = float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture);
                    float colorB = float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture);

                    string powerLabel = File.GetAttribute(text[pointer], 0);
                    if (powerLabel != "power")
                    {
                        return(null);
                    }
                    float power = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                    string posLabel = File.GetAttribute(text[pointer], 0);
                    if (posLabel != "pos")
                    {
                        return(null);
                    }
                    Vector3 pos = new Vector3(float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture));

                    string dirLabel = File.GetAttribute(text[pointer], 0);
                    if (dirLabel != "dir")
                    {
                        return(null);
                    }
                    Vector3 dir = new Vector3(float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture));

                    string innerAngleLabel = File.GetAttribute(text[pointer], 0);
                    if (innerAngleLabel != "inner_angle")
                    {
                        return(null);
                    }
                    float  innerAngle      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    string outerAngleLabel = File.GetAttribute(text[pointer], 0);
                    if (outerAngleLabel != "outer_angle")
                    {
                        return(null);
                    }
                    float outerAngle = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                    SortedList <float, float> goniometric = new SortedList <float, float>();

                    string gonioNumLabel = File.GetAttribute(text[pointer], 0);
                    if (gonioNumLabel != "gonio_count")
                    {
                        return(null);
                    }
                    uint gonioNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                    for (int j = 0; j < gonioNum; ++j)
                    {
                        float gonioIndex = float.Parse(File.GetAttribute(text[pointer], 0), CultureInfo.InvariantCulture);
                        float gonioValue = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                        goniometric.Add(gonioIndex, gonioValue);
                    }

                    lights.Add(new Light_(name, type, enabled, colorR, colorG, colorB, power, pos));

                    lights[lights.Count - 1].direction   = new Vector3(dir.X, dir.Y, dir.Z);
                    lights[lights.Count - 1].innerAngle  = innerAngle;
                    lights[lights.Count - 1].outerAngle  = outerAngle;
                    lights[lights.Count - 1].goniometric = goniometric;
                }
            }
            catch (Exception)
            {
                return(null);
            }

            return(lights);
        }
        public static List<Light_> LoadLights(string file)
        {
            List<Light_> lights = new List<Light_>();

            try
            {
                List<string> text = File.ReadFileLines(file);
                int pointer = 0;

                string lightsLabel = File.GetAttribute(text[pointer], 0);
                if(lightsLabel != "lights_count")
                {
                    return null;
                }
                uint lightsNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                for(int i = 0; i < lightsNum; ++i)
                {
                    string[] lightName = File.GetAttributes(text[pointer]);
                    if(lightName[0] != "light_name")
                    {
                        return null;
                    }
                    string name = name = File.CutFirstString(text[pointer]);
                    ++pointer;

                    string enabledLabel = File.GetAttribute(text[pointer], 0);
                    if(enabledLabel != "enabled")
                    {
                        return null;
                    }
                    bool enabled = int.Parse(File.GetAttribute(text[pointer++], 1)) == 1 ? true : false;

                    string typeLabel = File.GetAttribute(text[pointer], 0);
                    if(typeLabel != "light_type")
                    {
                        return null;
                    }
                    Light_Type type = Light_Type.Point;
                    switch(File.GetAttribute(text[pointer++], 1))
                    {
                        case "point":
                            type = Light_Type.Point;
                            break;

                        case "spot":
                            type = Light_Type.Spot;
                            break;

                        case "goniometric":
                            type = Light_Type.Goniometric;
                            break;
                    }

                    string colorLabel = File.GetAttribute(text[pointer], 0);
                    if(colorLabel != "rgb")
                    {
                        return null;
                    }
                    float colorR = float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture);
                    float colorG = float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture);
                    float colorB = float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture);

                    string powerLabel = File.GetAttribute(text[pointer], 0);
                    if(powerLabel != "power")
                    {
                        return null;
                    }
                    float power = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                    string posLabel = File.GetAttribute(text[pointer], 0);
                    if(posLabel != "pos")
                    {
                        return null;
                    }
                    Vector3 pos = new Vector3(float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture),
                        float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture),
                        float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture));

                    string dirLabel = File.GetAttribute(text[pointer], 0);
                    if(dirLabel != "dir")
                    {
                        return null;
                    }
                    Vector3 dir = new Vector3(float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture),
                        float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture),
                        float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture));

                    string innerAngleLabel = File.GetAttribute(text[pointer], 0);
                    if(innerAngleLabel != "inner_angle")
                    {
                        return null;
                    }
                    float innerAngle = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    string outerAngleLabel = File.GetAttribute(text[pointer], 0);
                    if(outerAngleLabel != "outer_angle")
                    {
                        return null;
                    }
                    float outerAngle = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                    SortedList<float, float> goniometric = new SortedList<float, float>();

                    string gonioNumLabel = File.GetAttribute(text[pointer], 0);
                    if(gonioNumLabel != "gonio_count")
                    {
                        return null;
                    }
                    uint gonioNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                    for(int j = 0; j < gonioNum; ++j)
                    {
                        float gonioIndex = float.Parse(File.GetAttribute(text[pointer], 0), CultureInfo.InvariantCulture);
                        float gonioValue = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                        goniometric.Add(gonioIndex, gonioValue);
                    }

                    lights.Add(new Light_(name, type, enabled, colorR, colorG, colorB, power, pos));

                    lights[lights.Count - 1].direction = new Vector3(dir.X, dir.Y, dir.Z);
                    lights[lights.Count - 1].innerAngle = innerAngle;
                    lights[lights.Count - 1].outerAngle = outerAngle;
                    lights[lights.Count - 1].goniometric = goniometric;
                }
            }
            catch(Exception)
            {
                return null;
            }

            return lights;
        }
        public static Scene ReadSceneFromFile(string file)
        {
            Scene scene = new Scene();

            try
            {
                List <string> text    = File.ReadFileLines(file);
                int           pointer = 0;

                string pointsNumLabel = File.GetAttribute(text[pointer], 0);
                if (pointsNumLabel != "points_count")
                {
                    return(null);
                }
                uint pointsNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                List <Vector3D> points = new List <Vector3D>();

                for (int i = 0; i < pointsNum; ++i)
                {
                    points.Add(new Vector3D(float.Parse(File.GetAttribute(text[pointer], 0), CultureInfo.InvariantCulture),
                                            float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture),
                                            float.Parse(File.GetAttribute(text[pointer++], 2), CultureInfo.InvariantCulture)));
                }

                string triangleNumLabel = File.GetAttribute(text[pointer], 0);
                if (triangleNumLabel != "triangles_count")
                {
                    return(null);
                }
                uint triangleNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                List <Triangle> triangles = new List <Triangle>();

                for (int i = 0; i < triangleNum; ++i)
                {
                    triangles.Add(new Triangle(uint.Parse(File.GetAttribute(text[pointer], 0)), uint.Parse(File.GetAttribute(text[pointer], 1)),
                                               uint.Parse(File.GetAttribute(text[pointer++], 2))));
                }

                string partsNumLabel = File.GetAttribute(text[pointer], 0);
                if (partsNumLabel != "parts_count")
                {
                    return(null);
                }
                uint partsNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                List <uint> trPart = new List <uint>();

                string[] atts = File.GetAttributes(text[pointer]);
                for (int i = 0; i < triangleNum; ++i)
                {
                    trPart.Add(uint.Parse(atts[i]));
                }
                ++pointer;

                List <Part> parts = new List <Part>();

                for (int i = 0; i < partsNum; ++i)
                {
                    List <int> partTriangles = new List <int>();

                    for (int j = 0; j < trPart.Count; ++j)
                    {
                        if (trPart[j] == i)
                        {
                            partTriangles.Add(j);
                        }
                    }

                    parts.Add(new Part(partTriangles));
                }


                string matNumLabel = File.GetAttribute(text[pointer], 0);
                if (matNumLabel != "materials_count")
                {
                    return(null);
                }
                uint matNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                List <Material_> materials = new List <Material_>();

                for (int i = 0; i < matNum; ++i)
                {
                    string matNameLabel = File.GetAttribute(text[pointer], 0);
                    if (matNameLabel != "mat_name")
                    {
                        return(null);
                    }
                    string name = File.GetAttribute(text[pointer++], 1);

                    string rgbLabel = File.GetAttribute(text[pointer], 0);
                    if (rgbLabel != "rgb")
                    {
                        return(null);
                    }
                    float colorR = float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture);
                    float colorG = float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture);
                    float colorB = float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture);

                    string kdCrLabel = File.GetAttribute(text[pointer], 0);
                    float  kdCr      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (kdCrLabel != "kdCr")
                    {
                        return(null);
                    }
                    string kdCgLabel = File.GetAttribute(text[pointer], 0);
                    float  kdCg      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (kdCgLabel != "kdCg")
                    {
                        return(null);
                    }
                    string kdCbLabel = File.GetAttribute(text[pointer], 0);
                    float  kdCb      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (kdCbLabel != "kdCb")
                    {
                        return(null);
                    }

                    string ksCrLabel = File.GetAttribute(text[pointer], 0);
                    float  ksCr      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (ksCrLabel != "ksCr")
                    {
                        return(null);
                    }
                    string ksCgLabel = File.GetAttribute(text[pointer], 0);
                    float  ksCg      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (ksCgLabel != "ksCg")
                    {
                        return(null);
                    }
                    string ksCbLabel = File.GetAttribute(text[pointer], 0);
                    float  ksCb      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (ksCbLabel != "ksCb")
                    {
                        return(null);
                    }

                    string krCrLabel = File.GetAttribute(text[pointer], 0);
                    float  krCr      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (krCrLabel != "krCr")
                    {
                        return(null);
                    }
                    string krCgLabel = File.GetAttribute(text[pointer], 0);
                    float  krCg      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (krCgLabel != "krCg")
                    {
                        return(null);
                    }
                    string krCbLabel = File.GetAttribute(text[pointer], 0);
                    float  krCb      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (krCbLabel != "krCb")
                    {
                        return(null);
                    }

                    string kaCrLabel = File.GetAttribute(text[pointer], 0);
                    float  kaCr      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (kaCrLabel != "kaCr")
                    {
                        return(null);
                    }
                    string kaCgLabel = File.GetAttribute(text[pointer], 0);
                    float  kaCg      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (kaCgLabel != "kaCg")
                    {
                        return(null);
                    }
                    string kaCbLabel = File.GetAttribute(text[pointer], 0);
                    float  kaCb      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (kaCbLabel != "kaCb")
                    {
                        return(null);
                    }

                    string gLabel = File.GetAttribute(text[pointer], 0);
                    float  g      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (gLabel != "g")
                    {
                        return(null);
                    }
                    string nLabel = File.GetAttribute(text[pointer], 0);
                    float  n      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    if (nLabel != "n")
                    {
                        return(null);
                    }

                    materials.Add(new Material_(name, colorR, colorG, colorB, kdCr, kdCg, kdCb, ksCr, ksCg, ksCb, krCr, krCg, krCb, kaCr, kaCg, kaCb, g, n));
                }

                List <string> matAssign = new List <string>();

                for (int i = 0; i < partsNum; ++i)
                {
                    matAssign.Add(File.GetAttribute(text[pointer++], 1));
                }

                string lightsLabel = File.GetAttribute(text[pointer], 0);
                if (lightsLabel != "lights_count")
                {
                    return(null);
                }
                uint lightsNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                List <Light_> lights = new List <Light_>();

                for (int i = 0; i < lightsNum; ++i)
                {
                    string nameLabel = File.GetAttribute(text[pointer], 0);
                    if (nameLabel != "light_name")
                    {
                        return(null);
                    }
                    string name = File.GetAttribute(text[pointer++], 1);

                    string enabledLabel = File.GetAttribute(text[pointer], 0);
                    if (enabledLabel != "enabled")
                    {
                        return(null);
                    }
                    bool enabled = int.Parse(File.GetAttribute(text[pointer++], 1)) == 1 ? true : false;

                    string typeLabel = File.GetAttribute(text[pointer], 0);
                    if (typeLabel != "light_type")
                    {
                        return(null);
                    }
                    Light_Type type = Light_Type.Point;
                    switch (File.GetAttribute(text[pointer++], 1))
                    {
                    case "point":
                        type = Light_Type.Point;
                        break;

                    case "spot":
                        type = Light_Type.Spot;
                        break;

                    case "goniometric":
                        type = Light_Type.Goniometric;
                        break;
                    }

                    string colorLabel = File.GetAttribute(text[pointer], 0);
                    if (colorLabel != "rgb")
                    {
                        return(null);
                    }
                    float colorR = float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture);
                    float colorG = float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture);
                    float colorB = float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture);

                    string powerLabel = File.GetAttribute(text[pointer], 0);
                    if (powerLabel != "power")
                    {
                        return(null);
                    }
                    float power = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                    string posLabel = File.GetAttribute(text[pointer], 0);
                    if (posLabel != "pos")
                    {
                        return(null);
                    }
                    Vector3 pos = new Vector3(float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture));

                    string dirLabel = File.GetAttribute(text[pointer], 0);
                    if (dirLabel != "dir")
                    {
                        return(null);
                    }
                    Vector3 dir = new Vector3(float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture));

                    string innerAngleLabel = File.GetAttribute(text[pointer], 0);
                    if (innerAngleLabel != "inner_angle")
                    {
                        return(null);
                    }
                    float  innerAngle      = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    string outerAngleLabel = File.GetAttribute(text[pointer], 0);
                    if (outerAngleLabel != "outer_angle")
                    {
                        return(null);
                    }
                    float outerAngle = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                    SortedList <float, float> goniometric = new SortedList <float, float>();

                    string gonioNumLabel = File.GetAttribute(text[pointer], 0);
                    if (gonioNumLabel != "gonio_count")
                    {
                        return(null);
                    }
                    uint gonioNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                    for (int j = 0; j < gonioNum; ++j)
                    {
                        float gonioIndex = float.Parse(File.GetAttribute(text[pointer], 0), CultureInfo.InvariantCulture);
                        float gonioValue = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                        goniometric.Add(gonioIndex, gonioValue);
                    }

                    lights.Add(new Light_(name, type, enabled, colorR, colorG, colorB, power, pos.X, pos.Y, pos.Z));

                    lights[lights.Count - 1].direction   = new Vector3(dir.X, dir.Y, dir.Z);
                    lights[lights.Count - 1].innerAngle  = innerAngle;
                    lights[lights.Count - 1].outerAngle  = outerAngle;
                    lights[lights.Count - 1].goniometric = goniometric;
                }

                string camsNumLabel = File.GetAttribute(text[pointer], 0);
                if (camsNumLabel != "cams_count")
                {
                    return(null);
                }
                uint camsNum = uint.Parse(File.GetAttribute(text[pointer++], 1));

                List <Camera> cams = new List <Camera>();

                string activeCamLabel = File.GetAttribute(text[pointer], 0);
                if (activeCamLabel != "active")
                {
                    return(null);
                }
                uint activeCam = uint.Parse(File.GetAttribute(text[pointer++], 1));

                for (int i = 0; i < camsNum; ++i)
                {
                    string nameLabel = File.GetAttribute(text[pointer], 0);
                    if (nameLabel != "cam_name")
                    {
                        return(null);
                    }
                    string name = File.GetAttribute(text[pointer++], 1);

                    string resLabel = File.GetAttribute(text[pointer], 0);
                    if (resLabel != "resolution")
                    {
                        return(null);
                    }
                    Pair <int, int> res = new Pair <int, int>(int.Parse(File.GetAttribute(text[pointer], 1)), int.Parse(File.GetAttribute(text[pointer++], 2)));

                    string posLabel = File.GetAttribute(text[pointer], 0);
                    if (posLabel != "pos")
                    {
                        return(null);
                    }
                    Vector3 pos = new Vector3(float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture),
                                              float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture));

                    string lookAtLabel = File.GetAttribute(text[pointer], 0);
                    if (lookAtLabel != "lookAt")
                    {
                        return(null);
                    }
                    Vector3 lookAt = new Vector3(float.Parse(File.GetAttribute(text[pointer], 1), CultureInfo.InvariantCulture),
                                                 float.Parse(File.GetAttribute(text[pointer], 2), CultureInfo.InvariantCulture),
                                                 float.Parse(File.GetAttribute(text[pointer++], 3), CultureInfo.InvariantCulture));

                    string fovAngleLabel = File.GetAttribute(text[pointer], 0);
                    if (fovAngleLabel != "fov")
                    {
                        return(null);
                    }
                    float  fovAngle         = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);
                    string rotateAngleLabel = File.GetAttribute(text[pointer], 0);
                    if (rotateAngleLabel != "rotation")
                    {
                        return(null);
                    }
                    float rotateAngle = float.Parse(File.GetAttribute(text[pointer++], 1), CultureInfo.InvariantCulture);

                    cams.Add(new Camera(name, res.First, res.Second, pos, lookAt, fovAngle, rotateAngle));
                }

                HierarchyNode root = new HierarchyNode("Hierarchy");

                ReadHierarchy(root, lights, text, pointer);
                if (root == null)
                {
                    return(null);
                }

                Hierarchy hierarchy = new Hierarchy();
                hierarchy.objects = root.hObjects;

                scene.points         = points;
                scene.triangles      = triangles;
                scene.parts          = parts;
                scene.materials      = materials;
                scene.materialAssign = matAssign;
                scene.lights         = lights;
                scene.cams           = cams;
                scene.activeCamera   = (int)activeCam;
                scene.hierarchy      = hierarchy;
            }
            catch (Exception)
            {
                return(null);
            }

            return(scene);
        }
Exemple #14
0
 public void Light(bool judge, Light_Type light)
 {
 }