Exemple #1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            Mesh AddNewMesh = new Mesh();
            AddNewMesh = Meshes.Load("NewObj" + usecounter, "DebugPointLight");
            usecounter++;
            int Count = AddNewMesh.Parts.Count();
            for (int i = 0; i < Count; i++)
                AddNewMesh.Parts[i].Material = Materials.Load("Checker");

            if (Count < AddNewMesh.Parts.Count && Count > 0)
            {
                for (int i = Count; i < AddNewMesh.Parts.Count; i++)
                    AddNewMesh.Parts[i].Material = AddNewMesh.Parts[0].Material;
            }
            Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes.Add(AddNewMesh);

            listBox1.Items.Clear();
            foreach (Mesh element in Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes)
            {
                listBox1.Items.Add(element.Name);
            }
        }
Exemple #2
0
        public static void LoadEngineContent()
        {
            foreach (var i in Textures.TexturesList)
            {
                if (i.EngineContent)
                {
                    Textures.Load(i.Name);
                }
            }

            foreach (var i in Shaders.ShadersList)
            {
                if (i.EngineContent)
                {
                    Shaders.Load(i.Name);
                }
            }

            foreach (var i in Materials.MaterialsList)
            {
                if (i.EngineContent)
                {
                    Materials.Load(i.Name);
                }
            }

            if (Settings.Debug.Enabled)
            {
                //DebugAmbientLight = Mesh.LoadFromFile("DebugAmbientLight", Engine.CombinePaths(Settings.Paths.EngineMeshes, "DebugAmbientLight.obj"));
                //DebugDirectionalLight = Mesh.LoadFromFile("DebugDirectionalLight", Engine.CombinePaths(Settings.Paths.EngineMeshes, "DebugDirectionalLight.obj"));
                //DebugPointLight = Mesh.LoadFromFile("DebugPointLight", Engine.CombinePaths(Settings.Paths.EngineMeshes, "DebugPointLight.obj"));
                //DebugSpotLight = Mesh.LoadFromFile("DebugSpotLight", Engine.CombinePaths(Settings.Paths.EngineMeshes, "DebugSpotLight.obj"));

                //DebugAmbientLight.Parts[0].Material = Materials.Load("DebugAmbientLight");
                //DebugDirectionalLight.Parts[0].Material = Materials.Load("DebugDirectionalLight");
                //DebugPointLight.Parts[0].Material = Materials.Load("DebugPointLight");
                //DebugSpotLight.Parts[0].Material = Materials.Load("DebugSpotLight");
            }
        }
Exemple #3
0
        public static void LoadMap(string MapName = "")
        {
            try
            {
                XmlDocument XML = new XmlDocument();
                XmlNode     xmlNode;
                XmlNodeList xmlNodeList;

                XML.Load(MapsList[MapName]);

                Maps.Name = XML.DocumentElement.SelectSingleNode("Name").InnerText;

                Log.WriteLine("Loading map: \"{0}\"", MapName);

                if (XML.DocumentElement.SelectNodes("Description").Count > 0)
                {
                    Maps.Description = XML.DocumentElement.SelectSingleNode("Description").InnerText;
                }

                #region PlayerStart
                if (XML.DocumentElement.SelectNodes("PlayerStart").Count > 0)
                {
                    xmlNode = XML.DocumentElement.SelectSingleNode("PlayerStart");

                    if (xmlNode.SelectNodes("Position").Count > 0)
                    {
                        string[] Position = xmlNode.SelectSingleNode("Position").InnerText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        Game.MainCamera.Position = new Vector3(float.Parse(Position[0]), float.Parse(Position[1]), float.Parse(Position[2]));
                        PlayerStartPos           = Game.MainCamera.Position;
                    }

                    if (xmlNode.SelectNodes("Rotation").Count > 0)
                    {
                        string[] Rotation = xmlNode.SelectSingleNode("Rotation").InnerText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        float    Yaw      = float.Parse(Rotation[0]);
                        float    Pitch    = float.Parse(Rotation[1]);
                        Game.MainCamera.YawPitch = new Vector2(
                            MathHelper.DegreesToRadians(-Yaw),
                            MathHelper.DegreesToRadians(Pitch));
                        PlayerStartRot = new Vector2(Yaw, Pitch);
                    }
                }
                #endregion

                #region Camera
                if (XML.DocumentElement.SelectNodes("Camera").Count > 0)
                {
                    xmlNode = XML.DocumentElement.SelectSingleNode("Camera");

                    if (xmlNode.SelectNodes("Near").Count > 0)
                    {
                        Game.MainCamera.zNear = float.Parse(xmlNode.SelectSingleNode("Near").InnerText);
                    }
                    if (xmlNode.SelectNodes("Far").Count > 0)
                    {
                        Game.MainCamera.zFar = float.Parse(xmlNode.SelectSingleNode("Far").InnerText);
                    }
                    if (xmlNode.SelectNodes("FOV").Count > 0)
                    {
                        Game.MainCamera.FOV = float.Parse(xmlNode.SelectSingleNode("FOV").InnerText);
                    }
                    if (xmlNode.SelectNodes("MoveSpeed").Count > 0)
                    {
                        Game.MainCamera.MoveSpeed = float.Parse(xmlNode.SelectSingleNode("MoveSpeed").InnerText);
                    }
                }
                #endregion

                #region SkyBox
                if (XML.DocumentElement.SelectNodes("Skybox").Count > 0)
                {
                    string SkyBox = XML.DocumentElement.SelectSingleNode("Skybox").InnerText;

                    if (SkyBox != null && SkyBox != String.Empty)
                    {
                        Game.SkyBox = new Mesh();
                        MeshPart MPart = MeshPart.MakeBox(Game.MainCamera.zFar * 2.0f / (float)Math.Sqrt(3.0), true); // Cube diagonal = side / sqrt(3)
                        MPart.Material = Materials.Load(SkyBox);
                        Game.SkyBox.Parts.Add(MPart);
                        Game.SkyBox.CalcBoundingObjects();
                    }
                }
                #endregion

                #region Fog
                if (XML.DocumentElement.SelectNodes("Fog").Count > 0)
                {
                    xmlNode = XML.DocumentElement.SelectSingleNode("Fog");

                    if (xmlNode.SelectNodes("Enabled").Count > 0)
                    {
                        Settings.Graphics.Fog.UseFogOnMap = Convert.ToBoolean(xmlNode.SelectSingleNode("Enabled").InnerText);
                    }

                    if (xmlNode.SelectNodes("Color").Count > 0)
                    {
                        try
                        {
                            string[] Color = xmlNode.SelectSingleNode("Color").InnerText.Split(
                                new char[] { ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);

                            float R, G, B;
                            switch (Color.Length)
                            {
                            case 1:
                                R = float.Parse(Color[0]);
                                Settings.Graphics.Fog.Color = new Vector3(R, R, R);
                                break;

                            case 3:
                                R = float.Parse(Color[0]);
                                G = float.Parse(Color[1]);
                                B = float.Parse(Color[2]);
                                Settings.Graphics.Fog.Color = new Vector3(R, G, B);
                                break;

                            default:
                                break;
                            }
                        }
                        catch { }
                    }

                    if (xmlNode.SelectNodes("DistanceMin").Count > 0)
                    {
                        Settings.Graphics.Fog.MinDistance = float.Parse(xmlNode.SelectSingleNode("DistanceMin").InnerText);
                    }

                    if (xmlNode.SelectNodes("DistanceMax").Count > 0)
                    {
                        Settings.Graphics.Fog.MaxDistance = float.Parse(xmlNode.SelectSingleNode("DistanceMax").InnerText);
                    }
                }

                #endregion

                #region Models
                foreach (XmlNode xmlNodeModel in XML.DocumentElement.SelectNodes("Model"))
                {
                    Model model = new Model();
                    model.Name = xmlNodeModel.SelectSingleNode("Name").InnerText;

                    if (xmlNodeModel.SelectNodes("Visible").Count > 0)
                    {
                        model.Visible = Convert.ToBoolean(xmlNodeModel.SelectSingleNode("Visible").InnerText);
                    }

                    foreach (XmlNode xmlNodeMesh in xmlNodeModel.SelectNodes("Mesh"))
                    {
                        Mesh   mesh = new Mesh();
                        string Name = xmlNodeMesh.SelectSingleNode("Name").InnerText;

                        MeshType meshType = MeshType.Mesh;

                        if (xmlNodeMesh.SelectNodes("Type").Count > 0)
                        {
                            string meshTypeStr = xmlNodeMesh.SelectSingleNode("Type").InnerText;

                            try
                            {
                                meshType = (MeshType)Enum.Parse(typeof(MeshType), meshTypeStr, true);
                            }
                            catch
                            {
                                meshType = MeshType.Mesh;
                            }
                        }

                        float    SideA, SideB, SideC;
                        MeshPart mp;
                        bool     FlipPolygons = false;
                        switch (meshType)
                        {
                        case MeshType.Plain:
                            mesh.Name     = Name;
                            mesh.MeshName = meshType.ToString();
                            SideA         = float.Parse(xmlNodeMesh.SelectSingleNode("SideA").InnerText);
                            SideB         = float.Parse(xmlNodeMesh.SelectSingleNode("SideB").InnerText);
                            mp            = MeshPart.MakePlain(SideA, SideB);
                            mesh.Parts.Add(mp);
                            mesh.CalcBoundingObjects();
                            break;

                        case MeshType.Box:
                            mesh.Name     = Name;
                            mesh.MeshName = meshType.ToString();
                            SideA         = float.Parse(xmlNodeMesh.SelectSingleNode("SideA").InnerText);
                            SideB         = float.Parse(xmlNodeMesh.SelectSingleNode("SideB").InnerText);
                            SideC         = float.Parse(xmlNodeMesh.SelectSingleNode("SideC").InnerText);

                            if (xmlNodeMesh.SelectNodes("FlipPolygons").Count > 0)
                            {
                                FlipPolygons = Convert.ToBoolean(xmlNodeMesh.SelectSingleNode("FlipPolygons").InnerText);
                            }

                            mp = MeshPart.MakeBox(SideA, SideB, SideC, FlipPolygons);
                            mesh.Parts.Add(mp);
                            mesh.CalcBoundingObjects();
                            break;

                        case MeshType.Mesh:
                        default:
                            string MeshName = xmlNodeMesh.SelectSingleNode("Mesh").InnerText;
                            mesh = Meshes.Load(Name, MeshName);
                            break;
                        }

                        string[] Pos = xmlNodeMesh.SelectSingleNode("Position").InnerText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        mesh.Position = new Vector3(float.Parse(Pos[0]), float.Parse(Pos[1]), float.Parse(Pos[2]));

                        string[] Rot = xmlNodeMesh.SelectSingleNode("Rotation").InnerText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        mesh.Rotation = new Vector3(MathHelper.DegreesToRadians(float.Parse(Rot[0])),
                                                    MathHelper.DegreesToRadians(float.Parse(Rot[1])), MathHelper.DegreesToRadians(float.Parse(Rot[2])));

                        string[] Scl = xmlNodeMesh.SelectSingleNode("Scale").InnerText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        mesh.Scale = new Vector3(float.Parse(Scl[0]), float.Parse(Scl[1]), float.Parse(Scl[2]));

                        XmlNodeList xmlMaterials = xmlNodeMesh.SelectSingleNode("Materials").SelectNodes("Material");
                        int         Count        = Math.Min(xmlMaterials.Count, mesh.Parts.Count);
                        for (int i = 0; i < Count; i++)
                        {
                            mesh.Parts[i].Material = Materials.Load(xmlMaterials[i].InnerText);
                        }

                        if (Count < mesh.Parts.Count && Count > 0)
                        {
                            for (int i = Count; i < mesh.Parts.Count; i++)
                            {
                                mesh.Parts[i].Material = mesh.Parts[0].Material;
                            }
                        }

                        model.Meshes.Add(mesh);
                    }

                    Models.MODELS.Add(model);
                }
                #endregion

                #region Light
                foreach (XmlNode xmlNodeLight in XML.DocumentElement.SelectNodes("Light"))
                {
                    Light light = new Light();
                    light.Name = xmlNodeLight.SelectSingleNode("Name").InnerText;

                    if (xmlNodeLight.SelectNodes("Enabled").Count > 0)
                    {
                        light.Enabled = Convert.ToBoolean(xmlNodeLight.SelectSingleNode("Enabled").InnerText);
                    }

                    LightType lightType = LightType.Point;
                    if (xmlNodeLight.SelectNodes("Type").Count > 0)
                    {
                        string meshTypeStr = xmlNodeLight.SelectSingleNode("Type").InnerText;

                        try
                        {
                            lightType = (LightType)Enum.Parse(typeof(LightType), meshTypeStr, true);
                        }
                        catch
                        {
                            lightType = LightType.Point;
                        }

                        light.Type = lightType;
                    }

                    #region Diffuse Light
                    xmlNodeList = xmlNodeLight.SelectNodes("Diffuse");
                    if (xmlNodeList.Count > 0)
                    {
                        try
                        {
                            string[] Diffuse = xmlNodeList.Item(0).InnerText.Split(
                                new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                            float R, G, B;
                            switch (Diffuse.Length)
                            {
                            case 1:
                                R             = float.Parse(Diffuse[0]);
                                light.Diffuse = new Vector3(R, R, R);
                                break;

                            case 3:
                                R             = float.Parse(Diffuse[0]);
                                G             = float.Parse(Diffuse[1]);
                                B             = float.Parse(Diffuse[2]);
                                light.Diffuse = new Vector3(R, G, B);
                                break;
                            }
                        }
                        catch { }
                    }
                    #endregion

                    #region Specular Light
                    xmlNodeList = xmlNodeLight.SelectNodes("Specular");
                    if (xmlNodeList.Count > 0)
                    {
                        string[] Specular = xmlNodeList.Item(0).InnerText.Split(
                            new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                        float R, G, B;
                        switch (Specular.Length)
                        {
                        case 1:
                            R = float.Parse(Specular[0]);
                            light.Specular = new Vector3(R, R, R);
                            break;

                        case 3:
                            R = float.Parse(Specular[0]);
                            G = float.Parse(Specular[1]);
                            B = float.Parse(Specular[2]);
                            light.Specular = new Vector3(R, G, B);
                            break;
                        }
                    }
                    #endregion

                    #region Position
                    xmlNodeList = xmlNodeLight.SelectNodes("Position");
                    if (xmlNodeList.Count > 0)
                    {
                        string[] Pos = xmlNodeList.Item(0).InnerText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        light.Position = new Vector3(float.Parse(Pos[0]), float.Parse(Pos[1]), float.Parse(Pos[2]));
                    }
                    #endregion

                    #region Direction
                    xmlNodeList = xmlNodeLight.SelectNodes("Direction");
                    if (xmlNodeList.Count > 0)
                    {
                        string[] Direct = xmlNodeList.Item(0).InnerText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                        light.Direction = Vector3.FromYawPitch(
                            MathHelper.DegreesToRadians(float.Parse(Direct[0])),
                            MathHelper.DegreesToRadians(float.Parse(Direct[1])));
                    }
                    #endregion

                    #region Attenuation
                    xmlNodeList = xmlNodeLight.SelectNodes("Attenuation");
                    if (xmlNodeList.Count > 0)
                    {
                        string[] Atten = xmlNodeList.Item(0).InnerText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        light.Attenuation = new Vector3(float.Parse(Atten[0]), float.Parse(Atten[1]), float.Parse(Atten[2]));
                    }
                    #endregion

                    if (xmlNodeLight.SelectNodes("CutOFF").Count > 0)
                    {
                        light.CutOFF = float.Parse(xmlNodeLight.SelectSingleNode("CutOFF").InnerText);
                    }

                    if (xmlNodeLight.SelectNodes("Exponent").Count > 0)
                    {
                        light.Exponent = float.Parse(xmlNodeLight.SelectSingleNode("Exponent").InnerText);
                    }

                    Lights.LIGHTS.Add(light);
                }
                #endregion

                #region Sounds
                //xmlNodeList = XML.DocumentElement.SelectSingleNode("Sounds").SelectNodes("Sound");

                //foreach (XmlNode xmlNodeSound in xmlNodeList)
                //{
                //    string SndName = xmlNodeSound.SelectSingleNode("Name").InnerText;
                //    bool SndEnabled = Convert.ToBoolean(xmlNodeSound.SelectSingleNode("Enabled").InnerText);
                //    string SndFile = xmlNodeSound.SelectSingleNode("File").InnerText;
                //    int SndVolume = Convert.ToInt32(xmlNodeSound.SelectSingleNode("Volume").InnerText);
                //    int SndRadius = Convert.ToInt32(xmlNodeSound.SelectSingleNode("Radius").InnerText);

                //    string[] SndPos = xmlNodeSound.SelectSingleNode("Position").InnerText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                //    Vector3 SndPosition = new Vector3(
                //        float.Parse(SndPos[0]),
                //        float.Parse(SndPos[1]),
                //        float.Parse(SndPos[2]));
                //}
                #endregion

                Log.WriteLineGreen("Done.");
            }
            catch
            {
                Log.WriteLineRed("Map \"{0}\" loading Error!\n\t", MapName);
            }
        }
Exemple #4
0
        private void PropetriesApplyButton_Click(object sender, EventArgs e)
        {
            try
            {
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].MeshName = MeshComboBox.GetItemText(MeshComboBox.SelectedItem);
                //List<string> matlist = new List<string>();
                //string tempmat = String.Empty;
                int Counter = 0;

                //foreach (MeshPart msh in Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Parts)
                //{
                //        Count++;
                //}

                Counter = Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Parts.Count;

                Meshes.Unload(Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex]);
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex] = Meshes.Load(NameBox.Text, MeshComboBox.GetItemText(MeshComboBox.SelectedItem));

                for (int i = 0; i < Counter; i++)
                    Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Parts[i].Material = Materials.Load(ObjMaterialComboBox.Items[i].ToString());

                if (Counter < Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Parts.Count && Counter > 0)
                {
                    for (int i = Counter; i < Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Parts.Count; i++)
                        Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Parts[i].Material = Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Parts[0].Material;
                }

                try
                {
                    //Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].FileName = Settings.Paths.Meshes + ObjFileTextBox.Text;
                }
                catch (Exception ex)
                {
                    Log.WriteLineRed("Map saving error.");
                    Log.WriteLineYellow(ex.Message);
                    //ObjFileTextBox.Clear();
                }

                //Engine content
                //if (Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].EngineContent == true)
                //    EngineCheckBox1.Checked = true;
                //else
                //    EngineCheckBox1.Checked = false;

                //Visible
                if (VisibleCheckBox1.Checked == true)
                    Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Visible = true;
                else
                    Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Visible = false;

                //Position
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Position.X = (float)Convert.ToDouble(XtextBox1.Text);
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Position.Y = (float)Convert.ToDouble(YtextBox2.Text);
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Position.Z = (float)Convert.ToDouble(ZtextBox3.Text);

                //Rotation
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Rotation.X = MathHelper.DegreesToRadians((float)Convert.ToDouble(RotBoxX.Text));
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Rotation.Y = MathHelper.DegreesToRadians((float)Convert.ToDouble(RotBoxY.Text));
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Rotation.Z = MathHelper.DegreesToRadians((float)Convert.ToDouble(RotBoxZ.Text));

                //Scale
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Scale.X = (float)Convert.ToDouble(SclBoxX.Text);
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Scale.Y = (float)Convert.ToDouble(SclBoxY.Text);
                Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes[listBox1.SelectedIndex].Scale.Z = (float)Convert.ToDouble(SclBoxZ.Text);

                int temp_index = listBox1.SelectedIndex;
                listBox1.Items.Clear();
                foreach (Mesh element in Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes)
                {
                    listBox1.Items.Add(element.Name);
                }
                listBox1.SelectedIndex = temp_index;
                objcountlabel.Visible = true;
                objcountlabel.Text = Models.MODELS[ModelsComboBox1.SelectedIndex].Meshes.Count().ToString() + " object(s)";
            }
            catch
            {

            }
        }
Exemple #5
0
        private void TexturesListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (MaterialTabs.SelectedTab == MaterialTabs.TabPages[0])
                {
                    #region Enable controls
                    NameTextBox.Enabled       = true;
                    MagFilterComboBox.Enabled = true;
                    MinFilterComboBox.Enabled = true;
                    EngineCheckBox.Enabled    = true;
                    ApplyButton.Enabled       = true;
                    FileButton.Enabled        = true;
                    FileTextBox.Enabled       = true;
                    #endregion
                    try
                    {
                        NameTextBox.Text = Textures.TexturesList[TexturesListBox.SelectedIndex].Name;
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (Textures.TexturesList[TexturesListBox.SelectedIndex].MagFilter.ToString() == String.Empty)
                        {
                            MagFilterComboBox.SelectedIndex = MagFilterComboBox.FindString("Undefined");
                        }
                        if (Textures.TexturesList[TexturesListBox.SelectedIndex].MinFilter.ToString() == String.Empty)
                        {
                            MinFilterComboBox.SelectedIndex = MinFilterComboBox.FindString("Undefined");
                        }
                    }
                    catch
                    {
                    }

                    pictureBox1.Show();
                    string path = String.Empty;

                    try
                    {
                        path = Textures.TexturesList[TexturesListBox.SelectedIndex].File;
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (Textures.TexturesList[TexturesListBox.SelectedIndex].EngineContent == true)
                        {
                            FileTextBox.BackColor = Color.White;
                            FileTextBox.Text      = Engine.FixPath(path.Substring(Settings.Paths.EngineTextures.Length + 1, path.Length - Settings.Paths.EngineTextures.Length - 1));
                        }
                        if (Textures.TexturesList[TexturesListBox.SelectedIndex].EngineContent == false)
                        {
                            FileTextBox.BackColor = Color.White;
                            FileTextBox.Text      = Engine.FixPath(path.Substring(Settings.Paths.Textures.Length + 1, path.Length - Settings.Paths.Textures.Length - 1));
                        }
                    }
                    catch
                    {
                        FileTextBox.BackColor = Color.Tomato;
                        FileTextBox.Text      = "Error";
                        pictureBox1.Hide();
                    }
                    try
                    {
                        pictureBox1.Image = Image.FromFile(path);
                    }
                    catch
                    {
                        FileTextBox.BackColor = Color.Tomato;
                        FileTextBox.Text      = "Error";
                        pictureBox1.Hide();
                    }
                    try
                    {
                        if (Textures.TexturesList[TexturesListBox.SelectedIndex].EngineContent == true)
                        {
                            EngineCheckBox.Checked = true;
                        }
                        if (Textures.TexturesList[TexturesListBox.SelectedIndex].EngineContent == false)
                        {
                            EngineCheckBox.Checked = false;
                        }
                    }
                    catch
                    {
                    }
                }

                if (MaterialTabs.SelectedTab == MaterialTabs.TabPages[1])
                {
                    #region Enable controls
                    NameTextBox.Enabled         = true;
                    MagFilterComboBox.Enabled   = true;
                    MinFilterComboBox.Enabled   = true;
                    EngineCheckBox.Enabled      = true;
                    ApplyButton.Enabled         = true;
                    CubeMapFileButton1.Enabled  = true;
                    CubeMapFileTextBox1.Enabled = true;
                    CubeMapFileButton2.Enabled  = true;
                    CubeMapFileTextBox2.Enabled = true;
                    CubeMapFileButton3.Enabled  = true;
                    CubeMapFileTextBox3.Enabled = true;
                    CubeMapFileButton4.Enabled  = true;
                    CubeMapFileTextBox4.Enabled = true;
                    CubeMapFileButton5.Enabled  = true;
                    CubeMapFileTextBox5.Enabled = true;
                    CubeMapFileButton6.Enabled  = true;
                    CubeMapFileTextBox6.Enabled = true;
                    #endregion
                    string path = String.Empty;
                    NameTextBox.Text = Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].Name;

                    pictureBox1.Show();

                    try
                    {
                        if (Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].MagFilter.ToString() == String.Empty)
                        {
                            MagFilterComboBox.SelectedIndex = MagFilterComboBox.FindString("Undefined");
                        }
                        if (Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].MinFilter.ToString() == String.Empty)
                        {
                            MinFilterComboBox.SelectedIndex = MinFilterComboBox.FindString("Undefined");
                        }
                    }
                    catch
                    {
                    }

                    try
                    {
                        path = Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].CubemapFiles[0];
                        CubeMapFileTextBox1.BackColor = Color.White;
                        CubeMapFileTextBox1.Text      = path.Substring(path.LastIndexOf("Cubemaps"));
                    }
                    catch
                    {
                        CubeMapFileTextBox1.BackColor = Color.Tomato;
                        CubeMapFileTextBox1.Text      = "Error";
                    }

                    try
                    {
                        path = Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].CubemapFiles[1];
                        CubeMapFileTextBox2.BackColor = Color.White;
                        CubeMapFileTextBox2.Text      = path.Substring(path.LastIndexOf("Cubemaps"));
                    }
                    catch
                    {
                        CubeMapFileTextBox2.BackColor = Color.Tomato;
                        CubeMapFileTextBox2.Text      = "Error";
                    }

                    try
                    {
                        path = Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].CubemapFiles[2];
                        CubeMapFileTextBox3.BackColor = Color.White;
                        CubeMapFileTextBox3.Text      = path.Substring(path.LastIndexOf("Cubemaps"));
                    }
                    catch
                    {
                        CubeMapFileTextBox3.BackColor = Color.Tomato;
                        CubeMapFileTextBox3.Text      = "Error";
                    }

                    try
                    {
                        path = Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].CubemapFiles[3];
                        CubeMapFileTextBox4.BackColor = Color.White;
                        CubeMapFileTextBox4.Text      = path.Substring(path.LastIndexOf("Cubemaps"));
                    }
                    catch
                    {
                        CubeMapFileTextBox4.BackColor = Color.Tomato;
                        CubeMapFileTextBox4.Text      = "Error";
                    }

                    try
                    {
                        path = Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].CubemapFiles[4];
                        CubeMapFileTextBox5.BackColor = Color.White;
                        CubeMapFileTextBox5.Text      = path.Substring(path.LastIndexOf("Cubemaps"));
                    }
                    catch
                    {
                        CubeMapFileTextBox5.BackColor = Color.Tomato;
                        CubeMapFileTextBox5.Text      = "Error";
                    }

                    try
                    {
                        path = Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].CubemapFiles[5];
                        CubeMapFileTextBox6.BackColor = Color.White;
                        CubeMapFileTextBox6.Text      = path.Substring(path.LastIndexOf("Cubemaps"));
                    }
                    catch
                    {
                        CubeMapFileTextBox6.BackColor = Color.Tomato;
                        CubeMapFileTextBox6.Text      = "Error";
                    }

                    try
                    {
                        pictureBox1.Image = Image.FromFile(path);
                        Game.SkyBox.Free();
                        Game.SkyBox = new Mesh();
                        MeshPart MPart = MeshPart.MakeBox(Game.MainCamera.zFar * 2.0f / (float)Math.Sqrt(3.0), true); // Cube diagonal = side / sqrt(3)
                        MPart.Material = Materials.Load(Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].Name);
                        Game.SkyBox.Parts.Add(MPart);
                        Game.SkyBox.CalcBoundingObjects();
                    }
                    catch
                    {
                    }
                    if (Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].EngineContent == true)
                    {
                        EngineCheckBox.Checked = true;
                    }
                    if (Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].EngineContent == false)
                    {
                        EngineCheckBox.Checked = false;
                    }
                }
                try
                {
                    foreach (var item in MagFilterComboBox.Items)
                    {
                        if (MaterialTabs.SelectedTab == MaterialTabs.TabPages[0])
                        {
                            if (Textures.TexturesList[TexturesListBox.SelectedIndex].MagFilter.ToString() != String.Empty)
                            {
                                if (item.ToString() == Textures.TexturesList[TexturesListBox.SelectedIndex].MagFilter.ToString())
                                {
                                    MagFilterComboBox.SelectedIndex = MagFilterComboBox.FindString(Textures.TexturesList[TexturesListBox.SelectedIndex].MagFilter.ToString());
                                }
                            }
                        }
                        if (MaterialTabs.SelectedTab == MaterialTabs.TabPages[1])
                        {
                            if (Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].MagFilter.ToString() != String.Empty)
                            {
                                if (item.ToString() == Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].MagFilter.ToString())
                                {
                                    MagFilterComboBox.SelectedIndex = MagFilterComboBox.FindString(Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].MagFilter.ToString());
                                }
                            }
                        }
                    }

                    foreach (var item in MinFilterComboBox.Items)
                    {
                        if (MaterialTabs.SelectedTab == MaterialTabs.TabPages[0])
                        {
                            if (Textures.TexturesList[TexturesListBox.SelectedIndex].MinFilter.ToString() != String.Empty)
                            {
                                if (item.ToString() == Textures.TexturesList[TexturesListBox.SelectedIndex].MinFilter.ToString())
                                {
                                    MinFilterComboBox.SelectedIndex = MinFilterComboBox.FindString(Textures.TexturesList[TexturesListBox.SelectedIndex].MinFilter.ToString());
                                }
                            }
                        }
                        if (MaterialTabs.SelectedTab == MaterialTabs.TabPages[1])
                        {
                            if (Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].MinFilter.ToString() != String.Empty)
                            {
                                if (item.ToString() == Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].MinFilter.ToString())
                                {
                                    MinFilterComboBox.SelectedIndex = MinFilterComboBox.FindString(Textures.TexturesList[TexturesListBox.SelectedIndex + TexturesListIndexCounter].MinFilter.ToString());
                                }
                            }
                        }
                    }
                }
                catch
                {
                    //Log.WriteLineRed("Texture Load Error.");
                }
            }
            catch
            {
                //Log.WriteLineRed("Texture Load Error.");
            }
        }
Exemple #6
0
        public static void LoadContentLists()
        {
            try
            {
                ClearLists();

                #region Paths
                string[] Paths = new string[] { Settings.Paths.EngineContentPath, Settings.Paths.GameDataPath };

                string[] MaterialsConfigs       = new string[] { Settings.Paths.ContentFiles.EngineMaterials, Settings.Paths.ContentFiles.Materials };
                string[] MeshesConfigs          = new string[] { Settings.Paths.ContentFiles.EngineMeshes, Settings.Paths.ContentFiles.Meshes };
                string[] ShadersConfigs         = new string[] { Settings.Paths.ContentFiles.EngineShaders, Settings.Paths.ContentFiles.Shaders };
                string[] TexturesConfigs        = new string[] { Settings.Paths.ContentFiles.EngineTextures, Settings.Paths.ContentFiles.Textures };
                string[] CubemapTexturesConfigs = new string[] { Settings.Paths.ContentFiles.EngineCubemapTextures, Settings.Paths.ContentFiles.CubemapTextures };

                string[] MapsPaths            = new string[] { Settings.Paths.EngineMaps, Settings.Paths.Maps };
                string[] MeshesPaths          = new string[] { Settings.Paths.EngineMeshes, Settings.Paths.Meshes };
                string[] ShadersPaths         = new string[] { Settings.Paths.EngineShaders, Settings.Paths.Shaders };
                string[] TexturesPaths        = new string[] { Settings.Paths.EngineTextures, Settings.Paths.Textures };
                string[] CubemapTexturesPaths = new string[] { Settings.Paths.EngineCubemapTextures, Settings.Paths.CubemapTextures };
                #endregion

                #region Load Lists
                ClearLists();

                for (int i = 0; i < Paths.Length; i++)
                {
                    bool EngineContent = false;
                    if (i == 0)
                    {
                        EngineContent = true;
                    }

                    Textures.LoadTexturesList(TexturesConfigs[i], TexturesPaths[i], EngineContent);
                }

                for (int i = 0; i < Paths.Length; i++)
                {
                    bool EngineContent = false;
                    if (i == 0)
                    {
                        EngineContent = true;
                    }

                    Textures.LoadCubemapTexturesList(CubemapTexturesConfigs[i], CubemapTexturesPaths[i], EngineContent);
                }

                for (int i = 0; i < Paths.Length; i++)
                {
                    bool EngineContent = false;
                    if (i == 0)
                    {
                        EngineContent = true;
                    }

                    Shaders.LoadShadersList(ShadersConfigs[i], ShadersPaths[i], EngineContent);
                }

                for (int i = 0; i < Paths.Length; i++)
                {
                    bool EngineContent = false;
                    if (i == 0)
                    {
                        EngineContent = true;
                    }

                    Materials.LoadMaterialsList(MaterialsConfigs[i], EngineContent);
                }

                for (int i = 0; i < Paths.Length; i++)
                {
                    bool EngineContent = false;
                    if (i == 0)
                    {
                        EngineContent = true;
                    }

                    Meshes.LoadMeshesList(MeshesConfigs[i], MeshesPaths[i], EngineContent);
                }

                for (int i = 0; i < Paths.Length; i++)
                {
                    bool EngineContent = false;
                    if (i == 0)
                    {
                        EngineContent = true;
                    }

                    Maps.LoadMapList(MapsPaths[i], EngineContent);
                }
                #endregion
            }
            catch (Exception e)
            {
                Log.WriteLineRed("Engine.LoadContentLists() Exception.");
                Log.WriteLineYellow(e.Message);
            }
        }