Пример #1
0
        public static void N3DS_NW4C_GFX_ToOBJ(String BCMDLPath, int ModelIdx, String OBJPath)
        {
            CGFX c = new CGFX(File.ReadAllBytes(BCMDLPath));

            if (c.Data.Models == null || c.Data.Models.Length <= ModelIdx)
            {
                throw new Exception("Model does not exist in the specified CGFX file!");
            }
            CMDL Model = c.Data.Models[ModelIdx];
            OBJ  o     = Model.ToOBJ();

            o.MTLPath = Path.GetFileNameWithoutExtension(OBJPath) + ".mtl";
            MTL m = Model.ToMTL(Path.GetFileNameWithoutExtension(OBJPath) + "_Tex");

            byte[] d  = o.Write();
            byte[] d2 = m.Write();
            File.Create(OBJPath).Close();
            File.WriteAllBytes(OBJPath, d);
            File.Create(Path.ChangeExtension(OBJPath, "mtl")).Close();
            File.WriteAllBytes(Path.ChangeExtension(OBJPath, "mtl"), d2);
            Directory.CreateDirectory(Path.GetDirectoryName(OBJPath) + "\\" + Path.GetFileNameWithoutExtension(OBJPath) + "_Tex");
            foreach (var v in c.Data.Textures)
            {
                if (!(v is ImageTextureCtr))
                {
                    continue;
                }
                ((ImageTextureCtr)v).GetBitmap().Save(Path.GetDirectoryName(OBJPath) + "\\" + Path.GetFileNameWithoutExtension(OBJPath) + "_Tex\\" + v.Name + ".png");
            }
        }
Пример #2
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            saveFileDialog1.FileName = Model.Name;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK &&
                saveFileDialog1.FileName.Length > 0)
            {
                switch (saveFileDialog1.FilterIndex - 1)
                {
                case 0:
                {
                    DAE o = Model.ToDAE(Resource);
                    File.Create(saveFileDialog1.FileName).Close();
                    File.WriteAllBytes(saveFileDialog1.FileName, o.Write());
                    Directory.CreateDirectory(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\Tex");
                    foreach (var v in Resource.Data.Textures)
                    {
                        if (!(v is ImageTextureCtr))
                        {
                            continue;
                        }
                        ((ImageTextureCtr)v).GetBitmap().Save(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\Tex\\" + v.Name + ".png");
                    }
                    break;
                }

                case 1:
                {
                    OBJ o = Model.ToOBJ();
                    o.MTLPath = Path.GetFileNameWithoutExtension(saveFileDialog1.FileName) + ".mtl";
                    MTL    m  = Model.ToMTL("Tex");
                    byte[] d  = o.Write();
                    byte[] d2 = m.Write();
                    File.Create(saveFileDialog1.FileName).Close();
                    File.WriteAllBytes(saveFileDialog1.FileName, d);
                    File.Create(Path.ChangeExtension(saveFileDialog1.FileName, "mtl")).Close();
                    File.WriteAllBytes(Path.ChangeExtension(saveFileDialog1.FileName, "mtl"), d2);
                    Directory.CreateDirectory(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\Tex");
                    foreach (var v in Resource.Data.Textures)
                    {
                        //if (v.NrLevels > 2) v.GetBitmap(2).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
                        //else if (v.NrLevels > 1) v.GetBitmap(1).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
                        //else v.GetBitmap(0).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
                        if (!(v is ImageTextureCtr))
                        {
                            continue;
                        }
                        ((ImageTextureCtr)v).GetBitmap().Save(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\Tex\\" + v.Name + ".png");
                    }
                    break;
                }
                }
            }
        }