svn merge ^/trunk/blender -r46300:46330
[blender.git] / source / blender / editors / sculpt_paint / sculpt.c
index 09c7ecd6b488c58de5188bb65afc0d5e8ce76e5f..81b418b51f5824b3ca4bac359ffad4c5301d201b 100644 (file)
@@ -101,26 +101,6 @@ void ED_sculpt_force_update(bContext *C)
                multires_force_update(ob);
 }
 
-float *ED_sculpt_get_last_stroke(struct Object *ob)
-{
-       return (ob && ob->sculpt && ob->sculpt->last_stroke_valid) ? ob->sculpt->last_stroke : NULL;
-}
-
-int ED_sculpt_minmax(bContext *C, float *min, float *max)
-{
-       Object *ob= CTX_data_active_object(C);
-
-       if (ob && ob->sculpt && ob->sculpt->last_stroke_valid) {
-               copy_v3_v3(min, ob->sculpt->last_stroke);
-               copy_v3_v3(max, ob->sculpt->last_stroke);
-
-               return 1;
-       }
-       else {
-               return 0;
-       }
-}
-
 /* Sculpt mode handles multires differently from regular meshes, but only if
  * it's the last modifier on the stack and it is not on the first level */
 struct MultiresModifierData *sculpt_multires_active(Scene *scene, Object *ob)
@@ -264,54 +244,6 @@ typedef struct StrokeCache {
        rcti previous_r; /* previous redraw rectangle */
 } StrokeCache;
 
-
-/*** paint mesh ***/
-
-static void paint_mesh_restore_co(Sculpt *sd, SculptSession *ss)
-{
-       StrokeCache *cache = ss->cache;
-       int i;
-
-       PBVHNode **nodes;
-       int n, totnode;
-
-#ifndef _OPENMP
-       (void)sd; /* quied unused warning */
-#endif
-
-       BLI_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
-
-       #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP)
-       for (n = 0; n < totnode; n++) {
-               SculptUndoNode *unode;
-               
-               unode = sculpt_undo_get_node(nodes[n]);
-               if (unode) {
-                       PBVHVertexIter vd;
-
-                       BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
-                               copy_v3_v3(vd.co, unode->co[vd.i]);
-                               if (vd.no) copy_v3_v3_short(vd.no, unode->no[vd.i]);
-                               else normal_short_to_float_v3(vd.fno, unode->no[vd.i]);
-
-                               if (vd.mvert) vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
-                       }
-                       BLI_pbvh_vertex_iter_end;
-
-                       BLI_pbvh_node_mark_update(nodes[n]);
-               }
-       }
-
-       if (ss->face_normals) {
-               float *fn = ss->face_normals;
-               for (i = 0; i < ss->totpoly; ++i, fn += 3)
-                       copy_v3_v3(fn, cache->face_norms[i]);
-       }
-
-       if (nodes)
-               MEM_freeN(nodes);
-}
-
 /*** BVH Tree ***/
 
 /* Get a screen-space rectangle of the modified area */
@@ -425,11 +357,11 @@ static int sculpt_brush_test_cube(SculptBrushTest *test, float co[3], float loca
        local_co[2] = fabs(local_co[2]);
 
        if (local_co[0] <= side && local_co[1] <= side && local_co[2] <= side) {
-               float p = 4.0f;
+               float p = 4;
                
                test->dist = ((powf(local_co[0], p) +
                               powf(local_co[1], p) +
-                              powf(local_co[2], p)) / powf(side, p));
+                              powf(local_co[2], p)) / pow(side, p));
 
                return 1;
        }
@@ -3241,7 +3173,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob,
        sd->special_rotation = cache->special_rotation;
 }
 
-static void sculpt_stroke_modifiers_check(const bContext *C, Object *ob)
+static void sculpt_stroke_modifiers_check(bContext *C, Object *ob)
 {
        SculptSession *ss = ob->sculpt;
 
@@ -3377,7 +3309,43 @@ static void sculpt_restore_mesh(Sculpt *sd, SculptSession *ss)
             BKE_brush_use_size_pressure(ss->cache->vc->scene, brush)) ||
            (brush->flag & BRUSH_RESTORE_MESH))
        {
-               paint_mesh_restore_co(sd, ss);
+               StrokeCache *cache = ss->cache;
+               int i;
+
+               PBVHNode **nodes;
+               int n, totnode;
+
+               BLI_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
+
+               #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP)
+               for (n = 0; n < totnode; n++) {
+                       SculptUndoNode *unode;
+                       
+                       unode = sculpt_undo_get_node(nodes[n]);
+                       if (unode) {
+                               PBVHVertexIter vd;
+
+                               BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
+                                       copy_v3_v3(vd.co, unode->co[vd.i]);
+                                       if (vd.no) copy_v3_v3_short(vd.no, unode->no[vd.i]);
+                                       else normal_short_to_float_v3(vd.fno, unode->no[vd.i]);
+
+                                       if (vd.mvert) vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+                               }
+                               BLI_pbvh_vertex_iter_end;
+
+                               BLI_pbvh_node_mark_update(nodes[n]);
+                       }
+               }
+
+               if (ss->face_normals) {
+                       float *fn = ss->face_normals;
+                       for (i = 0; i < ss->totpoly; ++i, fn += 3)
+                               copy_v3_v3(fn, cache->face_norms[i]);
+               }
+
+               if (nodes)
+                       MEM_freeN(nodes);
        }
 }
 
@@ -3487,7 +3455,7 @@ static void sculpt_brush_exit_tex(Sculpt *sd)
                ntreeTexEndExecTree(mtex->tex->nodetree->execdata, 1);
 }
 
-static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(stroke))
+static void sculpt_stroke_done(bContext *C, struct PaintStroke *UNUSED(stroke))
 {
        Object *ob = CTX_data_active_object(C);
        SculptSession *ss = ob->sculpt;
@@ -3514,11 +3482,6 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str
                        }
                }
 
-               /* update last stroke position */
-               ob->sculpt->last_stroke_valid= 1;
-               copy_v3_v3(ob->sculpt->last_stroke, ss->cache->true_location);
-               mul_m4_v3(ob->obmat, ob->sculpt->last_stroke);
-
                sculpt_cache_free(ss->cache);
                ss->cache = NULL;
 
@@ -3563,7 +3526,7 @@ static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *even
                                                  "ignore_background_click");
 
        if (ignore_background_click && !over_mesh(C, op, event->x, event->y)) {
-               paint_stroke_data_free(op);
+               paint_stroke_free(stroke);
                return OPERATOR_PASS_THROUGH;
        }
        
@@ -3595,10 +3558,6 @@ static int sculpt_brush_stroke_cancel(bContext *C, wmOperator *op)
        SculptSession *ss = ob->sculpt;
        Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
 
-       if (ss->cache) {
-               paint_mesh_restore_co(sd, ss);
-       }
-
        paint_stroke_cancel(C, op);
 
        if (ss->cache) {