Exemple #1
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = "Direct Draw Surface (.dds)|*.dds|" +
                             "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    if (ofd.FileName.EndsWith(".dds") && selected != null)
                    {
                        NUT.NUD_Texture tex = (NUT.NUD_Texture)(listBox2.SelectedItem);

                        DDS             dds  = new DDS(new FileData(ofd.FileName));
                        NUT.NUD_Texture ntex = dds.toNUT_Texture();

                        tex.height  = ntex.height;
                        tex.width   = ntex.width;
                        tex.type    = ntex.type;
                        tex.mipmaps = ntex.mipmaps;
                        tex.utype   = ntex.utype;

                        GL.DeleteTexture(selected.draw[tex.id]);
                        selected.draw.Remove(tex.id);
                        selected.draw.Add(tex.id, NUT.loadImage(tex));

                        FillForm();
                        listBox1.SelectedItem = selected;
                    }
                }
            }
        }
Exemple #2
0
        private void importBack(string filename)
        {
            if (dontModify)
            {
                return;
            }

            NUT.NUD_Texture tex = textureFromFile[filename];

            try
            {
                DDS             dds  = new DDS(new FileData(filename));
                NUT.NUD_Texture ntex = dds.toNUT_Texture();

                tex.height  = ntex.height;
                tex.width   = ntex.width;
                tex.type    = ntex.type;
                tex.mipmaps = ntex.mipmaps;
                tex.utype   = ntex.utype;

                GL.DeleteTexture(selected.draw[tex.id]);
                selected.draw.Remove(tex.id);
                selected.draw.Add(tex.id, NUT.loadImage(tex));

                FillForm();
                listBox1.SelectedItem = selected;
                listBox2.SelectedItem = tex;
                RenderTexture();
            }
            catch
            {
                Console.WriteLine("Could not be open for editing");
            }
        }
Exemple #3
0
 private NUT ReplaceTexture(NUT.NUD_Texture tex, int width, int height, NUT nut)
 {
     if (tex.width == width && tex.height == height)
     {
         tex.id = 0x280052B7;
         if (nut != null && nut.textures.Count > 0)
         {
             tex.id = nut.textures[0].id;
             nut.Destroy();
         }
         if (nut == null)
         {
             nut = new NUT();
         }
         nut.textures.Clear();
         nut.draw.Clear();
         nut.textures.Add(tex);
         nut.draw.Add(tex.id, NUT.loadImage(tex));
     }
     else
     {
         MessageBox.Show("Dimensions must be " + width + "x" + height);
     }
     return(nut);
 }
Exemple #4
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (selected != null)
            {
                using (var ofd = new OpenFileDialog())
                {
                    ofd.Filter = "Supported Formats|*.dds;*.png|" +
                                 "Direct Draw Surface (.dds)|*.dds|" +
                                 "Portable Networks Graphic (.png)|*.png|" +
                                 "All files(*.*)|*.*";

                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        int  texId;
                        bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(ofd.FileName), NumberStyles.HexNumber,
                                                  new CultureInfo("en-US"), out texId);

                        if (isTex)
                        {
                            foreach (NUT.NUD_Texture te in selected.textures)
                            {
                                if (texId == te.id)
                                {
                                    isTex = false;
                                }
                            }
                        }

                        NUT.NUD_Texture tex = null;

                        if (ofd.FileName.EndsWith(".dds") && selected != null)
                        {
                            DDS dds = new DDS(new FileData(ofd.FileName));
                            tex = dds.toNUT_Texture();
                        }
                        if (ofd.FileName.EndsWith(".png") && selected != null)
                        {
                            tex = fromPNG(ofd.FileName, 1);
                        }

                        if (tex != null)
                        {
                            if (isTex)
                            {
                                tex.id = texId;
                            }
                            else
                            {
                                tex.id = 0x40FFFF00 | (selected.textures.Count);
                            }
                            selected.textures.Add(tex);
                            selected.draw.Add(tex.id, NUT.loadImage(tex));
                            FillForm();
                            listBox1.SelectedItem = selected;
                        }
                    }
                }
            }
        }
Exemple #5
0
        public void fromNUT_Texture(NUT.NUD_Texture tex)
        {
            header             = new Header();
            header.width       = tex.width;
            header.height      = tex.height;
            header.mipmapCount = tex.mipmaps.Count <= 2 ? 1 : tex.mipmaps.Count - 2;
            switch (tex.type)
            {
            case PixelInternalFormat.CompressedRgbaS3tcDxt1Ext:
                header.dwFourCC = 0x31545844;
                break;

            case PixelInternalFormat.CompressedRgbaS3tcDxt3Ext:
                header.dwFourCC = 0x33545844;
                break;

            case PixelInternalFormat.CompressedRgbaS3tcDxt5Ext:
                header.dwFourCC = 0x35545844;
                break;

            case PixelInternalFormat.Rgba:
                if (tex.utype == OpenTK.Graphics.OpenGL.PixelFormat.Rgba)
                {
                    header.dwFourCC  = 0x0;
                    header.dwBitmask = 0x20;
                    header.dwCaps    = 0xFF;
                    header.dwCaps2   = 0xFF00;
                    header.dwCaps3   = 0xFF0000;
                    header.dwCaps4   = 0xFF000000;
                    header.reserve   = 0x401008;
                    header.dwFlags   = 0x41;
                }
                else
                {
                    header.dwFourCC = 0x0;
                }
                break;

            /*case PixelInternalFormat.CompressedRedRgtc1:
             *  break;*/
            case PixelInternalFormat.CompressedRgRgtc2:
                header.dwFourCC = 0x53354342;
                break;

            default:
                throw new NotImplementedException($"Unknown pixel format 0x{tex.type:X}");
            }
            List <byte> d = new List <byte>();

            foreach (byte[] b in tex.mipmaps)
            {
                d.AddRange(b);
            }
            data = d.ToArray();
        }
Exemple #6
0
 private void RemoveToolStripMenuItem1_Click_1(object sender, EventArgs e)
 {
     if (listBox2.SelectedIndex >= 0 && selected != null)
     {
         NUT.NUD_Texture tex = ((NUT.NUD_Texture)listBox2.SelectedItem);
         GL.DeleteTexture(selected.draw[tex.id]);
         selected.draw.Remove(tex.id);
         selected.textures.Remove(tex);
         FillForm();
         listBox1.SelectedItem  = selected;
         listBox2.SelectedIndex = 0;
     }
 }
Exemple #7
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                NUT.NUD_Texture tex = (NUT.NUD_Texture)(listBox2.SelectedItem);

                if (tex.type == PixelInternalFormat.Rgba)
                {
                    ofd.Filter = "Portable Networks Graphic (.png)|*.png|" +
                                 "All files(*.*)|*.*";
                }
                else
                {
                    ofd.Filter = "Direct Draw Surface (.dds)|*.dds|" +
                                 "All files(*.*)|*.*";
                }

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    NUT.NUD_Texture ntex = null;
                    if (ofd.FileName.EndsWith(".dds") && selected != null)
                    {
                        DDS dds = new DDS(new FileData(ofd.FileName));
                        ntex = dds.toNUT_Texture();
                    }

                    if (ofd.FileName.EndsWith(".png") && selected != null)
                    {
                        ntex = fromPNG(ofd.FileName, 1);
                    }

                    tex.height  = ntex.height;
                    tex.width   = ntex.width;
                    tex.type    = ntex.type;
                    tex.mipmaps = ntex.mipmaps;
                    tex.utype   = ntex.utype;

                    if (ntex == null)
                    {
                        return;
                    }

                    GL.DeleteTexture(selected.draw[tex.id]);
                    selected.draw.Remove(tex.id);
                    selected.draw.Add(tex.id, NUT.loadImage(tex));

                    FillForm();
                    listBox1.SelectedItem = selected;
                }
            }
        }
Exemple #8
0
        public NUT.NUD_Texture toNUT_Texture()
        {
            NUT.NUD_Texture tex = new NUT.NUD_Texture();
            tex.id     = 0x48415348;
            tex.height = header.height;
            tex.width  = header.width;
            float size = 1;
            int   mips = 4;

            if (mips > header.mipmapCount)
            {
                mips = header.mipmapCount;
                throw new Exception("No mipmaps");
            }

            switch (header.dwFourCC)
            {
            case 0x0:
                size      = 4f;
                tex.type  = PixelInternalFormat.Rgba;
                tex.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
                break;

            case 0x31545844:
                size     = 1 / 2f;
                tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                break;

            case 0x35545844:
                size     = 1f;
                tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                break;
            }

            // now for mipmap data...
            FileData d = new FileData(data);
            int      off = 0, w = header.width, h = header.height;

            for (int i = 0; i < 4; i++)
            {
                int s = (int)((w * h) * size);
                w /= 2;
                h /= 2;
                tex.mipmaps.Add(d.getSection(off, s));
                off += s;
            }

            return(tex);
        }
Exemple #9
0
 private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listBox2.SelectedIndex >= 0)
     {
         NUT.NUD_Texture tex = ((NUT.NUD_Texture)listBox2.SelectedItem);
         textBox1.Text = tex.ToString();
         label2.Text   = "Format: " + tex.type;
         label3.Text   = "Width: " + tex.width;
         label4.Text   = "Height:" + tex.height;
         label5.Text   = "Mipmap:" + tex.mipmaps.Count;
         RenderTexture();
     }
     else
     {
         textBox1.Text = "";
         label2.Text   = "Format:";
         label3.Text   = "Width:";
         label4.Text   = "Height:";
         label5.Text   = "Mipmap:";
     }
 }
Exemple #10
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = "Direct Draw Surface (.dds)|*.dds|" +
                             "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    if (ofd.FileName.EndsWith(".dds") && selected != null)
                    {
                        DDS             dds = new DDS(new FileData(ofd.FileName));
                        NUT.NUD_Texture tex = dds.toNUT_Texture();
                        tex.id = 0x40FFFF00 | (selected.textures.Count);
                        selected.textures.Add(tex);
                        selected.draw.Add(tex.id, NUT.loadImage(tex));
                        FillForm();
                        listBox1.SelectedItem = selected;
                    }
                }
            }
        }
Exemple #11
0
        private void ExportPNG(string fname, NUT.NUD_Texture tex)
        {
            if (tex.mipmaps.Count > 1)
            {
                MessageBox.Show("RGBA texture exported as PNG do no preserve mipmaps");
            }

            switch (tex.utype)
            {
            case OpenTK.Graphics.OpenGL.PixelFormat.Rgba:
                Pixel.fromRGBA(new FileData(tex.mipmaps[0]), tex.width, tex.height).Save(fname);
                break;

            case OpenTK.Graphics.OpenGL.PixelFormat.AbgrExt:
                Pixel.fromABGR(new FileData(tex.mipmaps[0]), tex.width, tex.height).Save(fname);
                break;

            case OpenTK.Graphics.OpenGL.PixelFormat.Bgra:
                Pixel.fromBGRA(new FileData(tex.mipmaps[0]), tex.width, tex.height).Save(fname);
                break;
            }
        }
Exemple #12
0
        //TODO fix?
        private void RenderTexture(GLControl glControl1, NUT nut)
        {
            glControl1.MakeCurrent();
            GL.Viewport(glControl1.ClientRectangle);
            GL.ClearColor(Color.Red);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.MatrixMode(MatrixMode.Projection);

            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcAlpha);

            NUT.NUD_Texture tex = nut.textures[0];

            if (tex == null)
            {
                return;
            }

            int rt = nut.draw[tex.id];

            GL.Begin(PrimitiveType.Quads);
            GL.BindTexture(TextureTarget.Texture2D, rt);

            GL.TexCoord2(1, 1);
            GL.Vertex2(1, -1);
            GL.TexCoord2(0, 1);
            GL.Vertex2(-1, -1);
            GL.TexCoord2(0, 0);
            GL.Vertex2(-1, 1);
            GL.TexCoord2(1, 0);
            GL.Vertex2(1, 1);
            GL.End();

            glControl1.SwapBuffers();
        }
Exemple #13
0
        public static NUT.NUD_Texture fromPNG(string fname, int mipcount)
        {
            Bitmap bmp = new Bitmap(fname);

            NUT.NUD_Texture tex = new NUT.NUD_Texture();

            tex.mipmaps.Add(fromPNG(bmp));
            for (int i = 1; i < mipcount; i++)
            {
                if (bmp.Width / (int)Math.Pow(2, i) < 4 || bmp.Height / (int)Math.Pow(2, i) < 4)
                {
                    break;
                }
                tex.mipmaps.Add(fromPNG(Pixel.ResizeImage(bmp, bmp.Width / (int)Math.Pow(2, i), bmp.Height / (int)Math.Pow(2, i))));
            }
            tex.width  = bmp.Width;
            tex.height = bmp.Height;
            tex.type   = PixelInternalFormat.Rgba;
            tex.utype  = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;

            return(tex);
        }
Exemple #14
0
        private void exportAsDDSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedItem == null)
            {
                return;
            }
            using (var sfd = new SaveFileDialog())
            {
                NUT.NUD_Texture tex = (NUT.NUD_Texture)(listBox2.SelectedItem);
                if (tex.type == PixelInternalFormat.Rgba)
                {
                    sfd.Filter = "Portable Networks Graphic (.png)|*.png|" +
                                 "All files(*.*)|*.*";
                }
                else
                {
                    sfd.Filter = "Direct Draw Surface (.dds)|*.dds|" +
                                 "All files(*.*)|*.*";
                }

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    // use png instead
                    if (sfd.FileName.EndsWith(".png") && selected != null && tex.type == PixelInternalFormat.Rgba)
                    {
                        ExportPNG(sfd.FileName, tex);
                    }
                    if (sfd.FileName.EndsWith(".dds") && selected != null)
                    {
                        DDS dds = new DDS();
                        dds.fromNUT_Texture(tex);
                        dds.Save(sfd.FileName);
                    }
                }
            }
        }
Exemple #15
0
        public NUT.NUD_Texture toNUT_Texture()
        {
            NUT.NUD_Texture tex = new NUT.NUD_Texture();
            tex.id     = 0x48415348;
            tex.height = header.height;
            tex.width  = header.width;
            float size = 1;
            int   mips = header.mipmapCount;

            /*if (mips > header.mipmapCount)
             * {
             *  mips = header.mipmapCount;
             *  MessageBox.Show("Possible texture error: Only one mipmap");
             * }*/

            switch (header.dwFourCC)
            {
            case 0x0:
                size      = 4f;
                tex.type  = PixelInternalFormat.Rgba;
                tex.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
                break;

            case 0x31545844:
                size     = 1 / 2f;
                tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                break;

            case 0x35545844:
                size     = 1f;
                tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                break;

            case 0x32495441:
                size     = 1 / 2f;
                tex.type = PixelInternalFormat.CompressedRedRgtc1;
                break;

            case 0x31495441:
                size     = 1f;
                tex.type = PixelInternalFormat.CompressedRgRgtc2;
                break;

            default:
                MessageBox.Show("Unsupported DDS format - 0x" + header.dwFourCC.ToString("x"));
                break;
            }

            // now for mipmap data...
            FileData d = new FileData(data);
            int      off = 0, w = header.width, h = header.height;

            if (header.mipmapCount == 0)
            {
                header.mipmapCount = 1;
            }
            for (int i = 0; i < header.mipmapCount; i++)
            {
                int s = (int)((w * h) * size);
                if (s < 0x8)
                {
                    s = 0x8;
                }
                //Console.WriteLine(off.ToString("x") + " " + s.ToString("x"));
                w /= 2;
                h /= 2;
                tex.mipmaps.Add(d.getSection(off, s));
                off += s;
            }
            Console.WriteLine(off.ToString("x"));

            return(tex);
        }
Exemple #16
0
        private void importNutFromFolder(object sender, EventArgs e)
        {
            using (FolderSelectDialog f = new FolderSelectDialog())
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (!Directory.Exists(f.SelectedPath))
                    {
                        Directory.CreateDirectory(f.SelectedPath);
                    }
                    NUT nut;
                    if (listBox1.SelectedItem == null)
                    {
                        nut = new NUT();
                    }
                    else
                    {
                        nut = selected;
                    }

                    foreach (var texPath in Directory.GetFiles(f.SelectedPath))
                    {
                        int  texId;
                        bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(texPath), NumberStyles.HexNumber,
                                                  new CultureInfo("en-US"), out texId);
                        if (isTex)
                        {
                            NUT.NUD_Texture texture = null;
                            foreach (var tex in nut.textures)
                            {
                                if (tex.id == texId)
                                {
                                    texture = tex;
                                }
                            }

                            if (texture == null)
                            {
                                //new texture
                                DDS             dds = new DDS(new FileData(texPath));
                                NUT.NUD_Texture tex = dds.toNUT_Texture();
                                tex.id = 0x40FFFF00 | (nut.textures.Count);
                                nut.textures.Add(tex);
                                nut.draw.Add(tex.id, NUT.loadImage(tex));
                            }
                            else
                            {
                                //old texture
                                NUT.NUD_Texture tex = texture;

                                DDS             dds  = new DDS(new FileData(texPath));
                                NUT.NUD_Texture ntex = dds.toNUT_Texture();

                                tex.height  = ntex.height;
                                tex.width   = ntex.width;
                                tex.type    = ntex.type;
                                tex.mipmaps = ntex.mipmaps;
                                tex.utype   = ntex.utype;

                                GL.DeleteTexture(selected.draw[tex.id]);
                                selected.draw.Remove(tex.id);
                                selected.draw.Add(tex.id, NUT.loadImage(tex));
                            }
                        }
                    }
                    if (!Runtime.TextureContainers.Contains(nut))
                    {
                        Runtime.TextureContainers.Add(nut);
                    }
                    FillForm();
                }
            }
        }
Exemple #17
0
 private void loadImage(NUT selected)
 {
     NUT.NUD_Texture tex = selected.textures[0];
     selected.draw.Add(tex.id, NUT.loadImage(tex));
 }
        private void RenderTexture()
        {
            if (!tabControl1.SelectedTab.Text.Equals("Textures"))
            {
                return;
            }
            glControl1.MakeCurrent();
            GL.Viewport(glControl1.ClientRectangle);
            GL.ClearColor(Color.Red);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            GL.Enable(EnableCap.Texture2D);

            NUT.NUD_Texture tex = null;
            int             rt  = 0;

            if (material[current].entries.ContainsKey("NU_materialHash") && listView1.SelectedIndices.Count > 0)
            {
                int hash = material[current].textures[listView1.SelectedIndices[0]].hash;

                foreach (NUT n in Runtime.TextureContainers)
                {
                    if (n.draw.ContainsKey(hash))
                    {
                        n.getTextureByID(hash, out tex);
                        rt = n.draw[hash];
                        break;
                    }
                }
            }
            float h = 1f, w = 1f;

            if (tex != null)
            {
                float texureRatioW = tex.width / tex.height;
                float widthPre     = texureRatioW * glControl1.Height;
                w = glControl1.Width / widthPre;
                if (texureRatioW > glControl1.AspectRatio)
                {
                    w = 1f;
                    float texureRatioH = tex.height / tex.width;
                    float HeightPre    = texureRatioH * glControl1.Width;
                    h = glControl1.Height / HeightPre;
                }
            }

            GL.BindTexture(TextureTarget.Texture2D, rt);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToBorder);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToBorder);
            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(w, h);
            GL.Vertex2(1, -1);
            GL.TexCoord2(0, h);
            GL.Vertex2(-1, -1);
            GL.TexCoord2(0, 0);
            GL.Vertex2(-1, 1);
            GL.TexCoord2(w, 0);
            GL.Vertex2(1, 1);
            GL.End();

            glControl1.SwapBuffers();
        }
Exemple #19
0
        private void LetsDance(object sender, EventArgs e)
        {
            VBNViewport view = MainForm.Instance.viewports[0];

            view.CurrentMode = VBNViewport.Mode.Normal;

            NUT n = null;

            if (((MenuItem)sender).GetContextMenu().SourceControl == stock_90_renderer)
            {
                n = stock_90;
            }
            if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer)
            {
                n = chr_00;
            }
            if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer)
            {
                n = chr_11;
            }
            if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer)
            {
                n = chr_13;
            }
            if (n == null)
            {
                return;
            }

            byte[] data = RenderTools.DXT5ScreenShot(view.glControl1, view.shootX, view.shootY, view.shootWidth, view.shootHeight);
            int    id   = n.textures.Count > 0 ? n.textures[0].id : 0x280052B7;

            n.Destroy();
            n.textures.Clear();
            n.draw.Clear();

            NUT.NUD_Texture tex = new NUT.NUD_Texture();
            tex.width  = view.shootWidth;
            tex.height = view.shootHeight;
            tex.mipmaps.Add(FlipDXT5(data, tex.width, tex.height));
            tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
            tex.id   = id;
            n.textures.Add(tex);
            n.draw.Add(tex.id, NUT.loadImage(tex));
            ((MenuItem)sender).GetContextMenu().SourceControl.Invalidate();

            if (((MenuItem)sender).GetContextMenu().SourceControl == stock_90_renderer)
            {
                if (stock_90_loc != null)
                {
                    stock_90.Save(stock_90_loc);
                }
            }
            if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer)
            {
                if (chr_00_loc != null)
                {
                    chr_00.Save(chr_00_loc);
                }
            }
            if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer)
            {
                if (chr_11_loc != null)
                {
                    chr_11.Save(chr_13_loc);
                }
            }
            if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer)
            {
                if (chr_13_loc != null)
                {
                    chr_13.Save(chr_13_loc);
                }
            }
        }