@@ -395,6 +395,7 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
395395
396396 if (new_surface.attribute_data .size ()) {
397397 s->attribute_buffer = RD::get_singleton ()->vertex_buffer_create (new_surface.attribute_data .size (), new_surface.attribute_data );
398+ s->attribute_buffer_size = new_surface.attribute_data .size ();
398399 }
399400 if (new_surface.skin_data .size ()) {
400401 s->skin_buffer = RD::get_singleton ()->vertex_buffer_create (new_surface.skin_data .size (), new_surface.skin_data , as_storage_flag);
@@ -411,6 +412,7 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
411412 bool is_index_16 = new_surface.vertex_count <= 65536 && new_surface.vertex_count > 0 ;
412413
413414 s->index_buffer = RD::get_singleton ()->index_buffer_create (new_surface.index_count , is_index_16 ? RD::INDEX_BUFFER_FORMAT_UINT16 : RD::INDEX_BUFFER_FORMAT_UINT32, new_surface.index_data , false );
415+ s->index_buffer_size = new_surface.index_data .size ();
414416 s->index_count = new_surface.index_count ;
415417 s->index_array = RD::get_singleton ()->index_array_create (s->index_buffer , 0 , s->index_count );
416418 if (new_surface.lods .size ()) {
@@ -420,6 +422,7 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
420422 for (int i = 0 ; i < new_surface.lods .size (); i++) {
421423 uint32_t indices = new_surface.lods [i].index_data .size () / (is_index_16 ? 2 : 4 );
422424 s->lods [i].index_buffer = RD::get_singleton ()->index_buffer_create (indices, is_index_16 ? RD::INDEX_BUFFER_FORMAT_UINT16 : RD::INDEX_BUFFER_FORMAT_UINT32, new_surface.lods [i].index_data );
425+ s->lods [i].index_buffer_size = new_surface.lods [i].index_data .size ();
423426 s->lods [i].index_array = RD::get_singleton ()->index_array_create (s->lods [i].index_buffer , 0 , indices);
424427 s->lods [i].edge_length = new_surface.lods [i].edge_length ;
425428 s->lods [i].index_count = indices;
@@ -437,6 +440,7 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
437440
438441 if (mesh->blend_shape_count > 0 ) {
439442 s->blend_shape_buffer = RD::get_singleton ()->storage_buffer_create (new_surface.blend_shape_data .size (), new_surface.blend_shape_data );
443+ s->blend_shape_buffer_size = new_surface.blend_shape_data .size ();
440444 }
441445
442446 if (use_as_storage) {
@@ -917,6 +921,35 @@ void MeshStorage::mesh_surface_remove(RID p_mesh, int p_surface) {
917921 }
918922}
919923
924+ void MeshStorage::mesh_debug_usage (List<RS::MeshInfo> *r_info) {
925+ for (const RID &mesh_rid : mesh_owner.get_owned_list ()) {
926+ Mesh *mesh = mesh_owner.get_or_null (mesh_rid);
927+ if (!mesh) {
928+ continue ;
929+ }
930+ RS::MeshInfo mesh_info;
931+ mesh_info.mesh = mesh_rid;
932+ mesh_info.path = mesh->path ;
933+
934+ for (uint32_t surface_index = 0 ; surface_index < mesh->surface_count ; surface_index++) {
935+ MeshStorage::Mesh::Surface *surface = mesh->surfaces [surface_index];
936+
937+ mesh_info.vertex_buffer_size += surface->vertex_buffer_size ;
938+ mesh_info.attribute_buffer_size += surface->attribute_buffer_size ;
939+ mesh_info.skin_buffer_size += surface->skin_buffer_size ;
940+ mesh_info.index_buffer_size += surface->index_buffer_size ;
941+ mesh_info.blend_shape_buffer_size += surface->blend_shape_buffer_size ;
942+ mesh_info.vertex_count += surface->vertex_count ;
943+
944+ for (uint32_t lod_index = 0 ; lod_index < surface->lod_count ; lod_index++) {
945+ mesh_info.lod_index_buffers_size += surface->lods [lod_index].index_buffer_size ;
946+ }
947+ }
948+
949+ r_info->push_back (mesh_info);
950+ }
951+ }
952+
920953bool MeshStorage::mesh_needs_instance (RID p_mesh, bool p_has_skeleton) {
921954 Mesh *mesh = mesh_owner.get_or_null (p_mesh);
922955 ERR_FAIL_NULL_V (mesh, false );
0 commit comments