Пример #1
0
        private static List <Mesh> ReadMeshes(EndianBinaryReader reader, int meshCount)
        {
            var context = new MeshContext();
            var list    = new List <Mesh>(meshCount);

            for (int i = 0; i < meshCount; i++)
            {
                var mesh = reader.ReadObject <Mesh>(context);
                list.Add(mesh);
            }

            return(list);
        }
Пример #2
0
        public void Write(EndianBinaryWriter writer, MeshContext context)
        {
            writer.ScheduleWriteListOffset(Parameters, 16, x => x.Write(writer));
            writer.Write(Parameters.Count);

            // Hack(TGE): look up index attributes flag in params to parse display lists
            foreach (var param in Parameters)
            {
                if (param.Type == MeshStateParamType.IndexAttributeFlags)
                {
                    context.IndexAttributeFlags = (( IndexAttributeFlagsParam )param).Flags;
                }
            }

            // Make sure to make a local copy of it for the display list write function because it's executed later
            var indexAttributeFlags = context.IndexAttributeFlags;

            var displayListSizeOffset = writer.Position + 4;

            writer.ScheduleWriteOffsetAligned(16, () =>
            {
                var displayListStart = writer.Position;

                // Write display lists
                foreach (var displayList in DisplayLists)
                {
                    writer.WriteObject(displayList, indexAttributeFlags);
                }

                writer.Write(( byte )0);
                writer.WriteAlignmentPadding(16);

                // Calculate & write display list size
                var displayListEnd  = writer.Position;
                var displayListSize = displayListEnd - displayListStart;
                writer.SeekBegin(displayListSizeOffset);
                writer.Write(( int )displayListSize);
                writer.SeekBegin(displayListEnd);
            });
            writer.Write(0);   // display list size
        }
Пример #3
0
        public void Read(EndianBinaryReader reader, MeshContext context)
        {
            var meshParamListOffset = reader.ReadInt32();
            var meshParamCount      = reader.ReadInt32();
            var displayListOffset   = reader.ReadInt32();
            var displayListSize     = reader.ReadInt32();

            reader.ReadAtOffset(meshParamListOffset, () =>
            {
                Parameters = new List <Param>();
                for (int i = 0; i < meshParamCount; i++)
                {
                    var type = ( MeshStateParamType )reader.ReadInt32();
                    Param param;

                    switch (type)
                    {
                    case MeshStateParamType.IndexAttributeFlags:
                        param = new IndexAttributeFlagsParam();
                        break;

                    case MeshStateParamType.Lighting:
                        param = new LightingParams();
                        break;

                    case MeshStateParamType.BlendAlpha:
                        param = new BlendAlphaParam();
                        break;

                    case MeshStateParamType.AmbientColor:
                        param = new AmbientColorParam();
                        break;

                    case MeshStateParamType.Texture:
                        param = new TextureParams();
                        break;

                    case MeshStateParamType.MipMap:
                        param = new MipMapParams();
                        break;

                    default:
                        param = new UnknownParam();
                        break;
                    }

                    param.ReadBody(type, reader);
                    Parameters.Add(param);
                }
            });

            // Hack(TGE): look up index attributes flag in params to parse display lists
            foreach (var param in Parameters)
            {
                if (param.Type == MeshStateParamType.IndexAttributeFlags)
                {
                    context.IndexAttributeFlags = (( IndexAttributeFlagsParam )param).Flags;
                }
            }

            reader.ReadAtOffset(displayListOffset, () =>
            {
                DisplayLists    = new List <GXDisplayList>();
                var endPosition = reader.Position + displayListSize;
                while (reader.ReadByte() != 0 && reader.Position < endPosition)
                {
                    reader.SeekCurrent(-1);
                    var displayList = reader.ReadObject <GXDisplayList>(context.IndexAttributeFlags);
                    DisplayLists.Add(displayList);
                }
            });
        }