public Vector3(BinaryReader reader, VectorCompression compression = VectorCompression.None) { if (compression == VectorCompression.None) { X = reader.ReadSingle(); Y = reader.ReadSingle(); Z = reader.ReadSingle(); } else { float compressionScale; switch (compression) { case VectorCompression.Collision: compressionScale = 128.0f; break; case VectorCompression.Animation: compressionScale = 1024.0f; break; default: compressionScale = 1.0f; break; } X = reader.ReadInt16() / compressionScale; Y = reader.ReadInt16() / compressionScale; Z = reader.ReadInt16() / compressionScale; } }
public void Given_mesh_animation_controller_when_serializing_and_then_deserializing_should_give_equivalent() { byte[] expectedSerializedData = { 0x02, 0x00, 0x48, 0xe1, 0x7a, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x38, 0xc0, 0x00, 0x40, 0x40, 0xab, 0xaa, 0x55, 0xd5, 0x00, 0x00, 0xaa, 0x2a, 0x55, 0x55, 0xff, 0x7f, 0xc0, 0x00, 0xc0, 0x38, 0x40, 0xff, 0x3f, 0xc0, 0x55, 0xd5, 0xab, 0xaa, 0x00, 0x80, 0x55, 0x55, 0xaa, 0x2a, 0x00, 0x00, 0x10, 0xff, 0xc0 }; _controller.Frames = new List <AnimationKeyFrame> { new AnimationKeyFrame { FrameNumber = 0, Time = 0.98f }, new AnimationKeyFrame { FrameNumber = 1, Time = 1.5f } }; _controller.CompressedFrames = new List <CompressedVectors> { VectorCompression.Compress( new List <Vector3> { new Vector3(1, 2, 3), new Vector3(4, 5, 6) } ), VectorCompression.Compress( new List <Vector3> { new Vector3(-4, -5, -6), new Vector3(-1, -2, -3) } ) }; _controller.Unknown0 = new byte[] { 0x10, 0xFF, 0xC0 }; MeshAnimationController deserializedController = new Mock <MeshAnimationController>().Object; // Act using (var ms = new MemoryStream()) { _sut.Serialize(ms, _controller); ms.Position = 0; _sut.Deserialize(ms, deserializedController); // Assert ms.Should().BeEof(); ms.ToArray().Should().BeEquivalentTo(expectedSerializedData); _controller.Should().BeEquivalentTo(deserializedController); } }
public Vector3(BinaryReader reader, VectorCompression compression = VectorCompression.None) { if (compression == VectorCompression.None) { X = reader.ReadSingle(); Y = reader.ReadSingle(); Z = reader.ReadSingle(); } else { float compressionScale; switch (compression) { case VectorCompression.Collision: compressionScale = 128.0f; break; case VectorCompression.Animation: compressionScale = 1024.0f; break; default: compressionScale = 1.0f; break; } X = reader.ReadInt16() / compressionScale; Y = reader.ReadInt16() / compressionScale; Z = reader.ReadInt16() / compressionScale; } }