Revision: 29521
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29521
Author:   jwilkins
Date:     2010-06-17 12:55:18 +0200 (Thu, 17 Jun 2010)

Log Message:
-----------
* reduced strength of thumb brush

* fixed MSVC warnings:
** removed unused FLATTEN_SAMPLE_SIZE from source, its no longer used
** use automatic memory for BoundBox bb in sculpt_get_redraw_planes
** quieted warning about unused parameter in update_cb
** sculpt_undo_get_node, sculpt_undo_push_end and sculpt_undo_push_begin do not 
use their SculptSession parameters
** rewrote 'non-constant agregate initializers' because they are not standard C
** changed the vert parameter of neighbor_average from int to unsigned to 
prevent mismatch
** do_brush_action doesn't need its cache parameter
** removed unused parameter 'C' from sculpt_update_cache_invariants
** sculpt_brush_stroke_init_properties doesn't use its SculptSession parameter
** in over_mesh, no need to cast return value of sculpt_stroke_get_location to 
int, it already returns an int
** sculpt_stroke_done doesn't use its 'stroke' parameter
** sculpt_set_persistent_base and sculpt_toggle_mode do not used their 
wmOperator parameters

* broke sculpt undo functions out into their own file sculpt_undo.c

Modified Paths:
--------------
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
    
branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt_intern.h

Added Paths:
-----------
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt_undo.c

Modified: 
branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c     
2010-06-17 10:47:55 UTC (rev 29520)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c     
2010-06-17 10:55:18 UTC (rev 29521)
@@ -91,8 +91,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-/* Number of vertices to average in order to determine the flatten distance */
-#define FLATTEN_SAMPLE_SIZE 10
+//#ifdef _OPENMP
+//#include <omp.h>
+//#endif
 
 /* ===== STRUCTS =====
  *
@@ -236,10 +237,12 @@
                                  RegionView3D *rv3d, Object *ob)
 {
        PBVH *pbvh= ob->sculpt->pbvh;
-       BoundBox *bb = MEM_callocN(sizeof(BoundBox), "sculpt boundbox");
+       BoundBox bb;
        bglMats mats;
        rcti rect;
 
+       memset(&bb, 0, sizeof(BoundBox));
+
        view3d_get_transformation(ar, rv3d, ob, &mats);
        sculpt_get_redraw_rect(ar, rv3d,ob, &rect);
 
@@ -258,288 +261,14 @@
        rect.ymax -= 2;
 #endif
 
-       view3d_calculate_clipping(bb, planes, &mats, &rect);
+       view3d_calculate_clipping(&bb, planes, &mats, &rect);
        mul_m4_fl(planes, -1.0f);
 
-       MEM_freeN(bb);
-
        /* clear redraw flag from nodes */
        if(pbvh)
                BLI_pbvh_update(pbvh, PBVH_UpdateRedraw, NULL);
 }
 
-/************************** Undo *************************/
-
-typedef struct SculptUndoNode {
-       struct SculptUndoNode *next, *prev;
-
-       char idname[MAX_ID_NAME];       /* name instead of pointer*/
-       void *node;                                     /* only during push, 
not valid afterwards! */
-
-       float (*co)[3];
-       short (*no)[3];
-       int totvert;
-
-       /* non-multires */
-       int maxvert;                            /* to verify if totvert it 
still the same */
-       int *index;                                     /* to restore into 
right location */
-
-       /* multires */
-       int maxgrid;                            /* same for grid */
-       int gridsize;                           /* same for grid */
-       int totgrid;                            /* to restore into right 
location */
-       int *grids;                                     /* to restore into 
right location */
-
-       /* layer brush */
-       float *layer_disp;
-} SculptUndoNode;
-
-static void update_cb(PBVHNode *node, void *data)
-{
-       BLI_pbvh_node_mark_update(node);
-}
-
-/* Checks whether full update mode (slower) needs to be used to work with 
modifiers */
-static int sculpt_modifiers_active(Scene *scene, Object *ob)
-{
-       ModifierData *md;
-       MultiresModifierData *mmd = sculpt_multires_active(scene, ob);
-
-       /* check if there are any modifiers after what we are sculpting,
-          for a multires modifier with a deform modifier in front, we
-          do no need to recalculate the modifier stack. note that this
-          needs to be in sync with ccgDM_use_grid_pbvh! */
-       if(mmd)
-               md= mmd->modifier.next;
-       else
-               md= modifiers_getVirtualModifierList(ob);
-       
-       /* exception for shape keys because we can edit those */
-       for(; md; md= md->next) {
-               if(modifier_isEnabled(scene, md, eModifierMode_Realtime))
-                       if(md->type != eModifierType_ShapeKey)
-                               return 1;
-       }
-       
-       return 0;
-}
-
-static void sculpt_undo_restore(bContext *C, ListBase *lb)
-{
-       Scene *scene = CTX_data_scene(C);
-       Object *ob = CTX_data_active_object(C);
-       DerivedMesh *dm = mesh_get_derived_final(scene, ob, 0);
-       SculptSession *ss = ob->sculpt;
-       SculptUndoNode *unode;
-       MVert *mvert;
-       MultiresModifierData *mmd;
-       int *index;
-       int i, j, update= 0;
-
-       sculpt_update_mesh_elements(scene, ob, 0);
-
-       for(unode=lb->first; unode; unode=unode->next) {
-               if(!(strcmp(unode->idname, ob->id.name)==0))
-                       continue;
-
-               if(unode->maxvert) {
-                       /* regular mesh restore */
-                       if(ss->totvert != unode->maxvert)
-                               continue;
-
-                       index= unode->index;
-                       mvert= ss->mvert;
-
-                       for(i=0; i<unode->totvert; i++) {
-                               swap_v3_v3(mvert[index[i]].co, unode->co[i]);
-                               mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
-                       }
-               }
-               else if(unode->maxgrid && dm->getGridData) {
-                       /* multires restore */
-                       DMGridData **grids, *grid;
-                       float (*co)[3];
-                       int gridsize;
-
-                       if(dm->getNumGrids(dm) != unode->maxgrid)
-                               continue;
-                       if(dm->getGridSize(dm) != unode->gridsize)
-                               continue;
-
-                       grids= dm->getGridData(dm);
-                       gridsize= dm->getGridSize(dm);
-
-                       co = unode->co;
-                       for(j=0; j<unode->totgrid; j++) {
-                               grid= grids[unode->grids[j]];
-
-                               for(i=0; i<gridsize*gridsize; i++, co++)
-                                       swap_v3_v3(grid[i].co, co[0]);
-                       }
-               }
-
-               update= 1;
-       }
-
-       if(update) {
-               if(ss->kb) sculpt_mesh_to_key(ss->ob, ss->kb);
-               if(ss->refkb) sculpt_key_to_mesh(ss->refkb, ob);
-
-               /* we update all nodes still, should be more clever, but also
-                  needs to work correct when exiting/entering sculpt mode and
-                  the nodes get recreated, though in that case it could do all 
*/
-               BLI_pbvh_search_callback(ss->pbvh, NULL, NULL, update_cb, NULL);
-               BLI_pbvh_update(ss->pbvh, 
PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw, NULL);
-
-               if((mmd=sculpt_multires_active(scene, ob)))
-                       multires_mark_as_modified(ob);
-
-               if(sculpt_modifiers_active(scene, ob))
-                       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
-       }
-}
-
-static void sculpt_undo_free(ListBase *lb)
-{
-       SculptUndoNode *unode;
-
-       for(unode=lb->first; unode; unode=unode->next) {
-               if(unode->co)
-                       MEM_freeN(unode->co);
-               if(unode->no)
-                       MEM_freeN(unode->no);
-               if(unode->index)
-                       MEM_freeN(unode->index);
-               if(unode->grids)
-                       MEM_freeN(unode->grids);
-               if(unode->layer_disp)
-                       MEM_freeN(unode->layer_disp);
-       }
-}
-
-static SculptUndoNode *sculpt_undo_get_node(SculptSession *ss, PBVHNode *node)
-{
-       ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH);
-       SculptUndoNode *unode;
-
-       if(!lb)
-               return NULL;
-
-       for(unode=lb->first; unode; unode=unode->next)
-               if(unode->node == node)
-                       return unode;
-
-       return NULL;
-}
-
-static SculptUndoNode *sculpt_undo_push_node(SculptSession *ss, PBVHNode *node)
-{
-       ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH);
-       Object *ob= ss->ob;
-       SculptUndoNode *unode;
-       int totvert, allvert, totgrid, maxgrid, gridsize, *grids;
-
-       /* list is manipulated by multiple threads, so we lock */
-       BLI_lock_thread(LOCK_CUSTOM1);
-
-       if((unode= sculpt_undo_get_node(ss, node))) {
-               BLI_unlock_thread(LOCK_CUSTOM1);
-               return unode;
-       }
-
-       unode= MEM_mallocN(sizeof(SculptUndoNode), "SculptUndoNode");
-       strcpy(unode->idname, ob->id.name);
-       unode->node= node;
-
-       BLI_pbvh_node_num_verts(ss->pbvh, node, &totvert, &allvert);
-       BLI_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid,
-               &maxgrid, &gridsize, NULL, NULL);
-
-       unode->totvert= totvert;
-       /* we will use this while sculpting, is mapalloc slow to access then? */
-       unode->co= MEM_mapallocN(sizeof(float)*3*allvert, "SculptUndoNode.co");
-       unode->no= MEM_mapallocN(sizeof(short)*3*allvert, "SculptUndoNode.no");
-       undo_paint_push_count_alloc(UNDO_PAINT_MESH, (sizeof(float)*3 + 
sizeof(short)*3 + sizeof(int))*allvert);
-       BLI_addtail(lb, unode);
-
-       if(maxgrid) {
-               /* multires */
-               unode->maxgrid= maxgrid;
-               unode->totgrid= totgrid;
-               unode->gridsize= gridsize;
-               unode->grids= MEM_mapallocN(sizeof(int)*totgrid, 
"SculptUndoNode.grids");
-
-               unode->maxvert = 0;
-               unode->index   = 0;
-       }
-       else {
-               /* regular mesh */
-               unode->maxvert= ss->totvert;
-               unode->index= MEM_mapallocN(sizeof(int)*allvert, 
"SculptUndoNode.index");
-
-               unode->maxgrid=  0;
-               unode->totgrid=  0;
-               unode->gridsize= 0;
-               unode->grids=    0;
-       }
-
-       BLI_unlock_thread(LOCK_CUSTOM1);
-
-       /* copy threaded, hopefully this is the performance critical part */
-       {
-               PBVHVertexIter vd;
-
-               BLI_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_ALL) {
-                       copy_v3_v3(unode->co[vd.i], vd.co);
-                       if(vd.no) VECCOPY(unode->no[vd.i], vd.no)
-                       else normal_float_to_short_v3(unode->no[vd.i], vd.fno);
-                       if(vd.vert_indices) unode->index[vd.i]= 
vd.vert_indices[vd.i];
-               }
-               BLI_pbvh_vertex_iter_end;
-       }
-
-       if(unode->grids) memcpy(unode->grids, grids, sizeof(int)*totgrid);
-
-       unode->layer_disp= 0;
-
-       return unode;
-}
-
-static void sculpt_undo_push_begin(SculptSession *ss, char *name)
-{
-       undo_paint_push_begin(UNDO_PAINT_MESH, name,
-               sculpt_undo_restore, sculpt_undo_free);
-}
-
-static void sculpt_undo_push_end(SculptSession *ss)
-{
-       ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH);
-       SculptUndoNode *unode;
-
-       /* we don't need normals in the undo stack */
-       for(unode=lb->first; unode; unode=unode->next) {
-               if(unode->no) {
-                       MEM_freeN(unode->no);
-                       unode->no= NULL;
-               }
-
-               if(unode->layer_disp) {
-                       MEM_freeN(unode->layer_disp);
-                       unode->layer_disp= NULL;
-               }
-       }
-
-       undo_paint_push_end(UNDO_PAINT_MESH);
-}
-
-void ED_sculpt_force_update(bContext *C)
-{
-       Object *ob= CTX_data_active_object(C);
-
-       if(ob && (ob->mode & OB_MODE_SCULPT))
-               multires_force_update(ob);
-}
-
 /************************ Brush Testing *******************/
 
 typedef struct SculptBrushTest {
@@ -563,37 +292,37 @@
        //test->symmetry_pass = ss->cache->symmetry_pass;
 }
 
-static int sculpt_brush_test_clip(SculptBrushTest* test, float co[3])
-{
-       //if (test->symmetry) {
-       //      int i;
+//static int sculpt_brush_test_clip(SculptBrushTest* test, float co[3])
+//{
+//     if (test->symmetry) {
+//             int i;
+//
+//             for (i = 0; i < 3; i++) {
+//                     if (test->symmetry_pass & (1<<i)) {
+//                             if (test->true_location[i] >= 0) {
+//                                     if (co[i] >= 0) return 0;
+//                             }
+//                             else if (test->true_location[i] < 0) {
+//                                     if (co[i] < 0) return 0;
+//                             }
+//                     }
+//                     else {
+//                             if (test->true_location[i] >= 0) {
+//                                     if (co[i] < 0) return 0;
+//                             }
+//                             else if (test->true_location[i] < 0) {
+//                                     if (co[i] >= 0) return 0;
+//                             }
+//                     }
+//             }
+//     }
+//
+//     return 1;
+//}
 
-       //      for (i = 0; i < 3; i++) {
-       //              if (test->symmetry_pass & (1<<i)) {
-       //                      if (test->true_location[i] >= 0) {
-       //                              if (co[i] >= 0) return 0;
-       //                      }
-       //                      else if (test->true_location[i] < 0) {
-       //                              if (co[i] < 0) return 0;
-       //                      }
-       //              }
-       //              else {
-       //                      if (test->true_location[i] >= 0) {
-       //                              if (co[i] < 0) return 0;
-       //                      }
-       //                      else if (test->true_location[i] < 0) {
-       //                              if (co[i] >= 0) return 0;
-       //                      }
-       //              }
-       //      }
-       //}
-
-       return 1;
-}
-
 static int sculpt_brush_test(SculptBrushTest *test, float co[3])
 {
-       if (sculpt_brush_test_clip(test, co)) {
+       //if (sculpt_brush_test_clip(test, co)) {
                float distsq = len_squared_v3v3(co, test->location);
 
                if(distsq < test->radius_squared) {
@@ -603,15 +332,15 @@
                else {
                        return 0;
                }
-       }
-       else {
-               return 0;
-       }
+       //}
+       //else {
+       //      return 0;
+       //}
 }
 
 static int sculpt_brush_test_sq(SculptBrushTest *test, float co[3])
 {
-       if (sculpt_brush_test_clip(test, co)) {
+       //if (sculpt_brush_test_clip(test, co)) {
                float distsq = len_squared_v3v3(co, test->location);
 
                if(distsq < test->radius_squared) {
@@ -621,20 +350,20 @@

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to