Пример #1
0
        public async Task Given_raw_chunk_data_when_deserializing_should_load_model(bool includeNormals, string resourceName)
        {
            byte[] rawChunkData = GetType().Assembly.GetManifestResourceStream(GetType(), resourceName).ToArray();

            ModelChunk expectedChunk = GetPopulatedModelChunk(includeNormals);

            using (var ms = new MemoryStream(rawChunkData))
            {
                // Act
                var deserializedChunk = new ModelChunk();
                await deserializedChunk.DeserializeAsync(ms, false);

                // Assert
                // For purpose of test, we use a very lax epsilon, since our vectors above are not remotely as precise as the binary representation.
                deserializedChunk.Should().BeEquivalentTo(expectedChunk, opts =>
                                                          opts.Using(new VectorEquivalencyStep <Vector3>(0.0000005f))
                                                          .Using(new VectorEquivalencyStep <Vector2>(0.0000005f)));
                ms.Should().BeEof();
            }
        }
Пример #2
0
        public async Task Given_model_when_serializing_and_deserializing_should_produce_same_model(bool includeNormals)
        {
            ModelChunk chunk = GetPopulatedModelChunk(includeNormals);

            using (var ms = new MemoryStream())
            {
                await chunk.SerializeAsync(ms, false);

                ms.Position = 0;

                // Act
                var deserializedChunk = new ModelChunk();
                await deserializedChunk.DeserializeAsync(ms, false);

                // Assert
                deserializedChunk.Should().BeEquivalentTo(chunk, opts =>
                                                          opts.Using(new VectorEquivalencyStep <Vector3>(float.Epsilon))
                                                          .Using(new VectorEquivalencyStep <Vector2>(float.Epsilon)));
                ms.Should().BeEof();
            }
        }
Пример #3
0
        public void When_creating_new_instance_should_set_defaults()
        {
            var newInstance       = new ModelChunk();
            var compareToInstance = new ModelChunk
            {
                ParentFile         = null,
                FileOffset         = 0,
                Magic              = DatFile.Magics.Model,
                Id                 = 0,
                SubType            = 0,
                MaterialIndices    = new byte[0],
                Normals            = new Vector3[0],
                TextureCoordinates = new Vector2[0],
                TextureIndices     = new UvMap[0],
                VertexIndices      = new ushort[0],
                Vertices           = new Vector3[0]
            };

            // Assert
            newInstance.Should().BeEquivalentTo(compareToInstance);
        }