public bool TessPolygon(float[] vertex2dCoords, int[] contourEndPoints) { //internal tess the polygon int ncoords = vertex2dCoords.Length / 2; tessListener.ResetAndLoadInputVertexList(ncoords); if (ncoords == 0) { return(false); } //----------------------- //this support sub contour in the same array of vertex2dCoords tess.BeginPolygon(); if (contourEndPoints == null) { //only 1 contour int beginAt = 0; int thisContourEndAt = vertex2dCoords.Length / 2; tess.BeginContour(); for (int i = beginAt; i < thisContourEndAt; ++i) { tess.AddVertex( vertex2dCoords[i << 1], //*2 vertex2dCoords[(i << 1) + 1], 0, i); //*2+1 } beginAt = thisContourEndAt + 1; tess.EndContour(); } else { //may have more than 1 contour int nContourCount = contourEndPoints.Length; int beginAt = 0; for (int m = 0; m < nContourCount; ++m) { int thisContourEndAt = (contourEndPoints[m] + 1) / 2; tess.BeginContour(); for (int i = beginAt; i < thisContourEndAt; ++i) { tess.AddVertex( vertex2dCoords[i << 1], //*2 vertex2dCoords[(i << 1) + 1], 0, i); //*2+1 } beginAt = thisContourEndAt + 1; tess.EndContour(); } } tess.EndPolygon(); //----------------------- return(true); }
public bool TessPolygon(IPolygonVerticeReader polygonReader, Tesselator.ITessListener listner) { //internal tess the polygon polygonReader.Reset(); listner.BeginRead(); // State state = polygonReader.CurrentState; int current_vertex = 0; float cur_x = 0; float cur_y = 0; for (; ;) { switch (state) { case State.BeginPolygon: _tess.BeginPolygon(); break; case State.BeginContour: _tess.BeginContour(); break; case State.Vertex: _tess.AddVertex(cur_x, cur_y, current_vertex); current_vertex++; break; case State.EndContour: _tess.EndContour(); break; case State.EndPolygon: _tess.EndPolygon(); goto EXIT_LOOP; } state = polygonReader.ReadNext(out cur_x, out cur_y); } EXIT_LOOP: return(true); }
public void EndContour() { m_Tesselator.EndContour(); }