Created
November 26, 2023 09:39
-
-
Save NathoSteveo/dfd23ef758e458491b47066257a915be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private MeshFilter filter; | |
public void CombineGridPointMeshes() | |
{ | |
combineInstances.Clear(); | |
HashSet<MeshFilter> meshes = new HashSet<MeshFilter>(gridPointMeshes); | |
foreach (MeshFilter filter in meshes) | |
{ | |
if (filter.sharedMesh == null) continue; | |
CombineInstance combineInstance = new() | |
{ | |
mesh = filter.sharedMesh, | |
transform = transform.worldToLocalMatrix * filter.transform.localToWorldMatrix | |
}; | |
combineInstances.Add(combineInstance); | |
} | |
//[ COMBINE MESHES ] | |
Mesh combinedMesh = new(); | |
combinedMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; | |
combinedMesh.CombineMeshes(combineInstances.ToArray()); | |
filter = chunkMesh.GetComponent<MeshFilter>(); | |
filter.sharedMesh = combinedMesh; | |
filter.gameObject.isStatic = true; | |
combinedMesh.name = type + "_" + worldPos.x + "_" + worldPos.y + "_" + worldPos.z + "_" + "MESH"; | |
//chunkMeshCollider.sharedMesh = combinedMesh; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment