private static void AddPolygon(GOTempPoly poly, Vector3 normal) { Profiler.BeginSample("Add polygon"); int ind1 = AddVertex(poly.vertices[0], normal); for (int i = 1; i < poly.vertices.Count - 1; i++) { int ind2 = AddVertex(poly.vertices[i], normal); int ind3 = AddVertex(poly.vertices[i + 1], normal); bufIndices.Add(ind1); bufIndices.Add(ind2); bufIndices.Add(ind3); } Profiler.EndSample(); }
public static GOTempPoly WrapPolygon(GOTempPoly polygon, Vector3[] convertedGeometry, GOMesh terrainMesh) { bool[] positive = new bool[polygon.vertices.Count]; int positiveCount = 0; for (int i = 0; i < polygon.vertices.Count; i++) { positive [i] = ContainsPoint2D(convertedGeometry, polygon.vertices[i]); if (positive[i]) { positiveCount++; } } if (positiveCount == 0) { return(null); // Fully outside the shape } return(polygon); // Return all polygon that are partially inside the shape }
public static void ProjectFeature(GOFeature feature, GOMesh terrainMesh, float maxAngle) { Profiler.BeginSample("Project feature"); Vector3[] vertices = terrainMesh.vertices; int[] triangles = terrainMesh.triangles; GOTempPoly poly; for (int i = 0; i < triangles.Length; i += 3) { int i1 = triangles[i]; int i2 = triangles[i + 1]; int i3 = triangles[i + 2]; Vector3 v1 = feature.goTile.position + vertices [i1]; Vector3 v2 = feature.goTile.position + vertices [i2]; Vector3 v3 = feature.goTile.position + vertices [i3]; Vector3 side1 = v2 - v1; Vector3 side2 = v3 - v1; Vector3 normal = Vector3.Cross(side1, side2).normalized; //// // if( Vector3.Angle(-Vector3.forward, normal) >= maxAngle ) // continue; // poly = new GOTempPoly(v1, v2, v3); poly = GOTempPoly.WrapPolygon(poly, feature.convertedGeometry.ToArray(), terrainMesh); if (poly == null) { continue; } AddPolygon(poly, normal); } Profiler.EndSample(); }