public override void Unserialize(GR2Reader reader) { Position = ReadVector3(reader); BoneWeights = ReadInfluences(reader); BoneIndices = ReadInfluences(reader); TextureCoordinates0 = ReadVector2(reader); }
public override void Unserialize(GR2Reader reader) { Position = ReadVector3(reader); Normal = ReadVector3(reader); Tangent = ReadVector3(reader); TextureCoordinates0 = ReadVector2(reader); }
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); }
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; }
public override void Unserialize(GR2Reader reader) { Position = ReadVector3(reader); BoneWeights = ReadInfluences(reader); BoneIndices = ReadInfluences(reader); Normal = ReadVector3(reader); Tangent = ReadVector3(reader); }
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); }
public UInt32 Size(GR2Reader gr2) { UInt32 size = 0; foreach (var member in Members) { size += member.Size(gr2); } return(size); }
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; }
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); }
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); }
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())); } }
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); }
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; }
protected Vector3 ReadVector3(GR2Reader reader) { Vector3 v; v.X = reader.Reader.ReadSingle(); v.Y = reader.Reader.ReadSingle(); v.Z = reader.Reader.ReadSingle(); return v; }
public override void Unserialize(GR2Reader reader) { Position = ReadVector3(reader); }
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; }
public abstract void Unserialize(GR2Reader reader);
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; }
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; }
protected Vector2 ReadVector2(GR2Reader reader) { Vector2 v; v.X = reader.Reader.ReadSingle(); v.Y = reader.Reader.ReadSingle(); return v; }
public override void Unserialize(GR2Reader reader) { Position = ReadVector3(reader); Normal = ReadVector3(reader); Tangent = ReadVector3(reader); }