Changeset View
Standalone View
source/blender/blenkernel/intern/mesh.c
| Show First 20 Lines • Show All 521 Lines • ▼ Show 20 Lines | void BKE_mesh_init(Mesh *me) | ||||
| CustomData_reset(&me->edata); | CustomData_reset(&me->edata); | ||||
| CustomData_reset(&me->fdata); | CustomData_reset(&me->fdata); | ||||
| CustomData_reset(&me->pdata); | CustomData_reset(&me->pdata); | ||||
| CustomData_reset(&me->ldata); | CustomData_reset(&me->ldata); | ||||
| BKE_mesh_runtime_reset(me); | BKE_mesh_runtime_reset(me); | ||||
| } | } | ||||
| void BKE_mesh_clear_geometry(Mesh *mesh) | |||||
| { | |||||
| /* Materials should be retained. */ | |||||
| struct Material **mesh_material_slots = mesh->mat; | |||||
| mesh->mat = NULL; | |||||
| BKE_mesh_free(mesh); | |||||
| mesh->mat = mesh_material_slots; | |||||
brecht: Don't do this kind of hacking, instead create a shared function that both `BKE_mesh_free` and… | |||||
sybrenAuthorUnsubmitted Done Inline ActionsDone, although I'm not really happy with the name mesh_free_most_data(). It does what it says, but it's not really descriptive either. I could name it mesh_free_data_except_materials_and_shapekeys(), but that's opening the door to code rot (add something to the mesh structure but not this function and the name has already gone bad). sybren: Done, although I'm not really happy with the name `mesh_free_most_data()`. It does what it says… | |||||
brechtUnsubmitted Done Inline ActionsYou could make BKE_mesh_free just call BKE_mesh_clear_geometry, the overhead will be negligible. brecht: You could make `BKE_mesh_free` just call `BKE_mesh_clear_geometry`, the overhead will be… | |||||
| mesh->totvert = 0; | |||||
| mesh->totedge = 0; | |||||
| mesh->totface = 0; | |||||
| mesh->totloop = 0; | |||||
| mesh->totpoly = 0; | |||||
| mesh->act_face = -1; | |||||
| mesh->totselect = 0; | |||||
| BKE_mesh_update_customdata_pointers(mesh, false); | |||||
| /* we could have the user do this but if they forget blender can easy crash | |||||
| * since the references arrays for the objects derived meshes are now invalid */ | |||||
| DEG_id_tag_update(&mesh->id, ID_RECALC_GEOMETRY); | |||||
brechtUnsubmitted Done Inline ActionsMost BKE functions don't have depsgraph tagging, better to put it next to the notifier I think since these usually go together. brecht: Most BKE functions don't have depsgraph tagging, better to put it next to the notifier I think… | |||||
| } | |||||
brechtUnsubmitted Not Done Inline ActionsThis function misses freeing shape keys. brecht: This function misses freeing shape keys. | |||||
sybrenAuthorUnsubmitted Done Inline ActionsI had a little discussion with @Sergey Sharybin (sergey) and he pointed out that freeing the shapekeys requires tagging the depsgraph for rebuilding relations. Since this is an expensive operation, I'd rather not have it here. The use case for this function is to make it cheaper for Python code to replace one generated mesh with another. I don't think it'll be common to have shape keys in this scenario. I'd rather keep such an expensive operation outside this function, and let people deal with shape keys explicitly when necessary. I added a comment to the code to indicate that shapekeys aren't freed. I also added this to the RNA function description (and also included that materials aren't freed either). sybren: I had a little discussion with @Sergey and he pointed out that freeing the shapekeys requires… | |||||
| Mesh *BKE_mesh_add(Main *bmain, const char *name) | Mesh *BKE_mesh_add(Main *bmain, const char *name) | ||||
| { | { | ||||
| Mesh *me; | Mesh *me; | ||||
| me = BKE_libblock_alloc(bmain, ID_ME, name, 0); | me = BKE_libblock_alloc(bmain, ID_ME, name, 0); | ||||
| BKE_mesh_init(me); | BKE_mesh_init(me); | ||||
| ▲ Show 20 Lines • Show All 1,498 Lines • Show Last 20 Lines | |||||
Don't do this kind of hacking, instead create a shared function that both BKE_mesh_free and this can call.
Otherwise it's too easy to make a change in BKE_mesh_free that breaks BKE_mesh_clear_geometry. It also helps a little to put these functions next to each other.