diff options
-rw-r--r-- | source/blender/blenkernel/BKE_mesh.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 46 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 4 | ||||
-rw-r--r-- | source/blender/bmesh/operators/mesh_conv.c | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 18 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_mesh_utils.h | 4 |
9 files changed, 50 insertions, 36 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 4f16f334870..8db9d3f5447 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -91,7 +91,7 @@ void unlink_mesh(struct Mesh *me); void free_mesh(struct Mesh *me, int unlink); struct Mesh *add_mesh(const char *name); struct Mesh *copy_mesh(struct Mesh *me); -void mesh_update_customdata_pointers(struct Mesh *me); +void mesh_update_customdata_pointers(struct Mesh *me, const short do_ensure_tess_cd); void make_local_mesh(struct Mesh *me); void boundbox_mesh(struct Mesh *me, float *loc, float *size); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 89440779eb9..628c07f7a6d 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -424,11 +424,11 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob) } /* yes, must be before _and_ after tesselate */ - mesh_update_customdata_pointers(&tmp); + mesh_update_customdata_pointers(&tmp, TRUE); tmp.totface = mesh_recalcTesselation(&tmp.fdata, &tmp.ldata, &tmp.pdata, tmp.mvert, tmp.totface, tmp.totloop, tmp.totpoly); - mesh_update_customdata_pointers(&tmp); + mesh_update_customdata_pointers(&tmp, TRUE); CustomData_free(&me->vdata, me->totvert); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index a3a75f07c9a..e7e8065e436 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -307,13 +307,14 @@ const char *mesh_cmp(Mesh *me1, Mesh *me2, float thresh) static void mesh_ensure_tesselation_customdata(Mesh *me) { - int tottex, totcol; + const int tottex_original = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY); + const int totcol_original = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL); - tottex = CustomData_number_of_layers(&me->fdata, CD_MTFACE); - totcol = CustomData_number_of_layers(&me->fdata, CD_MCOL); - - if (tottex != CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY) || - totcol != CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL)) + const int tottex_tessface = CustomData_number_of_layers(&me->fdata, CD_MTFACE); + const int totcol_tessface = CustomData_number_of_layers(&me->fdata, CD_MCOL); + + if (tottex_tessface != tottex_original || + totcol_tessface != totcol_original ) { CustomData_free(&me->fdata, me->totface); @@ -325,25 +326,38 @@ static void mesh_ensure_tesselation_customdata(Mesh *me) memset(&me->fdata, 0, sizeof(&me->fdata)); CustomData_from_bmeshpoly(&me->fdata, &me->pdata, &me->ldata, me->totface); - printf("Warning! Tesselation uvs or vcol data got out of sync, had to reset!\n"); + + /* note: this warning may be un-called for if we are inirializing the mesh for the + * first time from bmesh, rather then giving a warning about this we could be smarter + * and check if there was any data to begin with, for now just print the warning with + * some info to help troubleshoot whats going on - campbell */ + printf("%s: warning! Tesselation uvs or vcol data got out of sync, " + "had to reset!\n CD_MTFACE: %d != CD_MTEXPOLY: %d || CD_MCOL: %d != CD_MLOOPCOL: %d\n", + __func__, tottex_tessface, tottex_original, totcol_tessface, totcol_original); } } -/*this ensures grouped customdata (e.g. mtexpoly and mloopuv and mtface, or - mloopcol and mcol) have the same relative active/render/clone/mask indices.*/ -static void mesh_update_linked_customdata(Mesh *me) +/* this ensures grouped customdata (e.g. mtexpoly and mloopuv and mtface, or + * mloopcol and mcol) have the same relative active/render/clone/mask indices. + * + * note that for undo mesh data we want to skip 'ensure_tess_cd' call since + * we dont want to store memory for tessface when its only used for older + * versions of the mesh. - campbell*/ +static void mesh_update_linked_customdata(Mesh *me, const short do_ensure_tess_cd) { if (me->edit_btmesh) BMEdit_UpdateLinkedCustomData(me->edit_btmesh); - mesh_ensure_tesselation_customdata(me); + if (do_ensure_tess_cd) { + mesh_ensure_tesselation_customdata(me); + } CustomData_bmesh_update_active_layers(&me->fdata, &me->pdata, &me->ldata); } -void mesh_update_customdata_pointers(Mesh *me) +void mesh_update_customdata_pointers(Mesh *me, const short do_ensure_tess_cd) { - mesh_update_linked_customdata(me); + mesh_update_linked_customdata(me, do_ensure_tess_cd); me->mvert = CustomData_get_layer(&me->vdata, CD_MVERT); me->dvert = CustomData_get_layer(&me->vdata, CD_MDEFORMVERT); @@ -483,7 +497,7 @@ Mesh *copy_mesh(Mesh *me) CustomData_copy(&me->fdata, &men->fdata, CD_MASK_MESH, CD_DUPLICATE, men->totface); CustomData_copy(&me->ldata, &men->ldata, CD_MASK_MESH, CD_DUPLICATE, men->totloop); CustomData_copy(&me->pdata, &men->pdata, CD_MASK_MESH, CD_DUPLICATE, men->totpoly); - mesh_update_customdata_pointers(men); + mesh_update_customdata_pointers(men, TRUE); /* ensure indirect linked data becomes lib-extern */ for(i=0; i<me->fdata.totlayer; i++) { @@ -1100,7 +1114,7 @@ void mball_to_mesh(ListBase *lb, Mesh *me) &me->fdata, &me->ldata, &me->pdata, me->mvert, me->totface, me->totloop, me->totpoly); - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, TRUE); } } @@ -1927,7 +1941,7 @@ void convert_mfaces_to_mpolys(Mesh *mesh) /* note, we dont convert FGons at all, these are not even real ngons, * they have their own UV's, colors etc - its more an editing feature. */ - mesh_update_customdata_pointers(mesh); + mesh_update_customdata_pointers(mesh, TRUE); BLI_edgehash_free(eh, NULL); } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 241e993cbb2..dffcd17f3a9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3679,7 +3679,7 @@ static void lib_link_mesh(FileData *fd, Main *main) &me->fdata, &me->ldata, &me->pdata, me->mvert, me->totface, me->totloop, me->totpoly); - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, TRUE); me->id.flag -= LIB_NEEDLINK; } @@ -6570,7 +6570,7 @@ static void customdata_version_242(Mesh *me) } } - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, TRUE); } /*only copy render texface layer from active*/ diff --git a/source/blender/bmesh/operators/mesh_conv.c b/source/blender/bmesh/operators/mesh_conv.c index e9395a73e8c..938f0e94562 100644 --- a/source/blender/bmesh/operators/mesh_conv.c +++ b/source/blender/bmesh/operators/mesh_conv.c @@ -618,7 +618,7 @@ void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) CustomData_add_layer(&me->fdata, CD_NORMAL, CD_ASSIGN, facenors, me->totface); CustomData_from_bmeshpoly(&me->fdata, &bm->pdata, &bm->ldata, totface); - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, TRUE); i = 0; BM_ITER_INDEX(f, &iter, bm, BM_FACES_OF_MESH, NULL, j) { @@ -769,7 +769,7 @@ void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) if (vertMap) MEM_freeN(vertMap); } - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, dotess); { BMEditSelection *selected; diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 6bee0837819..996ffd1fdb2 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -113,7 +113,7 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la } else { CustomData_free_layer_active(data, type, tot); - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, TRUE); } if(!CustomData_has_layer(data, type) && (type == CD_MLOOPCOL && (ob->mode & OB_MODE_VERTEX_PAINT))) @@ -354,7 +354,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum); } - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, TRUE); } ED_mesh_uv_loop_reset(C, me); @@ -434,7 +434,7 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum); } - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, TRUE); } DAG_id_tag_update(&me->id, 0); @@ -767,7 +767,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges) mesh->totloop, mesh->totpoly); - mesh_update_customdata_pointers(mesh); + mesh_update_customdata_pointers(mesh, TRUE); polyindex = CustomData_get_layer(&mesh->fdata, CD_POLYINDEX); /* add a normals layer for tesselated faces, a tessface normal will @@ -809,7 +809,7 @@ static void mesh_add_verts(Mesh *mesh, int len) CustomData_free(&mesh->vdata, mesh->totvert); mesh->vdata= vdata; - mesh_update_customdata_pointers(mesh); + mesh_update_customdata_pointers(mesh, FALSE); /* scan the input list and insert the new vertices */ @@ -852,7 +852,7 @@ static void mesh_add_edges(Mesh *mesh, int len) CustomData_free(&mesh->edata, mesh->totedge); mesh->edata= edata; - mesh_update_customdata_pointers(mesh); + mesh_update_customdata_pointers(mesh, FALSE); /* new edges dont change tessellation */ /* set default flags */ medge= &mesh->medge[mesh->totedge]; @@ -882,7 +882,7 @@ static void mesh_add_faces(Mesh *mesh, int len) CustomData_free(&mesh->fdata, mesh->totface); mesh->fdata= fdata; - mesh_update_customdata_pointers(mesh); + mesh_update_customdata_pointers(mesh, TRUE); /* set default flags */ mface= &mesh->mface[mesh->totface]; @@ -911,7 +911,7 @@ static void mesh_add_loops(Mesh *mesh, int len) CustomData_free(&mesh->ldata, mesh->totloop); mesh->ldata= ldata; - mesh_update_customdata_pointers(mesh); + mesh_update_customdata_pointers(mesh, TRUE); mesh->totloop= totloop; } @@ -936,7 +936,7 @@ static void mesh_add_polys(Mesh *mesh, int len) CustomData_free(&mesh->pdata, mesh->totpoly); mesh->pdata= pdata; - mesh_update_customdata_pointers(mesh); + mesh_update_customdata_pointers(mesh, TRUE); /* set default flags */ mpoly= &mesh->mpoly[mesh->totpoly]; diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 4fcc2071d26..5e9762d16e7 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -522,7 +522,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) me->ldata= ldata; me->pdata= pdata; - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, TRUE); /* BMESH_TODO, check if this arg can be failse, non urgent - campbell */ /* old material array */ for(a=1; a<=ob->totcol; a++) { diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 77daa3cdc28..7cc15cd4e77 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -340,7 +340,7 @@ static void make_vertexcol(Object *ob) /* single ob */ CustomData_add_layer(&me->fdata, CD_MCOL, CD_DEFAULT, NULL, me->totface); if (!me->mloopcol) { CustomData_add_layer(&me->ldata, CD_MLOOPCOL, CD_DEFAULT, NULL, me->totloop); - mesh_update_customdata_pointers(me); + mesh_update_customdata_pointers(me, TRUE); } //if(shade) diff --git a/source/blender/makesrna/intern/rna_mesh_utils.h b/source/blender/makesrna/intern/rna_mesh_utils.h index 9f2a3c083b6..02afaa5b51d 100644 --- a/source/blender/makesrna/intern/rna_mesh_utils.h +++ b/source/blender/makesrna/intern/rna_mesh_utils.h @@ -83,7 +83,7 @@ for(cdl=data->layers, a=0; a<data->totlayer; cdl++, a++) { \ if(value.data == cdl) { \ CustomData_set_layer_##active_type##_index(data, layer_type, a); \ - mesh_update_customdata_pointers(me); \ + mesh_update_customdata_pointers(me, TRUE); \ return; \ } \ } \ @@ -101,5 +101,5 @@ CustomData *data = rna_mesh_##customdata_type(ptr); \ \ CustomData_set_layer_##active_type(data, layer_type, value); \ - mesh_update_customdata_pointers(me); \ + mesh_update_customdata_pointers(me, TRUE); \ } |