Example #1
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteInfluences(section, BoneWeights);
     WriteInfluences(section, BoneIndices);
     WriteVector2(section, TextureCoordinates0);
 }
Example #2
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteVector3(section, Normal);
     WriteVector3(section, Tangent);
     WriteVector2(section, TextureCoordinates0);
 }
Example #3
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteInfluences(section, BoneWeights);
     WriteInfluences(section, BoneIndices);
     WriteVector3(section, Normal);
     WriteVector3(section, Tangent);
 }
Example #4
0
        public void Write(GR2Writer writer, WritableSection section, MemberDefinition member, object obj)
        {
            var items = obj as List <UInt16>;

            for (int i = 0; i < items.Count; i++)
            {
                section.Writer.Write(items[i]);
            }
        }
Example #5
0
        internal void WriteSectionRelocations(WritableSection section)
        {
            section.Header.numRelocations    = (UInt32)section.Fixups.Count;
            section.Header.relocationsOffset = (UInt32)MainStream.Position;

            foreach (var fixup in section.Fixups)
            {
                Writer.Write(fixup.Key);
                WriteSectionReference(GR2.ObjectOffsets[fixup.Value]);
            }
        }
Example #6
0
        internal void WriteSectionMixedMarshallingRelocations(WritableSection section)
        {
            section.Header.numMixedMarshallingData    = (UInt32)section.MixedMarshalling.Count;
            section.Header.mixedMarshallingDataOffset = (UInt32)MainStream.Position;

            foreach (var marshal in section.MixedMarshalling)
            {
                Writer.Write(marshal.Count);
                Writer.Write(GR2.ObjectOffsets[marshal.Obj].Offset);
                WriteSectionReference(GR2.ObjectOffsets[marshal.Type]);
            }
        }
Example #7
0
 protected void WriteHalfVector4(WritableSection section, Vector4 v)
 {
     section.Writer.Write(HalfHelpers.SingleToHalf(v.X));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Y));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Z));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.W));
 }
Example #8
0
        public byte[] Write(object root)
        {
            using (this.Writer = new BinaryWriter(Stream))
            {
                this.Magic = InitMagic();
                WriteMagic(Magic);

                this.Header = InitHeader();
                WriteHeader(Header);

                for (int i = 0; i < Header.numSections; i++)
                {
                    var section = new WritableSection((SectionType)i, this);
                    WriteSectionHeader(section.Header);
                    Sections.Add(section);
                }

                Magic.headersSize = (UInt32)Stream.Position;

                CurrentSection = Sections[(int)SectionType.Main];
                CurrentSection.WriteStruct(root);

                while (ArrayWrites.Count > 0 || StructWrites.Count > 0 || StringWrites.Count > 0)
                {
                    FlushPendingWrites();
                }

                foreach (var defn in Types.Values)
                {
                    Sections[(int)SectionType.Discardable].WriteStructDefinition(defn);
                }

                // We need to do this again to flush strings written by WriteMemberDefinition()
                FlushPendingWrites();

                FinalizeOffsets();

                foreach (var section in Sections)
                {
                    section.Header.first16bit = (UInt32)section.MainStream.Length;
                    section.Header.first8bit = (UInt32)section.MainStream.Length;
                    section.Finish();
                }

                var relocSection = Sections[(int)SectionType.Discardable];
                foreach (var section in Sections)
                {
                    relocSection.WriteSectionRelocations(section);
                    relocSection.WriteSectionMixedMarshallingRelocations(section);
                }

                foreach (var section in Sections)
                {
                    // Pad section size to a multiple of 4
                    while (section.MainStream.Position % 4 > 0)
                        section.Writer.Write((Byte)0);

                    section.MainStream.Flush();
                    section.Header.offsetInFile = (UInt32)Stream.Position;
                    section.Header.uncompressedSize = (UInt32)section.MainStream.Length;
                    section.Header.compressedSize = (UInt32)section.MainStream.Length;
                    Writer.Write(section.MainStream.ToArray());
                }

                foreach (var section in Sections)
                {
                    section.Header.relocationsOffset += relocSection.Header.offsetInFile;
                    section.Header.mixedMarshallingDataOffset += relocSection.Header.offsetInFile;
                }

                var rootStruct = LookupStructDefinition(root.GetType());
                Header.rootType = ObjectOffsets[rootStruct];
                Header.rootNode = new SectionReference(SectionType.Main, 0);
                Header.fileSize = (UInt32)Stream.Length;

                Stream.Seek(Magic.MagicSize + Header.HeaderSize, SeekOrigin.Begin);

                foreach (var section in Sections)
                {
                    WriteSectionHeader(section.Header);
                }

                Header.crc = Header.CalculateCRC(Stream);
                Stream.Seek(0, SeekOrigin.Begin);
                WriteMagic(Magic);
                WriteHeader(Header);

                return Stream.ToArray();
            }
        }
Example #9
0
        internal void WriteSectionMixedMarshallingRelocations(WritableSection section)
        {
            section.Header.numMixedMarshallingData = (UInt32)section.MixedMarshalling.Count;
            section.Header.mixedMarshallingDataOffset = (UInt32)MainStream.Position;

            foreach (var marshal in section.MixedMarshalling)
            {
                Writer.Write(marshal.Count);
                Writer.Write(GR2.ObjectOffsets[marshal.Obj].Offset);
                WriteSectionReference(GR2.ObjectOffsets[marshal.Type]);
            }
        }
Example #10
0
        internal void WriteSectionRelocations(WritableSection section)
        {
            section.Header.numRelocations = (UInt32)section.Fixups.Count;
            section.Header.relocationsOffset = (UInt32)MainStream.Position;

            foreach (var fixup in section.Fixups)
            {
                Writer.Write(fixup.Key);
                WriteSectionReference(GR2.ObjectOffsets[fixup.Value]);
            }
        }
Example #11
0
File: P3.cs Project: Norbyte/lslib
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
 }
Example #12
0
 public void Write(GR2Writer writer, WritableSection section, MemberDefinition member, object obj)
 {
     (obj as Vertex).Serialize(section);
 }
Example #13
0
 public abstract void Serialize(WritableSection section);
Example #14
0
 public void Write(GR2Writer writer, WritableSection section, MemberDefinition member, object obj)
 {
     var items = obj as List<UInt16>;
     for (int i = 0; i < items.Count; i++)
         section.Writer.Write(items[i]);
 }
Example #15
0
 protected void WriteVector4(WritableSection section, Vector4 v)
 {
     section.Writer.Write(v.X);
     section.Writer.Write(v.Y);
     section.Writer.Write(v.Z);
     section.Writer.Write(v.W);
 }
Example #16
0
 protected void WriteHalfVector3As4(WritableSection section, Vector3 v)
 {
     section.Writer.Write(HalfHelpers.SingleToHalf(v.X));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Y));
     section.Writer.Write(HalfHelpers.SingleToHalf(v.Z));
     section.Writer.Write((ushort)0);
 }
Example #17
0
 protected void WriteVector2(WritableSection section, Vector2 v)
 {
     section.Writer.Write(v.X);
     section.Writer.Write(v.Y);
 }
Example #18
0
        public byte[] Write(object root)
        {
            using (this.Writer = new BinaryWriter(Stream))
            {
                this.Magic = InitMagic();
                WriteMagic(Magic);

                this.Header = InitHeader();
                WriteHeader(Header);

                for (int i = 0; i < Header.numSections; i++)
                {
                    var section = new WritableSection((SectionType)i, this);
                    WriteSectionHeader(section.Header);
                    Sections.Add(section);
                }

                Magic.headersSize = (UInt32)Stream.Position;

                CurrentSection = Sections[(int)SectionType.Main];
                CurrentSection.WriteStruct(root);

                while (ArrayWrites.Count > 0 || StructWrites.Count > 0 || StringWrites.Count > 0)
                {
                    FlushPendingWrites();
                }

                foreach (var defn in Types.Values)
                {
                    Sections[(int)SectionType.Discardable].WriteStructDefinition(defn);
                }

                // We need to do this again to flush strings written by WriteMemberDefinition()
                FlushPendingWrites();

                FinalizeOffsets();

                foreach (var section in Sections)
                {
                    section.Header.first16bit = (UInt32)section.MainStream.Length;
                    section.Header.first8bit  = (UInt32)section.MainStream.Length;
                    section.Finish();
                }

                var relocSection = Sections[(int)SectionType.Discardable];
                foreach (var section in Sections)
                {
                    relocSection.WriteSectionRelocations(section);
                }

                foreach (var section in Sections)
                {
                    relocSection.WriteSectionMixedMarshallingRelocations(section);
                }

                foreach (var section in Sections)
                {
                    // Pad section size to a multiple of the section alignment
                    while ((section.MainStream.Position % section.Header.alignment) > 0)
                    {
                        section.Writer.Write((Byte)0);
                    }

                    section.MainStream.Flush();
                    section.Header.offsetInFile     = (UInt32)Stream.Position;
                    section.Header.uncompressedSize = (UInt32)section.MainStream.Length;
                    section.Header.compressedSize   = (UInt32)section.MainStream.Length;
                    Writer.Write(section.MainStream.ToArray());
                }

                foreach (var section in Sections)
                {
                    section.Header.relocationsOffset          += relocSection.Header.offsetInFile;
                    section.Header.mixedMarshallingDataOffset += relocSection.Header.offsetInFile;
                }

                var rootStruct = LookupStructDefinition(root.GetType(), root);
                Header.rootType = ObjectOffsets[rootStruct];
                Header.rootNode = new SectionReference(SectionType.Main, 0);
                Header.fileSize = (UInt32)Stream.Length;

                Stream.Seek(Magic.MagicSize + Header.Size(), SeekOrigin.Begin);

                foreach (var section in Sections)
                {
                    WriteSectionHeader(section.Header);
                }

                Header.crc = Header.CalculateCRC(Stream);
                Stream.Seek(0, SeekOrigin.Begin);
                WriteMagic(Magic);
                WriteHeader(Header);

                return(Stream.ToArray());
            }
        }
Example #19
0
 protected void WriteInfluences(WritableSection section, BoneWeight v)
 {
     section.Writer.Write(v.A);
     section.Writer.Write(v.B);
     section.Writer.Write(v.C);
     section.Writer.Write(v.D);
 }
Example #20
0
 public override void Serialize(WritableSection section)
 {
     WriteVector3(section, Position);
     WriteVector3(section, Normal);
     WriteVector3(section, Tangent);
 }