예제 #1
0
        private void importNutFromFolder(object sender, EventArgs e)
        {
            using (FolderSelectDialog f = new FolderSelectDialog())
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    Edited = true;
                    if (!Directory.Exists(f.SelectedPath))
                    {
                        Directory.CreateDirectory(f.SelectedPath);
                    }
                    NUT nut;
                    nut = currentNut;

                    foreach (var texPath in Directory.GetFiles(f.SelectedPath))
                    {
                        string extension = Path.GetExtension(texPath).ToLowerInvariant();
                        if (!(extension == ".dds" || extension == ".png"))
                        {
                            continue;
                        }
                        int  texId;
                        bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(texPath), NumberStyles.HexNumber,
                                                  new CultureInfo("en-US"), out texId);

                        NutTexture texture = null;
                        if (isTex)
                        {
                            foreach (NutTexture tex in nut.Nodes)
                            {
                                if (tex.HashId == texId)
                                {
                                    texture = tex;
                                }
                            }
                        }

                        if (texture == null)
                        {
                            //new texture
                            NutTexture tex = null;
                            if (extension == ".dds")
                            {
                                DDS dds = new DDS(new FileData(texPath));
                                tex = dds.ToNutTexture();
                            }
                            else if (extension == ".png")
                            {
                                tex = fromPNG(texPath, 1);
                            }

                            if (isTex)
                            {
                                tex.HashId = texId;
                            }
                            else
                            {
                                tex.HashId = nut.Nodes.Count;
                            }
                            nut.Nodes.Add(tex);
                            currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                            FillForm();
                        }
                        else
                        {
                            //existing texture
                            NutTexture tex = texture;

                            NutTexture ntex = null;
                            if (extension == ".dds")
                            {
                                DDS dds = new DDS(new FileData(texPath));
                                ntex = dds.ToNutTexture();
                            }
                            else if (extension == ".png")
                            {
                                ntex = fromPNG(texPath, 1);
                            }

                            tex.Height = ntex.Height;
                            tex.Width  = ntex.Width;
                            tex.pixelInternalFormat = ntex.pixelInternalFormat;
                            tex.surfaces            = ntex.surfaces;
                            tex.pixelFormat         = ntex.pixelFormat;

                            //GL.DeleteTexture(NUT.glTexByHashId[tex.HASHID]);
                            currentNut.glTexByHashId.Remove(tex.HashId);
                            currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                            FillForm();
                        }
                    }
                    if (!Runtime.TextureContainers.Contains(nut))
                    {
                        Runtime.TextureContainers.Add(nut);
                    }
                }
            }
            FillForm();
        }
예제 #2
0
        private void importNutFromFolder(object sender, EventArgs e)
        {
            using (FolderSelectDialog f = new FolderSelectDialog())
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    Edited = true;
                    if (!Directory.Exists(f.SelectedPath))
                    {
                        Directory.CreateDirectory(f.SelectedPath);
                    }
                    NUT nut;
                    nut = NUT;

                    foreach (var texPath in Directory.GetFiles(f.SelectedPath))
                    {
                        if (!(texPath.ToLower().EndsWith(".dds") || texPath.ToLower().EndsWith(".png")))
                        {
                            return;
                        }
                        int  texId;
                        bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(texPath), NumberStyles.HexNumber,
                                                  new CultureInfo("en-US"), out texId);

                        NUT_Texture texture = null;
                        foreach (NUT_Texture tex in nut.Nodes)
                        {
                            if (tex.HASHID == texId)
                            {
                                texture = tex;
                            }
                        }

                        if (texture == null)
                        {
                            //new texture
                            NUT_Texture tex = null;
                            if (texPath.ToLower().EndsWith(".png"))
                            {
                                tex = fromPNG(texPath, 1);
                            }
                            if (texPath.ToLower().EndsWith(".dds"))
                            {
                                DDS dds = new DDS(new FileData(texPath));
                                tex = dds.toNUT_Texture();
                            }
                            if (isTex)
                            {
                                tex.HASHID = texId;
                            }
                            else
                            {
                                tex.HASHID = nut.Nodes.Count;
                            }
                            nut.Nodes.Add(tex);
                            nut.draw.Add(tex.HASHID, NUT.loadImage(tex));
                            FillForm();
                        }
                        else
                        {
                            //old texture
                            NUT_Texture tex = texture;

                            NUT_Texture ntex = null;
                            if (texPath.ToLower().EndsWith(".png"))
                            {
                                ntex = fromPNG(texPath, 1);
                            }
                            if (texPath.ToLower().EndsWith(".dds"))
                            {
                                DDS dds = new DDS(new FileData(texPath));
                                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(NUT.draw[tex.HASHID]);
                            NUT.draw.Remove(tex.HASHID);
                            NUT.draw.Add(tex.HASHID, NUT.loadImage(tex));
                            FillForm();
                        }
                    }
                    if (!Runtime.TextureContainers.Contains(nut))
                    {
                        Runtime.TextureContainers.Add(nut);
                    }
                }
            }
            FillForm();
        }
예제 #3
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentNut == null)
            {
                return;
            }
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = "Supported Formats|*.dds;*.png|" +
                             "DirectDraw Surface (.dds)|*.dds|" +
                             "Portable Network Graphics (.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 (NutTexture te in currentNut.Nodes)
                        {
                            if (texId == te.HashId)
                            {
                                isTex = false;
                            }
                        }
                    }

                    NutTexture tex       = null;
                    string     extension = Path.GetExtension(ofd.FileName).ToLowerInvariant();
                    if (extension == ".dds")
                    {
                        DDS dds = new DDS(new FileData(ofd.FileName));
                        tex = dds.ToNutTexture();
                    }
                    else if (extension == ".png")
                    {
                        tex = fromPNG(ofd.FileName, 1);
                    }
                    else
                    {
                        return;
                    }

                    Edited = true;

                    if (isTex)
                    {
                        tex.HashId = texId;
                    }
                    else
                    {
                        tex.HashId = 0x40FFFF00 | (currentNut.Nodes.Count);
                    }

                    // Replace OpenGL texture.
                    if (currentNut.glTexByHashId.ContainsKey(tex.HashId))
                    {
                        currentNut.glTexByHashId.Remove(tex.HashId);
                    }

                    currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));

                    currentNut.Nodes.Add(tex);
                    FillForm();
                }
            }
        }
예제 #4
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (NUT != 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)
                    {
                        Edited = true;
                        int  texId;
                        bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(ofd.FileName), NumberStyles.HexNumber,
                                                  new CultureInfo("en-US"), out texId);

                        if (isTex)
                        {
                            foreach (NUT_Texture te in NUT.Nodes)
                            {
                                if (texId == te.HASHID)
                                {
                                    isTex = false;
                                }
                            }
                        }

                        NUT_Texture tex = null;

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

                        if (tex != null)
                        {
                            if (isTex)
                            {
                                tex.HASHID = texId;
                            }
                            else
                            {
                                tex.HASHID = 0x40FFFF00 | (NUT.Nodes.Count);
                            }

                            if (NUT.draw.ContainsKey(tex.HASHID))
                            {
                                NUT.draw.Remove(tex.HASHID);
                            }

                            NUT.Nodes.Add(tex);
                            NUT.draw.Add(tex.HASHID, NUT.loadImage(tex));
                            FillForm();
                        }
                    }
                }
            }
        }