/// Rebuilds the mesh from scratch deleting the old one if necessary. public void RebuildMesh() { if (TerrainCurve.Count < 2 || Terrain.CurveIntercrossing) { DestroyMesh(); return; } EnsureMeshComponentsExist(); ResetMeshObjectsTransforms(); // create the shape polygon List <Vector2> polygon = GetShapePolygon(); // triangulate the polygon e2dTriangulator triangulator = new e2dTriangulator(polygon.ToArray()); List <int> triangleList = triangulator.Triangulate(); triangleList.Reverse(); int[] triangles = triangleList.ToArray(); // generate 3d vertices and UVs Vector3[] vertices = new Vector3[polygon.Count]; Vector3[] normals = new Vector3[vertices.Length]; Vector2[] uvs = new Vector2[vertices.Length]; for (int i = 0; i < polygon.Count; i++) { vertices[i] = polygon[i]; normals[i] = Vector3.back; uvs[i] = GetPointFillUV(polygon[i]); } // set the result to the mesh MeshFilter filter = transform.FindChild(e2dConstants.FILL_MESH_NAME).GetComponent <MeshFilter>(); filter.sharedMesh.Clear(); filter.sharedMesh.vertices = vertices; filter.sharedMesh.normals = normals; filter.sharedMesh.uv = uvs; filter.sharedMesh.triangles = triangles; if (SomeMaterialsMissing()) { RebuildMaterial(); } }
public void RebuildMesh() { if (base.TerrainCurve.Count < 2 || base.Terrain.CurveIntercrossing) { this.DestroyMesh(); return; } base.EnsureMeshComponentsExist(); base.ResetMeshObjectsTransforms(); List <Vector2> shapePolygon = this.GetShapePolygon(); e2dTriangulator e2dTriangulator = new e2dTriangulator(shapePolygon.ToArray()); List <int> list = e2dTriangulator.Triangulate(); list.Reverse(); int[] triangles = list.ToArray(); Vector3[] array = new Vector3[shapePolygon.Count]; Vector3[] array2 = new Vector3[array.Length]; Vector2[] array3 = new Vector2[array.Length]; for (int i = 0; i < shapePolygon.Count; i++) { array[i] = shapePolygon[i]; array2[i] = Vector3.back; array3[i] = this.GetPointFillUV(shapePolygon[i]); } MeshFilter component = base.transform.Find(e2dConstants.FILL_MESH_NAME).GetComponent <MeshFilter>(); component.sharedMesh.Clear(); component.sharedMesh.vertices = array; component.sharedMesh.normals = array2; component.sharedMesh.uv = array3; component.sharedMesh.triangles = triangles; if (this.SomeMaterialsMissing()) { this.RebuildMaterial(); } }
/// Rebuilds the mesh from scratch deleting the old one if necessary. public void RebuildMesh() { if (TerrainCurve.Count < 2 || Terrain.CurveIntercrossing) { DestroyMesh(); return; } EnsureMeshComponentsExist(); ResetMeshObjectsTransforms(); // create the shape polygon List<Vector2> polygon = GetShapePolygon(); // triangulate the polygon e2dTriangulator triangulator = new e2dTriangulator(polygon.ToArray()); List<int> triangleList = triangulator.Triangulate(); triangleList.Reverse(); int[] triangles = triangleList.ToArray(); // generate 3d vertices and UVs Vector3[] vertices = new Vector3[polygon.Count]; Vector3[] normals = new Vector3[vertices.Length]; Vector2[] uvs = new Vector2[vertices.Length]; for (int i = 0; i < polygon.Count; i++) { vertices[i] = polygon[i]; normals[i] = Vector3.back; uvs[i] = GetPointFillUV(polygon[i]); } // set the result to the mesh MeshFilter filter = transform.FindChild(e2dConstants.FILL_MESH_NAME).GetComponent<MeshFilter>(); filter.sharedMesh.Clear(); filter.sharedMesh.vertices = vertices; filter.sharedMesh.normals = normals; filter.sharedMesh.uv = uvs; filter.sharedMesh.triangles = triangles; if (SomeMaterialsMissing()) RebuildMaterial(); }