Skip to content

Commit ed06faf

Browse files
committed
remove empty mmi
1 parent 583d889 commit ed06faf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/terrain_3d_instancer.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void Terrain3DInstancer::_update_vertex_spacing(const real_t p_vertex_spacing) {
6666
region->set_vertex_spacing(p_vertex_spacing);
6767
region->set_modified(true);
6868
}
69+
destroy();
6970
_update_mmis();
7071
}
7172

@@ -564,6 +565,15 @@ void Terrain3DInstancer::remove_instances(const Vector3 &p_global_position, cons
564565
triple[2] = true;
565566
cells_dict[cell] = triple;
566567
} else {
568+
// free the mmi for this cell
569+
// _mmi_nodes{region_loc} -> mesh{v2i(mesh_id,lod)} -> cell{v2i} -> MultiMeshInstance3D
570+
Dictionary region_mmis = _mmi_nodes[region_loc];
571+
Dictionary mesh_mmis = region_mmis[Vector2i(m, 0)];
572+
if (mesh_mmis.has(cell)) {
573+
MultiMeshInstance3D *mmi = cast_to<MultiMeshInstance3D>(mesh_mmis[cell]);
574+
remove_from_tree(mmi);
575+
memdelete_safely(mmi);
576+
}
567577
cells_dict.erase(cell);
568578
}
569579
}

0 commit comments

Comments
 (0)