Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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();
            }
        }
Exemple #3
0
        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++;
            }
        }
Exemple #4
0
 public BoxOutline(BoundingBox boundingBox)
 {
     this.boundingBox = boundingBox;
     if (boxBuffer == null)
     {
         boxBuffer = new DynamicVertexIndexBuffer <VertexPositionColor>();
         var axis = new[] { Vector3.Right, Vector3.Up, Vector3.Backward };
         for (int i = 0; i < 12; i++)
         {
             var color     = Color.White;
             var mainAxis  = axis[i % 3];
             var otherAxis = axis.Where(x => x != mainAxis).ToArray();
             var offset    = Vector3.Zero;
             if (i / 3 % 2 == 1)
             {
                 offset += otherAxis[0];
             }
             if (i / 3 / 2 == 1)
             {
                 offset += otherAxis[1];
             }
             boxBuffer.AddVertices(new List <VertexPositionColor>()
             {
                 new VertexPositionColor(offset, color)
             });
             boxBuffer.AddVertices(new List <VertexPositionColor>()
             {
                 new VertexPositionColor(offset + mainAxis, color)
             });
             boxBuffer.AddIndices(new List <int>()
             {
                 i * 2, i * 2 + 1
             });
         }
     }
     if (emptyBuffer == null)
     {
         emptyBuffer = new DynamicVertexIndexBuffer <VertexPositionColor>();
         var axis = new[] { Vector3.Right, Vector3.Up, Vector3.Backward };
         for (int i = 0; i < axis.Length; i++)
         {
             var color = Color.White;
             emptyBuffer.AddVertices(new List <VertexPositionColor>()
             {
                 new VertexPositionColor(-axis[i], color)
             });
             emptyBuffer.AddVertices(new List <VertexPositionColor>()
             {
                 new VertexPositionColor(axis[i], color)
             });
             emptyBuffer.AddIndices(new List <int>()
             {
                 i * 2, i * 2 + 1
             });
         }
     }
 }
Exemple #5
0
 public FaceMesh()
 {
     buffer = new DynamicVertexIndexBuffer <VertexPositionNormalTexture>();
 }
Exemple #6
0
 public LineMesh()
 {
     buffer = new DynamicVertexIndexBuffer <VertexPositionColor>();
 }
Exemple #7
0
 public PointMesh()
 {
     buffer = new DynamicVertexIndexBuffer <VertexPositionColorTexture>();
 }