public void AddContour(ContourVertex[] vertices, ContourOrientation forceOrientation) { if (_mesh == null) { _mesh = new Mesh(); } bool flag = false; if (forceOrientation != 0) { float num = SignedArea(vertices); flag = ((forceOrientation == ContourOrientation.Clockwise && num < 0f) || (forceOrientation == ContourOrientation.CounterClockwise && num > 0f)); } MeshUtils.Edge edge = null; for (int i = 0; i < vertices.Length; i++) { if (edge == null) { edge = _mesh.MakeEdge(); Mesh mesh = _mesh; MeshUtils.Edge edge2 = edge; mesh.Splice(edge2, edge2._Sym); } else { _mesh.SplitEdge(edge); edge = edge._Lnext; } int num2 = flag ? (vertices.Length - 1 - i) : i; edge._Org._coords = vertices[num2].Position; edge._Org._data = vertices[num2].Data; edge._winding = 1; edge._Sym._winding = -1; } }
/// <summary> /// Adds a closed contour to be tessellated. /// </summary> /// <param name="vertices"> Vertices of the contour. </param> /// <param name="forceOrientation"> /// Orientation of the contour. /// <see cref="ContourOrientation.Original"/> keeps the orientation of the input vertices. /// <see cref="ContourOrientation.Clockwise"/> and <see cref="ContourOrientation.CounterClockwise"/> /// force the vertices to have a specified orientation. /// </param> public void AddContour(IList <Vector3> vertices, ContourOrientation forceOrientation = ContourOrientation.Original) { var contour = new ContourVertex[vertices.Count]; for (int i = 0; i < vertices.Count; i++) { Vector3 vertex = vertices[i]; contour[i].Position = new Vec3(vertex.x, vertex.y, vertex.z); } tess.AddContour(contour, forceOrientation); }
public void AddContour(ContourVertex[] vertices, ContourOrientation forceOrientation) { if (_mesh == null) { _mesh = Mesh.Create(); _mesh.Init(); } bool reverse = false; if (forceOrientation != ContourOrientation.Original) { var area = SignedArea(vertices); reverse = (forceOrientation == ContourOrientation.Clockwise && area < 0.0f) || (forceOrientation == ContourOrientation.CounterClockwise && area > 0.0f); } MeshUtils.Edge e = null; for (int i = 0; i < vertices.Length; ++i) { if (e == null) { e = _mesh.MakeEdge(); _mesh.Splice(e, e._Sym); } else { // Create a new vertex and edge which immediately follow e // in the ordering around the left face. _mesh.SplitEdge(e); e = e._Lnext; } int index = reverse ? vertices.Length - 1 - i : i; // The new vertex is now e._Org. e._Org._coords = vertices[index].Position; e._Org._data = vertices[index].Data; // The winding of an edge says how the winding number changes as we // cross from the edge's right face to its left face. We add the // vertices in such an order that a CCW contour will add +1 to // the winding number of the region inside the contour. e._winding = 1; e._Sym._winding = -1; } }
public static PolygonSet LoadDat(Stream resourceStream) { var points = new List <PolygonPoint>(); var polys = new PolygonSet(); int lineNum = 0; string line; Color currentColor = Color.White; ContourOrientation currentOrientation = ContourOrientation.Original; using (var stream = new StreamReader(resourceStream)) { while ((line = stream.ReadLine()) != null) { ++lineNum; line = line.Trim(); if (string.IsNullOrEmpty(line)) { if (points.Count > 0) { var p = new Polygon(points) { Orientation = currentOrientation }; currentOrientation = ContourOrientation.Original; polys.Add(p); points.Clear(); } continue; } if (line.StartsWith("//") || line.StartsWith("#") || line.StartsWith(";")) { continue; } if (line.StartsWith("force", true, CultureInfo.InvariantCulture)) { var force = line.Split(new[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (force.Length == 2) { if (string.Compare(force[1], "cw", true) == 0) { currentOrientation = ContourOrientation.Clockwise; } if (string.Compare(force[1], "ccw", true) == 0) { currentOrientation = ContourOrientation.CounterClockwise; } } } else if (line.StartsWith("color", true, CultureInfo.InvariantCulture)) { var rgba = line.Split(new[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries); int r = 255, g = 255, b = 255, a = 255; if (rgba != null) { if (rgba.Length == 4 && int.TryParse(rgba[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out r) && int.TryParse(rgba[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out g) && int.TryParse(rgba[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out b)) { currentColor = Color.FromArgb(r, g, b); polys.HasColors = true; } else if (rgba.Length == 5 && int.TryParse(rgba[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out r) && int.TryParse(rgba[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out g) && int.TryParse(rgba[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out b) && int.TryParse(rgba[4], NumberStyles.Integer, CultureInfo.InvariantCulture, out a)) { currentColor = Color.FromArgb(a, r, g, b); polys.HasColors = true; } } } else { float x = 0, y = 0, z = 0; var xyz = line.Split(new[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (xyz != null) { if (xyz.Length >= 1) { float.TryParse(xyz[0], NumberStyles.Float, CultureInfo.InvariantCulture, out x); } if (xyz.Length >= 2) { float.TryParse(xyz[1], NumberStyles.Float, CultureInfo.InvariantCulture, out y); } if (xyz.Length >= 3) { float.TryParse(xyz[2], NumberStyles.Float, CultureInfo.InvariantCulture, out z); } points.Add(new PolygonPoint { X = x, Y = y, Z = z, Color = currentColor }); } else { throw new InvalidDataException("Invalid input data"); } } } if (points.Count > 0) { Polygon p = new Polygon(points) { Orientation = currentOrientation }; polys.Add(p); } } return(polys); }
/// <summary> /// Adds a closed contour to be tessellated. /// </summary> /// <param name="vertices"> Vertices of the contour. </param> /// <param name="forceOrientation"> /// Orientation of the contour. /// <see cref="ContourOrientation.Original"/> keeps the orientation of the input vertices. /// <see cref="ContourOrientation.Clockwise"/> and <see cref="ContourOrientation.CounterClockwise"/> /// force the vertices to have a specified orientation. /// </param> public void AddContour(IList <ContourVertex> vertices, ContourOrientation forceOrientation = ContourOrientation.Original) { AddContourInternal(vertices, forceOrientation); }
public void AddContour(ContourVertex[] vertices, ContourOrientation forceOrientation) { AddContour(vertices, vertices.Length, ContourOrientation.Original); }
public void AddContour(ContourVertex[] vertices, ContourOrientation forceOrientation) { if (_mesh == null) { _mesh = new Mesh(); } bool reverse = false; if (forceOrientation != ContourOrientation.Original) { float area = SignedArea(vertices); reverse = (forceOrientation == ContourOrientation.Clockwise && area < 0.0f) || (forceOrientation == ContourOrientation.CounterClockwise && area > 0.0f); } MeshUtils.Edge e = null; for (int i = 0; i < vertices.Length; ++i) { if (e == null) { e = _mesh.MakeEdge(); _mesh.Splice(e, e._Sym); } else { // Create a new vertex and edge which immediately follow e // in the ordering around the left face. _mesh.SplitEdge(e); e = e._Lnext; } int index = reverse ? vertices.Length - 1 - i : i; // The new vertex is now e._Org. e._Org._coords = vertices[index].Position; e._Org._data = vertices[index].Data; // The winding of an edge says how the winding number changes as we // cross from the edge's right face to its left face. We add the // vertices in such an order that a CCW contour will add +1 to // the winding number of the region inside the contour. e._winding = 1; e._Sym._winding = -1; } }