Exemplo n.º 1
0
		public static Mesh TriangulateFaces(IVertexSource vertexSource)
		{
			vertexSource.rewind();
			CachedTesselator teselatedSource = new CachedTesselator();
			Graphics2DOpenGL.SendShapeToTesselator(teselatedSource, vertexSource);

			Mesh extrudedVertexSource = new Mesh();

			int numIndicies = teselatedSource.IndicesCache.Count;

			// build the top first so it will render first when we are translucent
			for (int i = 0; i < numIndicies; i += 3)
			{
				Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position;
				Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position;
				Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position;
				if (v0 == v1 || v1 == v2 || v2 == v0)
				{
					continue;
				}

				Vertex topVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, 0));
				Vertex topVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, 0));
				Vertex topVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, 0));

				extrudedVertexSource.CreateFace(new Vertex[] { topVertex0, topVertex1, topVertex2 });
			}

			return extrudedVertexSource;
		}
Exemplo n.º 2
0
        public static Mesh Extrude(IVertexSource vertexSource, double zHeight)
        {
            vertexSource.rewind();
            CachedTesselator teselatedSource = new CachedTesselator();

            Graphics2DOpenGL.SendShapeToTesselator(teselatedSource, vertexSource);

            Mesh extrudedVertexSource = new Mesh();

            int numIndicies = teselatedSource.IndicesCache.Count;

            // build the top first so it will render first when we are translucent
            for (int i = 0; i < numIndicies; i += 3)
            {
                Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position;
                Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position;
                Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position;
                if (v0 == v1 || v1 == v2 || v2 == v0)
                {
                    continue;
                }

                Vertex topVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, zHeight));
                Vertex topVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, zHeight));
                Vertex topVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, zHeight));

                extrudedVertexSource.CreateFace(new Vertex[] { topVertex0, topVertex1, topVertex2 });
            }

            // then the outside edge
            for (int i = 0; i < numIndicies; i += 3)
            {
                Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position;
                Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position;
                Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position;
                if (v0 == v1 || v1 == v2 || v2 == v0)
                {
                    continue;
                }

                Vertex bottomVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, 0));
                Vertex bottomVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, 0));
                Vertex bottomVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, 0));

                Vertex topVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, zHeight));
                Vertex topVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, zHeight));
                Vertex topVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, zHeight));

                if (teselatedSource.IndicesCache[i + 0].IsEdge)
                {
                    extrudedVertexSource.CreateFace(new Vertex[] { bottomVertex0, bottomVertex1, topVertex1, topVertex0 });
                }

                if (teselatedSource.IndicesCache[i + 1].IsEdge)
                {
                    extrudedVertexSource.CreateFace(new Vertex[] { bottomVertex1, bottomVertex2, topVertex2, topVertex1 });
                }

                if (teselatedSource.IndicesCache[i + 2].IsEdge)
                {
                    extrudedVertexSource.CreateFace(new Vertex[] { bottomVertex2, bottomVertex0, topVertex0, topVertex2 });
                }
            }

            // then the bottom
            for (int i = 0; i < numIndicies; i += 3)
            {
                Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position;
                Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position;
                Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position;
                if (v0 == v1 || v1 == v2 || v2 == v0)
                {
                    continue;
                }

                Vertex bottomVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, 0));
                Vertex bottomVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, 0));
                Vertex bottomVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, 0));

                extrudedVertexSource.CreateFace(new Vertex[] { bottomVertex2, bottomVertex1, bottomVertex0 });
            }

            return(extrudedVertexSource);
        }