예제 #1
0
        //public static Mesh Triangulate(T.Tesselator<Vector3> tess, IEnumerable<Vector3> path, Mesh outMesh) {
        public static Mesh Triangulate(T.Tesselator <Vector3> tess,
                                       IList <Vector3> path,
                                       Mesh outMesh)
        {
            tess.BeginPolygon();
            tess.BeginContour();
            int i = 0;

            double[][] coords = new double[path.Count][];
            foreach (Vector3 v in path)
            {
                double [] tv = { v.x, v.y, v.z };
                coords[i] = tv;

                tess.AddVertex(coords[i], v);
                i++;
            }
            tess.EndContour();
            tess.EndPolygon();

            outMesh.Clear();
            outMesh.vertices  = tess.Vertice.ToArray();
            outMesh.triangles = tess.Indices.ToArray();

            return(outMesh);
        }
예제 #2
0
        /*
         * public static Mesh Triangulate(IList<Vector3> path, Mesh outMesh
         *
         *      List<Vector3> vertices = new List<Vector3>(path.Count * 2);
         *      List<int> triangles = new List<int>();
         *              Debug.Log("prev tess");
         *      T.Tesselator<int>.combineVertexD combineIdx = delegate (double[] loc, int[] inVertices, float[] weight) {
         *
         *              int idx = vertices.Count;
         *
         *              vertices.Add(new Vector3((float) loc[0], (float) loc[1], (float) loc[2]));
         *
         *              return idx;
         *      };
         *
         *      using (T.Tesselator<int> tess = new T.Tesselator<int>(combineIdx)) {
         *
         *              tess.VertexEv += delegate(T.Tesselator<int> t, int idx) {
         *                      triangles.Add(idx);
         *              };
         *
         *              tess.BeginPolygon();
         *              tess.BeginContour();
         *
         *              for (int i = 0; i < path.Count; ++i) {
         *                      int idx = vertices.Count;
         *                      Vector3 v = path[i];
         *                      vertices.Add(v);
         *              //	uv.Add(inUV[i]);
         *                      double[] coords = { v.x, v.y, v.z };
         *                      tess.AddVertex(coords, idx);
         *              }
         *
         *              tess.EndContour();
         *              tess.EndPolygon();
         *      }
         *
         *      outMesh.Clear();
         *      outMesh.vertices = vertices.ToArray();
         *      outMesh.triangles = triangles.ToArray();
         *      //outMesh.uv = uv.ToArray();
         *
         *      return outMesh;
         * }
         *
         *
         * public static Mesh Triangulate(IList<Vector3> path) {
         *      Mesh mesh = new Mesh();
         *      mesh.name = "triangulation";
         *      return Triangulate(path, mesh);
         * }
         *
         */

        public static Mesh TTriangulate(TTFTextOutline outline, Mesh outMesh)
        {
            List <Vector3> vertices  = new List <Vector3>(outline.numVertices * 2);
            List <int>     triangles = new List <int>();

            T.Tesselator <int> .combineVertexD combineIdx =
                delegate(double[] loc, int[] inVertices, float[] weight) {
                int idx = vertices.Count;
                vertices.Add(new Vector3((float)loc[0], (float)loc[1], (float)loc[2]));
                return(idx);
            };


            using (T.Tesselator <int> tess = new T.Tesselator <int>(combineIdx)) {
                //Debug.Log("SetWindingRule");
                tess.SetWindingRule(Triangulation.Glu.TessWinding.WindingPositive);

                tess.VertexEv += delegate(T.Tesselator <int> t, int idx) {
                    triangles.Add(idx);
                };



                double [][][] tcoords = new double[outline.blengthes.Count][][];



                //using () {
                tess.BeginPolygon();
//			int i=0;
                int cp = 0;
                //Debug.Log ("Tess Beg Poly");
                foreach (TTFTextOutline.Boundary lv in outline.boundaries)
                {
                    tcoords[cp] = new double[lv.Count][];
                    int ci = 0;
                    tess.BeginContour();
                    foreach (Vector3 v in lv)
                    {
                        int idx = vertices.Count;
                        vertices.Add(v);
                        //double[] coords = { v.x, v.y, v.z };
                        double [] ttcoords = { v.x, v.y, v.z };
                        tcoords[cp][ci] = ttcoords;
                        tess.AddVertex(tcoords[cp][ci], idx);
                        //tess.AddVertex(coords, idx);
                        //i++;
                        ci++;
                    }

                    tess.EndContour();
                    cp++;
                }
                //Debug.Log ("Tess End Poly");
                tess.EndPolygon();

                //for (int ix=0;ix<tcoords.Length;ix++) {
                //	tcoords[ix]=null;
                //}

                //}
            }


            outMesh.Clear();
            outMesh.vertices  = vertices.ToArray();
            outMesh.triangles = triangles.ToArray();
            //outMesh.uv = uv.ToArray();

            return(outMesh);
        }