merge from 22334 to 22606
authorLukas Steiblys <imbusy@imbusy.org>
Tue, 18 Aug 2009 18:06:11 +0000 (18:06 +0000)
committerLukas Steiblys <imbusy@imbusy.org>
Tue, 18 Aug 2009 18:06:11 +0000 (18:06 +0000)
1  2 
projectfiles_vc9/blender/blender.sln
source/blender/blenkernel/BKE_sculpt.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c
source/blender/windowmanager/intern/wm_init_exit.c

Simple merge
index f551ce768ae587911466efb2c0d7a69ce713589e,f7f72d611dc46a690a7a5458212ff956b5032910..909ddec17ff5432c74644d06337f16facb269b56
@@@ -329,34 -318,21 +319,34 @@@ static void calc_area_normal(Sculpt *sd
  static void do_draw_brush(Sculpt *sd, SculptSession *ss, const ListBase* active_verts)
  {
        float area_normal[3];
-       int i, j, found;
++      int j;
        ActiveData *node= active_verts->first;
 +      float* buffer;
  
-       calc_area_normal(sd, area_normal, active_verts);
+       calc_area_normal(sd, ss, area_normal, active_verts);
        
 +      buffer = (float *)GPU_buffer_lock( ss->drawobject->vertices );
        while(node){
                float *co= ss->mvert[node->Index].co;
  
                const float val[3]= {co[0]+area_normal[0]*ss->cache->radius*node->Fade*ss->cache->scale[0],
                                     co[1]+area_normal[1]*ss->cache->radius*node->Fade*ss->cache->scale[1],
                                     co[2]+area_normal[2]*ss->cache->radius*node->Fade*ss->cache->scale[2]};
 -                                   
 +
 +              if( buffer != 0 ) {
 +                      IndexLink *cur = &ss->drawobject->indices[node->Index];
 +                      while( cur != 0 && cur->element != -1 ) {
-                               sculpt_clip(sd, &buffer[cur->element*3], val);
++                              sculpt_clip(sd, ss, &buffer[cur->element*3], val);
 +                              cur = cur->next;
 +                      }
 +              }
 +
-               sculpt_clip(sd, co, val);
+               sculpt_clip(sd, ss, co, val);
 -              
 +
                node= node->next;
        }
 +      if( buffer != 0 )
 +              GPU_buffer_unlock( ss->drawobject->vertices );
  }
  
  /* For the smooth brush, uses the neighboring vertices around vert to calculate
@@@ -403,10 -379,9 +393,10 @@@ static void neighbor_average(SculptSess
                VecCopyf(avg, ss->mvert[vert].co);
  }
  
- static void do_smooth_brush(Sculpt *s, const ListBase* active_verts)
+ static void do_smooth_brush(Sculpt *s, SculptSession *ss, const ListBase* active_verts)
  {
        ActiveData *node= active_verts->first;
-       float *buffer = (float *)GPU_buffer_lock( s->session->drawobject->vertices );
++      float *buffer = (float *)GPU_buffer_lock( ss->drawobject->vertices );
        int i;
        
        for(i = 0; i < 2; ++i) {
                        val[1] = co[1]+(avg[1]-co[1])*node->Fade;
                        val[2] = co[2]+(avg[2]-co[2])*node->Fade;
                        
-                       if( buffer != 0 ) {
-                               IndexLink *cur = &s->session->drawobject->indices[node->Index];
 -                      sculpt_clip(s, ss, co, val);
++                      sculpt_clip(s, ss, co, val);                    
++                      if( buffer != 0 ) {                             
++                              IndexLink *cur = &ss->drawobject->indices[node->Index]; 
 +                              while( cur != 0 && cur->element != -1 ) {
-                                       sculpt_clip(s, &buffer[cur->element*3], val);
++                                      sculpt_clip(s, ss, &buffer[cur->element*3], val);
 +                                      cur = cur->next;
 +                              }
 +                      }
-                       sculpt_clip(s, co, val);
                        node= node->next;
                }
        }
-               GPU_buffer_unlock( s->session->drawobject->vertices );
 +      if( buffer != 0 )
++              GPU_buffer_unlock( ss->drawobject->vertices );
  }
  
- static void do_pinch_brush(Sculpt *s, const ListBase* active_verts)
+ static void do_pinch_brush(Sculpt *s, SculptSession *ss, const ListBase* active_verts)
  {
        ActiveData *node= active_verts->first;
-       float *buffer = (float *)GPU_buffer_lock( s->session->drawobject->vertices );
++      float *buffer = (float *)GPU_buffer_lock( ss->drawobject->vertices );
  
        while(node) {
-               float *co= s->session->mvert[node->Index].co;
-               const float val[3]= {co[0]+(s->session->cache->location[0]-co[0])*node->Fade,
-                                    co[1]+(s->session->cache->location[1]-co[1])*node->Fade,
-                                    co[2]+(s->session->cache->location[2]-co[2])*node->Fade};
+               float *co= ss->mvert[node->Index].co;
+               const float val[3]= {co[0]+(ss->cache->location[0]-co[0])*node->Fade,
+                                    co[1]+(ss->cache->location[1]-co[1])*node->Fade,
+                                    co[2]+(ss->cache->location[2]-co[2])*node->Fade};
 +
 +              if( buffer != 0 ) {
-                       IndexLink *cur = &s->session->drawobject->indices[node->Index];
++                      IndexLink *cur = &ss->drawobject->indices[node->Index];
 +                      while( cur != 0 && cur->element != -1 ) {
-                               sculpt_clip(s, &buffer[cur->element*3], val);
++                              sculpt_clip(s, ss, &buffer[cur->element*3], val);
 +                              cur = cur->next;
 +                      }
 +              }
 +
-               sculpt_clip(s, co, val);
+               sculpt_clip(s, ss, co, val);
                node= node->next;
        }
-               GPU_buffer_unlock( s->session->drawobject->vertices );
 +      if( buffer != 0 )
++              GPU_buffer_unlock( ss->drawobject->vertices );
  }
  
  static void do_grab_brush(Sculpt *sd, SculptSession *ss)
                VecCopyf(add, grab_delta);
                VecMulf(add, node->Fade);
                VecAddf(add, add, co);
-                               sculpt_clip(sd, &buffer[cur->element*3], add);
 +
 +              if( buffer != 0 ) {
 +                      IndexLink *cur = &ss->drawobject->indices[node->Index];
 +                      while( cur != 0 && cur->element != -1 ) {
-               sculpt_clip(sd, co, add);
++                              sculpt_clip(sd, ss, &buffer[cur->element*3], add);
 +                              cur = cur->next;
 +                      }
 +              }
 +
+               sculpt_clip(sd, ss, co, add);
  
                node= node->next;
        }
@@@ -504,9 -444,8 +493,9 @@@ static void do_layer_brush(Sculpt *sd, 
        if(ss->cache->flip)
                lim = -lim;
  
-       calc_area_normal(sd, area_normal, active_verts);
+       calc_area_normal(sd, ss, area_normal, active_verts);
  
 +      buffer = (float *)GPU_buffer_lock( ss->drawobject->vertices );
        while(node){
                float *disp= &ss->layer_disps[node->Index];
                float *co= ss->mvert[node->Index].co;
                val[1] = ss->mesh_co_orig[node->Index][1]+area_normal[1] * *disp*ss->cache->scale[1];
                val[2] = ss->mesh_co_orig[node->Index][2]+area_normal[2] * *disp*ss->cache->scale[2];
  
-                               sculpt_clip(sd, &buffer[cur->element*3], val);
 +              if( buffer != 0 ) {
 +                      IndexLink *cur = &ss->drawobject->indices[node->Index];
 +                      while( cur != 0 && cur->element != -1 ) {
-               sculpt_clip(sd, co, val);
++                              sculpt_clip(sd, ss, &buffer[cur->element*3], val);
 +                              cur = cur->next;
 +                      }
 +              }
 +
+               sculpt_clip(sd, ss, co, val);
  
                node= node->next;
        }
 +      if( buffer != 0 )
 +              GPU_buffer_unlock( ss->drawobject->vertices );
  }
  
- static void do_inflate_brush(Sculpt *s, const ListBase *active_verts)
+ static void do_inflate_brush(Sculpt *s, SculptSession *ss, const ListBase *active_verts)
  {
        ActiveData *node= active_verts->first;
-       SculptSession *ss = s->session;
        float add[3];
 -      
 +      float *buffer = (float *)GPU_buffer_lock( ss->drawobject->vertices );
 +
        while(node) {
                float *co= ss->mvert[node->Index].co;
                short *no= ss->mvert[node->Index].no;
                add[2]*= ss->cache->scale[2];
                VecAddf(add, add, co);
                
-                               sculpt_clip(s, &buffer[cur->element*3], add);
 +              if( buffer != 0 ) {
 +                      IndexLink *cur = &ss->drawobject->indices[node->Index];
 +                      while( cur != 0 && cur->element != -1 ) {
-               sculpt_clip(s, co, add);
++                              sculpt_clip(s, ss, &buffer[cur->element*3], add);
 +                              cur = cur->next;
 +                      }
 +              }
 +
+               sculpt_clip(s, ss, co, add);
  
                node= node->next;
        }
@@@ -602,52 -547,53 +618,65 @@@ static void do_flatten_clay_brush(Sculp
        ActiveData *node= active_verts->first;
        /* area_normal and cntr define the plane towards which vertices are squashed */
        float area_normal[3];
-       float cntr[3];
+       float cntr[3], cntr2[3], bstr;
+       int flip = 0;
 -
 +      float *buffer;
-       calc_area_normal(sd, area_normal, active_verts);
+       calc_area_normal(sd, ss, area_normal, active_verts);
        calc_flatten_center(ss, node, cntr);
  
-       buffer = (float *)GPU_buffer_lock( ss->drawobject->vertices );
+       if(clay) {
+               bstr= brush_strength(sd, ss->cache);
+               /* Limit clay application to here */
+               cntr2[0]=cntr[0]+area_normal[0]*bstr*ss->cache->scale[0];
+               cntr2[1]=cntr[1]+area_normal[1]*bstr*ss->cache->scale[1];
+               cntr2[2]=cntr[2]+area_normal[2]*bstr*ss->cache->scale[2];
+               flip = bstr < 0;
+       }
 -      
++
++      buffer = (float *)GPU_buffer_lock( ss->drawobject->vertices );  
++
        while(node){
                float *co= ss->mvert[node->Index].co;
-               float p1[3], sub1[3], sub2[3], intr[3], val[3];
-               
-               /* Find the intersection between squash-plane and vertex (along the area normal) */
-               VecSubf(p1, co, area_normal);
-               VecSubf(sub1, cntr, p1);
-               VecSubf(sub2, co, p1);
-               VecSubf(intr, co, p1);
-               VecMulf(intr, Inpf(area_normal, sub1) / Inpf(area_normal, sub2));
-               VecAddf(intr, intr, p1);
-               
-               VecSubf(val, intr, co);
-               VecMulf(val, fabs(node->Fade));
-               VecAddf(val, val, co);
+               float intr[3], val[3];
                
-               if(clay) {
-                       /* Clay brush displaces after flattening */
-                       float tmp[3];
-                       VecCopyf(tmp, area_normal);
-                       VecMulf(tmp, ss->cache->radius * node->Fade * 0.1);
-                       VecAddf(val, val, tmp);
-               }
+               if(!clay || plane_point_side(co, area_normal, cntr2, flip)) {
+                       /* Find the intersection between squash-plane and vertex (along the area normal) */             
+                       point_plane_project(intr, co, area_normal, cntr);
  
-               if( buffer != 0 ) {
-                       IndexLink *cur = &ss->drawobject->indices[node->Index];
-                       while( cur != 0 && cur->element != -1 ) {
-                               sculpt_clip(sd, &buffer[cur->element*3], val);
-                               cur = cur->next;
+                       VecSubf(val, intr, co);
+                       if(clay) {
+                               if(bstr > FLT_EPSILON)
+                                       VecMulf(val, node->Fade / bstr);
+                               else
+                                       VecMulf(val, node->Fade);
+                               /* Clay displacement */
+                               val[0]+=area_normal[0] * ss->cache->scale[0]*node->Fade;
+                               val[1]+=area_normal[1] * ss->cache->scale[1]*node->Fade;
+                               val[2]+=area_normal[2] * ss->cache->scale[2]*node->Fade;
                        }
-               }
+                       else
+                               VecMulf(val, fabs(node->Fade));
+                       VecAddf(val, val, co);
++                      if( buffer != 0 ) {
++                              IndexLink *cur = &ss->drawobject->indices[node->Index];
++                              while( cur != 0 && cur->element != -1 ) {
++                                      sculpt_clip(sd, ss, &buffer[cur->element*3], val);
++                                      cur = cur->next;
++                              }
++                      }                       
+                       sculpt_clip(sd, ss, co, val);
 +
-               sculpt_clip(sd, co, val);
+               }
                
                node= node->next;
        }
 +      if( buffer != 0 )
 +              GPU_buffer_unlock( ss->drawobject->vertices );
  }
-  
  /* Uses symm to selectively flip any axis of a coordinate. */
  static void flip_coord(float out[3], float in[3], const char symm)
  {
@@@ -1099,13 -1015,12 +1124,13 @@@ static struct MultiresModifierData *scu
  
  static void sculpt_update_mesh_elements(bContext *C)
  {
-       SculptSession *ss = CTX_data_tool_settings(C)->sculpt->session;
        Object *ob = CTX_data_active_object(C);
-       DerivedMesh *dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH);
+       SculptSession *ss = ob->sculpt;
        int oldtotvert = ss->totvert;
++      DerivedMesh *dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH);
  
        if((ss->multires = sculpt_multires_active(ob))) {
 -              DerivedMesh *dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH);
 +              //DerivedMesh *dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH);
                ss->totvert = dm->getNumVerts(dm);
                ss->totface = dm->getNumFaces(dm);
                ss->mvert = dm->getVertDataArray(dm, CD_MVERT);
@@@ -1473,16 -1382,14 +1498,16 @@@ static int sculpt_brush_stroke_invoke(b
        return OPERATOR_RUNNING_MODAL;
  }
  
- static void sculpt_restore_mesh(Sculpt *sd)
+ static void sculpt_restore_mesh(Sculpt *sd, SculptSession *ss)
  {
-       SculptSession *ss = sd->session;
        StrokeCache *cache = ss->cache;
+       Brush *brush = paint_brush(&sd->paint);
 +      float *buffer;
        int i;
 -      
 +
        /* Restore the mesh before continuing with anchored stroke */
-       if((sd->brush->flag & BRUSH_ANCHORED) && ss->mesh_co_orig) {
+       if((brush->flag & BRUSH_ANCHORED) && ss->mesh_co_orig) {
 +              buffer = (float *)GPU_buffer_lock( ss->drawobject->normals );
                for(i = 0; i < ss->totvert; ++i) {
                        VecCopyf(ss->mvert[i].co, ss->mesh_co_orig[i]);
                        ss->mvert[i].no[0] = cache->orig_norms[i][0];
index 7d3999db9e8e67f77551373c85d98e4297dd555c,da67bd8707e504916b92423988051f68b7042c54..a4d7ae802f622d33e2f4639d075b0ae8db6dd831
@@@ -641,10 -561,9 +642,10 @@@ void draw_mesh_textured(Scene *scene, V
        draw_textured_begin(scene, v3d, rv3d, ob);
  
        if(ob == scene->obedit) {
 +              glColor4f(1.0f,1.0f,1.0f,1.0f);
                dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, me->edit_mesh);
        } else if(faceselect) {
-               if(G.f & G_WEIGHTPAINT)
+               if(ob->mode & OB_MODE_WEIGHT_PAINT)
                        dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, me, 1);
                else
                        dm->drawMappedFacesTex(dm, draw_tface_mapped__set_draw, me);