Example #1
0
 public override void Unserialize(GR2Reader reader)
 {
     Position = ReadVector3(reader);
     BoneWeights = ReadInfluences(reader);
     BoneIndices = ReadInfluences(reader);
     TextureCoordinates0 = ReadVector2(reader);
 }
Example #2
0
 public override void Unserialize(GR2Reader reader)
 {
     Position = ReadVector3(reader);
     Normal = ReadVector3(reader);
     Tangent = ReadVector3(reader);
     TextureCoordinates0 = ReadVector2(reader);
 }
Example #3
0
        public StructDefinition Resolve(GR2Reader gr2)
        {
            Debug.Assert(IsValid);
            // Type definitions use a 2-level cache
            // First we'll check the reference itself, if it has a cached ref to the resolved type
            // If it has, we have nothing to do

            // If the struct wasn't resolved yet, try the type definition cache
            // When a type definition is read from the GR2 file, it is stored here using its definition address as a key
            if (Type == null)
            {
                gr2.Types.TryGetValue(this, out Type);
            }

            if (Type == null)
            {
                // We haven't seen this type before, read its definition from the file and cache it
#if DEBUG_GR2_SERIALIZATION
                System.Console.WriteLine(String.Format(" ===== Struct definition at {0:X8} ===== ", Offset));
#endif
                var originalPos = gr2.Stream.Position;
                gr2.Seek(this);
                Type = gr2.ReadStructDefinition();
                gr2.Stream.Seek(originalPos, SeekOrigin.Begin);
                gr2.Types[this] = Type;
            }

            return(Type);
        }
Example #4
0
 public object Read(GR2Reader gr2, StructDefinition definition, MemberDefinition member, uint arraySize, object parent)
 {
     var controls = new List<UInt16>((int)arraySize);
     for (int i = 0; i < arraySize; i++)
         controls.Add(gr2.Reader.ReadUInt16());
     return controls;
 }
Example #5
0
 public override void Unserialize(GR2Reader reader)
 {
     Position = ReadVector3(reader);
     BoneWeights = ReadInfluences(reader);
     BoneIndices = ReadInfluences(reader);
     Normal = ReadVector3(reader);
     Tangent = ReadVector3(reader);
 }
Example #6
0
        public object Read(GR2Reader gr2, StructDefinition definition, MemberDefinition member, uint arraySize, object parent)
        {
            var controls = new List <UInt16>((int)arraySize);

            for (int i = 0; i < arraySize; i++)
            {
                controls.Add(gr2.Reader.ReadUInt16());
            }
            return(controls);
        }
Example #7
0
        public UInt32 Size(GR2Reader gr2)
        {
            UInt32 size = 0;

            foreach (var member in Members)
            {
                size += member.Size(gr2);
            }
            return(size);
        }
Example #8
0
 private Root LoadGR2(string inPath)
 {
     var root = new LSLib.Granny.Model.Root();
     FileStream fs = new FileStream(inPath, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
     var gr2 = new LSLib.Granny.GR2.GR2Reader(fs);
     gr2.Read(root);
     root.PostLoad();
     fs.Close();
     fs.Dispose();
     return root;
 }
Example #9
0
        private Root LoadGR2(string inPath)
        {
            var        root = new LSLib.Granny.Model.Root();
            FileStream fs   = new FileStream(inPath, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
            var        gr2  = new LSLib.Granny.GR2.GR2Reader(fs);

            gr2.Read(root);
            root.PostLoad();
            fs.Close();
            fs.Dispose();
            return(root);
        }
Example #10
0
        public string Resolve(GR2Reader gr2)
        {
            Debug.Assert(IsValid);
            // Don't use a global string cache here, as string constants are rarely referenced twice,
            // unlike struct definitions
            if (Value == null)
            {
                var originalPos = gr2.Stream.Position;
                gr2.Seek(this);
                Value = gr2.ReadString();
                gr2.Stream.Seek(originalPos, SeekOrigin.Begin);
            }

            return(Value);
        }
Example #11
0
        public UInt32 Size(GR2Reader gr2)
        {
            switch (Type)
            {
            case MemberType.Inline:
                return(Definition.Resolve(gr2).Size(gr2));

            case MemberType.Int8:
            case MemberType.BinormalInt8:
            case MemberType.UInt8:
            case MemberType.NormalUInt8:
                return(1);

            case MemberType.Int16:
            case MemberType.BinormalInt16:
            case MemberType.UInt16:
            case MemberType.NormalUInt16:
                return(2);

            case MemberType.Reference:
            case MemberType.String:
            case MemberType.Real32:
            case MemberType.Int32:
            case MemberType.UInt32:
                return(4);

            case MemberType.VariantReference:
            case MemberType.ArrayOfReferences:
            case MemberType.ReferenceToArray:
                return(8);

            case MemberType.ReferenceToVariantArray:
                return(12);

            case MemberType.Transform:
                return(17 * 4);

            default:
                throw new ParsingException(String.Format("Unhandled member type: {0}", Type.ToString()));
            }
        }
Example #12
0
        public List <RelocatableReference> Resolve(GR2Reader gr2)
        {
            Debug.Assert(IsValid);
            if (Items == null)
            {
#if DEBUG_GR2_SERIALIZATION
                System.Console.WriteLine(String.Format("    (Reference list at {0:X8})", Offset));
#endif
                var originalPos = gr2.Stream.Position;
                gr2.Seek(this);
                Items = new List <RelocatableReference>();
                for (int i = 0; i < Size; i++)
                {
                    Items.Add(gr2.ReadReference());
#if DEBUG_GR2_SERIALIZATION
                    System.Console.WriteLine(String.Format("        {0:X8}", r.Offset));
#endif
                }
                gr2.Stream.Seek(originalPos, SeekOrigin.Begin);
            }

            return(Items);
        }
Example #13
0
        public object Read(GR2Reader reader, StructDefinition definition, MemberDefinition member, uint arraySize, object parent)
        {
            Type type;
            if (!VertexTypeCache.TryGetValue(parent, out type))
            {
                type = SelectType(member, definition, parent);
                VertexTypeCache.Add(parent, type);
            }

            var vertex = Helpers.CreateInstance(type);
            (vertex as Vertex).Unserialize(reader);
            return vertex;
        }
Example #14
0
 protected Vector3 ReadVector3(GR2Reader reader)
 {
     Vector3 v;
     v.X = reader.Reader.ReadSingle();
     v.Y = reader.Reader.ReadSingle();
     v.Z = reader.Reader.ReadSingle();
     return v;
 }
Example #15
0
File: P3.cs Project: Norbyte/lslib
 public override void Unserialize(GR2Reader reader)
 {
     Position = ReadVector3(reader);
 }
Example #16
0
 protected Vector4 ReadVector4(GR2Reader reader)
 {
     Vector4 v;
     v.X = reader.Reader.ReadSingle();
     v.Y = reader.Reader.ReadSingle();
     v.Z = reader.Reader.ReadSingle();
     v.W = reader.Reader.ReadSingle();
     return v;
 }
Example #17
0
 public abstract void Unserialize(GR2Reader reader);
Example #18
0
 protected BoneWeight ReadInfluences(GR2Reader reader)
 {
     BoneWeight v;
     v.A = reader.Reader.ReadByte();
     v.B = reader.Reader.ReadByte();
     v.C = reader.Reader.ReadByte();
     v.D = reader.Reader.ReadByte();
     return v;
 }
Example #19
0
 protected Vector4 ReadHalfVector4(GR2Reader reader)
 {
     Vector4 v;
     v.X = HalfHelpers.HalfToSingle(reader.Reader.ReadUInt16());
     v.Y = HalfHelpers.HalfToSingle(reader.Reader.ReadUInt16());
     v.Z = HalfHelpers.HalfToSingle(reader.Reader.ReadUInt16());
     v.W = HalfHelpers.HalfToSingle(reader.Reader.ReadUInt16());
     return v;
 }
Example #20
0
 protected Vector2 ReadVector2(GR2Reader reader)
 {
     Vector2 v;
     v.X = reader.Reader.ReadSingle();
     v.Y = reader.Reader.ReadSingle();
     return v;
 }
Example #21
0
 public override void Unserialize(GR2Reader reader)
 {
     Position = ReadVector3(reader);
     Normal = ReadVector3(reader);
     Tangent = ReadVector3(reader);
 }