Inheritance: MtbSubSection
        public static void LoadCurves(BinaryReaderEx reader, SpuBinary spuBinary)
        {
            var numBones = spuBinary.NumBones;

            foreach (var section in spuBinary.Sections)
            {
                var bones = CreateBoneArray(numBones);

                foreach (var chunk in section.Chunks)
                {
                    reader.BaseStream.Position = spuBinary.SpuBasePosition + chunk.Offset;

                    for (var i = 0; i < chunk.NumChildren; i++)
                    {
                        var boneId = reader.ReadInt16(Endianness.BigEndian);
                        var type = reader.ReadInt16(Endianness.BigEndian);
                        var count = reader.ReadInt16(Endianness.BigEndian);
                        reader.ReadInt16(); // Skip 2 unused bytes

                        if ((type == 0 && chunk.Flag != 1) || (type != 0 && chunk.Flag == 1))
                        {
                            throw new InvalidOperationException(String.Format("Flag/Type mismatch? Flag = {0} Type = {1}", chunk.Flag, type));
                        }

                        AnimatedComponent component = DetermineAnimatedComponent(type);

                        Curves.CurveBase curve;
                        switch (type)
                        {
                            case 0x00:
                                curve = CreateQuaternionCurve(reader, count);
                                break;
                            case 0x04:
                            case 0x05:
                            case 0x06:
                            case 0x07:
                            case 0x08:
                            case 0x09:
                                curve = CreateCompressedLinearCurve(reader, component, count);
                                break;
                            case 0x0B:
                            case 0x0C:
                            case 0x0D:
                            case 0x0E:
                            case 0x0F:
                            case 0x10:
                                curve = CreateConstantCurve(reader, component, count);
                                break;
                            case 0x11:
                            case 0x12:
                            case 0x13:
                                curve = CreateUncompressedLinearCurve(reader, component, count);
                                break;
                            default:
                                throw new InvalidOperationException("Unknown curve type " + type);
                        }

                        if (curve.CurveValues.Count == 0) { throw new InvalidOperationException("No Curve Values!?"); }
                        AddCurveToBone(bones, boneId, curve);
                    }
                }

                for (var i = 0; i < numBones; i++)
                {
                    var bone = bones[i];
                    if (bone == null) { continue; }

                    var boneNode = new AnimatedBoneNode();
                    boneNode.Bone = bone;
                    boneNode.Parent = section;
                    section.Children.Add(boneNode);
                }
            }
        }
Beispiel #2
0
        public override void LoadSection(BinaryReaderEx reader)
        {
            base.LoadSection(reader);

            reader.BaseStream.Position += 16;
            this.NumSections            = reader.ReadInt32();
            sectionOffsets              = new int[this.NumSections];
            for (var i = 0; i < this.NumSections; i++)
            {
                sectionOffsets[i] = reader.ReadInt32();
            }

            this.NumSectionNames    = reader.ReadInt32();
            this.sectionNameOffsets = new int[this.NumSectionNames];
            for (var i = 0; i < this.NumSectionNames; i++)
            {
                sectionNameOffsets[i] = reader.ReadInt32();
            }

            this.NumChunkNames    = reader.ReadInt32();
            this.chunkNameOffsets = new int[this.NumChunkNames];
            for (var i = 0; i < this.NumChunkNames; i++)
            {
                chunkNameOffsets[i] = reader.ReadInt32();
            }

            this.SectionNames = new List <string>();
            this.ChunkNames   = new List <string>();
            LoadStrings(reader, sectionNameOffsets, this.SectionNames);
            LoadStrings(reader, chunkNameOffsets, this.ChunkNames);

            // Read Sections --------------------------------------
            this.Sections = new List <MtbSubSection>();
            this.Children = new List <INavigable>();
            for (var i = 0; i < this.NumSections; i++)
            {
                reader.BaseStream.Position = this.SectionStart + this.sectionOffsets[i];
                int nameIdx = reader.ReadInt32();
                reader.BaseStream.Seek(-4, System.IO.SeekOrigin.Current);

                if (nameIdx >= this.NumSectionNames)
                {
                    throw new InvalidOperationException("Unexpectedly large section name index");
                }

                string        sectionName = this.SectionNames[nameIdx];
                MtbSubSection section     = null;
                switch (sectionName)
                {
                case "Header":
                    section = new MtbHeader();
                    break;

                case "SpuBinary":
                    section = new SpuBinary();
                    break;

                default:
                    section = new MtbGenericSection();
                    break;
                }

                if (section != null)
                {
                    section.Parent = this;
                    this.Children.Add(section);
                    this.Sections.Add(section);
                    section.Load(reader);
                    section.SectionName = sectionName;
                }
            }

            this.Header = (MtbHeader)FindSection("Header", 0);
        }
Beispiel #3
0
        public static void LoadCurves(BinaryReaderEx reader, SpuBinary spuBinary)
        {
            var numBones = spuBinary.NumBones;

            foreach (var section in spuBinary.Sections)
            {
                var bones = CreateBoneArray(numBones);

                foreach (var chunk in section.Chunks)
                {
                    reader.BaseStream.Position = spuBinary.SpuBasePosition + chunk.Offset;

                    for (var i = 0; i < chunk.NumChildren; i++)
                    {
                        var boneId = reader.ReadInt16(Endianness.BigEndian);
                        var type   = reader.ReadInt16(Endianness.BigEndian);
                        var count  = reader.ReadInt16(Endianness.BigEndian);
                        reader.ReadInt16(); // Skip 2 unused bytes

                        if ((type == 0 && chunk.Flag != 1) || (type != 0 && chunk.Flag == 1))
                        {
                            throw new InvalidOperationException(String.Format("Flag/Type mismatch? Flag = {0} Type = {1}", chunk.Flag, type));
                        }

                        AnimatedComponent component = DetermineAnimatedComponent(type);

                        Curves.CurveBase curve;
                        switch (type)
                        {
                        case 0x00:
                            curve = CreateQuaternionCurve(reader, count);
                            break;

                        case 0x04:
                        case 0x05:
                        case 0x06:
                        case 0x07:
                        case 0x08:
                        case 0x09:
                            curve = CreateCompressedLinearCurve(reader, component, count);
                            break;

                        case 0x0B:
                        case 0x0C:
                        case 0x0D:
                        case 0x0E:
                        case 0x0F:
                        case 0x10:
                            curve = CreateConstantCurve(reader, component, count);
                            break;

                        case 0x11:
                        case 0x12:
                        case 0x13:
                            curve = CreateUncompressedLinearCurve(reader, component, count);
                            break;

                        default:
                            throw new InvalidOperationException("Unknown curve type " + type);
                        }

                        if (curve.CurveValues.Count == 0)
                        {
                            throw new InvalidOperationException("No Curve Values!?");
                        }
                        AddCurveToBone(bones, boneId, curve);
                    }
                }

                for (var i = 0; i < numBones; i++)
                {
                    var bone = bones[i];
                    if (bone == null)
                    {
                        continue;
                    }

                    var boneNode = new AnimatedBoneNode();
                    boneNode.Bone   = bone;
                    boneNode.Parent = section;
                    section.Children.Add(boneNode);
                }
            }
        }
Beispiel #4
0
        public override void LoadSection(BinaryReaderEx reader)
        {
            base.LoadSection(reader);

            reader.BaseStream.Position += 16;
            this.NumSections = reader.ReadInt32();
            sectionOffsets = new int[this.NumSections];
            for (var i = 0; i < this.NumSections; i++)
            {
                sectionOffsets[i] = reader.ReadInt32();
            }

            this.NumSectionNames = reader.ReadInt32();
            this.sectionNameOffsets = new int[this.NumSectionNames];
            for (var i = 0; i < this.NumSectionNames; i++)
            {
                sectionNameOffsets[i] = reader.ReadInt32();
            }

            this.NumChunkNames = reader.ReadInt32();
            this.chunkNameOffsets = new int[this.NumChunkNames];
            for (var i = 0; i < this.NumChunkNames; i++)
            {
                chunkNameOffsets[i] = reader.ReadInt32();
            }

            this.SectionNames = new List<string>();
            this.ChunkNames = new List<string>();
            LoadStrings(reader, sectionNameOffsets, this.SectionNames);
            LoadStrings(reader, chunkNameOffsets, this.ChunkNames);

            // Read Sections --------------------------------------
            this.Sections = new List<MtbSubSection>();
            this.Children = new List<INavigable>();
            for (var i = 0; i < this.NumSections; i++)
            {
                reader.BaseStream.Position = this.SectionStart + this.sectionOffsets[i];
                int nameIdx = reader.ReadInt32();
                reader.BaseStream.Seek(-4, System.IO.SeekOrigin.Current);

                if (nameIdx >= this.NumSectionNames)
                {
                    throw new InvalidOperationException("Unexpectedly large section name index");
                }

                string sectionName = this.SectionNames[nameIdx];
                MtbSubSection section = null;
                switch (sectionName)
                {
                    case "Header":
                        section = new MtbHeader();
                        break;
                    case "SpuBinary":
                        section = new SpuBinary();
                        break;
                    default:
                        section = new MtbGenericSection();
                        break;
                }

                if (section != null)
                {
                    section.Parent = this;
                    this.Children.Add(section);
                    this.Sections.Add(section);
                    section.Load(reader);
                    section.SectionName = sectionName;
                }
            }

            this.Header = (MtbHeader)FindSection("Header", 0);
        }