Skip to content

Instantly share code, notes, and snippets.

@NathoSteveo
Created November 26, 2023 09:39
Show Gist options
  • Save NathoSteveo/dfd23ef758e458491b47066257a915be to your computer and use it in GitHub Desktop.
Save NathoSteveo/dfd23ef758e458491b47066257a915be to your computer and use it in GitHub Desktop.
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