public void Read(byte[] data) { using (var reader = new VBFile(new MemoryStream(data))){ Version = reader.ReadInt32(); Name = reader.ReadPascalString(); BoneCount = reader.ReadInt16(); System.Diagnostics.Debug.WriteLine("========== Skeleton =========="); System.Diagnostics.Debug.WriteLine("Version: " + Version); System.Diagnostics.Debug.WriteLine("Name: " + Name); System.Diagnostics.Debug.WriteLine("BoneCount: " + BoneCount); Bones = new Bone[BoneCount]; for (var i = 0; i < BoneCount; i++) { System.Diagnostics.Debug.WriteLine("\n [Bone " + i + "]"); Bones[i] = ReadBone(reader); } /** Construct tree **/ foreach (var bone in Bones) { bone.Children = Bones.Where(x => x.ParentName == bone.Name).ToArray(); } RootBone = Bones.FirstOrDefault(x => x.ParentName == "NULL"); } }
public void Read(byte[] data) { using(var reader = new VBFile(new MemoryStream(data))){ Version = reader.ReadInt32(); Name = reader.ReadPascalString(); BoneCount = reader.ReadInt16(); System.Diagnostics.Debug.WriteLine("========== Skeleton =========="); System.Diagnostics.Debug.WriteLine("Version: " + Version); System.Diagnostics.Debug.WriteLine("Name: " + Name); System.Diagnostics.Debug.WriteLine("BoneCount: " + BoneCount); Bones = new Bone[BoneCount]; for (var i = 0; i < BoneCount; i++){ System.Diagnostics.Debug.WriteLine("\n [Bone " + i + "]"); Bones[i] = ReadBone(reader); } /** Construct tree **/ foreach (var bone in Bones){ bone.Children = Bones.Where(x => x.ParentName == bone.Name).ToArray(); } RootBone = Bones.FirstOrDefault(x => x.ParentName == "NULL"); } }
private Bone ReadBone(VBFile reader) { var bone = new Bone(); bone.Unknown = reader.ReadInt32(); bone.Name = reader.ReadPascalString(); bone.ParentName = reader.ReadPascalString(); System.Diagnostics.Debug.WriteLine("Name: " + bone.Name); System.Diagnostics.Debug.WriteLine("ParentName: " + bone.ParentName); bone.HasProps = reader.ReadByte(); if (bone.HasProps != 0) { var propertyCount = reader.ReadInt32(); var property = new PropertyListItem(); for (var i = 0; i < propertyCount; i++) { var pairCount = reader.ReadInt32(); for (var x = 0; x < pairCount; x++) { property.KeyPairs.Add(new KeyValuePair <string, string>( reader.ReadPascalString(), reader.ReadPascalString() )); } } bone.Properties.Add(property); } if (bone.Name == "ROOT") { var y = true; } var xx = -reader.ReadFloat(); bone.Translation = new Vector3( xx, reader.ReadFloat(), reader.ReadFloat() ); bone.Rotation = new Vector4( reader.ReadFloat(), -reader.ReadFloat(), -reader.ReadFloat(), reader.ReadFloat() ); bone.CanTranslate = reader.ReadInt32(); bone.CanRotate = reader.ReadInt32(); bone.CanBlend = reader.ReadInt32(); bone.WiggleValue = reader.ReadFloat(); bone.WigglePower = reader.ReadFloat(); return(bone); }
private Bone ReadBone(VBFile reader) { var bone = new Bone(); bone.Unknown = reader.ReadInt32(); bone.Name = reader.ReadPascalString(); bone.ParentName = reader.ReadPascalString(); System.Diagnostics.Debug.WriteLine("Name: " + bone.Name); System.Diagnostics.Debug.WriteLine("ParentName: " + bone.ParentName); bone.HasProps = reader.ReadByte(); if (bone.HasProps != 0) { var propertyCount = reader.ReadInt32(); var property = new PropertyListItem(); for (var i = 0; i < propertyCount; i++){ var pairCount = reader.ReadInt32(); for (var x = 0; x < pairCount; x++){ property.KeyPairs.Add(new KeyValuePair<string, string>( reader.ReadPascalString(), reader.ReadPascalString() )); } } bone.Properties.Add(property); } if (bone.Name == "ROOT") { var y = true; } var xx = -reader.ReadFloat(); bone.Translation = new Vector3( xx, reader.ReadFloat(), reader.ReadFloat() ); bone.Rotation = new Vector4( reader.ReadFloat(), -reader.ReadFloat(), -reader.ReadFloat(), reader.ReadFloat() ); bone.CanTranslate = reader.ReadInt32(); bone.CanRotate = reader.ReadInt32(); bone.CanBlend = reader.ReadInt32(); bone.WiggleValue = reader.ReadFloat(); bone.WigglePower = reader.ReadFloat(); return bone; }
public void Read(byte[] data) { using (var reader = new VBFile(new MemoryStream(data))) { System.Diagnostics.Debug.WriteLine("========== Mesh =========="); Version = reader.ReadInt32(); BoneCount = reader.ReadInt32(); System.Diagnostics.Debug.WriteLine("Version: " + Version); System.Diagnostics.Debug.WriteLine("BoneCount: " + BoneCount); /** Read bone names |str_len|str_body| **/ BoneNames = new string[BoneCount]; for (var i = 0; i < BoneCount; i++){ BoneNames[i] = reader.ReadPascalString(); System.Diagnostics.Debug.WriteLine("| Bone " + (i + 1) + ": " + BoneNames[i]); } /** Faces **/ FaceCount = reader.ReadInt32(); System.Diagnostics.Debug.WriteLine("FaceCount: " + FaceCount); FaceData = new Face[FaceCount]; for (var i = 0; i < FaceCount; i++){ FaceData[i] = new Face { VertexA = reader.ReadInt32(), VertexB = reader.ReadInt32(), VertexC = reader.ReadInt32() }; } /** Bone bindings **/ BindingCount = reader.ReadInt32(); BoneBindings = new BoneBinding[BindingCount]; for (var i = 0; i < BindingCount; i++){ BoneBindings[i] = new BoneBinding { BoneIndex = reader.ReadInt32(), FirstRealVertex = reader.ReadInt32(), RealVertexCount = reader.ReadInt32(), FirstBlendVertex = reader.ReadInt32(), BlendVertexCount = reader.ReadInt32() }; } /** Texture vertex data **/ RealVertexCount = reader.ReadInt32(); //VertexData = new MeshVertex[RealVertexCount]; var textureData = new Vector2[RealVertexCount]; for (var i = 0; i < RealVertexCount; i++){ textureData[i] = new Vector2( reader.ReadFloat(), reader.ReadFloat() ); } /** Blend data **/ BlendVertexCount = reader.ReadInt32(); var blend = new BlendData[BlendVertexCount]; for (var i = 0; i < BlendVertexCount; i++) { blend[i] = new BlendData { Weight = (float)reader.ReadInt32()/0x8000, OtherVertex = reader.ReadInt32() }; } TotalVertexCount = reader.ReadInt32(); //VertexData = new MeshVertex[TotalVertexCount]; //TransformedVertexData = new MeshVertex[TotalVertexCount]; Vertex = new MeshVertexData[TotalVertexCount]; TransformedVertex = new MeshVertexData[TotalVertexCount]; for (var i = 0; i < TotalVertexCount; i++){ var vertexData = new MeshVertex { Coord = new Vector3( -reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat() ) }; var tVertexData = new MeshVertex { Coord = vertexData.Coord, NormalCoord = new Vector3( -reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat() ) }; var vertex = new MeshVertexData { Vertex = vertexData }; var tVertex = new MeshVertexData{ Vertex = tVertexData }; if (i < RealVertexCount) { tVertex.Vertex.TextureCoord = textureData[i]; } else { tVertex.BlendData = blend[i - RealVertexCount]; } //VertexData[i] = vertexData; //TransformedVertexData[i] = tVertexData; Vertex[i] = vertex; TransformedVertex[i] = tVertex; } } }
public void Read(byte[] data) { using (var reader = new VBFile(new MemoryStream(data))) { System.Diagnostics.Debug.WriteLine("========== Mesh =========="); Version = reader.ReadInt32(); BoneCount = reader.ReadInt32(); System.Diagnostics.Debug.WriteLine("Version: " + Version); System.Diagnostics.Debug.WriteLine("BoneCount: " + BoneCount); /** Read bone names |str_len|str_body| **/ BoneNames = new string[BoneCount]; for (var i = 0; i < BoneCount; i++) { BoneNames[i] = reader.ReadPascalString(); System.Diagnostics.Debug.WriteLine("| Bone " + (i + 1) + ": " + BoneNames[i]); } /** Faces **/ FaceCount = reader.ReadInt32(); System.Diagnostics.Debug.WriteLine("FaceCount: " + FaceCount); FaceData = new Face[FaceCount]; for (var i = 0; i < FaceCount; i++) { FaceData[i] = new Face { VertexA = reader.ReadInt32(), VertexB = reader.ReadInt32(), VertexC = reader.ReadInt32() }; } /** Bone bindings **/ BindingCount = reader.ReadInt32(); BoneBindings = new BoneBinding[BindingCount]; for (var i = 0; i < BindingCount; i++) { BoneBindings[i] = new BoneBinding { BoneIndex = reader.ReadInt32(), FirstRealVertex = reader.ReadInt32(), RealVertexCount = reader.ReadInt32(), FirstBlendVertex = reader.ReadInt32(), BlendVertexCount = reader.ReadInt32() }; } /** Texture vertex data **/ RealVertexCount = reader.ReadInt32(); //VertexData = new MeshVertex[RealVertexCount]; var textureData = new Vector2[RealVertexCount]; for (var i = 0; i < RealVertexCount; i++) { textureData[i] = new Vector2( reader.ReadFloat(), reader.ReadFloat() ); } /** Blend data **/ BlendVertexCount = reader.ReadInt32(); var blend = new BlendData[BlendVertexCount]; for (var i = 0; i < BlendVertexCount; i++) { blend[i] = new BlendData { Weight = (float)reader.ReadInt32() / 0x8000, OtherVertex = reader.ReadInt32() }; } TotalVertexCount = reader.ReadInt32(); //VertexData = new MeshVertex[TotalVertexCount]; //TransformedVertexData = new MeshVertex[TotalVertexCount]; Vertex = new MeshVertexData[TotalVertexCount]; TransformedVertex = new MeshVertexData[TotalVertexCount]; for (var i = 0; i < TotalVertexCount; i++) { var vertexData = new MeshVertex { Coord = new Vector3( -reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat() ) }; var tVertexData = new MeshVertex { Coord = vertexData.Coord, NormalCoord = new Vector3( -reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat() ) }; var vertex = new MeshVertexData { Vertex = vertexData }; var tVertex = new MeshVertexData { Vertex = tVertexData }; if (i < RealVertexCount) { tVertex.Vertex.TextureCoord = textureData[i]; } else { tVertex.BlendData = blend[i - RealVertexCount]; } //VertexData[i] = vertexData; //TransformedVertexData[i] = tVertexData; Vertex[i] = vertex; TransformedVertex[i] = tVertex; } } }