예제 #1
0
        public void ExportModel(string folderPath, DAE.ExportSettings settings)
        {
            foreach (LM3_Model mdl in Nodes)
            {
                List <STGenericMaterial> Materials = new List <STGenericMaterial>();
                foreach (STGenericObject mesh in mdl.RenderedMeshes)
                {
                    if (mesh.GetMaterial() != null)
                    {
                        Materials.Add(mesh.GetMaterial());
                    }
                }

                if (!mdl.loaded)
                {
                    mdl.UpdateVertexData();
                }

                var model = new STGenericModel();
                model.Materials = Materials;
                model.Objects   = mdl.RenderedMeshes;

                settings.SuppressConfirmDialog = true;

                DAE.Export($"{folderPath}/{mdl.Text}.dae", settings, model, new List <STGenericTexture>());
            }

            System.Windows.Forms.MessageBox.Show($"Exported models Successfuly!");
        }
예제 #2
0
        public static void LoadKeyblade(string modelName, string movesetName, ref Model target)
        {
            Model keyblade = null;

            if (File.Exists(@"Content\Models\" + modelName + @"\" + modelName + ".dae"))
            {
                keyblade = new DAE(@"Content\Models\" + modelName + @"\" + modelName + ".dae");
                keyblade.Parse();
                MainGame.ResourceFiles.Add(keyblade);
                keyblade.Render      = true;
                keyblade.Opacity     = 0;
                keyblade.DestOpacity = 0;
            }

            if (keyblade != null && Directory.Exists(@"Content\Models\" + movesetName + @"\MSET"))
            {
                BinaryMoveset keybladeMset = new BinaryMoveset(@"Content\Models\" + movesetName + @"\MSET");
                keybladeMset.Links.Add(keyblade);
                keybladeMset.Master = (target.Links[0] as Moveset);

                keybladeMset.Parse();
                MainGame.ResourceFiles.Add(keybladeMset);
                keybladeMset.Render = true;

                keybladeMset.PlayingIndex = keybladeMset.idle_;

                keyblade.Links.Add(keybladeMset);
                keyblade.Master = target;
                target.Keyblade = keyblade;
            }
        }
예제 #3
0
        private void ExportAction(object sender, EventArgs args)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter   = "Collada DAE |*.dae;";
            sfd.FileName = System.IO.Path.GetFileNameWithoutExtension(FileName);
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                var model     = new STGenericModel();
                var materials = new List <STGenericMaterial>();
                var textures  = new List <STGenericTexture>();
                foreach (var mesh in Renderer.Meshes)
                {
                    materials.Add(mesh.GetMaterial());
                }
                foreach (var mesh in Renderer.Meshes)
                {
                    mesh.MaterialIndex = materials.IndexOf(mesh.GetMaterial());
                }
                foreach (var tex in Renderer.TextureList)
                {
                    textures.Add(tex);
                }

                model.Materials = materials;
                model.Objects   = Renderer.Meshes;

                ExportModelSettings exportDlg = new ExportModelSettings();
                if (exportDlg.ShowDialog() == DialogResult.OK)
                {
                    DAE.Export(sfd.FileName, exportDlg.Settings, model, textures, Skeleton);
                }
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            foreach (var arg in args)
            {
                if (Directory.Exists(arg))
                {
                    string folder      = Path.GetFileName(arg);
                    string daeFile     = $"{arg}/{folder}.dae";
                    var    importModel = (DaeFile)STFileLoader.OpenFileFormat(daeFile);

                    HSF hsf = new HSF()
                    {
                        FileInfo = new File_Info()
                    };
                    hsf.FromGeneric(importModel.Scene);
                    STFileSaver.SaveFileFormat(hsf, $"{folder}.new.hsf");
                }
                else if (File.Exists(arg))
                {
                    string folder = Path.GetFileNameWithoutExtension(arg);
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }

                    var file = STFileLoader.OpenFileFormat(arg);
                    Console.WriteLine($"file {file != null}");
                    DAE.Export($"{folder}/{folder}.dae", new DAE.ExportSettings()
                    {
                        ImageFolder = folder,
                    }, (IModelFormat)file);
                }
            }
        }
예제 #5
0
        public Bulle(string textFilename, int textIndex)
        {
            if (bulle == null)
            {
                bulle = new DAE("Content\\Effects\\Visual\\Bulle\\bulle.dae");
                bulle.Parse();
                VertexPositionColorTexture[] replace = new VertexPositionColorTexture[bulle.VertexBufferColor.Length * 2];
                Array.Copy(bulle.VertexBufferColor, 0, replace, 0, bulle.VertexBufferColor.Length);
                Array.Copy(bulle.VertexBufferColor, 0, replace, bulle.VertexBufferColor.Length, bulle.VertexBufferColor.Length);
                for (int i = 0; i < bulle.VertexBufferColor.Length; i++)
                {
                    replace[i].TextureCoordinate.Y += 0.25f;
                }

                /*bulle.VertexBufferColor = new VertexPositionColorTexture[bulle.VertexBufferColor.Length * 2];
                 * Array.Copy(replace, 0, bulle.VertexBufferColor, 0, bulle.VertexBufferColor.Length);*/
                bulle.VertexBufferColor    = replace;
                bulle.MeshesOffsets[0][1] *= 2;
                bulle.vBuffer              = new VertexBuffer(Program.game.graphics.GraphicsDevice, typeof(VertexPositionColorTexture), bulle.VertexBufferColor.Length, BufferUsage.None);
            }
            this.TextFileName = textFilename;
            this.SetText(textFilename, textIndex);
            this.NextText();

            /*this.Color = BulleColor.Red;
             * this.Type= BulleType.Information;*/


            /*this.Width = SpeechWidth;
             * this.Height = SpeechHeight;*/
            this.displayType = DisplayType.None;
        }
예제 #6
0
        static void ExportModel(MDL model)
        {
            IFileFormat fileFormat = (IFileFormat)model;
            string      daePath    = fileFormat.FileInfo.FileName.Replace(".mdl", ".dae");
            string      folder     = Path.GetFileNameWithoutExtension(fileFormat.FileInfo.FileName);
            string      folderDir  = Path.Combine(Path.GetDirectoryName(fileFormat.FileInfo.FilePath), folder);

            if (!Directory.Exists($"{folder}"))
            {
                Directory.CreateDirectory($"{folder}");
            }

            var materials    = model.Header.Materials;
            var drawElements = model.Header.DrawElements;

            //Export by draw element to export shape flags
            for (int i = 0; i < drawElements.Length; i++)
            {
                File.WriteAllText($"{folder}/Mesh{i}.json",
                                  model.ExportMaterial(drawElements[i]));
            }

            File.WriteAllText($"{folder}/SamplerList.json", model.ExportSamplers());

            var settings = new DAE.ExportSettings();

            settings.ImageFolder = folder;
            DAE.Export(Path.Combine(folderDir, daePath), settings, model);

            Console.WriteLine($"Exported model {model.FileInfo.FileName}!");
        }
예제 #7
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();

            foreach (var mesh in Renderer.Meshes)
            {
                if (mesh.GetMaterial() != null)
                {
                    Materials.Add(mesh.GetMaterial());
                }
            }

            var textures = new List <STGenericTexture>();

            foreach (var tex in PluginRuntime.stikersTextures)
            {
                textures.Add(tex);
            }

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = Renderer.Meshes;

            STSkeleton skeleton = null;

            if (DrawableContainer.Drawables.Count > 1)
            {
                skeleton = (STSkeleton)DrawableContainer.Drawables[1];
            }

            DAE.Export(fileName, settings, model, textures, skeleton);
        }
예제 #8
0
파일: GMX.cs 프로젝트: week9/Switch-Toolbox
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            var model = new STGenericModel();

            model.Materials = new List <STGenericMaterial>();
            model.Objects   = Renderer.Meshes;

            DAE.Export(fileName, settings, model, new List <STGenericTexture>(), new STSkeleton());
        }
예제 #9
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = Shapes;

            DAE.Export(fileName, settings, model, BcresParent.GetTextures(), Skeleton.Renderable);
        }
예제 #10
0
        public bool Convert(int FilterIndex, String Path)
        {
            switch (FilterIndex)
            {
            case 0:
            {
                DAE o = ToDAE(0);
                File.Create(Path).Close();
                File.WriteAllBytes(Path, o.Write());
                Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path) + "\\Tex");
                foreach (var v in Data.Textures)
                {
                    if (!(v is ImageTextureCtr))
                    {
                        continue;
                    }
                    ((ImageTextureCtr)v).GetBitmap().Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
                }
                return(true);
            }

            case 1:
            {
                if (Data.Models.Length == 0)
                {
                    return(false);
                }
                OBJ o = ToOBJ(0);
                o.MTLPath = System.IO.Path.GetFileNameWithoutExtension(Path) + ".mtl";
                MTL    m  = ToMTL(0);
                byte[] d  = o.Write();
                byte[] d2 = m.Write();
                File.Create(Path).Close();
                File.WriteAllBytes(Path, d);
                File.Create(System.IO.Path.ChangeExtension(Path, "mtl")).Close();
                File.WriteAllBytes(System.IO.Path.ChangeExtension(Path, "mtl"), d2);
                Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path) + "\\Tex");
                foreach (var v in 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(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
                }
                return(true);
            }

            default:
                return(false);
            }
        }
예제 #11
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;
                }
                }
            }
        }
예제 #12
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();
            //  foreach (var msh in DataDictionary.Renderer.Meshes)
            //    Materials.Add(msh.GetMaterial());

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = RenderedMeshes;

            DAE.Export(fileName, settings, model, new List <STGenericTexture>(), new STSkeleton());
        }
예제 #13
0
        public void Load(Stream stream)
        {
            this.Label = FileInfo.FileName;
            Tag        = this;
            Header     = DAE.Read(stream, FileInfo.FilePath);

            var model = ToGeneric();

            Header.Models[0].Skeleton.Reset();
            foreach (var child in model.CreateTreeHiearchy().Children)
            {
                AddChild(child);
            }
        }
예제 #14
0
        public void ExportModel(IExportableModel exportableModel, string fileName, DAE.ExportSettings settings)
        {
            var model = new STGenericModel();

            model.Materials = exportableModel.ExportableMaterials;
            model.Objects   = exportableModel.ExportableMeshes;
            var textures = new List <STGenericTexture>();

            foreach (var tex in exportableModel.ExportableTextures)
            {
                textures.Add(tex);
            }

            DAE.Export(fileName, settings, model, textures, exportableModel.ExportableSkeleton);
        }
예제 #15
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();

            foreach (STGenericMaterial mat in Nodes[0].Nodes)
            {
                Materials.Add(mat);
            }

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = ((GenericModelRenderer)DrawableContainer.Drawables[1]).Meshes;

            DAE.Export(fileName, settings, model, new List <STGenericTexture>(), ((STSkeleton)DrawableContainer.Drawables[0]));
        }
예제 #16
0
            public void BatchExportCombined(object sender, EventArgs args)
            {
                OpenFileDialog ofd = new OpenFileDialog();

                ofd.Multiselect = true;
                ofd.Filter      = "Supported Formats|*.bin";
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                SaveFileDialog sfd = new SaveFileDialog();

                sfd.Filter = "Supported Formats|*.dae";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    List <STGenericObject>   Objects   = new List <STGenericObject>();
                    STSkeleton               Skeleton  = new STSkeleton();
                    List <STGenericMaterial> Materials = new List <STGenericMaterial>();

                    int MatIndex = 0;
                    foreach (var file in ofd.FileNames)
                    {
                        LM2_ARCADE_Model model = new LM2_ARCADE_Model();
                        var stream             = File.Open(file, FileMode.Open);
                        model.Load(stream);
                        stream.Dispose();

                        foreach (STGenericMaterial mat in model.Nodes[0].Nodes)
                        {
                            mat.Text = $"Material {MatIndex++}";
                            Materials.Add(mat);
                        }

                        Skeleton.bones.AddRange(((STSkeleton)model.DrawableContainer.Drawables[0]).bones);
                        Objects.AddRange(((GenericModelRenderer)model.DrawableContainer.Drawables[1]).Meshes);

                        model.Unload();
                    }

                    ExportModelSettings settings = new ExportModelSettings();
                    if (settings.ShowDialog() == DialogResult.OK)
                    {
                        DAE.Export(sfd.FileName, settings.Settings, Objects, Materials, new List <STGenericTexture>(), Skeleton);
                    }
                }
            }
예제 #17
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();

            foreach (STGenericObject mesh in RenderedMeshes)
            {
                if (mesh.GetMaterial() != null)
                {
                    Materials.Add(mesh.GetMaterial());
                }
            }

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = RenderedMeshes;

            DAE.Export(fileName, settings, model, new List <STGenericTexture>());
        }
예제 #18
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            var model = new STGenericModel();

            model.Materials = Model.GenericMaterials;
            model.Objects   = Model.GenericMeshes;
            var textures = new List <STGenericTexture>();

            foreach (var bntx in PluginRuntime.bntxContainers)
            {
                foreach (var tex in bntx.Textures.Values)
                {
                    if (Model.Textures.Contains(tex.Text))
                    {
                        textures.Add(tex);
                    }
                }
            }

            DAE.Export(fileName, settings, model, textures, Model.Skeleton);
        }
예제 #19
0
        public void CalculateAnglesFromMatrices()
        {
            this.Scale     = this.Matrix.ExtractScale();
            this.Translate = this.Matrix.ExtractTranslation();
            Matrix4 mq       = Matrix4.CreateFromQuaternion(this.Matrix.ExtractRotation());
            double  sy       = Math.Sqrt(mq.M11 * mq.M11 + mq.M12 * mq.M12);
            bool    singular = sy < 1e-6;

            if (!singular)
            {
                this.Rotate.X = DAE.GetSingle(Math.Atan2(mq.M23, mq.M33));
                this.Rotate.Y = DAE.GetSingle(Math.Atan2(-mq.M13, sy));
                this.Rotate.Z = DAE.GetSingle(Math.Atan2(mq.M12, mq.M11));
            }
            else
            {
                this.Rotate.X = DAE.GetSingle(Math.Atan2(-mq.M32, mq.M22));
                this.Rotate.Y = DAE.GetSingle(Math.Atan2(-mq.M13, sy));
                this.Rotate.Z = 0;
            }
        }
예제 #20
0
        private void ExportModel(string FileName)
        {
            var model = new STGenericModel();
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();

            foreach (STGenericObject mesh in DataDictionary.Renderer.Meshes)
            {
                if (mesh.GetMaterial() != null)
                {
                    Materials.Add(mesh.GetMaterial());
                }
            }

            model.Materials = Materials;
            model.Objects   = DataDictionary.Renderer.Meshes;

            ExportModelSettings settings = new ExportModelSettings();

            if (settings.ShowDialog() == DialogResult.OK)
            {
                DAE.Export(FileName, settings.Settings, model, new List <STGenericTexture>());
            }
        }
예제 #21
0
        public PAX(string filename)
        {
            /*FileStream fs = new FileStream(@"D:\Desktop\KHDebug\KHDebug\bin\DesktopGL\AnyCPU\Debug\Content\Effects\Visual\SavePoint\p0\MSET\move_001.frames", FileMode.Create);
             * BinaryWriter wr = new BinaryWriter(fs);
             *
             * for (int i=0;i<500;i++)
             * {
             *
             *      float v1 = (float)(Math.Sin((i/250f)*Math.PI)+1)/2f;
             *      float v2 = 1- v1;
             *
             *      wr.Write((ushort)11);
             *      wr.Write((ushort)0);
             *      wr.Write(1.000f * v1 + 0.745f * v2);
             *
             *      wr.Write((ushort)12);
             *      wr.Write((ushort)0);
             *      wr.Write(0.999f * v1 + 1.000f * v2);
             *
             *      wr.Write((ushort)13);
             *      wr.Write((ushort)0);
             *      wr.Write(0.745f * v1 + 0.982f * v2);
             *
             *      wr.Write((ushort)11);
             *      wr.Write((ushort)2);
             *      wr.Write(1.000f * v1 + 0.745f * v2);
             *
             *      wr.Write((ushort)12);
             *      wr.Write((ushort)2);
             *      wr.Write(0.999f * v1 + 1.000f * v2);
             *
             *      wr.Write((ushort)13);
             *      wr.Write((ushort)2);
             *      wr.Write(0.745f * v1 + 0.982f * v2);
             *
             *
             *      if ((i >= 43 && i < 63)||
             *              (i >= 168 && i < 188)||
             *              (i >= 294 && i < 314)||
             *              (i >= 420 && i < 440))
             *      {
             *              wr.Write((ushort)10);
             *              wr.Write((ushort)1);
             *              if (i >= 420)
             *                      wr.Write(1f- ((i - 420) / 20f));
             *              else if (i >= 294)
             *                      wr.Write(1f - ((i - 294) / 20f));
             *              else if (i >= 168)
             *                      wr.Write(1f - ((i - 168) / 20f));
             *              else
             *                      wr.Write(1f - ((i - 43) / 20f));
             *      }
             *      else
             *
             *              if (i < 43 ||
             *              (i >= 126 && i < 168) ||
             *              (i >= 251 && i < 294) ||
             *              (i >= 377 && i < 420))
             *      {
             *              wr.Write((ushort)10);
             *              wr.Write((ushort)1);
             *              wr.Write(1f);
             *      }
             *      else
             *      {
             *              wr.Write((ushort)10);
             *              wr.Write((ushort)1);
             *              wr.Write(0f);
             *      }
             *
             *
             *      if (i < 10)
             *      {
             *              wr.Write((ushort)10);
             *              wr.Write((ushort)0);
             *              wr.Write((i / 9f));
             *
             *              wr.Write((ushort)10);
             *              wr.Write((ushort)2);
             *              wr.Write(i / 9f);
             *
             *              wr.Write((ushort)10);
             *              wr.Write((ushort)3);
             *              wr.Write(i / 9f);
             *      }
             *
             *      wr.Write(-1);
             * }
             *
             * wr.Close();
             * fs.Close();*/

            /*FileStream fs = new FileStream(@"Content\Effects\Visual\FakeHUD\MSET\move_002.frames", FileMode.OpenOrCreate);
             * BinaryWriter wr = new BinaryWriter(fs);
             * for (int i = 0; i < 1; i++)
             * {
             *  wr.Write((ushort)14);
             *  wr.Write((ushort)0);
             *  wr.Write(0f);
             *
             *  wr.Write(-1);
             * }
             *
             * wr.Close();
             * fs.Close();
             * fs.Close();*/

            if (File.Exists(filename.Replace(".dae", ".info")))
            {
                string[] input = File.ReadAllLines(filename.Replace(".dae", ".info"));
                switch (input[0])
                {
                case "None":
                    this.DType = DrawType.None;
                    break;

                case "ToScreen2D":
                    this.DType = DrawType.ToScreen2D;
                    break;

                case "FullScreen":
                    this.DType = DrawType.FullScreen;
                    break;

                case "YawPitchX":
                    this.DType = DrawType.YawPitchX;
                    break;

                case "YawPitchY":
                    this.DType = DrawType.YawPitchY;
                    break;

                case "YawPitchAll":
                    this.DType = DrawType.YawPitchAll;
                    break;

                case "YawX":
                    this.DType = DrawType.YawX;
                    break;

                case "YawY":
                    this.DType = DrawType.YawY;
                    break;

                case "YawAll":
                    this.DType = DrawType.YawAll;
                    break;

                case "PitchX":
                    this.DType = DrawType.PitchX;
                    break;

                case "PitchY":
                    this.DType = DrawType.PitchY;
                    break;

                case "PitchAll":
                    this.DType = DrawType.PitchAll;
                    break;
                }
                if (input[1] == "CullNone")
                {
                    this.Cull = false;
                }
                if (input[2] == "DepthNone")
                {
                    this.Depth = false;
                }
            }

            daeFile = new DAE(filename);
            daeFile.Parse();
            RecreateVertexBuffer(true);
            //daeFile.ModelType = Model.MDType.Sky;
            //daeFile.Location = new Vector3(0, 0, 0);

            if (Directory.Exists(filename.Replace(Path.GetFileName(filename), "MSET")))
            {
                moveFile = new BinaryMoveset(filename.Replace(Path.GetFileName(filename), "MSET"));
                moveFile.Links.Add(daeFile);
                moveFile.Parse();
                moveFile.PlayingIndex         = 0;
                moveFile.InterpolateAnimation = false;
                daeFile.Links.Add(moveFile);

                string[] frameFiles = Directory.GetFiles(filename.Replace(Path.GetFileName(filename), "MSET"), "*.frames");
                Array.Sort(frameFiles);

                Frames        = new byte[frameFiles.Length][];
                FramesIndices = new List <int> [frameFiles.Length];

                for (int i = 0; i < Frames.Length; i++)
                {
                    Frames[i]        = File.ReadAllBytes(frameFiles[i]);
                    FramesIndices[i] = new List <int>(0);
                    FramesIndices[i].Add(0);
                    for (int j = 0; j < Frames[i].Length - 4; j += 4)
                    {
                        int read = BitConverter.ToInt32(Frames[i], j);
                        if (read == -1)
                        {
                            FramesIndices[i].Add(j + 4);
                        }
                    }
                }
            }
        }
예제 #22
0
        /// <summary>
        ///     Exports a file of a given type.
        ///     Formats available to export will depend on the type of the data.
        /// </summary>
        /// <param name="type">Type of the data to be exported</param>
        /// <param name="data">The data</param>
        /// <param name="arguments">Optional arguments to be used by the exporter</param>
        public static void export(fileType type, object data, params int[] arguments)
        {
            string fileName = null;

            switch (type)
            {
            case fileType.container:
                foreach (OContainer.fileEntry file in ((OContainer)data).content)
                {
                    Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\" + ((OContainer)data).name);

                    fileName = Path.Combine(System.Environment.CurrentDirectory + "\\" + ((OContainer)data).name, file.name);
                    string dir = Path.GetDirectoryName(fileName);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    byte[] buffer;

                    if (file.loadFromDisk)
                    {
                        buffer = new byte[file.fileLength];
                        ((OContainer)data).data.Seek(file.fileOffset, SeekOrigin.Begin);
                        ((OContainer)data).data.Read(buffer, 0, buffer.Length);
                    }
                    else
                    {
                        buffer = file.data;
                    }

                    if (file.doDecompression)
                    {
                        buffer = LZSS_Ninty.decompress(buffer);
                    }

                    File.WriteAllBytes(fileName, buffer);
                    Console.WriteLine("Extracted file: " + fileName);
                }
                break;

            case fileType.model:
                for (int i = 0; i < ((RenderBase.OModelGroup)data).model.Count; i++)
                {
                    fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OModelGroup)data).model[i].name);

                    switch (arguments[0])
                    {
                    case 0: DAE.export(((RenderBase.OModelGroup)data), fileName + ".dae", i); break;

                    case 1: SMD.export(((RenderBase.OModelGroup)data), fileName + ".smd", i); break;

                    case 2: OBJ.export(((RenderBase.OModelGroup)data), fileName + ".obj", i); break;

                    case 3: CMDL.export(((RenderBase.OModelGroup)data), fileName + ".cmdl", i); break;
                    }

                    Console.WriteLine("Extracted file: " + fileName);
                }
                break;

            case fileType.texture:
                if (data.GetType().Equals(typeof(RenderBase.OModelGroup)))       //if extracting textures from a model
                {
                    Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\" + ((RenderBase.OModelGroup)data).model[0].name + "_tex");

                    foreach (RenderBase.OTexture tex in ((RenderBase.OModelGroup)data).texture)
                    {
                        fileName = Path.Combine(System.Environment.CurrentDirectory + "\\" + ((RenderBase.OModelGroup)data).model[0].name + "_tex", tex.name + ".png");
                        tex.texture.Save(fileName);
                        Console.WriteLine("Extracted file: " + fileName);
                    }
                }
                else     // not a model
                {
                    fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OTexture)data).name + ".png");
                    ((RenderBase.OTexture)data).texture.Save(fileName);
                    Console.WriteLine("Extracted file: " + fileName);
                }
                break;

            case fileType.skeletalAnimation:
                fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OModelGroup)data).model[0].name);
                SMD.export((RenderBase.OModelGroup)data, fileName, arguments[0], arguments[1]);
                Console.WriteLine("Extracted file: " + fileName);
                break;
            }
            Console.WriteLine("Extracting files completed!");
        }
예제 #23
0
        public void Parse()
        {
            this.ResourceIndex = Array.IndexOf(Resource.ResourceIndices, this.FileName.Split('.')[0] + ".");
            this.IsSky         = this.Name.Contains("SKY");


            FileStream   fs     = new FileStream(this.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader reader = new BinaryReader(fs);

            this.ModelType = (MDType)reader.ReadSByte();
            this.NoCull    = reader.ReadSByte() < 0;
            this.ZIndex    = (int)reader.ReadSByte();
            reader.ReadSByte();
            int textureCount = reader.ReadInt32();

            if (this.ModelType == MDType.Map)
            {
                for (int i = 0; i < 10; i++)
                {
                    if (File.Exists(Path.GetDirectoryName(this.FileName) + @"\SKY\" + this.Name + "-SKY" + i + ".dae"))
                    {
                        string fname = Path.GetDirectoryName(this.FileName) + @"\SKY\" + this.Name + "-SKY" + i + ".dae";

                        Model model = new DAE(Path.GetDirectoryName(this.FileName) + @"\SKY\" + this.Name + "-SKY" + i + ".dae");
                        model.Parse();

                        BinaryMoveset bm = null;
                        if (Directory.Exists(Path.GetDirectoryName(fname) + "\\" + Path.GetFileNameWithoutExtension(fname)))
                        {
                            bm = new BinaryMoveset(Path.GetDirectoryName(fname) + "\\" + Path.GetFileNameWithoutExtension(fname));
                            bm.Links.Add(model);
                            bm.Parse();
                            bm.PlayingIndex = 0;
                            bm.Render       = true;
                            model.Links.Add(bm);
                        }
                        this.SuppMsets.Add(bm);
                        this.Supp.Add(model);
                    }
                }
            }
            if (Directory.Exists(Path.GetDirectoryName(this.FileName) + @"\OBJECTS"))
            {
                string[] files = Directory.GetFiles(Path.GetDirectoryName(this.FileName) + @"\OBJECTS", "*.dae");

                for (int i = 0; i < files.Length; i++)
                {
                    Model dae = new DAE(files[i])
                    {
                        Render    = true,
                        ModelType = files[i].Contains("-sp") ? MDType.Specular : MDType.Sky
                    };
                    dae.Parse();
                    //(dae as DAE).ExportBin();

                    BinaryMoveset bm = null;

                    if (Directory.Exists(Path.GetDirectoryName(files[i]) + "\\" + Path.GetFileNameWithoutExtension(files[i])))
                    {
                        bm = new BinaryMoveset(Path.GetDirectoryName(files[i]) + "\\" + Path.GetFileNameWithoutExtension(files[i]));
                        bm.Links.Add(dae);
                        bm.Parse();
                        bm.PlayingIndex     = 0;
                        bm.ObjectMsetRender = bm.Name.Contains("-mdl-");
                        bm.Render           = true;
                        dae.Links.Add(bm);
                    }

                    this.SuppMsets.Add(bm);
                    this.Supp.Add(dae);
                }
            }
            this.FogStart = reader.ReadInt16() * 10f;
            this.FogEnd   = reader.ReadInt16() * 10f;
            this.FogColor = (new Microsoft.Xna.Framework.Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte())).ToVector3();

            reader.Close();
            fs.Close();

            if (sunbeamList == null)
            {
                sunbeamList = File.ReadAllLines("Content\\Effects\\Visual\\Sun\\sunpositions.txt");
            }
            for (int i = 0; i < sunbeamList.Length; i++)
            {
                string[] spli = sunbeamList[i].Split('|');
                if (spli[0] == this.Name)
                {
                    spli         = spli[1].Split(';');
                    this.sunbeam = new SunBeam
                    {
                        From = new Vector3(MainGame.SingleParse(spli[0]), MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]))
                    };
                    this.sunbeam.coll = new Collision("Content\\Effects\\Visual\\Sun\\" + this.Name + ".obj");
                }
            }


            for (int i = 0; i < this.Supp.Count; i++)
            {
                for (int j = i + 1; j < this.Supp.Count; j++)
                {
                    if (this.Supp[j].ZIndex < this.Supp[i].ZIndex)
                    {
                        var curr = this.Supp[j];
                        this.Supp.RemoveAt(j);
                        this.Supp.Insert(0, curr);
                        var currM = this.SuppMsets[j];
                        this.SuppMsets.RemoveAt(j);
                        this.SuppMsets.Insert(0, currM);
                    }
                }
            }


            base.Parse();
        }
        private void ok()
        {
            if (!Directory.Exists(TxtOutFolder.Text))
            {
                MessageBox.Show("Invalid output directory!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            Settings.Default.meOutFolder = TxtOutFolder.Text;

            int format = 0;

            if (RadioSMD.Checked)
            {
                format = 1;
            }
            else if (RadioOBJ.Checked)
            {
                format = 2;
            }
            else if (RadioCMDL.Checked)
            {
                format = 3;
            }

            Settings.Default.meFormat        = format;
            Settings.Default.meExportAllMdls = ChkExportAllModels.Checked;
            Settings.Default.meExportAllAnms = ChkExportAllAnimations.Checked;

            Settings.Default.Save();

            if (ChkExportAllModels.Checked && !ChkExportAllAnimations.Checked)
            {
                for (int i = 0; i < mdls.model.Count; i++)
                {
                    string fileName = Path.Combine(TxtOutFolder.Text, mdls.model[i].name);

                    switch (format)
                    {
                    case 0: DAE.export(mdls, fileName + ".dae", i); break;

                    case 1: SMD.export(mdls, fileName + ".smd", i); break;

                    case 2: OBJ.export(mdls, fileName + ".obj", i); break;

                    case 3: CMDL.export(mdls, fileName + ".cmdl", i); break;
                    }
                }
            }
            else if (mdlIndex > -1)
            {
                string fileName = Path.Combine(TxtOutFolder.Text, TxtModelName.Text);

                switch (format)
                {
                case 0: DAE.export(mdls, fileName + ".dae", mdlIndex); break;

                case 1:
                    SMD.export(mdls, fileName + ".smd", mdlIndex);
                    if (ChkExportAllAnimations.Checked)
                    {
                        for (int i = 0; i < mdls.skeletalAnimation.list.Count; i++)
                        {
                            string name = mdls.skeletalAnimation.list[i].name + ".smd";
                            SMD.export(mdls, Path.Combine(TxtOutFolder.Text, name), mdlIndex, i);
                        }
                    }
                    break;

                case 2: OBJ.export(mdls, fileName + ".obj", mdlIndex); break;

                case 3: CMDL.export(mdls, fileName + ".cmdl", mdlIndex); break;
                }
            }

            Close();
        }
예제 #25
0
        public DAE ToDAE(CGFX Resource)
        {
            var m = this;
            var o = new DAE();
            o.Content.scene = new DAE.COLLADA._scene();
            o.Content.scene.instance_visual_scene = new DAE.InstanceWithExtra();
            o.Content.scene.instance_visual_scene.url = "#ID1";
            o.Content.library_visual_scenes = new DAE.library_visual_scenes();
            var scene = new DAE.visual_scene("ID1");
            var rootnode = new DAE.node(m.Name);
            scene.node.Add(rootnode);
            o.Content.library_visual_scenes.visual_scene.Add(scene);
            o.Content.library_geometries = new DAE.library_geometries();
            o.Content.library_materials = new DAE.library_materials();
            o.Content.library_effects = new DAE.library_effects();
            if (Resource.Data.Textures != null && Resource.Data.Textures.Length > 0) o.Content.library_images = new DAE.library_images();
            int id = 2;
            int i = 0;
            foreach (var matt in m.Materials)
            {
                var mat2 = new DAE.material();
                mat2.id = "ID" + id++;
                mat2.name = matt.Name;
                var eff = new DAE.effect();
                eff.id = "ID" + id++;
                mat2.instance_effect = new DAE.instance_effect();
                mat2.instance_effect.url = "#" + eff.id;
                eff.profile_COMMON = new DAE.profile_COMMON();
                eff.profile_COMMON.technique = new DAE.profile_COMMON._technique();
                eff.profile_COMMON.technique.sid = "COMMON";
                eff.profile_COMMON.technique.lambert = new DAE.profile_COMMON._technique._lambert();
                eff.profile_COMMON.technique.lambert.diffuse = new DAE.common_color_or_texture_type();
                if (matt.Tex0 != null && matt.Tex0.TextureObject is ReferenceTexture)
                {
                    string texid = "ID" + id++;
                    o.Content.library_images.image.Add(new DAE.image() { id = texid, init_from = "Tex/" + ((ReferenceTexture)matt.Tex0.TextureObject).LinkedTextureName + ".png" });

                    var param1 = new DAE.common_newparam_type() { sid = "ID" + id++, choice = new DAE.fx_surface_common() { type = DAE.fx_surface_type_enum._2D } };
                    ((DAE.fx_surface_common)param1.choice).init_from.Add(new DAE.fx_surface_init_from_common() { content = texid });
                    eff.profile_COMMON.newparam = new List<DAE.common_newparam_type>();
                    eff.profile_COMMON.newparam.Add(param1);
                    eff.profile_COMMON.newparam.Add(new DAE.common_newparam_type() { sid = "ID" + id++, choice = new DAE.fx_sampler2D_common() { source = param1.sid } });
                    eff.profile_COMMON.technique.lambert.diffuse.texture = new DAE.common_color_or_texture_type._texture() { texture = eff.profile_COMMON.newparam[1].sid, texcoord = "UVSET0" };
                }
                else
                {
                    eff.profile_COMMON.technique.lambert.diffuse.color = new DAE.common_color_or_texture_type._color();
                    eff.profile_COMMON.technique.lambert.diffuse.color.content = Color.White;
                }
                o.Content.library_materials.material.Add(mat2);
                o.Content.library_effects.effect.Add(eff);
            }

            int ff = 0;
            //foreach (CMDL m in Models)
            {
                foreach (var vv in m.Shapes)
                {
                    var geometry = new DAE.geometry();
                    geometry.id = "ID" + id++;

                    Polygon p = vv.GetVertexData(m);
                    var mat = m.Materials[m.Meshes[ff].MaterialIndex];

                    geometry.mesh = new DAE.mesh();
                    geometry.mesh.vertices = new DAE.vertices() { id = "ID" + id++ };
                    if (p.Vertex != null)
                    {
                        var src = new DAE.source() { id = "ID" + id++ };
                        src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Vertex.Length * 3 };
                        foreach (var v in p.Vertex)
                        {
                            src.float_array.content.Add(v.X);
                            src.float_array.content.Add(v.Y);
                            src.float_array.content.Add(v.Z);
                        }
                        src.technique_common = new DAE.source._technique_common();
                        src.technique_common.accessor = new DAE.accessor();
                        src.technique_common.accessor.count = (uint)p.Vertex.Length;
                        src.technique_common.accessor.source = "#" + src.float_array.id;
                        src.technique_common.accessor.stride = 3;
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "X", type = "float" });
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "Y", type = "float" });
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "Z", type = "float" });
                        geometry.mesh.source.Add(src);
                        geometry.mesh.vertices.input.Add(new DAE.InputLocal() { semantic = "POSITION", source = "#" + src.id });
                    }
                    if (p.Normals != null)
                    {
                        var src = new DAE.source() { id = "ID" + id++ };
                        src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Normals.Length * 3 };
                        foreach (var v in p.Normals)
                        {
                            src.float_array.content.Add(v.X);
                            src.float_array.content.Add(v.Y);
                            src.float_array.content.Add(v.Z);
                        }
                        src.technique_common = new DAE.source._technique_common();
                        src.technique_common.accessor = new DAE.accessor();
                        src.technique_common.accessor.count = (uint)p.Normals.Length;
                        src.technique_common.accessor.source = "#" + src.float_array.id;
                        src.technique_common.accessor.stride = 3;
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "X", type = "float" });
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "Y", type = "float" });
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "Z", type = "float" });
                        geometry.mesh.source.Add(src);
                        geometry.mesh.vertices.input.Add(new DAE.InputLocal() { semantic = "NORMAL", source = "#" + src.id });
                    }
                    DAE.source texcoordsrc = null;
                    if (p.TexCoords != null)
                    {
                        if (mat.NrActiveTextureCoordiators > 0 && mat.TextureCoordiators[0].MappingMethod == 0)
                        {
                            Vector2[] texc;
                            if (mat.TextureCoordiators[0].SourceCoordinate == 0)
                            {
                                texc = p.TexCoords.ToArray();
                            }
                            else if (mat.TextureCoordiators[0].SourceCoordinate == 1)
                            {
                                texc = p.TexCoords2.ToArray();
                            }
                            else
                            {
                                texc = p.TexCoords3.ToArray();
                            }

                            var src = texcoordsrc = new DAE.source() { id = "ID" + id++ };
                            src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)texc.Length * 2 };
                            foreach (var v in texc)
                            {
                                Vector2 result = v * new Matrix34(mat.TextureCoordiators[0].Matrix);
                                src.float_array.content.Add(result.X);
                                src.float_array.content.Add(result.Y);
                            }
                            src.technique_common = new DAE.source._technique_common();
                            src.technique_common.accessor = new DAE.accessor();
                            src.technique_common.accessor.count = (uint)p.TexCoords.Length;
                            src.technique_common.accessor.source = "#" + src.float_array.id;
                            src.technique_common.accessor.stride = 2;
                            src.technique_common.accessor.param.Add(new DAE.param() { name = "S", type = "float" });
                            src.technique_common.accessor.param.Add(new DAE.param() { name = "T", type = "float" });
                            geometry.mesh.source.Add(src);
                        }
                    }
                    DAE.source colorsrc = null;
                    if (p.Colors != null)
                    {
                        var src = colorsrc = new DAE.source() { id = "ID" + id++ };
                        src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Colors.Length * 4 };
                        foreach (var v in p.Colors)
                        {
                            src.float_array.content.Add(v.R / 255f);
                            src.float_array.content.Add(v.G / 255f);
                            src.float_array.content.Add(v.B / 255f);
                            src.float_array.content.Add(v.A / 255f);
                        }
                        src.technique_common = new DAE.source._technique_common();
                        src.technique_common.accessor = new DAE.accessor();
                        src.technique_common.accessor.count = (uint)p.Colors.Length;
                        src.technique_common.accessor.source = "#" + src.float_array.id;
                        src.technique_common.accessor.stride = 4;
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "R", type = "float" });
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "G", type = "float" });
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "B", type = "float" });
                        src.technique_common.accessor.param.Add(new DAE.param() { name = "A", type = "float" });
                        geometry.mesh.source.Add(src);
                    }

                    foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
                    {
                        Vector3[] defs = q.GetFaceData();

                        var tri = new DAE.triangles() { count = (uint)defs.Length, material = mat.Name };
                        uint offs = 0;
                        tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "VERTEX", source = "#" + geometry.mesh.vertices.id });
                        if (texcoordsrc != null) tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "TEXCOORD", source = "#" + texcoordsrc.id });
                        if (colorsrc != null) tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "COLOR", source = "#" + colorsrc.id, set = 0 });
                        tri.p.Add(new DAE.p());
                        foreach (Vector3 d in defs)
                        {
                            tri.p[0].content.Add((ulong)d.X);
                            if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.X);
                            if (colorsrc != null) tri.p[0].content.Add((ulong)d.X);
                            tri.p[0].content.Add((ulong)d.Y);
                            if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.Y);
                            if (colorsrc != null) tri.p[0].content.Add((ulong)d.Y);
                            tri.p[0].content.Add((ulong)d.Z);
                            if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.Z);
                            if (colorsrc != null) tri.p[0].content.Add((ulong)d.Z);
                        }
                        geometry.mesh.triangles.Add(tri);
                    }
                    o.Content.library_geometries.geometry.Add(geometry);
                    var instgem = new DAE.instance_geometry() { url = "#" + geometry.id };
                    instgem.bind_material = new DAE.bind_material();
                    instgem.bind_material.technique_common = new DAE.bind_material._technique_common();
                    var instmat = new DAE.instance_material();
                    instmat.symbol = mat.Name;
                    instmat.target = "#" + o.Content.library_materials.material[(int)m.Meshes[ff].MaterialIndex].id;
                    instmat.bind_vertex_input.Add(new DAE.instance_material._bind_vertex_input() { semantic = "UVSET0", input_semantic = "TEXCOORD", input_set = 0 });
                    instgem.bind_material.technique_common.instance_material.Add(instmat);
                    rootnode.instance_geometry.Add(instgem);
                    ff++;
                }
            }
            return o;
        }
예제 #26
0
파일: Form1.cs 프로젝트: VelouriasMoon/FEAT
        private void Open(string infile)
        {
            FileAttributes fileAttributes = File.GetAttributes(infile);

            if (fileAttributes.HasFlag(FileAttributes.Directory))
            {
                if (ModifierKeys == Keys.Control)
                {
                    AddLine(richTextBox1, $"Building Arc from {Path.GetFileName(infile)}...");
                    FEArc.PackArc(infile, Alignment, enablePaddingToolStripMenuItem.Checked);
                    AddLine(richTextBox1, "Done");
                }
                else if (ModifierKeys == Keys.Shift)
                {
                    AddLine(richTextBox1, $"Building BCH from {Path.GetFileName(infile)}...");

                    if (infile.EndsWith("_"))
                    {
                        infile = infile.Substring(0, infile.Length - "_".Length);
                    }

                    if (File.Exists(infile + ".bch"))
                    {
                        File.Delete(infile + ".bch");
                    }

                    List <string> files = Directory.GetFiles(infile, "*.*", SearchOption.AllDirectories).ToList();
                    H3D           Scene = new H3D();
                    Scene.ConverterVersion      = 44139;
                    Scene.BackwardCompatibility = 34;
                    Scene.ForwardCompatibility  = 35;
                    foreach (string file in files)
                    {
                        Bitmap texture;
                        try
                        {
                            texture = (Bitmap)Bitmap.FromFile(file);
                        }
                        catch (OutOfMemoryException)
                        {
                            Console.WriteLine("invalid image format, skipping");
                            continue;
                        }
                        Scene.Textures.Add(new H3DTexture(Path.GetFileNameWithoutExtension(file), texture, SPICA.PICA.Commands.PICATextureFormat.RGBA8));
                    }

                    if (Scene.Textures.Count <= 0)
                    {
                        AddLine(richTextBox1, "Error");
                        AddLine(richTextBox1, $"No images found in {Path.GetFileName(infile)}");
                    }
                    else
                    {
                        H3D.Save($"{infile}.bch", Scene);
                        AddLine(richTextBox1, "Done");
                    }
                    return;
                }
                else if (ModifierKeys == Keys.Alt)
                {
                    AddLine(richTextBox1, $"Building CTPK from {Path.GetFileName(infile)}...");
                    CTPK.MakeCTPK(infile);
                    AddLine(richTextBox1, "Done");
                }
                else
                {
                    foreach (string p in (new DirectoryInfo(infile)).GetFiles().Select(f => f.FullName))
                    {
                        Open(p);
                    }
                    foreach (string p in (new DirectoryInfo(infile)).GetDirectories().Select(f => f.FullName))
                    {
                        Open(p);
                    }
                }
            }
            else
            {
                byte[] data    = File.ReadAllBytes(infile);
                string magic   = FEIO.GetMagic(data);
                string ext     = Path.GetExtension(infile);
                string outpath = ext.Length == 0 ? infile : infile.Replace(ext, "");

                if (ModifierKeys == Keys.Control || batchCompressToolStripMenuItem.Checked) // Compression Method
                {
                    byte[] cmp;
                    if (lZ10CompressionToolStripMenuItem.Checked)
                    {
                        AddLine(richTextBox1, $"Compressing {Path.GetFileName(infile)} to {Path.GetFileName(infile)}.lz using lz10...");
                        try
                        {
                            cmp = FEIO.LZ10Compress(data);
                        }
                        catch (Exception ex)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Compress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile + ".lz", cmp);
                        AddLine(richTextBox1, "Done");
                    }
                    else if (lZ11ToolStripMenuItem.Checked)
                    {
                        AddLine(richTextBox1, $"Compressing {Path.GetFileName(infile)} to {Path.GetFileName(infile)}.lz using lz11...");
                        try
                        {
                            cmp = FEIO.LZ11Compress(data);
                        }
                        catch (Exception ex)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Compress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile + ".lz", cmp);
                        AddLine(richTextBox1, "Done");
                    }
                    else if (lZ13ToolStripMenuItem.Checked)
                    {
                        AddLine(richTextBox1, $"Compressing {Path.GetFileName(infile)} to {Path.GetFileName(infile)}.lz using lz13...");
                        try
                        {
                            cmp = FEIO.LZ13Compress(data);
                        }
                        catch (Exception ex)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Compress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile + ".lz", cmp);
                        AddLine(richTextBox1, "Done");
                    }
                    else
                    {
                        AddLine(richTextBox1, "No Compression Method Selected, How did this even happen?");
                    }
                }
                else if (ext == ".lz" || magic == "Yaz0" || ext == ".cms" || ext == ".cmp") // Decompress Method
                {
                    byte[] dcmp;
                    if (data[0] == 0x10)
                    {
                        AddLine(richTextBox1, $"Decompressing {Path.GetFileName(infile)} using lz10...");
                        try
                        {
                            dcmp = FEIO.LZ10Decompress(data);
                        }
                        catch (Exception e)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Decompress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile.Replace(".lz", ""), dcmp);
                        AddLine(richTextBox1, "Done");
                    } //LZ10
                    else if (data[0] == 0x11)
                    {
                        AddLine(richTextBox1, $"Decompressing {Path.GetFileName(infile)} using lz11...");
                        try
                        {
                            dcmp = FEIO.LZ11Decompress(data);
                        }
                        catch (Exception e)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Decompress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile.Replace(".lz", ""), dcmp);
                        AddLine(richTextBox1, "Done");
                    } //LZ11
                    else if (data[0] == 0x13 && data[4] == 0x11)
                    {
                        AddLine(richTextBox1, $"Decompressing {Path.GetFileName(infile)} using lz13...");
                        try
                        {
                            dcmp = FEIO.LZ13Decompress(data);
                        }
                        catch (Exception e)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Decompress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile.Replace(".lz", ""), dcmp);
                        AddLine(richTextBox1, "Done");
                    } //LZ13
                    else if (magic == "Yaz0")
                    {
                        AddLine(richTextBox1, "Yaz0 Method not implemented");
                        return;
                    } //Yaz0
                    if (File.Exists(infile.Replace(".lz", "")) && autoExtractToolStripMenuItem.Checked)
                    {
                        Open(infile.Replace(".lz", ""));
                    }
                }
                else if (ext == ".arc") //Archive file
                {
                    AddLine(richTextBox1, $"Extract Files from {Path.GetFileName(infile)}...");
                    FEArc.ExtractArc(outpath, data);
                    AddLine(richTextBox1, "Done");
                }
                else if (magic == "BCH" || magic == "CGFX") //BCH / Bcres file
                {
                    H3D Scene = new H3D();
                    if (magic == "CGFX")
                    {
                        Scene = Gfx.Open(infile).ToH3D();
                    }
                    else
                    {
                        Scene = H3D.Open(data);
                    }

                    if (Directory.Exists(outpath))
                    {
                        Directory.Delete(outpath, true);
                    }
                    if (File.Exists(outpath))
                    {
                        outpath = outpath + "_";
                    }

                    //Export method for textures, this is always enabled by default
                    if (Scene.Textures.Count > 0)
                    {
                        AddLine(richTextBox1, $"Extracting Textures from {Path.GetFileName(infile)}...");
                        if (!Directory.Exists(outpath))
                        {
                            Directory.CreateDirectory(outpath);
                        }

                        foreach (var texture in Scene.Textures)
                        {
                            Image img = texture.ToBitmap();
                            img.Save($"{outpath}\\{texture.Name}.png", System.Drawing.Imaging.ImageFormat.Png);
                        }
                        AddLine(richTextBox1, "Done");
                    }
                    if (exportDaeToolStripMenuItem.Checked || exportSMDToolStripMenuItem.Checked && Scene.Models.Count > 0)
                    {
                        AddLine(richTextBox1, $"Extracting Models from {Path.GetFileName(infile)}...");
                        if (!Directory.Exists(outpath))
                        {
                            Directory.CreateDirectory(outpath);
                        }

                        for (int i = 0; i < Scene.Models.Count; i++)
                        {
                            if (exportDaeToolStripMenuItem.Checked)
                            {
                                DAE dae = new DAE(Scene, i);
                                dae.Save($"{outpath}\\{Scene.Models[i].Name}.dae");
                            }
                            if (exportSMDToolStripMenuItem.Checked)
                            {
                                SMD smd = new SMD(Scene, i);
                                smd.Save($"{outpath}\\{Scene.Models[i].Name}.smd");
                            }
                        }
                        AddLine(richTextBox1, "Done");
                    }
                }
                else if (magic == "CTPK") //CTPK file
                {
                    AddLine(richTextBox1, $"Extract Textures from {Path.GetFileName(infile)}...");
                    CTPK.ExtractCTPK(infile);
                    AddLine(richTextBox1, "Done");
                }
                else if (ext == ".bin")
                {
                    if (FEIO.ReadStringFromArray(data, Encoding.UTF8, 0x20).Contains("MESS_ARCHIVE"))
                    {
                        AddLine(richTextBox1, $"Extracting Message Archive {Path.GetFileName(infile)}...");
                        FEMessage.ExtractMessage(infile.Replace(ext, ".txt"), data);
                        AddLine(richTextBox1, "Done");
                    }
                    else if (enableBinDecomplingToolStripMenuItem.Checked)
                    {
                        AddLine(richTextBox1, $"Decompiling {Path.GetFileName(infile)} to txt...");
                        FEBin.ExtractBin(infile);
                        AddLine(richTextBox1, "Done");
                    }
                }
                if (deleteAfterProcessingToolStripMenuItem.Checked)
                {
                    File.Delete(infile);
                }
            }
        }
예제 #27
0
        public Scene(string fname)
        {
            this.Commands     = new List <SceneCommand>(0);
            this.Instructions = new List <object>(0);
            this.StartFrames  = new List <int>(0);

            string[] content = File.ReadAllLines(@"Content\Scenes\" + fname + ".txt");
            string[] spli1, spli2;
            for (int i = 0; i < content.Length; i++)
            {
                spli1 = content[i].Split('|');
                spli2 = spli1[2].Split(';');
                int startFrame = int.Parse(spli1[0]);

                switch (spli1[1])
                {
                case "Goto":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }

                    Model mdl_ = null;
                    for (int r = 0; r < MainGame.ResourceFiles.Count; r++)
                    {
                        if (MainGame.ResourceFiles[r].Name == spli2[0])
                        {
                            mdl_ = MainGame.ResourceFiles[r] as Model;
                            break;
                        }
                    }
                    Vector3 dest = new Vector3(MainGame.SingleParse(spli2[1]), MainGame.SingleParse(spli2[2]), MainGame.SingleParse(spli2[3]));

                    this.Instructions.Add(new GotoDest(mdl_, dest));
                    this.Commands.Add(SceneCommand.Goto);
                    break;

                case "SetBGMVolume":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }

                    this.Instructions.Add(new int[] { int.Parse(spli1[2]), int.Parse(spli1[3]) });
                    this.Commands.Add(SceneCommand.SetBGMVolume);
                    break;

                case "ContactCollison":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }

                    this.Instructions.Add(Boolean.Parse(spli2[0]));
                    this.Commands.Add(SceneCommand.ContactCollison);
                    break;

                case "SetCamera":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }
                    Vector3[] insts = new Vector3[spli2.Length / 3];
                    for (int n = 0; n < spli2.Length; n++)
                    {
                        float val = Single.NaN;
                        Single.TryParse(spli2[n], out val);

                        if (n % 3 == 0)
                        {
                            insts[n / 3].X = val;
                        }
                        if (n % 3 == 1)
                        {
                            insts[n / 3].Y = val;
                        }
                        if (n % 3 == 2)
                        {
                            insts[n / 3].Z = val;
                        }
                    }
                    this.Instructions.Add(insts);
                    this.Commands.Add(SceneCommand.SetCamera);
                    break;

                case "Gameplay":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }
                    this.Instructions.Add(null);
                    this.Commands.Add(SceneCommand.Gameplay);
                    break;

                case "PlayAnim":
                    Animation anm = new Animation();

                    for (int n = 0; n < spli2.Length; n += 6)
                    {
                        spli2[n + 0] = spli2[n + 0].Replace("player", Program.game.Player.Name);
                        spli2[n + 1] = spli2[n + 1].Replace("player", Program.game.Player.Name);
                        Model         mdl  = null;
                        BinaryMoveset mset = null;
                        for (int r = 0; r < MainGame.ResourceFiles.Count; r++)
                        {
                            if (MainGame.ResourceFiles[r].Name == spli2[n + 0])
                            {
                                mdl = MainGame.ResourceFiles[r] as Model;
                                break;
                            }
                        }
                        if (mdl == null)
                        {
                            for (int r = 0; r < Program.game.Map.Supp.Count; r++)
                            {
                                if (Program.game.Map.Supp[r].Name == spli2[n + 0])
                                {
                                    mdl = Program.game.Map.Supp[r] as Model;
                                    break;
                                }
                            }
                        }
                        if (mdl == null)
                        {
                            mdl = new DAE(@"Content\Models\" + spli2[n + 0] + @"\" + spli2[n + 0] + ".dae");
                            mdl.Parse();
                            MainGame.ResourceFiles.Add(mdl);
                            mdl.Render = false;
                        }

                        mdl.Cutscene = true;
                        int index = -1;
                        if (mdl.Links.Count > 0)
                        {
                            (mdl.Links[0] as BinaryMoveset).PlayingIndex = -1;
                        }

                        if (int.TryParse(spli2[n + 1], out index))
                        {
                            if (mdl.Links.Count == 0)
                            {
                                mset = new BinaryMoveset(mdl.FileName.Replace(mdl.Name + ".dae", @"\MSET"));
                                mset.Links.Add(mdl);
                                mset.Parse();
                                MainGame.ResourceFiles.Add(mset);
                                mdl.Links.Add(mset);
                            }
                            else
                            {
                                mset = (mdl.Links[0] as BinaryMoveset);
                            }
                        }
                        else
                        {
                            string name = Path.GetFileNameWithoutExtension(@"Content\Scenes\ANB\" + spli2[n + 1]);

                            for (int r = 0; r < MainGame.ResourceFiles.Count; r++)
                            {
                                if (MainGame.ResourceFiles[r].Name == name)
                                {
                                    mset = MainGame.ResourceFiles[r] as BinaryMoveset;
                                }
                            }
                            if (mset == null)
                            {
                                mset = new BinaryMoveset(@"Content\Scenes\ANB\" + spli2[n + 1]);
                                MainGame.ResourceFiles.Add(mset);
                            }
                            index = 0;
                        }
                        mset.Render = true;


                        if (mset.Links.Count == 0)
                        {
                            mset.Links.Add(mdl);
                        }

                        mset.Skeleton = mdl.Skeleton;
                        if (mdl.Links.Count > 0)
                        {
                            mset.Voices = (mdl.Links[0] as Moveset).Voices;
                        }

                        //mset.Parse();

                        Vector3 startPos = Vector3.Zero;
                        startPos.X = MainGame.SingleParse(spli2[n + 2]);
                        startPos.Y = MainGame.SingleParse(spli2[n + 3]);
                        startPos.Z = MainGame.SingleParse(spli2[n + 4]);
                        float rot = MainGame.SingleParse(spli2[n + 5]);
                        anm.Append(mdl, mset, index, startPos, rot);

                        if (startFrame + mset.MaxTick > this.MaxFrame)
                        {
                            this.MaxFrame = startFrame + mset.MaxTick;
                        }
                    }
                    this.Instructions.Add(anm);
                    this.Commands.Add(SceneCommand.PlayAnim);
                    break;
                }
                this.StartFrames.Add(startFrame);
            }
        }
예제 #28
0
        protected override void OnLoad(EventArgs e)
        {
            var random = new Random();

            StaticReferences.GraphicsSettings();
            StaticReferences.InitReferences();
            models = new List <Model>(0);


            Model model = new MDLX(@"binary_files\bb00.map");

            model.Compile();
            models.Add(model);

            for (int i = 0; i < 1; i++)
            {
                model = new DAE(@"debug_files\P_EX100\P_EX100.dae");
                model.Compile();
                model.Skeleton.Position = new Vector3(-100, 0, 0);
                model.Controller.Moveset.AnimationIndex = random.Next(0, model.Controller.Moveset.Animations.Count);
                model.Controller.Moveset.AnimationFrame = random.Next(0, (int)(model.Controller.Moveset.Animations[model.Controller.Moveset.AnimationIndex].MaxFrame - 1));
                System.Threading.Thread.Sleep(1);
                float x = random.Next(-500, 500);
                System.Threading.Thread.Sleep(1);
                float y = random.Next(-500, 500);
                model.Skeleton.Position = new Vector3(x, 0, y);

                models.Add(model);
                Camera.Current.Target = model;
            }

            /*
             *  model = new MDLX(@"binary_files\H_EX510\H_EX510.mdlx");
             *  model.Compile();
             *  model.Skeleton.Position = new Vector3(100, 0, 0);
             *  models.Add(model);
             */


            /*string[] mdlxes = Directory.GetFiles(@"E:\Jeux\KingdomHearts\app_KH2Tools\export\@KH2\obj\", "*.mdlx");
             * int count = 0;
             * while (count<50)
             * {
             *  int randomIndex = random.Next(0, mdlxes.Length);
             *  FileInfo f = new FileInfo(mdlxes[randomIndex]);
             *  if (f.Name.Contains("H_") && f.Length>200*1024)
             *  {
             *      model = new MDLX(f.FullName);
             *      model.Compile();
             *      float x = random.Next(-500, 500);
             *      System.Threading.Thread.Sleep(1);
             *      float y = random.Next(-500, 500);
             *      model.Skeleton.Position = new Vector3(x,0,y);
             *      models.Add(model);
             *      count++;
             *  }
             * }
             *
             */


            model = new DAE(@"debug_files\cube\cube.dae");
            model.Compile();
            model.Skeleton.Position = new Vector3(-100, 0, 100);
            models.Add(model);

            model = new DAE(@"debug_files\cube2\cube2.dae");
            model.Compile();
            model.Skeleton.Position = new Vector3(100, 0, 100);
            models.Add(model);

            OnUpdateFrame(null);
            base.OnLoad(e);
        }
예제 #29
0
        public DAE ToDAE(int Model)
        {
            if (Data.Models.Length == 0 || Data.Models.Length <= Model)
            {
                return(null);
            }
            var m = Data.Models[Model];
            var o = new DAE();

            o.Content.scene = new DAE.COLLADA._scene();
            o.Content.scene.instance_visual_scene     = new DAE.InstanceWithExtra();
            o.Content.scene.instance_visual_scene.url = "#ID1";
            o.Content.library_visual_scenes           = new DAE.library_visual_scenes();
            var scene    = new DAE.visual_scene("ID1");
            var rootnode = new DAE.node(m.Name);

            scene.node.Add(rootnode);
            o.Content.library_visual_scenes.visual_scene.Add(scene);
            o.Content.library_geometries = new DAE.library_geometries();
            o.Content.library_materials  = new DAE.library_materials();
            o.Content.library_effects    = new DAE.library_effects();
            if (Data.Textures != null && Data.Textures.Length > 0)
            {
                o.Content.library_images = new DAE.library_images();
            }
            int id = 2;
            int i  = 0;

            foreach (var matt in m.Materials)
            {
                var mat2 = new DAE.material();
                mat2.id   = "ID" + id++;
                mat2.name = matt.Name;
                var eff = new DAE.effect();
                eff.id = "ID" + id++;
                mat2.instance_effect                         = new DAE.instance_effect();
                mat2.instance_effect.url                     = "#" + eff.id;
                eff.profile_COMMON                           = new DAE.profile_COMMON();
                eff.profile_COMMON.technique                 = new DAE.profile_COMMON._technique();
                eff.profile_COMMON.technique.sid             = "COMMON";
                eff.profile_COMMON.technique.lambert         = new DAE.profile_COMMON._technique._lambert();
                eff.profile_COMMON.technique.lambert.diffuse = new DAE.common_color_or_texture_type();
                if (matt.Tex0 != null && matt.Tex0.TextureObject is ReferenceTexture)
                {
                    string texid = "ID" + id++;
                    o.Content.library_images.image.Add(new DAE.image()
                    {
                        id = texid, init_from = "Tex/" + ((ReferenceTexture)matt.Tex0.TextureObject).LinkedTextureName + ".png"
                    });

                    var param1 = new DAE.common_newparam_type()
                    {
                        sid = "ID" + id++, choice = new DAE.fx_surface_common()
                        {
                            type = DAE.fx_surface_type_enum._2D
                        }
                    };
                    ((DAE.fx_surface_common)param1.choice).init_from.Add(new DAE.fx_surface_init_from_common()
                    {
                        content = texid
                    });
                    eff.profile_COMMON.newparam = new List <DAE.common_newparam_type>();
                    eff.profile_COMMON.newparam.Add(param1);
                    eff.profile_COMMON.newparam.Add(new DAE.common_newparam_type()
                    {
                        sid = "ID" + id++, choice = new DAE.fx_sampler2D_common()
                        {
                            source = param1.sid
                        }
                    });
                    eff.profile_COMMON.technique.lambert.diffuse.texture = new DAE.common_color_or_texture_type._texture()
                    {
                        texture = eff.profile_COMMON.newparam[1].sid, texcoord = "UVSET0"
                    };
                }
                else
                {
                    eff.profile_COMMON.technique.lambert.diffuse.color         = new DAE.common_color_or_texture_type._color();
                    eff.profile_COMMON.technique.lambert.diffuse.color.content = Color.White;
                }
                o.Content.library_materials.material.Add(mat2);
                o.Content.library_effects.effect.Add(eff);
            }

            int ff = 0;

            //foreach (CMDL m in Models)
            {
                foreach (var vv in m.Shapes)
                {
                    var geometry = new DAE.geometry();
                    geometry.id = "ID" + id++;

                    Polygon p   = vv.GetVertexData(m);
                    var     mat = m.Materials[m.Meshes[ff].MaterialIndex];

                    geometry.mesh          = new DAE.mesh();
                    geometry.mesh.vertices = new DAE.vertices()
                    {
                        id = "ID" + id++
                    };
                    if (p.Vertex != null)
                    {
                        var src = new DAE.source()
                        {
                            id = "ID" + id++
                        };
                        src.float_array = new DAE.source._float_array()
                        {
                            id = "ID" + id++, count = (uint)p.Vertex.Length * 3
                        };
                        foreach (var v in p.Vertex)
                        {
                            src.float_array.content.Add(v.X);
                            src.float_array.content.Add(v.Y);
                            src.float_array.content.Add(v.Z);
                        }
                        src.technique_common                 = new DAE.source._technique_common();
                        src.technique_common.accessor        = new DAE.accessor();
                        src.technique_common.accessor.count  = (uint)p.Vertex.Length;
                        src.technique_common.accessor.source = "#" + src.float_array.id;
                        src.technique_common.accessor.stride = 3;
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "X", type = "float"
                        });
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "Y", type = "float"
                        });
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "Z", type = "float"
                        });
                        geometry.mesh.source.Add(src);
                        geometry.mesh.vertices.input.Add(new DAE.InputLocal()
                        {
                            semantic = "POSITION", source = "#" + src.id
                        });
                    }
                    if (p.Normals != null)
                    {
                        var src = new DAE.source()
                        {
                            id = "ID" + id++
                        };
                        src.float_array = new DAE.source._float_array()
                        {
                            id = "ID" + id++, count = (uint)p.Normals.Length * 3
                        };
                        foreach (var v in p.Normals)
                        {
                            src.float_array.content.Add(v.X);
                            src.float_array.content.Add(v.Y);
                            src.float_array.content.Add(v.Z);
                        }
                        src.technique_common                 = new DAE.source._technique_common();
                        src.technique_common.accessor        = new DAE.accessor();
                        src.technique_common.accessor.count  = (uint)p.Normals.Length;
                        src.technique_common.accessor.source = "#" + src.float_array.id;
                        src.technique_common.accessor.stride = 3;
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "X", type = "float"
                        });
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "Y", type = "float"
                        });
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "Z", type = "float"
                        });
                        geometry.mesh.source.Add(src);
                        geometry.mesh.vertices.input.Add(new DAE.InputLocal()
                        {
                            semantic = "NORMAL", source = "#" + src.id
                        });
                    }
                    DAE.source texcoordsrc = null;
                    if (p.TexCoords != null)
                    {
                        if (mat.NrActiveTextureCoordiators > 0 && mat.TextureCoordiators[0].MappingMethod == 0)
                        {
                            Vector2[] texc;
                            if (mat.TextureCoordiators[0].SourceCoordinate == 0)
                            {
                                texc = p.TexCoords.ToArray();
                            }
                            else if (mat.TextureCoordiators[0].SourceCoordinate == 1)
                            {
                                texc = p.TexCoords2.ToArray();
                            }
                            else
                            {
                                texc = p.TexCoords3.ToArray();
                            }

                            var src = texcoordsrc = new DAE.source()
                            {
                                id = "ID" + id++
                            };
                            src.float_array = new DAE.source._float_array()
                            {
                                id = "ID" + id++, count = (uint)texc.Length * 2
                            };
                            foreach (var v in texc)
                            {
                                Vector2 result = v * new Matrix34(mat.TextureCoordiators[0].Matrix);
                                src.float_array.content.Add(result.X);
                                src.float_array.content.Add(result.Y);
                            }
                            src.technique_common                 = new DAE.source._technique_common();
                            src.technique_common.accessor        = new DAE.accessor();
                            src.technique_common.accessor.count  = (uint)p.TexCoords.Length;
                            src.technique_common.accessor.source = "#" + src.float_array.id;
                            src.technique_common.accessor.stride = 2;
                            src.technique_common.accessor.param.Add(new DAE.param()
                            {
                                name = "S", type = "float"
                            });
                            src.technique_common.accessor.param.Add(new DAE.param()
                            {
                                name = "T", type = "float"
                            });
                            geometry.mesh.source.Add(src);
                        }
                    }
                    DAE.source colorsrc = null;
                    if (p.Colors != null)
                    {
                        var src = colorsrc = new DAE.source()
                        {
                            id = "ID" + id++
                        };
                        src.float_array = new DAE.source._float_array()
                        {
                            id = "ID" + id++, count = (uint)p.Colors.Length * 4
                        };
                        foreach (var v in p.Colors)
                        {
                            src.float_array.content.Add(v.R / 255f);
                            src.float_array.content.Add(v.G / 255f);
                            src.float_array.content.Add(v.B / 255f);
                            src.float_array.content.Add(v.A / 255f);
                        }
                        src.technique_common                 = new DAE.source._technique_common();
                        src.technique_common.accessor        = new DAE.accessor();
                        src.technique_common.accessor.count  = (uint)p.Colors.Length;
                        src.technique_common.accessor.source = "#" + src.float_array.id;
                        src.technique_common.accessor.stride = 4;
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "R", type = "float"
                        });
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "G", type = "float"
                        });
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "B", type = "float"
                        });
                        src.technique_common.accessor.param.Add(new DAE.param()
                        {
                            name = "A", type = "float"
                        });
                        geometry.mesh.source.Add(src);
                    }

                    foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
                    {
                        Vector3[] defs = q.GetFaceData();

                        var tri = new DAE.triangles()
                        {
                            count = (uint)defs.Length, material = mat.Name
                        };
                        uint offs = 0;
                        tri.input.Add(new DAE.InputLocalOffset()
                        {
                            offset = offs++, semantic = "VERTEX", source = "#" + geometry.mesh.vertices.id
                        });
                        if (texcoordsrc != null)
                        {
                            tri.input.Add(new DAE.InputLocalOffset()
                            {
                                offset = offs++, semantic = "TEXCOORD", source = "#" + texcoordsrc.id
                            });
                        }
                        if (colorsrc != null)
                        {
                            tri.input.Add(new DAE.InputLocalOffset()
                            {
                                offset = offs++, semantic = "COLOR", source = "#" + colorsrc.id, set = 0
                            });
                        }
                        tri.p.Add(new DAE.p());
                        foreach (Vector3 d in defs)
                        {
                            tri.p[0].content.Add((ulong)d.X);
                            if (texcoordsrc != null)
                            {
                                tri.p[0].content.Add((ulong)d.X);
                            }
                            if (colorsrc != null)
                            {
                                tri.p[0].content.Add((ulong)d.X);
                            }
                            tri.p[0].content.Add((ulong)d.Y);
                            if (texcoordsrc != null)
                            {
                                tri.p[0].content.Add((ulong)d.Y);
                            }
                            if (colorsrc != null)
                            {
                                tri.p[0].content.Add((ulong)d.Y);
                            }
                            tri.p[0].content.Add((ulong)d.Z);
                            if (texcoordsrc != null)
                            {
                                tri.p[0].content.Add((ulong)d.Z);
                            }
                            if (colorsrc != null)
                            {
                                tri.p[0].content.Add((ulong)d.Z);
                            }
                        }
                        geometry.mesh.triangles.Add(tri);
                    }
                    o.Content.library_geometries.geometry.Add(geometry);
                    var instgem = new DAE.instance_geometry()
                    {
                        url = "#" + geometry.id
                    };
                    instgem.bind_material = new DAE.bind_material();
                    instgem.bind_material.technique_common = new DAE.bind_material._technique_common();
                    var instmat = new DAE.instance_material();
                    instmat.symbol = mat.Name;
                    instmat.target = "#" + o.Content.library_materials.material[(int)m.Meshes[ff].MaterialIndex].id;
                    instmat.bind_vertex_input.Add(new DAE.instance_material._bind_vertex_input()
                    {
                        semantic = "UVSET0", input_semantic = "TEXCOORD", input_set = 0
                    });
                    instgem.bind_material.technique_common.instance_material.Add(instmat);
                    rootnode.instance_geometry.Add(instgem);
                    ff++;
                }
            }
            return(o);
        }
예제 #30
0
 public void Load(Stream stream)
 {
     this.Label = FileInfo.FileName;
     Tag        = this;
     Header     = DAE.Read(stream);
 }
예제 #31
0
        public override void Export(string FileName)
        {
            string ext = Utils.GetExtension(FileName);

            if (ext == ".bfska")
            {
                if (GetResFileU() != null)
                {
                    SkeletalAnimU.Export(FileName, GetResFileU());
                }
                else
                {
                    SkeletalAnim.Export(FileName, GetResFile());
                }
            }
            else if (ext == ".json")
            {
                if (SkeletalAnimU != null)
                {
                    System.IO.File.WriteAllText(FileName, Newtonsoft.Json.JsonConvert.SerializeObject(SkeletalAnimU,
                                                                                                      Newtonsoft.Json.Formatting.Indented));
                }
                else
                {
                    System.IO.File.WriteAllText(FileName, Newtonsoft.Json.JsonConvert.SerializeObject(SkeletalAnim,
                                                                                                      Newtonsoft.Json.Formatting.Indented));
                }
            }
            else
            {
                STSkeleton skeleton = GetActiveSkeleton();
                if (skeleton == null)
                {
                    throw new Exception("No skeleton found to assign! Make sure a model is open in the viewport.");
                }

                if (ext == ".chr0")
                {
                    if (SkeletalAnimU != null)
                    {
                        BrawlboxHelper.FSKAConverter.Fska2Chr0(BfresPlatformConverter.FSKAConvertWiiUToSwitch(SkeletalAnimU), FileName);
                    }
                    else
                    {
                        BrawlboxHelper.FSKAConverter.Fska2Chr0(SkeletalAnim, FileName);
                    }
                }
                else if (ext == ".smd")
                {
                    SMD.Save(this, skeleton, FileName);
                }
                else if (ext == ".anim")
                {
                    ANIM.CreateANIM(FileName, this, skeleton);
                }
                else if (ext == ".seanim")
                {
                    SEANIM.SaveAnimation(FileName, this, skeleton);
                }
                else if (ext == ".dae")
                {
                    DAE.ExportAnimation(FileName, this, skeleton);
                }
            }
        }