use struct type for VPaintData.vertexcosnos rather then float*.
authorCampbell Barton <ideasman42@gmail.com>
Sat, 15 Dec 2012 16:13:27 +0000 (16:13 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 15 Dec 2012 16:13:27 +0000 (16:13 +0000)
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/editors/sculpt_paint/paint_vertex.c

index 617c4cd2bc8817e7efd009f8051ce85d941be5b1..ed90c63d9493b6c4e2540872b6bc849cb43f5b66 100644 (file)
@@ -105,6 +105,11 @@ struct PBVH;
  *       Also, the mface origindex layer indexes mpolys, not mfaces.
  */
 
+typedef struct DMCoNo {
+       float co[3];
+       float no[3];
+} DMCoNo;
+
 typedef struct DMGridAdjacency {
        int index[4];
        int rotation[4];
@@ -603,7 +608,7 @@ void vDM_ColorBand_store(struct ColorBand *coba);
 /** Simple function to get me->totvert amount of vertices/normals,
  * correctly deformed and subsurfered. Needed especially when vertexgroups are involved.
  * In use now by vertex/weight paint and particles */
-float *mesh_get_mapped_verts_nors(struct Scene *scene, struct Object *ob);
+DMCoNo *mesh_get_mapped_verts_nors(struct Scene *scene, struct Object *ob);
 
 /* */
 DerivedMesh *mesh_get_derived_final(struct Scene *scene, struct Object *ob,
index 6b8baf423183041283ad53bd00d2b26fde6a3dc5..010839764b2e16bf5dead5a57a89637f6dcd3763 100644 (file)
@@ -2334,29 +2334,29 @@ static void make_vertexcosnos__mapFunc(void *userData, int index, const float co
 /* it stores the normals as floats, but they can still be scaled as shorts (32767 = unit) */
 /* in use now by vertex/weight paint and particle generating */
 
-float *mesh_get_mapped_verts_nors(Scene *scene, Object *ob)
+DMCoNo *mesh_get_mapped_verts_nors(Scene *scene, Object *ob)
 {
        Mesh *me = ob->data;
        DerivedMesh *dm;
-       float *vertexcosnos;
+       DMCoNo *vertexcosnos;
        
        /* lets prevent crashing... */
        if (ob->type != OB_MESH || me->totvert == 0)
                return NULL;
        
        dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
-       vertexcosnos = MEM_callocN(6 * sizeof(float) * me->totvert, "vertexcosnos map");
+       vertexcosnos = MEM_callocN(sizeof(DMCoNo) * me->totvert, "vertexcosnos map");
        
        if (dm->foreachMappedVert) {
                dm->foreachMappedVert(dm, make_vertexcosnos__mapFunc, vertexcosnos);
        }
        else {
-               float *fp = vertexcosnos;
+               DMCoNo *v_co_no = vertexcosnos;
                int a;
                
-               for (a = 0; a < me->totvert; a++, fp += 6) {
-                       dm->getVertCo(dm, a, fp);
-                       dm->getVertNo(dm, a, fp + 3);
+               for (a = 0; a < me->totvert; a++, v_co_no++) {
+                       dm->getVertCo(dm, a, v_co_no->co);
+                       dm->getVertNo(dm, a, v_co_no->no);
                }
        }
        
index 76d666c7e27238d0bf31effdd933740b3619d748..073aee1d974379a0160ff3a0cf243859561cd2a7 100644 (file)
@@ -851,12 +851,12 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x
 }
 
 /* whats _dl mean? */
-static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float vert_nor[3],
+static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float co[3],
                                  const float mval[2], const float brush_size_pressure)
 {
        float vertco[2];
 
-       if (ED_view3d_project_float_global(vc->ar, vert_nor, vertco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+       if (ED_view3d_project_float_global(vc->ar, co, vertco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
                float delta[2];
                float dist_squared;
 
@@ -873,24 +873,23 @@ static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float vert_n
 }
 
 static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc,
-                              float vpimat[3][3], const float *vert_nor,
+                              float vpimat[3][3], const DMCoNo *v_co_no,
                               const float mval[2],
                               const float brush_size_pressure, const float brush_alpha_pressure)
 {
-       float strength = calc_vp_strength_dl(vp, vc, vert_nor, mval, brush_size_pressure);
+       float strength = calc_vp_strength_dl(vp, vc, v_co_no->co, mval, brush_size_pressure);
 
        if (strength > 0.0f) {
                float alpha = brush_alpha_pressure * strength;
 
                if (vp->flag & VP_NORMALS) {
                        float dvec[3];
-                       const float *no = vert_nor + 3;
 
                        /* transpose ! */
-                       dvec[2] = dot_v3v3(vpimat[2], no);
+                       dvec[2] = dot_v3v3(vpimat[2], v_co_no->no);
                        if (dvec[2] > 0.0f) {
-                               dvec[0] = dot_v3v3(vpimat[0], no);
-                               dvec[1] = dot_v3v3(vpimat[1], no);
+                               dvec[0] = dot_v3v3(vpimat[0], v_co_no->no);
+                               dvec[1] = dot_v3v3(vpimat[1], v_co_no->no);
 
                                alpha *= dvec[2] / len_v3(dvec);
                        }
@@ -2038,7 +2037,7 @@ struct WPaintData {
        int *indexar;
        int vgroup_active;
        int vgroup_mirror;
-       float *vertexcosnos;
+       DMCoNo *vertexcosnos;
        float wpimat[3][3];
        
        /* variables for auto normalize */
@@ -2286,7 +2285,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
                                ml = me->mloop + mpoly->loopstart;
                                for (i = 0; i < mpoly->totloop; i++, ml++) {
                                        unsigned int vidx = ml->v;
-                                       const float fac = calc_vp_strength_dl(wp, vc, wpd->vertexcosnos + 6 * vidx, mval, brush_size_pressure);
+                                       const float fac = calc_vp_strength_dl(wp, vc, wpd->vertexcosnos[vidx].co, mval, brush_size_pressure);
                                        if (fac > 0.0f) {
                                                dw = dw_func(&me->dvert[vidx], wpi.vgroup_active);
                                                paintweight += dw ? (dw->weight * fac) : 0.0f;
@@ -2312,7 +2311,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
                                unsigned int vidx = ml->v;
 
                                if (me->dvert[vidx].flag) {
-                                       alpha = calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos + 6 * vidx,
+                                       alpha = calc_vp_alpha_dl(wp, vc, wpd->wpimat, &wpd->vertexcosnos[vidx],
                                                                 mval, brush_size_pressure, brush_alpha_pressure);
                                        if (alpha) {
                                                do_weight_paint_vertex(wp, ob, &wpi, vidx, alpha, paintweight);
@@ -2548,7 +2547,7 @@ typedef struct VPaintData {
        ViewContext vc;
        unsigned int paintcol;
        int *indexar;
-       float *vertexcosnos;
+       DMCoNo *vertexcosnos;
        float vpimat[3][3];
 
        /* modify 'me->mcol' directly, since the derived mesh is drawing from this array,
@@ -2696,7 +2695,7 @@ static void vpaint_paint_poly(VPaint *vp, VPaintData *vpd, Object *ob,
        ml = me->mloop + mpoly->loopstart;
        for (i = 0; i < mpoly->totloop; i++, ml++) {
                alpha = calc_vp_alpha_dl(vp, vc, vpd->vpimat,
-                                        vpd->vertexcosnos + 6 * ml->v, mval,
+                                        &vpd->vertexcosnos[ml->v], mval,
                                         brush_size_pressure, brush_alpha_pressure);
                if (alpha > 0.0f) {
                        const int alpha_i = (int)(alpha * 255.0f);