Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/editmesh.c
| Show All 17 Lines | |||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup bke | * \ingroup bke | ||||
| */ | */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_key_types.h" | |||||
| #include "DNA_listBase.h" | #include "DNA_listBase.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_listbase.h" | |||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_cdderivedmesh.h" | #include "BKE_cdderivedmesh.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_mesh_iterators.h" | #include "BKE_mesh_iterators.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | # ifndef NDEBUG | ||||
| if (((Mesh *)ob->data)->edit_mesh) { | if (((Mesh *)ob->data)->edit_mesh) { | ||||
| BLI_assert(((Mesh *)ob->data)->edit_mesh->ob == ob); | BLI_assert(((Mesh *)ob->data)->edit_mesh->ob == ob); | ||||
| } | } | ||||
| # endif | # endif | ||||
| #endif | #endif | ||||
| return ((Mesh *)ob->data)->edit_mesh; | return ((Mesh *)ob->data)->edit_mesh; | ||||
| } | } | ||||
| /** | |||||
| * \warning This can invalidate the #Mesh runtime cache of other objects (for linked duplicates). | |||||
| * Most callers should run #DEG_id_tag_update on \a ob->data, see: T46738, T46913 | |||||
| */ | |||||
| void BKE_editmesh_load_ex(struct Main *bmain, BMEditMesh *em, bool free_data) | |||||
| { | |||||
| Object *ob = em->ob; | |||||
| Mesh *me = ob->data; | |||||
| BLI_assert(me->edit_mesh == em); | |||||
| BMesh *bm = me->edit_mesh->bm; | |||||
| /* Workaround for T42360, 'ob->shapenr' should be 1 in this case. | |||||
| * however this isn't synchronized between objects at the moment. */ | |||||
| if (UNLIKELY((ob->shapenr == 0) && (me->key && !BLI_listbase_is_empty(&me->key->block)))) { | |||||
| bm->shapenr = 1; | |||||
| } | |||||
| BM_mesh_bm_to_me(bmain, | |||||
| bm, | |||||
| me, | |||||
| (&(struct BMeshToMeshParams){ | |||||
| .calc_object_remap = true, | |||||
| .update_shapekey_indices = !free_data, | |||||
| })); | |||||
| /* Free derived mesh. usually this would happen through depsgraph but there | |||||
| * are exceptions like file save that will not cause this, and we want to | |||||
| * avoid ending up with an invalid derived mesh then. | |||||
| * | |||||
| * Do it for all objects which shares the same mesh datablock, since their | |||||
| * derived meshes might also be referencing data which was just freed, | |||||
| * | |||||
| * Annoying enough, but currently seems most efficient way to avoid access | |||||
| * of freed data on scene update, especially in cases when there are dependency | |||||
| * cycles. | |||||
| */ | |||||
| #if 0 | |||||
| for (Object *other_object = bmain->objects.first; other_object != NULL; | |||||
| other_object = other_object->id.next) { | |||||
| if (other_object->data == ob->data) { | |||||
| BKE_object_free_derived_caches(other_object); | |||||
| } | |||||
| } | |||||
| #endif | |||||
| } | |||||
| void BKE_editmesh_load(struct Main *bmain, BMEditMesh *em) | |||||
| { | |||||
| BKE_editmesh_load_ex(bmain, em, true); | |||||
| } | |||||
| static void editmesh_tessface_calc_intern(BMEditMesh *em) | static void editmesh_tessface_calc_intern(BMEditMesh *em) | ||||
| { | { | ||||
| /* allocating space before calculating the tessellation */ | /* allocating space before calculating the tessellation */ | ||||
| BMesh *bm = em->bm; | BMesh *bm = em->bm; | ||||
| /* This assumes all faces can be scan-filled, which isn't always true, | /* This assumes all faces can be scan-filled, which isn't always true, | ||||
| * worst case we over allocate a little which is acceptable. */ | * worst case we over allocate a little which is acceptable. */ | ||||
| ▲ Show 20 Lines • Show All 172 Lines • Show Last 20 Lines | |||||