Пример #1
0
        public static H3D IdentifyAndOpen(string FileName, H3DDict <H3DBone> Skeleton = null)
        {
            //Formats that can by identified by extensions
            string FilePath = Path.GetDirectoryName(FileName);

            switch (Path.GetExtension(FileName).ToLower())
            {
            case ".txt":
                H3D AllFiles = new H3D();

                string[] files = File.ReadAllLines(FileName);

                string Parent = FilePath;

                foreach (string File in files)
                {
                    AllFiles.Merge(IdentifyAndOpen(Path.Combine(Parent, File)));
                }

                return(AllFiles);

            case ".gmp":
                GF1MotionPack MotPack = new GF1MotionPack(new BinaryReader(new FileStream(FileName, FileMode.Open)));
                return(MotPack.ToH3D(Skeleton));

            case ".smd": return(new SMD(FileName).ToH3D(FilePath));

            case ".obj": return(new OBJ(FileName).ToH3D(FilePath));

            case ".mtl": return(new OBJ(FileName).ToH3D(FilePath));

            case ".cmif": return(new CMIFFile(new FileStream(FileName, FileMode.Open)).ToH3D());

            case ".png":
                H3D Out = new H3D();
                Out.Textures.Add(new H3DTexture(FileName, true));
                return(Out);

            case ".gfbmdl":
                return(new GFModel(new BinaryReader(new FileStream(FileName, FileMode.Open)), Path.GetFileNameWithoutExtension(FileName)).ToH3D());

            case ".mbn":
                using (FileStream Input = new FileStream(FileName, FileMode.Open))
                {
                    H3D BaseScene = H3D.Open(File.ReadAllBytes(FileName.Replace(".mbn", ".bch")));

                    MBn ModelBinary = new MBn(new BinaryReader(Input), BaseScene);

                    return(ModelBinary.ToH3D());
                }
            }

            //Formats that can only be indetified by "magic numbers"
            H3D Output = null;

            using (FileStream FS = new FileStream(FileName, FileMode.Open))
            {
                Output = IdentifyByMagic(FS, Skeleton, FileName);
            }

            return(Output);
        }
Пример #2
0
        public static H3D IdentifyAndOpen(string FileName, H3DDict <H3DBone> Skeleton = null)
        {
            //Formats that can by identified by extensions
            string FilePath = Path.GetDirectoryName(FileName);

            switch (Path.GetExtension(FileName).ToLower())
            {
            case ".txt":
                H3D AllFiles = new H3D();

                string[] files = File.ReadAllLines(FileName);

                string Parent = FilePath;

                foreach (string File in files)
                {
                    AllFiles.Merge(IdentifyAndOpen(Path.Combine(Parent, File)));
                }

                return(AllFiles);

            case ".gmp":
                H3D           OutputH3D = new H3D();
                GF1MotionPack MotPack   = new GF1MotionPack(new BinaryReader(new FileStream(FileName, FileMode.Open)));
                foreach (GF1Motion Mot in MotPack)
                {
                    H3DAnimation SklAnim = Mot.ToH3DSkeletalAnimation(Skeleton);

                    SklAnim.Name = $"Motion_{Mot.Index}";

                    OutputH3D.SkeletalAnimations.Add(SklAnim);
                }
                return(OutputH3D);

            case ".smd": return(new SMD(FileName).ToH3D(FilePath));

            case ".obj": return(new OBJ(FileName).ToH3D(FilePath));

            case ".mtl": return(new OBJ(FileName).ToH3D(FilePath));

            case ".cmif": return(new CMIFFile(new FileStream(FileName, FileMode.Open)).ToH3D());

            case ".png":
                H3D Out = new H3D();
                Out.Textures.Add(new H3DTexture(FileName, true));
                return(Out);

            case ".gfbmdl":
                H3DModel model = new GFModel(new BinaryReader(new FileStream(FileName, FileMode.Open)), Path.GetFileNameWithoutExtension(FileName)).ToH3DModel();
                H3D      Scene = new H3D();
                Scene.Models.Add(model);
                return(Scene);

            case ".mbn":
                using (FileStream Input = new FileStream(FileName, FileMode.Open))
                {
                    H3D BaseScene = H3D.Open(File.ReadAllBytes(FileName.Replace(".mbn", ".bch")));

                    MBn ModelBinary = new MBn(new BinaryReader(Input), BaseScene);

                    return(ModelBinary.ToH3D());
                }
            }

            //Formats that can only be indetified by "magic numbers"
            H3D Output = null;

            using (FileStream FS = new FileStream(FileName, FileMode.Open))
            {
                if (FS.Length > 4)
                {
                    BinaryReader Reader = new BinaryReader(FS);

                    uint MagicNum = Reader.ReadUInt32();

                    FS.Seek(-4, SeekOrigin.Current);

                    string Magic = Encoding.ASCII.GetString(Reader.ReadBytes(4));

                    FS.Seek(0, SeekOrigin.Begin);

                    if (Magic.StartsWith("BCH"))
                    {
                        return(H3D.Open(Reader.ReadBytes((int)FS.Length)));
                    }
                    else if (Magic.StartsWith("MOD"))
                    {
                        return(LoadMTModel(Reader, FileName, Path.GetDirectoryName(FileName)));
                    }
                    else if (Magic.StartsWith("TEX"))
                    {
                        return(new MTTexture(Reader, Path.GetFileNameWithoutExtension(FileName)).ToH3D());
                    }
                    else if (Magic.StartsWith("MFX"))
                    {
                        MTShader = new MTShaderEffects(Reader);
                    }
                    else if (Magic.StartsWith("CGFX"))
                    {
                        return(Gfx.Open(FS));
                    }
                    else if (Magic.StartsWith("CMIF"))
                    {
                        return(new CMIFFile(new FileStream(FileName, FileMode.Open)).ToH3D());
                    }
                    else
                    {
                        if (GFPackage.IsValidPackage(FS))
                        {
                            GFPackage.Header PackHeader = GFPackage.GetPackageHeader(FS);

                            switch (PackHeader.Magic)
                            {
                            case "AL": Output = GFAreaLOD.OpenAsH3D(FS, PackHeader, 1); break;

                            case "AD": Output = GFPackedTexture.OpenAsH3D(FS, PackHeader, 1); break;

                            //case "BG": Output = GFL2OverWorld.OpenAsH3D(FS, PackHeader, Skeleton); break;
                            case "BS": Output = GFBtlSklAnim.OpenAsH3D(FS, PackHeader, Skeleton); break;

                            case "CM": Output = GFCharaModel.OpenAsH3D(FS, PackHeader); break;

                            case "GR": Output = GFOWMapModel.OpenAsH3D(FS, PackHeader); break;

                            case "MM": Output = GFOWCharaModel.OpenAsH3D(FS, PackHeader); break;

                            case "PC": Output = GFPkmnModel.OpenAsH3D(FS, PackHeader, Skeleton); break;

                            case "LL":
                            default:
                            case "PT": Output = GFPackedTexture.OpenAsH3D(FS, PackHeader, 0); break;

                            case "PK":
                            case "PB":
                                Output = GFPkmnSklAnim.OpenAsH3D(FS, PackHeader, Skeleton); break;
                            }
                        }
                        else
                        {
                            switch (MagicNum)
                            {
                            case 0x15122117:
                                Output = new H3D();

                                Output.Models.Add(new GFModel(Reader, "Model").ToH3DModel());

                                break;

                            case 0x15041213:
                                Output = new H3D();

                                Output.Textures.Add(new GFTexture(Reader).ToH3DTexture());

                                break;

                            case 0x00010000: Output = new GFModelPack(Reader).ToH3D(); break;

                            case 0x00060000:
                                if (Skeleton != null)
                                {
                                    Output = new H3D();

                                    GFMotion Motion = new GFMotion(Reader, 0);

                                    H3DAnimation    SklAnim = Motion.ToH3DSkeletalAnimation(Skeleton);
                                    H3DMaterialAnim MatAnim = Motion.ToH3DMaterialAnimation();
                                    H3DAnimation    VisAnim = Motion.ToH3DVisibilityAnimation();

                                    if (SklAnim != null)
                                    {
                                        Output.SkeletalAnimations.Add(SklAnim);
                                    }
                                    if (MatAnim != null)
                                    {
                                        Output.MaterialAnimations.Add(MatAnim);
                                    }
                                    if (VisAnim != null)
                                    {
                                        Output.VisibilityAnimations.Add(VisAnim);
                                    }
                                }

                                break;
                            }
                        }
                    }
                }
            }

            return(Output);
        }
Пример #3
0
        public static H3D IdentifyAndOpen(string fileName, H3DDict <H3DBone> skeleton = null)
        {
            //Formats that can by identified by extensions
            var filePath = Path.GetDirectoryName(fileName);

            switch (Path.GetExtension(fileName).ToLower())
            {
            case ".smd": return(new SMD(fileName).ToH3D(filePath));

            case ".obj": return(new OBJ(fileName).ToH3D(filePath));

            case ".mbn":
                using (var input = new FileStream(fileName, FileMode.Open))
                {
                    var baseScene = H3D.Open(File.ReadAllBytes(fileName.Replace(".mbn", ".bch")));

                    var modelBinary = new MBn(new BinaryReader(input), baseScene);

                    return(modelBinary.ToH3D());
                }
            }

            //Formats that can only be indetified by "magic numbers"
            var output = default(H3D);

            using (var fs = new FileStream(fileName, FileMode.Open))
            {
                if (fs.Length > 4)
                {
                    var reader = new BinaryReader(fs);

                    var magicNum = reader.ReadUInt32();

                    fs.Seek(-4, SeekOrigin.Current);

                    var magic = Encoding.ASCII.GetString(reader.ReadBytes(4));

                    fs.Seek(0, SeekOrigin.Begin);

                    if (magic.StartsWith("BCH"))
                    {
                        return(H3D.Open(reader.ReadBytes((int)fs.Length)));
                    }
                    else if (magic.StartsWith("MOD"))
                    {
                        return(LoadMTModel(reader, fileName, Path.GetDirectoryName(fileName)));
                    }
                    else if (magic.StartsWith("TEX"))
                    {
                        return(new MTTexture(reader, Path.GetFileNameWithoutExtension(fileName)).ToH3D());
                    }
                    else if (magic.StartsWith("MFX"))
                    {
                        _mtShader = new MTShaderEffects(reader);
                    }
                    else if (magic.StartsWith("CGFX"))
                    {
                        return(Gfx.Open(fs));
                    }
                    else
                    {
                        if (GFPackage.IsValidPackage(fs))
                        {
                            var packHeader = GFPackage.GetPackageHeader(fs);

                            switch (packHeader.Magic)
                            {
                            case "AD": output = GFPackedTexture.OpenAsH3D(fs, packHeader, 1); break;

                            case "BG": output = GFL2OverWorld.OpenAsH3D(fs, packHeader, skeleton); break;

                            case "BS": output = GFBtlSklAnim.OpenAsH3D(fs, packHeader, skeleton); break;

                            case "CM": output = GFCharaModel.OpenAsH3D(fs, packHeader); break;

                            case "GR": output = GFOWMapModel.OpenAsH3D(fs, packHeader); break;

                            case "MM": output = GFOWCharaModel.OpenAsH3D(fs, packHeader); break;

                            case "PC": output = GFPkmnModel.OpenAsH3D(fs, packHeader, skeleton); break;

                            case "PT": output = GFPackedTexture.OpenAsH3D(fs, packHeader, 0); break;

                            case "PK":
                            case "PB": output = GFPkmnSklAnim.OpenAsH3D(fs, packHeader, skeleton); break;
                            }
                        }
                        else
                        {
                            switch (magicNum)
                            {
                            case 0x15122117:
                                output = new H3D();

                                output.Models.Add(new GFModel(reader, "Model").ToH3DModel());

                                break;

                            case 0x15041213:
                                output = new H3D();

                                output.Textures.Add(new GFTexture(reader).ToH3DTexture());

                                break;

                            case 0x00010000: output = new GFModelPack(reader).ToH3D(); break;

                            case 0x00060000:
                                if (skeleton != null)
                                {
                                    output = new H3D();

                                    var motion = new GFMotion(reader, 0);

                                    var sklAnim = motion.ToH3DSkeletalAnimation(skeleton);
                                    var matAnim = motion.ToH3DMaterialAnimation();
                                    var visAnim = motion.ToH3DVisibilityAnimation();

                                    if (sklAnim != null)
                                    {
                                        output.SkeletalAnimations.Add(sklAnim);
                                    }
                                    if (matAnim != null)
                                    {
                                        output.MaterialAnimations.Add(matAnim);
                                    }
                                    if (visAnim != null)
                                    {
                                        output.VisibilityAnimations.Add(visAnim);
                                    }
                                }

                                break;
                            }
                        }
                    }
                }
            }

            return(output);
        }