예제 #1
0
        public SBDobjAttachment()
        {
            Text = "DOBJ List";
            Dock = DockStyle.Fill;
            //this.s
            ApplicationSettings.SkinControl(this);

            dobjList               = new SBTreeView();
            dobjList.Dock          = DockStyle.Top;
            dobjList.Size          = new Size(200, 200);
            dobjList.CheckBoxes    = true;
            dobjList.HideSelection = false;
            dobjList.AfterCheck   += (sender, args) =>
            {
                if (args.Node != null && args.Node.Tag is SBHsdMesh mesh)
                {
                    mesh.Visible = args.Node.Checked;
                }
            };
            dobjList.AfterSelect += (sender, args) =>
            {
                foreach (TreeNode v in dobjList.Nodes)
                {
                    if (v.Tag is SBHsdMesh mesh)
                    {
                        mesh.Selected = false;
                    }
                }
                propertyGrid.SelectedObject = null;
                if (dobjList.SelectedNode != null)
                {
                    if (dobjList.SelectedNode.Tag is SBHsdMesh mesh)
                    {
                        mesh.Selected = true;
                    }
                    propertyGrid.SelectedObject = dobjList.SelectedNode.Tag;
                }
            };

            propertyGrid      = new PropertyGrid();
            propertyGrid.Dock = DockStyle.Fill;
            propertyGrid.Size = new Size(200, 400);
            propertyGrid.SelectedObjectsChanged += (sender, args) =>
            {
                removeTexture.Visible = propertyGrid.SelectedObject is HSD_TOBJ;
                exportTexture.Visible = propertyGrid.SelectedObject is HSD_TOBJ;
                importTexture.Visible = propertyGrid.SelectedObject != null;
            };


            clearTextures        = new SBButton("Clear Textures");
            clearTextures.Dock   = DockStyle.Top;
            clearTextures.Click += (sender, args) =>
            {
                if (scene != null)
                {
                    if (scene.HasMaterialAnimations)
                    {
                        MessageBox.Show("Eror: DATs with material animations must keep their textures intact");
                    }
                    else
                    {
                        if (MessageBox.Show("Are you sure? This cannot be undone", "Clear Textures", MessageBoxButtons.OKCancel) != DialogResult.OK)
                        {
                            return;
                        }
                        //TODO:
                        //scene.ClearMaterialAnimations();
                        //return;
                        foreach (SBHsdMesh m in scene.GetMeshObjects())
                        {
                            m.ClearTextures();
                        }
                        RefreshList();
                    }
                }
            };

            optionPanel      = new GroupBox();
            optionPanel.Text = "Options";
            ApplicationSettings.SkinControl(optionPanel);
            optionPanel.Dock = DockStyle.Top;

            //AutoScroll = true;

            exportTexture         = new SBButton("Export Texture");
            exportTexture.Dock    = DockStyle.Top;
            exportTexture.Visible = false;
            optionPanel.Controls.Add(exportTexture);
            exportTexture.Click += (sender, args) =>
            {
                string filePath;

                if (propertyGrid.SelectedObject is HSD_TOBJ tobj)
                {
                    var filter = "PNG (*.png)|*.png;";

                    //if (tobj.ImageData != null && tobj.ImageData.Format == GXTexFmt.CMP)
                    //    filter = "DDS (*.dds)|*.dds;";

                    if (FileTools.TrySaveFile(out filePath, filter))
                    {
                        //TODO: dds export / import

                        /*if (tobj.ImageData != null && tobj.ImageData.Format == GXTexFmt.CMP)
                         * {
                         *  SBSurface s = new SBSurface();
                         *  s.Width = tobj.ImageData.Width;
                         *  s.Height = tobj.ImageData.Height;
                         *  s.InternalFormat = OpenTK.Graphics.OpenGL.InternalFormat.CompressedRgbaS3tcDxt1Ext;
                         *  s.Arrays.Add(new MipArray() { Mipmaps = new List<byte[]>() { HSDRaw.Tools.TPLConv.ToCMP(tobj.ImageData.ImageData, tobj.ImageData.Width, tobj.ImageData.Height) } });
                         *
                         *  IO_DDS.Export(filePath, s);
                         * }
                         * else*/
                        {
                            FileTools.WriteBitmapFile(filePath, tobj.ImageData.Width, tobj.ImageData.Height, tobj.GetDecodedImageData());
                        }
                    }
                }
            };

            removeTexture         = new SBButton("Remove Texture");
            removeTexture.Dock    = DockStyle.Top;
            removeTexture.Visible = false;
            optionPanel.Controls.Add(removeTexture);
            removeTexture.Click += (sender, args) =>
            {
                if (dobjList.SelectedNode.Tag is HSD_TOBJ tobj)
                {
                    // remove tobj from list
                    var mobj = (HSD_MOBJ)dobjList.SelectedNode.Parent.Tag;

                    HSD_TOBJ prevTexture = null;
                    if (mobj.Textures != null)
                    {
                        foreach (var tex in mobj.Textures.List)
                        {
                            if (tex._s == tobj._s)
                            {
                                if (prevTexture == null)
                                {
                                    mobj.Textures = tex.Next;
                                }
                                else
                                {
                                    prevTexture.Next = tex.Next;
                                }
                                // update texture and flag stuff
                                break;
                            }
                            prevTexture = tex;
                        }
                    }

                    FixMOBJTexIDs(mobj);

                    var root = dobjList.SelectedNode.Parent.Parent;
                    root.Nodes.Clear();
                    root.Nodes.Add(CreateMOBJNode(mobj));
                    scene.RefreshRendering();
                }
            };

            importTexture         = new SBButton("Import Texture");
            importTexture.Dock    = DockStyle.Top;
            importTexture.Visible = false;
            optionPanel.Controls.Add(importTexture);
            importTexture.Click += (sender, args) =>
            {
                // select texture
                HSD_MOBJ   mobj = null;
                SBTreeNode root = null;
                if (dobjList.SelectedNode.Tag is SBHsdMesh mesh)
                {
                    if (mesh.DOBJ.Mobj != null)
                    {
                        mobj = mesh.DOBJ.Mobj;
                        root = (SBTreeNode)dobjList.SelectedNode;
                    }
                }
                if (dobjList.SelectedNode.Tag is HSD_MOBJ m)
                {
                    mobj = m;
                    root = (SBTreeNode)dobjList.SelectedNode.Parent;
                }
                if (dobjList.SelectedNode.Tag is HSD_TOBJ)
                {
                    if (dobjList.SelectedNode.Parent.Tag is HSD_MOBJ mo)
                    {
                        mobj = mo;
                        root = (SBTreeNode)dobjList.SelectedNode.Parent.Parent;
                    }
                }
                if (mobj == null)
                {
                    return;
                }
                string filePath;
                if (FileTools.TryOpenFile(out filePath, "Supported Formats (*.png*.dds)|*.png;*.dds"))
                {
                    var settings = new TOBJImportSettings();
                    // select textue import options
                    using (SBCustomDialog d = new SBCustomDialog(settings))
                    {
                        if (d.ShowDialog() == DialogResult.OK)
                        {
                            // create tobj and attach to selected mobj
                            HSD_TOBJ tobj = new HSD_TOBJ();
                            tobj.MagFilter = GXTexFilter.GX_LINEAR;
                            tobj.HScale    = 1;
                            tobj.WScale    = 1;
                            tobj.WrapS     = GXWrapMode.REPEAT;
                            tobj.WrapT     = GXWrapMode.REPEAT;
                            tobj.SX        = 1;
                            tobj.SY        = 1;
                            tobj.SZ        = 1;

                            if (System.IO.Path.GetExtension(filePath.ToLower()) == ".dds")
                            {
                                var dxtsurface = IO_DDS.Import(filePath);

                                if (dxtsurface.InternalFormat != OpenTK.Graphics.OpenGL.InternalFormat.CompressedRgbaS3tcDxt1Ext)
                                {
                                    throw new NotSupportedException("DDS format " + dxtsurface.InternalFormat.ToString() + " not supported");
                                }

                                tobj.EncodeImageData(dxtsurface.Arrays[0].Mipmaps[0], dxtsurface.Width, dxtsurface.Height, GXTexFmt.CMP, GXTlutFmt.IA8);
                            }
                            else
                            {
                                var bmp = new Bitmap(filePath);

                                var bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                                var length     = bitmapData.Stride * bitmapData.Height;

                                byte[] bytes = new byte[length];

                                Marshal.Copy(bitmapData.Scan0, bytes, 0, length);
                                bmp.UnlockBits(bitmapData);

                                tobj.EncodeImageData(bytes, bmp.Width, bmp.Height, settings.ImageFormat, settings.PaletteFormat);

                                bmp.Dispose();
                            }

                            if (settings.UseBlending && mobj.PEDesc == null)
                            {
                                mobj.PEDesc = new HSD_PEDesc();
                            }

                            //TODO: set flags for texture types
                            if (settings.TextureType == TOBJTextureType.Diffuse)
                            {
                                mobj.RenderFlags |= RENDER_MODE.DIFFUSE;
                                tobj.Flags       |= TOBJ_FLAGS.LIGHTMAP_DIFFUSE;
                            }
                            if (settings.TextureType == TOBJTextureType.Specular)
                            {
                                mobj.RenderFlags |= RENDER_MODE.SPECULAR;
                                tobj.Flags       |= TOBJ_FLAGS.LIGHTMAP_SPECULAR;
                            }
                            if (settings.TextureType == TOBJTextureType.Bump)
                            {
                                tobj.Flags |= TOBJ_FLAGS.BUMP;
                            }

                            switch (settings.UVType)
                            {
                            case TOBJUVType.Sphere:
                                tobj.Flags |= TOBJ_FLAGS.COORD_REFLECTION;
                                break;

                            case TOBJUVType.TextureCoord:
                                tobj.Flags |= TOBJ_FLAGS.COORD_UV;
                                break;
                            }

                            if (mobj.Textures == null)
                            {
                                mobj.Textures = tobj;
                                tobj.Flags   |= TOBJ_FLAGS.COLORMAP_REPLACE;
                            }
                            else
                            {
                                tobj.Flags |= TOBJ_FLAGS.COLORMAP_BLEND;
                            }
                            propertyGrid.SelectedObject = tobj;

                            FixMOBJTexIDs(mobj);

                            root.Nodes.Clear();
                            root.Nodes.Add(CreateMOBJNode(mobj));
                            scene.RefreshRendering();
                        }
                    }
                }
            };

            propertyPanel      = new GroupBox();
            propertyPanel.Text = "Properties";
            propertyPanel.Dock = DockStyle.Top;
            propertyPanel.Controls.Add(propertyGrid);
            propertyPanel.Height = 300;
            ApplicationSettings.SkinControl(propertyPanel);

            Controls.Add(propertyPanel);
            Controls.Add(new Splitter()
            {
                Dock = DockStyle.Top, Height = 10, BackColor = ApplicationSettings.BGColor2
            });
            Controls.Add(optionPanel);
            Controls.Add(new Splitter()
            {
                Dock = DockStyle.Top, Height = 10, BackColor = ApplicationSettings.BGColor2
            });
            Controls.Add(dobjList);
            Controls.Add(clearTextures);
        }
예제 #2
0
        public SBTextureList()
        {
            Text = "Texture List";
            Dock = DockStyle.Fill;
            ApplicationSettings.SkinControl(this);

            TextureList      = new ListBox();
            TextureList.Dock = DockStyle.Top;
            TextureList.SelectedIndexChanged += (sender, args) =>
            {
                if (TextureList.SelectedIndex != -1)
                {
                    PropertyGrid.SelectedObject = TextureList.Items[TextureList.SelectedIndex];
                }
            };

            PropertyGrid      = new PropertyGrid();
            PropertyGrid.Dock = DockStyle.Top;
            PropertyGrid.Size = new Size(200, 500);
            PropertyGrid.SelectedObjectsChanged += (sender, agrs) =>
            {
                if (PropertyGrid.SelectedObject is SBSurface surface && surface.Arrays.Count > 0)
                {
                    MipLevel.Maximum = surface.Arrays[0].Mipmaps.Count - 1;
                }
            };

            DisplayBox      = new GroupBox();
            DisplayBox.Text = "Texture Options";
            DisplayBox.Dock = DockStyle.Top;
            DisplayBox.Size = new Size(400, 140);
            ApplicationSettings.SkinControl(DisplayBox);

            MipLevel         = new TrackBar();
            MipLevel.Maximum = 20;
            MipLevel.Dock    = DockStyle.Top;
            DisplayBox.Controls.Add(MipLevel);

            DisplayBox.Controls.Add(new Label()
            {
                Text = "Mip Level", Dock = DockStyle.Top
            });

            SBHBox hungryBox = new SBHBox();

            hungryBox.Dock = DockStyle.Top;
            DisplayBox.Controls.Add(hungryBox);

            SBHBox buttons = new SBHBox();

            buttons.Dock = DockStyle.Top;
            DisplayBox.Controls.Add(buttons);

            Export        = new SBButton("Export Texture");
            Export.Click += (sender, args) =>
            {
                string fileName;
                string supported = string.Join(";*", Extension());
                if (Tools.FileTools.TrySaveFile(out fileName, "Supported Formats|*" + supported))
                {
                    Save(fileName);
                }
            };
            buttons.AddControl(Export);

            Replace        = new SBButton("Replace");
            Replace.Click += (sender, args) =>
            {
                string fileName;
                string supported = string.Join(";*", Extension());
                if (Tools.FileTools.TryOpenFile(out fileName, "Supported Formats|*" + supported))
                {
                    var sur = OpenFile(fileName);
                    if (sur != null)
                    {
                        if (PropertyGrid.SelectedObject is SBSurface surface)
                        {
                            surface.Arrays         = sur.Arrays;
                            surface.Width          = sur.Width;
                            surface.Height         = sur.Height;
                            surface.PixelFormat    = sur.PixelFormat;
                            surface.InternalFormat = sur.InternalFormat;
                            surface.Depth          = sur.Depth;
                            surface.TextureTarget  = sur.TextureTarget;
                            surface.RefreshRendering();
                            PropertyGrid.SelectedObject = surface;
                        }
                    }
                }
            };
            buttons.AddControl(Replace);

            Import        = new SBButton("Import");
            Import.Click += (sender, args) =>
            {
                string[] fileNames;
                string   supported = string.Join(";*", Extension());
                if (Tools.FileTools.TryOpenFiles(out fileNames, "Supported Formats|*" + supported))
                {
                    foreach (var fileName in fileNames)
                    {
                        var surface = OpenFile(fileName);
                        if (surface != null)
                        {
                            if (TextureBank != null)
                            {
                                TextureBank.Add(surface);
                            }
                            TextureList.Items.Add(surface);
                        }
                    }
                }
            };
            buttons.AddControl(Import);

            R           = new SBButton("R");
            R.BackColor = Color.Red;
            R.Width     = 32;
            R.Click    += (sender, args) =>
            {
                if (R.BackColor == Color.Gray)
                {
                    R.BackColor = Color.Red;
                }
                else
                {
                    R.BackColor = Color.Gray;
                }
            };
            hungryBox.AddControl(R);

            G           = new SBButton("G");
            G.BackColor = Color.Green;
            G.Width     = 32;
            G.Click    += (sender, args) =>
            {
                if (G.BackColor == Color.Gray)
                {
                    G.BackColor = Color.Green;
                }
                else
                {
                    G.BackColor = Color.Gray;
                }
            };
            hungryBox.AddControl(G);

            B           = new SBButton("B");
            B.BackColor = Color.Blue;
            B.Width     = 32;
            B.Click    += (sender, args) =>
            {
                if (B.BackColor == Color.Gray)
                {
                    B.BackColor = Color.Blue;
                }
                else
                {
                    B.BackColor = Color.Gray;
                }
            };
            hungryBox.AddControl(B);

            A           = new SBButton("A");
            A.BackColor = Color.Black;
            A.Width     = 32;
            A.Click    += (sender, args) =>
            {
                if (A.BackColor == Color.Gray)
                {
                    A.BackColor = Color.Black;
                }
                else
                {
                    A.BackColor = Color.Gray;
                }
            };
            hungryBox.AddControl(A);

            Controls.Add(new Splitter()
            {
                Dock = DockStyle.Top, Height = 10
            });
            Controls.Add(PropertyGrid);
            Controls.Add(new Splitter()
            {
                Dock = DockStyle.Top, Height = 10
            });
            Controls.Add(DisplayBox);
            Controls.Add(new Splitter()
            {
                Dock = DockStyle.Top, Height = 10
            });
            Controls.Add(TextureList);
        }
예제 #3
0
        public LVDAttachment()
        {
            Text = "LVD Editor";
            Dock = DockStyle.Fill;

            ApplicationSettings.SkinControl(this);

            ToolPanel           = new GroupBox();
            ToolPanel.Text      = "Options";
            ToolPanel.ForeColor = ApplicationSettings.ForegroundColor;
            ToolPanel.Dock      = DockStyle.Top;
            ToolPanel.Height    = 40;

            Tools      = new SBToolStrip();
            Tools.Dock = DockStyle.Top;

            ExportLVD        = new SBButton("Export LVD");
            ExportLVD.Click += (sender, args) =>
            {
                string fileName;
                if (FileTools.TrySaveFile(out fileName, "Smash Level Data |*.lvd;*.ssf"))
                {
                    if (fileName.EndsWith(".ssf"))
                    {
                        IO_SSF.Export(LVD, fileName);
                    }
                    else
                    {
                        LVD.Save(fileName);
                    }
                }
            };

            PointToolStrip = new SBToolStrip();

            ToolStripButton addVertex = new ToolStripButton();

            addVertex.Text   = "Add";
            addVertex.Click += (object sender, EventArgs args) => {
                if (PropertyGrid.SelectedObject is LVDVector2 point)
                {
                    AddNewPoint(point);
                }
            };
            ToolStripButton deleteVertex = new ToolStripButton();

            deleteVertex.Text   = "Delete";
            deleteVertex.Click += (object sender, EventArgs args) => {
                if (PropertyGrid.SelectedObject is LVDVector2 point)
                {
                    DeleteVertex(point);
                }
            };
            PointToolStrip.Items.Add(addVertex);
            PointToolStrip.Items.Add(deleteVertex);

            NodeTree              = new SBTreeView();
            NodeTree.Dock         = DockStyle.Top;
            NodeTree.AfterSelect += SelectNode;

            PropertyGrid                         = new PropertyGrid();
            PropertyGrid.Dock                    = DockStyle.Top;
            PropertyGrid.Size                    = new Size(200, 500);
            PropertyGrid.PropertySort            = PropertySort.Categorized;
            PropertyGrid.SelectedObjectsChanged += SelectObjectChanged;

            Controls.Add(new Splitter()
            {
                Dock = DockStyle.Top, Height = 10
            });
            Controls.Add(PropertyGrid);
            Controls.Add(new Splitter()
            {
                Dock = DockStyle.Top, Height = 10
            });
            Controls.Add(NodeTree);
            Controls.Add(ToolPanel);
        }