private void UpdateGeometryVertices(Mesh mesh) { float[] flatVertices = chunkData.GetVertices(); UnityEngine.Vector3[] verticesAsVectors = RenderingTypeConverter.ConvertFlatFloatArrayToVector3Array(flatVertices); mesh.SetVertices(verticesAsVectors); }
public void TestThatRenderingBlocksInOnePointOneChunkIsDoneProperly() { Island islandToRender = new Island(31); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(18, 2, 18)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(19, 2, 18)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(18, 2, 19)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(19, 2, 19)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(18, 1, 18)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(19, 1, 18)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(18, 1, 19)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(19, 1, 19)); ChunkPresenter testCandidate = new ChunkPresenter(); testCandidate.PresentChunk(islandToRender, 1, 1); VisualChunkData lastRenderedChunkData = ChunkRendererMock.GetLastRenderChunkCallData(); Assert.That(lastRenderedChunkData, Is.Not.Null); Assert.That(lastRenderedChunkData.GetWorldX(), Is.EqualTo(1)); Assert.That(lastRenderedChunkData.GetWorldY(), Is.EqualTo(1)); Assert.That(lastRenderedChunkData.GetVertices().Length, Is.EqualTo(288)); Assert.That(lastRenderedChunkData.GetIndices().Length, Is.EqualTo(144)); Assert.That(lastRenderedChunkData.GetNormals().Length, Is.EqualTo(288)); Assert.That(lastRenderedChunkData.GetUvCoordinates().Length, Is.EqualTo(192)); }
public void TestThatCoveredMiddleBlockIsNotRendered() { Island islandToRender = new Island(46); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(34, 3, 18)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(35, 3, 18)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(36, 3, 18)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(34, 3, 19)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(35, 3, 19)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(36, 3, 19)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(34, 3, 20)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(35, 3, 20)); islandToRender.PlaceBlockAt(GrassyEarthBlock.GetInstance(), new BlockPosition(36, 3, 20)); islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(34, 2, 18)); islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(35, 2, 18)); islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(36, 2, 18)); islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(34, 2, 19)); islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(35, 2, 19)); islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(36, 2, 19)); islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(34, 2, 20)); islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(35, 2, 20)); islandToRender.PlaceBlockAt(EarthBlock.GetInstance(), new BlockPosition(36, 2, 20)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(34, 1, 18)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(35, 1, 18)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(36, 1, 18)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(34, 1, 19)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(35, 1, 19)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(36, 1, 19)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(34, 1, 20)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(35, 1, 20)); islandToRender.PlaceBlockAt(RockBlock.GetInstance(), new BlockPosition(36, 1, 20)); ChunkPresenter testCandidate = new ChunkPresenter(); testCandidate.PresentChunk(islandToRender, 2, 1); VisualChunkData lastRenderedChunkData = ChunkRendererMock.GetLastRenderChunkCallData(); Assert.That(lastRenderedChunkData, Is.Not.Null); Assert.That(lastRenderedChunkData.GetWorldX(), Is.EqualTo(2)); Assert.That(lastRenderedChunkData.GetWorldY(), Is.EqualTo(1)); Assert.That(lastRenderedChunkData.GetVertices().Length, Is.EqualTo(648)); Assert.That(lastRenderedChunkData.GetIndices().Length, Is.EqualTo(324)); Assert.That(lastRenderedChunkData.GetNormals().Length, Is.EqualTo(648)); Assert.That(lastRenderedChunkData.GetUvCoordinates().Length, Is.EqualTo(432)); }
public IEnumerator FlattenedVerticesAreCalculatedFromTemporaryBuffer() { VisualChunkData testCandidate = new VisualChunkData(); float[] vertices = { 0.2f, 0.3f, 0.4f, 0.3f, 0.7f, 0.1f }; float[] secondVertices = { 0.3f, 0.4f, 0.5f, 0.6f, 0.8f, 0.3f }; testCandidate.SetUpWithNumberOfBlocksInChunk(2); testCandidate.AddVerticesToTemporaryBuffer(vertices); testCandidate.AddVerticesToTemporaryBuffer(secondVertices); testCandidate.AddIndicesToTemporaryBuffer(new int[0]); testCandidate.AddIndicesToTemporaryBuffer(new int[0]); testCandidate.AddNormalsToTemporaryBuffer(new float[0]); testCandidate.AddNormalsToTemporaryBuffer(new float[0]); testCandidate.AddUvCoordinatesToTemporaryBuffer(new float[0]); testCandidate.AddUvCoordinatesToTemporaryBuffer(new float[0]); testCandidate.BuildChunkData(); float[] result = testCandidate.GetVertices(); yield return(null); Assert.That(result.Length, Is.EqualTo(12)); Assert.That(result[0], Is.EqualTo(0.2f)); Assert.That(result[1], Is.EqualTo(0.3f)); Assert.That(result[2], Is.EqualTo(0.4f)); Assert.That(result[3], Is.EqualTo(0.3f)); Assert.That(result[4], Is.EqualTo(0.7f)); Assert.That(result[5], Is.EqualTo(0.1f)); Assert.That(result[6], Is.EqualTo(0.3f)); Assert.That(result[7], Is.EqualTo(0.4f)); Assert.That(result[8], Is.EqualTo(0.5f)); Assert.That(result[9], Is.EqualTo(0.6f)); Assert.That(result[10], Is.EqualTo(0.8f)); Assert.That(result[11], Is.EqualTo(0.3f)); }