Exemplo n.º 1
0
        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "All Files (*.*)|*.*";
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            MeshModel model;

            try
            {
                model = MeshModel.LoadFromFile(ofd.FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this.form,
                    ex.Message,
                    this.form.Text,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            if (this.model != null)
            {
                this.model.Dispose();
            }
            this.model = model;

            this.InitializeModelUI(this.model);
        }
Exemplo n.º 2
0
 private MeshModel GetModelFromName(string model)
 {
     if (this.models.ContainsKey(model) == false)
     {
         this.models[model] = MeshModel.LoadFromFile("./Models/" + Path.GetFileNameWithoutExtension(model) + ".bwm");
     }
     return(this.models[model]);
 }
Exemplo n.º 3
0
        protected override void OnLoad()
        {
            this.objectShader = Shader.CompileFromResource(
                "BlocksWorld.Shaders.Object.vs",
                "BlocksWorld.Shaders.Object.fs");

            this.blockTextures = TextureArray.LoadFromResource(
                "BlocksWorld.Textures.Blocks.png");
            this.modelTextures = TextureArray.LoadFromResource(
                "BlocksWorld.Textures.Models.png");

            this.playerModel = MeshModel.LoadFromResource(
                "BlocksWorld.Models.Player.bwm");

            this.debug.Load();
            this.worldRenderer.Load();
            this.ui.Load();
        }
Exemplo n.º 4
0
        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "All Files (*.*)|*.*";
            if (ofd.ShowDialog() != DialogResult.OK)
                return;
            MeshModel model;
            try
            {
                model = MeshModel.LoadFromFile(ofd.FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this.form,
                    ex.Message,
                    this.form.Text,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            if (this.model != null)
                this.model.Dispose();
            this.model = model;

            this.InitializeModelUI(this.model);
        }
Exemplo n.º 5
0
        private void InitializeModelUI(MeshModel model)
        {
            this.modelData.Controls.Clear();

            var meshes = model.Meshes.ToArray();
            for (int i = 0; i < meshes.Length; i++)
            {
                var mesh = meshes[i];
                GroupBox box = new GroupBox()
                {
                    Dock = DockStyle.Top,
                    Text = "Mesh " + (i.ToString())
                };

                var table = new TableLayoutPanel()
                {
                    Dock = DockStyle.Fill
                };
                table.ColumnCount = 2;
                table.RowCount = 1;
                table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 0.5f));
                table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 0.5f));

                Action<Func<Tuple<string, Control>>> addRow = (func) =>
                {
                    var row = func();

                    var label = new Label()
                    {
                        Dock = DockStyle.Fill,
                        AutoSize = false,
                        TextAlign = ContentAlignment.MiddleLeft,
                        Text = row.Item1
                    };

                    table.Controls.Add(label);
                    table.Controls.Add(row.Item2);

                    table.SetCellPosition(label, new TableLayoutPanelCellPosition(0, table.RowCount-1));
                    table.SetCellPosition(row.Item2, new TableLayoutPanelCellPosition(1, table.RowCount - 1));

                    table.RowStyles.Add(new RowStyle(SizeType.Absolute, 28));

                    table.RowCount += 1;
                };

                // Texture Editor
                addRow(() =>
                {
                    var editor = new NumericUpDown()
                    {
                        Dock = DockStyle.Fill,
                        Minimum = 0,
                        Maximum = this.textures.Count - 1,
                        Value = Math.Min(this.textures.Count - 1, mesh.Texture),
                        Increment = 1,
                    };
                    editor.ValueChanged += (s, e) =>
                    {
                        mesh.SetTexture((int)editor.Value);
                    };
                    return new Tuple<string, Control>("Texture:", editor);
                });

                // Scale tool
                addRow(() =>
                {
                    var editor = new TextBox()
                    {
                        Dock = DockStyle.Fill,
                        Text = "1.0"
                    };
                    var button = new Button()
                    {
                        Text = "Scale",
                        Dock = DockStyle.Right
                    };

                    button.Click += (s, e) =>
                    {
                        float scale = float.Parse(editor.Text, CultureInfo.InvariantCulture);
                        for (int j = 0; j < mesh.Vertices.Length; j++)
                        {
                            mesh.Vertices[j].position *= scale;
                        }
                        mesh.Update();
                    };

                    var panel = new Panel()
                    {
                        Dock = DockStyle.Fill,
                        Height = 24
                    };
                    panel.Controls.Add(editor);
                    panel.Controls.Add(button);

                    return new Tuple<string, Control>("Scale:", panel);
                });

                // Translate tool
                addRow(() =>
                {
                    Func<Vector3, EventHandler> rotateMesh = (angle) =>
                    {
                        return (s, e) =>
                        {
                            Matrix4 mat =
                                Matrix4.CreateRotationX(angle.X) *
                                Matrix4.CreateRotationY(angle.Y) *
                                Matrix4.CreateRotationZ(angle.Z);
                            for (int j = 0; j < mesh.Vertices.Length; j++)
                            {
                                mesh.Vertices[j].position = Vector3.Transform(mesh.Vertices[j].position, mat);
                            }
                            mesh.Update();
                        };
                    };

                    var panel = new Panel()
                    {
                        Dock = DockStyle.Fill,
                        Height = 28
                    };

                    Action<string, Vector3> addButton = (text, rot) =>
                    {
                        var button = new Button()
                        {
                            Text = text,
                            Dock = DockStyle.Left,
                            Width = 32
                        };
                        button.Click += rotateMesh(rot);
                        panel.Controls.Add(button);
                    };

                    addButton("Z⤴",  0.5f * (float)Math.PI * Vector3.UnitX);
                    addButton("Z⤵", -0.5f * (float)Math.PI * Vector3.UnitX);

                    addButton("Y⤴",  0.5f * (float)Math.PI * Vector3.UnitY);
                    addButton("Y⤵", -0.5f * (float)Math.PI * Vector3.UnitY);

                    addButton("Z⤴",  0.5f * (float)Math.PI * Vector3.UnitZ);
                    addButton("Z⤵", -0.5f * (float)Math.PI * Vector3.UnitZ);

                    return new Tuple<string, Control>("Transform:", panel);
                });

                box.Controls.Add(table);
                this.modelData.Controls.Add(box);
            }
        }
Exemplo n.º 6
0
		protected override void OnLoad()
		{
			this.objectShader = Shader.CompileFromResource(
				"BlocksWorld.Shaders.Object.vs",
				"BlocksWorld.Shaders.Object.fs");

			this.blockTextures = TextureArray.LoadFromResource(
				"BlocksWorld.Textures.Blocks.png");
			this.modelTextures = TextureArray.LoadFromResource(
				"BlocksWorld.Textures.Models.png");

			this.playerModel = MeshModel.LoadFromResource(
				"BlocksWorld.Models.Player.bwm");

			this.debug.Load();
			this.worldRenderer.Load();
			this.ui.Load();
		}
Exemplo n.º 7
0
        private void InitializeModelUI(MeshModel model)
        {
            this.modelData.Controls.Clear();

            var meshes = model.Meshes.ToArray();

            for (int i = 0; i < meshes.Length; i++)
            {
                var      mesh = meshes[i];
                GroupBox box  = new GroupBox()
                {
                    Dock = DockStyle.Top,
                    Text = "Mesh " + (i.ToString())
                };

                var table = new TableLayoutPanel()
                {
                    Dock = DockStyle.Fill
                };
                table.ColumnCount = 2;
                table.RowCount    = 1;
                table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 0.5f));
                table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 0.5f));

                Action <Func <Tuple <string, Control> > > addRow = (func) =>
                {
                    var row = func();

                    var label = new Label()
                    {
                        Dock      = DockStyle.Fill,
                        AutoSize  = false,
                        TextAlign = ContentAlignment.MiddleLeft,
                        Text      = row.Item1
                    };

                    table.Controls.Add(label);
                    table.Controls.Add(row.Item2);

                    table.SetCellPosition(label, new TableLayoutPanelCellPosition(0, table.RowCount - 1));
                    table.SetCellPosition(row.Item2, new TableLayoutPanelCellPosition(1, table.RowCount - 1));

                    table.RowStyles.Add(new RowStyle(SizeType.Absolute, 28));

                    table.RowCount += 1;
                };

                // Texture Editor
                addRow(() =>
                {
                    var editor = new NumericUpDown()
                    {
                        Dock      = DockStyle.Fill,
                        Minimum   = 0,
                        Maximum   = this.textures.Count - 1,
                        Value     = Math.Min(this.textures.Count - 1, mesh.Texture),
                        Increment = 1,
                    };
                    editor.ValueChanged += (s, e) =>
                    {
                        mesh.SetTexture((int)editor.Value);
                    };
                    return(new Tuple <string, Control>("Texture:", editor));
                });

                // Scale tool
                addRow(() =>
                {
                    var editor = new TextBox()
                    {
                        Dock = DockStyle.Fill,
                        Text = "1.0"
                    };
                    var button = new Button()
                    {
                        Text = "Scale",
                        Dock = DockStyle.Right
                    };

                    button.Click += (s, e) =>
                    {
                        float scale = float.Parse(editor.Text, CultureInfo.InvariantCulture);
                        for (int j = 0; j < mesh.Vertices.Length; j++)
                        {
                            mesh.Vertices[j].position *= scale;
                        }
                        mesh.Update();
                    };


                    var panel = new Panel()
                    {
                        Dock   = DockStyle.Fill,
                        Height = 24
                    };
                    panel.Controls.Add(editor);
                    panel.Controls.Add(button);

                    return(new Tuple <string, Control>("Scale:", panel));
                });


                // Translate tool
                addRow(() =>
                {
                    Func <Vector3, EventHandler> rotateMesh = (angle) =>
                    {
                        return((s, e) =>
                        {
                            Matrix4 mat =
                                Matrix4.CreateRotationX(angle.X) *
                                Matrix4.CreateRotationY(angle.Y) *
                                Matrix4.CreateRotationZ(angle.Z);
                            for (int j = 0; j < mesh.Vertices.Length; j++)
                            {
                                mesh.Vertices[j].position = Vector3.Transform(mesh.Vertices[j].position, mat);
                            }
                            mesh.Update();
                        });
                    };

                    var panel = new Panel()
                    {
                        Dock   = DockStyle.Fill,
                        Height = 28
                    };

                    Action <string, Vector3> addButton = (text, rot) =>
                    {
                        var button = new Button()
                        {
                            Text  = text,
                            Dock  = DockStyle.Left,
                            Width = 32
                        };
                        button.Click += rotateMesh(rot);
                        panel.Controls.Add(button);
                    };

                    addButton("Z⤴", 0.5f * (float)Math.PI * Vector3.UnitX);
                    addButton("Z⤵", -0.5f * (float)Math.PI * Vector3.UnitX);

                    addButton("Y⤴", 0.5f * (float)Math.PI * Vector3.UnitY);
                    addButton("Y⤵", -0.5f * (float)Math.PI * Vector3.UnitY);

                    addButton("Z⤴", 0.5f * (float)Math.PI * Vector3.UnitZ);
                    addButton("Z⤵", -0.5f * (float)Math.PI * Vector3.UnitZ);


                    return(new Tuple <string, Control>("Transform:", panel));
                });

                box.Controls.Add(table);
                this.modelData.Controls.Add(box);
            }
        }