示例#1
0
        void ConvertEFE(byte[] Data, string Name)
        {
            _3DS.NintendoWare.GFX.CGFX mod = new _3DS.NintendoWare.GFX.CGFX(Data);
            CommonFiles.OBJ            o   = mod.Data.Models[0].ToOBJ();
            o.MTLPath = Path.GetFileNameWithoutExtension(Name) + ".mtl";
            MTL m = mod.Data.Models[0].ToMTL("Tex");

            byte[] d  = o.Write();
            byte[] d2 = m.Write();
            File.Create(Name).Close();
            File.WriteAllBytes(Name, d);
            File.Create(Path.ChangeExtension(Name, "mtl")).Close();
            File.WriteAllBytes(Path.ChangeExtension(Name, "mtl"), d2);
            Directory.CreateDirectory(Path.GetDirectoryName(Name) + "\\Tex");
            foreach (var v in mod.Data.Textures)
            {
                if (!(v is ImageTextureCtr))
                {
                    continue;
                }
                ((ImageTextureCtr)v).GetBitmap().Save(Path.GetDirectoryName(Name) + "\\Tex\\" + v.Name + ".png");
            }
        }
示例#2
0
        private void FrmObjImport_Load(object sender, EventArgs e)
        {
            OpenFileDialog opn = new OpenFileDialog();

            opn.Title  = "Open a model file";
            opn.Filter = "Supported formats (.bcmdl, .obj)|*.bcmdl; *.obj";
            bool ok = true;

            if (opn.ShowDialog() != DialogResult.OK)
            {
                ok = false;
            }
            if (Path.GetExtension(opn.FileName).ToLower() == ".obj")
            {
                if (MessageBox.Show("The obj will be converted to bcmdl with Every File Explorer's method, this is known to have problems, especially with models made in sketchup.\r\nDo you want to continue ?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    modelPath    = opn.FileName;
                    ObjModelPath = modelPath;
                    IsObj        = true;
                    render.addModel(modelPath, "Model", new System.Windows.Media.Media3D.Vector3D(0, 0, 0), new System.Windows.Media.Media3D.Vector3D(1, 1, 1), 0, 0, 0);
                }
                else
                {
                    MessageBox.Show("You can convert the model to bcmdl with the leaked tools");
                    this.Close();
                }
            }
            else if (Path.GetExtension(opn.FileName).ToLower() == ".bcmdl")
            {
                tmpPath = Path.GetTempPath() + "TmpT4D";
                string Name = tmpPath + "\\model.obj";
                Directory.CreateDirectory(tmpPath);
                CGFX mod = null;
                mod = new _3DS.NintendoWare.GFX.CGFX(File.ReadAllBytes(opn.FileName));
                CommonFiles.OBJ o = mod.Data.Models[0].ToOBJ();
                o.MTLPath = Path.GetFileNameWithoutExtension(Name) + ".mtl";
                MTL    m  = mod.Data.Models[0].ToMTL("Tex");
                byte[] d  = o.Write();
                byte[] d2 = m.Write();
                File.Create(Name).Close();
                File.WriteAllBytes(Name, d);
                File.Create(Path.ChangeExtension(Name, "mtl")).Close();
                File.WriteAllBytes(Path.ChangeExtension(Name, "mtl"), d2);
                Directory.CreateDirectory(tmpPath + "\\Tex");
                foreach (var v in mod.Data.Textures)
                {
                    if (!(v is ImageTextureCtr))
                    {
                        continue;
                    }
                    ((ImageTextureCtr)v).GetBitmap().Save(tmpPath + "\\Tex\\" + v.Name + ".png");
                }
                modelPath    = opn.FileName;
                ObjModelPath = Name;
                IsObj        = false;
                render.addModel(Name, "Model", new System.Windows.Media.Media3D.Vector3D(0, 0, 0), new System.Windows.Media.Media3D.Vector3D(1, 1, 1), 0, 0, 0);
                textBox1.Text    = mod.Data.Models[0].Name;
                textBox1.Enabled = false;
                render.SetSortFrequency(0);
            }
            else
            {
                if (ok)
                {
                    MessageBox.Show("File not supported");
                }
                else
                {
                    MessageBox.Show("You must select your model file to use this function");
                }
                this.Close();
            }
        }