void Start() { ////to get a nice and clear mesh without too many points close to each other //make a mesh which has a high autoweld threshold. Too high to be a visual mesh - it will leave gaps //work out what edges are on the outside MeshFilter meshFilter = GetComponent <MeshFilter>(); Mesh mesh = meshFilter.mesh; autoWeldedMesh = new Mesh(); autoWeldedMesh = mesh; autoWeldedMesh = AutoWeld.AutoWeldFunction(autoWeldedMesh, 1, 2000); // meshFilter.mesh = autoWeldedMesh; // outline = BuildManifoldEdges(meshFilter.mesh); //use the EdgeHelpers static class to work out the boundary could also be called in BushesForCell? boundaryPath = EdgeHelpers.GetEdges(autoWeldedMesh.triangles).FindBoundary().SortEdges(); //use this new glued emsh to create a ring of edge points //fills pointsOnEdge CreateListOfEdgePoints(autoWeldedMesh); //PathOnEdge(boundaryPath); }
Mesh WeldedMesh(List <GameObject> cellsToWeld) { //combine meshes MeshFilter[] meshFilters = new MeshFilter[cellsToWeld.Count]; for (int a = 0; a < cellsToWeld.Count; a++) { meshFilters[a] = cellsToWeld[a].GetComponent <MeshFilter>(); } CombineInstance[] combine = new CombineInstance[meshFilters.Length]; int i = 0; while (i < meshFilters.Length) { combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; meshFilters[i].gameObject.SetActive(false); i++; } Mesh combinedMesh = new Mesh(); combinedMesh.CombineMeshes(combine); //now weld vertices together Mesh weldedMesh = AutoWeld.AutoWeldFunction(combinedMesh, .01f, 100); //check for vertices with no triangles? Vector3[] vertices = weldedMesh.vertices; int[] triangles = weldedMesh.triangles; for (int a = 0; a < vertices.Length; a++) { int matches = 0; for (int b = 0; b < triangles.Length; b++) { if (triangles[b] == a) { matches++; } } if (matches == 0) { GameObject c = GameObject.CreatePrimitive(PrimitiveType.Cube); c.transform.position = vertices[a]; c.name = "No Tris"; } } return(weldedMesh); }
IEnumerator AddToGo(GameObject go) { yield return(new WaitForEndOfFrame()); var renderer = go.GetComponent <MeshRenderer>(); if (!receiveShadows) { renderer.receiveShadows = false; } if (!castShadows) { renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } if (addAutoWeld) { AutoWeld aw = go.AddComponent <AutoWeld>(); aw.addFindEdges = true; } //realign before adding mesh collider if (reAlignCell) { Realign(); } if (addMeshCollider) { go.AddComponent <MeshCollider>(); } yield break; }