Beispiel #1
0
        internal void SaveHeader(EndianBinaryWriter output, bool isIndexed, bool is16Bit)
        {
            byte sectionFlags = (byte)(
                ((Obj1StripsCcw.Count != 0) ? 0x01 : 0) |
                ((Obj1StripsCw.Count != 0) ? 0x02 : 0) |
                ((Obj2StripsCcw.Count != 0) ? 0x04 : 0) |
                ((Obj2StripsCw.Count != 0) ? 0x08 : 0));

            IEnumerable <GcmfVertex> allVertices = Obj1StripsCcw.Union(Obj1StripsCw)
                                                   .Union(Obj2StripsCcw).Union(Obj2StripsCw).SelectMany(sg => sg);
            uint vertexFlagsCalc = allVertices.First().VertexFlags;

            if (allVertices.All(v => v.VertexFlags != vertexFlagsCalc))
            {
                throw new InvalidGmaFileException("All vertices within the same mesh must have the same components.");
            }

            output.Write((uint)RenderFlags);
            output.Write(Unk4);
            output.Write(Unk8);
            output.Write(UnkC);
            output.Write(Unk10);
            byte calculatedUsedMaterialCount = (byte)(
                ((PrimaryMaterialIdx != ushort.MaxValue) ? 1 : 0) +
                ((SecondaryMaterialIdx != ushort.MaxValue) ? 1 : 0) +
                ((TertiaryMaterialIdx != ushort.MaxValue) ? 1 : 0));

            output.Write(calculatedUsedMaterialCount);
            output.Write(sectionFlags);
            output.Write(Unk14);
            output.Write(PrimaryMaterialIdx);
            output.Write(SecondaryMaterialIdx);
            output.Write(TertiaryMaterialIdx);
            output.Write(vertexFlagsCalc);
            output.Write(TransformMatrixSpecificIdxsObj1, 0, 8);
            if (!isIndexed)
            {
                output.Write((Obj1StripsCcw.Count != 0) ? Obj1StripsCcw.SizeOfNonIndexed(is16Bit) : 0);
                output.Write((Obj1StripsCw.Count != 0) ? Obj1StripsCw.SizeOfNonIndexed(is16Bit) : 0);
            }
            else
            {
                // This field contains the number of 32-bit integers instead of the number of bytes, hence the div. by 4
                output.Write((Obj1StripsCcw.Count != 0) ? (Obj1StripsCcw.SizeOfIndexed() / 4) : 0);
                output.Write((Obj1StripsCw.Count != 0) ? (Obj1StripsCw.SizeOfIndexed() / 4) : 0);
            }
            output.Write(BoundingSphereCenter.X);
            output.Write(BoundingSphereCenter.Y);
            output.Write(BoundingSphereCenter.Z);
            output.Write(Unk3C);
            output.Write(Unk40);
            output.Write(0);
            output.Write(0);
            output.Write(0);
            output.Write(0);
            output.Write(0);
            output.Write(0);
            output.Write(0);
        }
Beispiel #2
0
        internal int SizeOfIndexedData()
        {
            int size = 0;

            if (Obj1StripsCcw.Count != 0)
            {
                size += Obj1StripsCcw.SizeOfIndexed();
            }

            if (Obj1StripsCw.Count != 0)
            {
                size += Obj1StripsCw.SizeOfIndexed();
            }

            return(size);
        }