Beispiel #1
0
        public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header)
        {
            H3D Output;

            //Model
            byte[] Buffer = new byte[Header.Entries[0].Length];

            Input.Seek(Header.Entries[0].Address, SeekOrigin.Begin);

            Input.Read(Buffer, 0, Buffer.Length);

            using (MemoryStream MS = new MemoryStream(Buffer))
            {
                Output = H3D.Open(MS);
            }

            //Skeletal Animations
            if (Header.Entries.Length > 1)
            {
                Input.Seek(Header.Entries[1].Address, SeekOrigin.Begin);

                GF1MotionPack MotPack = new GF1MotionPack(Input);

                foreach (GF1Motion Mot in MotPack)
                {
                    H3DAnimation SklAnim = Mot.ToH3DSkeletalAnimation(Output.Models[0].Skeleton);

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

                    Output.SkeletalAnimations.Add(SklAnim);
                }
            }

            //Material Animations
            if (Header.Entries.Length > 2)
            {
                Input.Seek(Header.Entries[2].Address, SeekOrigin.Begin);

                byte[] Data = new byte[Header.Entries[2].Length];

                Input.Read(Data, 0, Data.Length);

                H3D MatAnims = H3D.Open(Data);

                Output.Merge(MatAnims);
            }

            return(Output);
        }
        public static H3D OpenAsH3D(Stream input, GFPackage.Header header)
        {
            var output = default(H3D);

            //Model
            var buffer = new byte[header.Entries[0].Length];

            input.Seek(header.Entries[0].Address, SeekOrigin.Begin);

            input.Read(buffer, 0, buffer.Length);

            using (var ms = new MemoryStream(buffer))
                output = H3D.Open(ms);

            //Skeletal Animations
            if (header.Entries.Length > 1)
            {
                input.Seek(header.Entries[1].Address, SeekOrigin.Begin);

                var motPack = new GF1MotionPack(input);

                foreach (var mot in motPack)
                {
                    var sklAnim = mot.ToH3DSkeletalAnimation(output.Models[0].Skeleton);

                    sklAnim.Name = $"Motion_{mot.Index}";

                    output.SkeletalAnimations.Add(sklAnim);
                }
            }

            //Material Animations
            if (header.Entries.Length > 2)
            {
                input.Seek(header.Entries[2].Address, SeekOrigin.Begin);

                var data = new byte[header.Entries[2].Length];

                input.Read(data, 0, data.Length);

                var matAnims = H3D.Open(data);

                output.Merge(matAnims);
            }

            return(output);
        }
Beispiel #3
0
        public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header, H3DDict <H3DBone> Skeleton)
        {
            H3D Output = new H3D();

            BinaryReader Reader = new BinaryReader(Input);

            int Index = 0;

            foreach (GFPackage.Entry Entry in Header.Entries)
            {
                Input.Seek(Entry.Address, SeekOrigin.Begin);

                if (Index == 20)
                {
                    break;
                }

                if (Index == 0)
                {
                    GF1MotionPack MotPack = new GF1MotionPack(Reader);

                    foreach (GF1Motion Mot in MotPack)
                    {
                        H3DAnimation Anim = Mot.ToH3DSkeletalAnimation(Skeleton);

                        Anim.Name = $"Motion_{Index++}";

                        Output.SkeletalAnimations.Add(Anim);
                    }
                }
                else
                {
                    byte[] Data = Reader.ReadBytes(Entry.Length);

                    if (Data.Length > 4 &&
                        Data[0] == 'B' &&
                        Data[1] == 'C' &&
                        Data[2] == 'H' &&
                        Data[3] == '\0')
                    {
                        Output.Merge(H3D.Open(Data));
                    }
                }
            }

            return(Output);
        }
        public static H3D OpenAsH3D(Stream input, GFPackage.Header header, H3DDict <H3DBone> skeleton)
        {
            var output = new H3D();

            var reader = new BinaryReader(input);

            var index = 0;

            foreach (var entry in header.Entries)
            {
                input.Seek(entry.Address, SeekOrigin.Begin);

                if (index == 20)
                {
                    break;
                }

                if (index == 0)
                {
                    var motPack = new GF1MotionPack(reader);

                    foreach (var mot in motPack)
                    {
                        var anim = mot.ToH3DSkeletalAnimation(skeleton);

                        anim.Name = $"Motion_{index++}";

                        output.SkeletalAnimations.Add(anim);
                    }
                }
                else
                {
                    var data = reader.ReadBytes(entry.Length);

                    if (data.Length > 4 &&
                        data[0] == 'B' &&
                        data[1] == 'C' &&
                        data[2] == 'H' &&
                        data[3] == '\0')
                    {
                        output.Merge(H3D.Open(data));
                    }
                }
            }

            return(output);
        }
        public static H3D OpenAsH3D(Stream input, GFPackage.Header header, H3DDict <H3DBone> skeleton)
        {
            var output = new H3D();

            //Skeletal Animations
            input.Seek(header.Entries[0].Address, SeekOrigin.Begin);

            var motPack = new GF1MotionPack(input);

            foreach (var mot in motPack)
            {
                var sklAnim = mot.ToH3DSkeletalAnimation(skeleton);

                sklAnim.Name = $"Motion_{mot.Index}";

                output.SkeletalAnimations.Add(sklAnim);
            }

            //Material Animations
            input.Seek(header.Entries[1].Address, SeekOrigin.Begin);

            var packHeader = GFPackage.GetPackageHeader(input);

            foreach (var entry in packHeader.Entries)
            {
                input.Seek(entry.Address, SeekOrigin.Begin);

                if (entry.Length > 0)
                {
                    var data = new byte[entry.Length];

                    input.Read(data, 0, data.Length);

                    var matAnims = H3D.Open(data);

                    output.Merge(matAnims);
                }
            }

            return(output);
        }
Beispiel #6
0
        public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header, H3DDict <H3DBone> Skeleton)
        {
            H3D Output = new H3D();

            //Skeletal Animations
            Input.Seek(Header.Entries[0].Address, SeekOrigin.Begin);

            GF1MotionPack MotPack = new GF1MotionPack(Input);

            foreach (GF1Motion Mot in MotPack)
            {
                H3DAnimation SklAnim = Mot.ToH3DSkeletalAnimation(Skeleton);

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

                Output.SkeletalAnimations.Add(SklAnim);
            }

            //Material Animations
            Input.Seek(Header.Entries[1].Address, SeekOrigin.Begin);

            GFPackage.Header PackHeader = GFPackage.GetPackageHeader(Input);

            foreach (GFPackage.Entry Entry in PackHeader.Entries)
            {
                Input.Seek(Entry.Address, SeekOrigin.Begin);

                if (Entry.Length > 0)
                {
                    byte[] Data = new byte[Entry.Length];

                    Input.Read(Data, 0, Data.Length);

                    H3D MatAnims = H3D.Open(Data);

                    Output.Merge(MatAnims);
                }
            }

            return(Output);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        public static H3D IdentifyByMagic(Stream Stream, H3DDict <H3DBone> Skeleton, string FileName)
        {
            H3D Output = null;

            if (Stream.Length > 4)
            {
                BinaryReader Reader = new BinaryReader(Stream);

                uint MagicNum = Reader.ReadUInt32();

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

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

                Stream.Seek(0, SeekOrigin.Begin);

                if (Magic.StartsWith("BCH"))
                {
                    return(H3D.Open(Reader.ReadBytes((int)Stream.Length)));
                }
                else if (Magic.StartsWith("MOD") && FileName != null)
                {
                    return(LoadMTModel(Reader, FileName, Path.GetDirectoryName(FileName)));
                }
                else if (Magic.StartsWith("TEX") && FileName != null)
                {
                    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(Stream));
                }
                else if (Magic.StartsWith("CMIF"))
                {
                    return(new CMIFFile(Stream).ToH3D());
                }
                else
                {
                    switch (MagicNum)
                    {
                    case GFModel.MagicNum:
                        GFModel Model = new GFModel(Reader, "Model");
                        Output = Model.ToH3D();
                        Output.SourceData.Add(Model);

                        break;

                    case GFTexture.MagicNum:
                        //Can be GFShader or GFTexture
                        Reader.BaseStream.Seek(0x8, SeekOrigin.Current);

                        string GFMagicStr = StringUtils.ReadPaddedString(Reader, 8);

                        if (GFMagicStr == GFTexture.MagicStr)
                        {
                            Reader.BaseStream.Seek(-0x10, SeekOrigin.Current);
                            Output = new H3D();
                            Output.Textures.Add(new GFTexture(Reader).ToH3DTexture());
                        }
                        else
                        {
                            Reader.BaseStream.Seek(0x8, SeekOrigin.Current);
                            GFMagicStr = StringUtils.ReadPaddedString(Reader, 8);

                            if (GFMagicStr == GFShader.MagicStr)
                            {
                                Reader.BaseStream.Seek(-0x18, SeekOrigin.Current);
                                Output = new H3D();
                                Output.SourceData.Add(new GFShader(Reader));
                            }
                        }

                        break;

                    case GFModelPack.MagicNum:
                        if (GFModelPack.IsModelPack(Reader))
                        {
                            Output = new GFModelPack(Reader).ToH3D();
                        }
                        break;

                    case GFMotion.MagicNum:
                        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;
                    }

                    if (GFMotionPack.IsGFL2MotionPack(Reader))
                    {
                        GFMotionPack Pack = new GFMotionPack(Reader);
                        Output = Pack.ToH3D(Skeleton);
                    }
                    if (GF1MotionPack.IsGFL1MotionPack(Reader))
                    {
                        Output = new GF1MotionPack(Reader).ToH3D(Skeleton);
                    }
                }
            }

            return(Output);
        }
Beispiel #9
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);
        }