ensure tessface's are available while sculpting.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 5 Feb 2012 07:12:46 +0000 (07:12 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 5 Feb 2012 07:12:46 +0000 (07:12 +0000)
source/blender/blenkernel/BKE_mesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenloader/intern/readfile.c
source/blender/bmesh/operators/mesh_conv.c
source/blender/editors/mesh/mesh_data.c
source/blender/editors/sculpt_paint/sculpt.c

index 70d2773..270e07b 100644 (file)
@@ -260,6 +260,9 @@ void BKE_mesh_calc_edges(struct Mesh *mesh, int update);
 
 void BKE_mesh_ensure_navmesh(struct Mesh *me);
 
+void BKE_mesh_calc_tessface(struct Mesh *mesh);
+void BKE_mesh_ensure_tessface(struct Mesh *mesh);
+
 /*convert a triangle of loop facedata to mface facedata*/
 void mesh_loops_to_mface_corners(struct CustomData *fdata, struct CustomData *ldata,
                                  struct CustomData *pdata, int lindex[4], int findex,
index b4af827..939fe2c 100644 (file)
@@ -446,13 +446,7 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
        /* yes, must be before _and_ after tesselate */
        mesh_update_customdata_pointers(&tmp, TRUE);
 
-       tmp.totface = mesh_recalcTesselation(&tmp.fdata, &tmp.ldata, &tmp.pdata,
-                                            tmp.mvert,
-                                            tmp.totface, tmp.totloop, tmp.totpoly,
-                                            TRUE);
-
-       mesh_update_customdata_pointers(&tmp, TRUE);
-
+       BKE_mesh_calc_tessface(&tmp);
 
        CustomData_free(&me->vdata, me->totvert);
        CustomData_free(&me->edata, me->totedge);
index d10bda3..7f217eb 100644 (file)
@@ -2950,3 +2950,21 @@ void BKE_mesh_ensure_navmesh(Mesh *me)
                CustomData_add_layer_named(&me->fdata, CD_RECAST, CD_REFERENCE, recastData, numFaces, "recastData");
        }
 }
+
+void BKE_mesh_calc_tessface(Mesh *mesh)
+{
+       mesh->totface = mesh_recalcTesselation(&mesh->fdata, &mesh->ldata, &mesh->pdata,
+                                              mesh->mvert,
+                                              mesh->totface, mesh->totloop, mesh->totpoly,
+                                              /* calc normals right after, dont copy from polys here */
+                                              FALSE);
+
+       mesh_update_customdata_pointers(mesh, TRUE);
+}
+
+void BKE_mesh_ensure_tessface(Mesh *mesh)
+{
+       if (mesh->totpoly && mesh->totface == 0) {
+               BKE_mesh_calc_tessface(mesh);
+       }
+}
index 2f7a59f..8a58687 100644 (file)
@@ -3703,12 +3703,7 @@ static void lib_link_mesh(FileData *fd, Main *main)
                         *    waiting until edit mode has been entered/exited, making it easier
                         *    to recognize problems that would otherwise only show up after edits).
                         */
-                       me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata,
-                                                            me->mvert,
-                                                            me->totface, me->totloop, me->totpoly,
-                                                            TRUE);
-
-                       mesh_update_customdata_pointers(me, TRUE);
+                       BKE_mesh_calc_tessface(me);
 
                        me->id.flag -= LIB_NEEDLINK;
                }
index f4a63c9..39f312c 100644 (file)
@@ -631,11 +631,7 @@ void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op)
        }
 
        if (dotess) {
-               me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata,
-                                                    me->mvert,
-                                                    me->totface, me->totloop, me->totpoly,
-                                                    /* possibly can set to FALSE here, but defaults to true */
-                                                    TRUE);
+               BKE_mesh_calc_tessface(me);
        }
 
        mesh_update_customdata_pointers(me, dotess);
index 0ced2d9..4c345f8 100644 (file)
@@ -758,13 +758,8 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges)
        if(calc_edges || (mesh->totpoly && mesh->totedge == 0))
                BKE_mesh_calc_edges(mesh, calc_edges);
 
-       mesh->totface = mesh_recalcTesselation(&mesh->fdata, &mesh->ldata, &mesh->pdata,
-                                              mesh->mvert,
-                                              mesh->totface, mesh->totloop, mesh->totpoly,
-                                              /* calc normals right after, dont copy from polys here */
-                                              FALSE);
-
-       mesh_update_customdata_pointers(mesh, TRUE);
+       /* TODO, make this optional, we dont always want this! */
+       BKE_mesh_calc_tessface(mesh);
 
        polyindex = CustomData_get_layer(&mesh->fdata, CD_POLYINDEX);
        /* add a normals layer for tesselated faces, a tessface normal will
index d14e7da..b813f71 100644 (file)
@@ -2548,7 +2548,7 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob)
                /* Modifiers could depend on mesh normals, so we should update them/
                   Note, then if sculpting happens on locked key, normals should be re-calculated
                   after applying coords from keyblock on base mesh */
-               mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
+               mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL);
        } else if (ss->kb)
                sculpt_update_keyblock(ob);
 }
@@ -2723,6 +2723,9 @@ void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_
                ss->multires = NULL;
        }
 
+       /* BMESH ONLY --- at some point we should move sculpt code to use polygons only - but for now it needs tessfaces */
+       BKE_mesh_ensure_tessface(ob->data);
+
        ss->pbvh = dm->getPBVH(ob, dm);
        ss->pmap = (need_pmap && dm->getPolyMap)? dm->getPolyMap(ob, dm): NULL;