Beispiel #1
0
        /// <summary>
        /// Add a tessellated face to the mesh.
        /// </summary>
        /// <param name="perimeter">A Polygon representing the perimeter of the face.</param>
        /// <param name="voids">A collection of Polygons representing voids in the face.</param>
        /// <param name="transform">A Transform to apply to all vertices of the supplied perimeter.</param>
        /// <param name="reversed">A flag indicating whether the winding of the Polygons should be reversed.</param>
        public void AddTesselatedFace(Polygon perimeter, IList <Polygon> voids, Transform transform, bool reversed = false)
        {
            var tess = new Tess();

            AddContour(tess, perimeter, reversed);

            if (voids != null)
            {
                foreach (var p in voids)
                {
                    AddContour(tess, p, reversed);
                }
            }

            tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3);

            for (var i = 0; i < tess.ElementCount; i++)
            {
                var a = tess.Vertices[tess.Elements[i * 3]].Position.ToVector3();
                var b = tess.Vertices[tess.Elements[i * 3 + 1]].Position.ToVector3();
                var c = tess.Vertices[tess.Elements[i * 3 + 2]].Position.ToVector3();
                AddTriangle(transform.OfPoint(a), transform.OfPoint(b), transform.OfPoint(c));
            }
        }
Beispiel #2
0
    public static UnityEngine.Vector3[] ToUnityVertices(this IEnumerable <double> arr, Hypar.Geometry.Transform t)
    {
        var list  = arr.ToList();
        var count = arr.Count();
        var verts = new UnityEngine.Vector3[count / 3];
        var index = 0;

        for (var i = 0; i < count; i += 3)
        {
            var vt = t.OfPoint(new Vector3(list[i], list[i + 1], list[i + 2]));
            // var v = new UnityEngine.Vector3((float)list[i], (float)list[i+1], (float)list[i+2]);
            var v = vt.ToUnityVector3();
            verts[index] = v;
            index++;
        }
        return(verts);
    }
Beispiel #3
0
 /// <summary>
 /// Transform the polygon by the specified transform.
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public Polygon Transform(Transform t)
 {
     return(new Polygon(this.Vertices.Select(v => t.OfPoint(v)).ToList()));
 }