public void RecalculateEverything() { if (buffer != null) { buffer.Dispose(); } buffer = new DynamicVertexIndexBuffer <VertexPositionColor>(); Dictionary <VertexData, int> verticesAdded = new Dictionary <VertexData, int>(); foreach (var item in items) { foreach (var v in item) { if (!verticesAdded.ContainsKey(v)) { buffer.AddVertices(new List <VertexPositionColor>() { new VertexPositionColor(v.position, v.color) }); verticesAdded.Add(v, verticesAdded.Count); } } var indices = item.Select(x => verticesAdded[x]).ToList(); buffer.AddIndices(indices); } }
public void RecalculateEverything() { if (buffer != null) { buffer.Dispose(); } buffer = new DynamicVertexIndexBuffer <VertexPositionNormalTexture>(); int verticesAdded = 0; foreach (var item in items) { var normal = CalculateNormal(item.Select(x => x.position).ToArray()); var vertices = item.Select(x => new VertexPositionNormalTexture(x.position, normal, new Vector2(0, 0))).ToList(); var indices = new List <int>(); for (int i = 0; i < item.Length - 2; i++) { indices.Add(verticesAdded); indices.Add(verticesAdded + i + 1); indices.Add(verticesAdded + i + 2); } buffer.AddVertices(vertices); buffer.AddIndices(indices); verticesAdded += vertices.Count(); } }
public void RecalculateEverything() { if (buffer != null) { buffer.Dispose(); } buffer = new DynamicVertexIndexBuffer <VertexPositionColorTexture>(); int verticesAdded = 0; foreach (var item in items) { var vertices = new List <VertexPositionColorTexture>(); vertices.Add(new VertexPositionColorTexture(item.position, item.color, new Vector2(0, 0))); vertices.Add(new VertexPositionColorTexture(item.position, item.color, new Vector2(1, 0))); vertices.Add(new VertexPositionColorTexture(item.position, item.color, new Vector2(1, 1))); vertices.Add(new VertexPositionColorTexture(item.position, item.color, new Vector2(0, 1))); var indices = new List <int>(); indices.Add(verticesAdded * 4); indices.Add(verticesAdded * 4 + 1); indices.Add(verticesAdded * 4 + 2); indices.Add(verticesAdded * 4); indices.Add(verticesAdded * 4 + 2); indices.Add(verticesAdded * 4 + 3); buffer.AddVertices(vertices); buffer.AddIndices(indices); verticesAdded++; } }