Commit: fc47db0479d4a0ef3d95d5ef6d69fadff9c7437e
Author: Antony Riakiotakis
Date:   Fri Apr 4 21:30:53 2014 +0300
https://developer.blender.org/rBfc47db0479d4a0ef3d95d5ef6d69fadff9c7437e

Texture painting now supports painting on named UV layers but does not
yet display those correctly (still active uv map used for display)

===================================================================

M       source/blender/blenkernel/intern/material.c
M       source/blender/editors/sculpt_paint/paint_image.c
M       source/blender/editors/sculpt_paint/paint_image_proj.c
M       source/blender/editors/sculpt_paint/paint_utils.c
M       source/blender/editors/space_view3d/drawmesh.c
M       source/blender/makesdna/DNA_material_types.h
M       source/blender/makesrna/intern/rna_material.c

===================================================================

diff --git a/source/blender/blenkernel/intern/material.c 
b/source/blender/blenkernel/intern/material.c
index ac10a44..8cb057e 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1300,12 +1300,12 @@ void refresh_texpaint_image_cache(Material *ma)
        if (!ma)
                return;
 
-       ma->texpaintima = NULL;
+       ma->texpaintslot = NULL;
 
        for(mtex = ma->mtex; i < MAX_MTEX; i++, mtex++) {
                if (get_mtex_slot_valid_texpaint(*mtex)) {
-                       if (index++ == ma->texactpaint) {
-                               ma->texpaintima = (*mtex)->tex->ima;
+                       if (index++ == ma->paint_active_slot) {
+                               ma->texpaintslot = (*mtex);
                                return;
                        }
 
@@ -1315,8 +1315,8 @@ void refresh_texpaint_image_cache(Material *ma)
 
        /* possible to not have selected anything as active texture. Just set 
to a valid index */
        if (index > 0) {
-               ma->texactpaint = index;
-               ma->texpaintima = validmtex->tex->ima;
+               ma->paint_active_slot = index;
+               ma->texpaintslot = validmtex;
        }
 
        return;
@@ -1344,7 +1344,7 @@ struct MTex *give_current_texpaint_slot(Material *ma)
 
        for(mtex = ma->mtex; i < MAX_MTEX; i++, mtex++) {
                if (get_mtex_slot_valid_texpaint(*mtex)) {
-                       if (index++ == ma->texactpaint)
+                       if (index++ == ma->paint_active_slot)
                                return (*mtex);
 
                        validmtex = *mtex;
@@ -1353,7 +1353,7 @@ struct MTex *give_current_texpaint_slot(Material *ma)
 
        /* possible to not have selected anything as active texture. Just set 
to a valid index */
        if (index > 0) {
-               ma->texactpaint = index;
+               ma->paint_active_slot = index;
        }
 
        return validmtex;
diff --git a/source/blender/editors/sculpt_paint/paint_image.c 
b/source/blender/editors/sculpt_paint/paint_image.c
index dd3e5e5..29638c8 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1425,7 +1425,7 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob)
                        if (ma) {
                                has_material = true;
                                refresh_texpaint_image_cache(ma);
-                               if (!ma->texpaintima) {
+                               if (!ma->texpaintslot) {
                                        proj_paint_add_slot(C, MAP_COL, ma);
                                        refresh_texpaint_image_cache(ma);
                                }
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c 
b/source/blender/editors/sculpt_paint/paint_image_proj.c
index a414866..2f7e21c 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -219,7 +219,7 @@ typedef struct ProjPaintState {
 
        MVert          *dm_mvert;
        MFace          *dm_mface;
-       MTFace         *dm_mtface;
+       MTFace         **dm_mtface;
        MTFace         *dm_mtface_clone;    /* other UV map, use for cloning 
between layers */
        MTFace         *dm_mtface_stencil;
 
@@ -360,12 +360,25 @@ static Image *project_paint_face_image(const 
ProjPaintState *ps, int face_index)
        else {
                MFace *mf = ps->dm_mface + face_index;
                Material *ma = give_current_material(ps->ob, mf->mat_nr + 1);
-               ima = ma->texpaintima;
+               ima = ma->texpaintslot->tex->ima;
        }
 
        return ima;
 }
 
+static MTex *project_paint_face_paint_slot(const ProjPaintState *ps, int 
face_index)
+{
+       if (ps->do_new_shading_nodes) { /* cached 
BKE_scene_use_new_shading_nodes result */
+               return NULL;
+       }
+       else {
+               MFace *mf = ps->dm_mface + face_index;
+               Material *ma = give_current_material(ps->ob, mf->mat_nr + 1);
+               return ma->texpaintslot;
+       }
+}
+
+
 static Image *project_paint_mtface_image(const ProjPaintState *ps, MTFace 
*dm_mtface, int face_index)
 {
        Image *ima;
@@ -569,7 +582,7 @@ static bool project_paint_PickColor(const ProjPaintState 
*ps, const float pt[2],
        if (face_index == -1)
                return 0;
 
-       tf = ps->dm_mtface + face_index;
+       tf = *(ps->dm_mtface + face_index);
 
        if (side == 0) {
                interp_v2_v2v2v2(uv, tf->uv[0], tf->uv[1], tf->uv[2], w);
@@ -918,7 +931,7 @@ static bool check_seam(const ProjPaintState *ps,
        MFace *mf;
        MTFace *tf;
        const MFace *orig_mf = ps->dm_mface + orig_face;
-       const MTFace *orig_tf = ps->dm_mtface + orig_face;
+       const MTFace *orig_tf = ps->dm_mtface[orig_face];
 
        /* vert indices from face vert order indices */
        i1 = (*(&orig_mf->v1 + orig_i1_fidx));
@@ -946,7 +959,7 @@ static bool check_seam(const ProjPaintState *ps,
                                BLI_assert(i1_fidx != -1);
 
                                /* This IS an adjacent face!, now lets check if 
the UVs are ok */
-                               tf = ps->dm_mtface + face_index;
+                               tf = ps->dm_mtface[face_index];
 
                                /* set up the other face */
                                *other_face = face_index;
@@ -2305,7 +2318,7 @@ static void project_paint_face_init(const ProjPaintState 
*ps, const int thread_i
                      ps->projImages + image_index
                        };
        const MFace *mf = ps->dm_mface + face_index;
-       const MTFace *tf = ps->dm_mtface + face_index;
+       const MTFace *tf = ps->dm_mtface[face_index];
 
        /* UV/pixel seeking data */
        int x; /* Image X-Pixel */
@@ -2947,11 +2960,13 @@ static void project_paint_begin(ProjPaintState *ps)
 
        ProjPaintImage *projIma;
        Image *tpage_last = NULL, *tpage;
+       MTex *slot_last = NULL, *slot;
 
        /* Face vars */
        MPoly *mpoly_orig;
        MFace *mf;
-       MTFace *tf;
+       MTFace **tf;
+       MTFace *tf_base;
 
        int a, i; /* generic looping vars */
        int image_index = -1, face_index;
@@ -3008,7 +3023,7 @@ static void project_paint_begin(ProjPaintState *ps)
 
        ps->dm_mvert = ps->dm->getVertArray(ps->dm);
        ps->dm_mface = ps->dm->getTessFaceArray(ps->dm);
-       ps->dm_mtface = ps->dm->getTessFaceDataArray(ps->dm, CD_MTFACE);
+       ps->dm_mtface = MEM_mallocN(ps->dm->getNumTessFaces(ps->dm) * sizeof 
(MTFace *), "proj_paint_mtfaces");
 
        ps->dm_totvert = ps->dm->getNumVerts(ps->dm);
        ps->dm_totface = ps->dm->getNumTessFaces(ps->dm);
@@ -3038,7 +3053,7 @@ static void project_paint_begin(ProjPaintState *ps)
                if (layer_num != -1)
                        ps->dm_mtface_clone = 
CustomData_get_layer_n(&ps->dm->faceData, CD_MTFACE, layer_num);
 
-               if (ps->dm_mtface_clone == NULL || ps->dm_mtface_clone == 
ps->dm_mtface) {
+               if (ps->dm_mtface_clone == NULL) {
                        ps->do_layer_clone = false;
                        ps->dm_mtface_clone = NULL;
                }
@@ -3050,7 +3065,7 @@ static void project_paint_begin(ProjPaintState *ps)
                if (layer_num != -1)
                        ps->dm_mtface_stencil = 
CustomData_get_layer_n(&ps->dm->faceData, CD_MTFACE, layer_num);
 
-               if (ps->dm_mtface_stencil == NULL || ps->dm_mtface_stencil == 
ps->dm_mtface) {
+               if (ps->dm_mtface_stencil == NULL) {
                        ps->do_layer_stencil = false;
                        ps->dm_mtface_stencil = NULL;
                }
@@ -3328,7 +3343,25 @@ static void project_paint_begin(ProjPaintState *ps)
                        is_face_sel = true;
                }
 
-               if (is_face_sel && (tpage = project_paint_face_image(ps, 
face_index))) {
+               slot = project_paint_face_paint_slot(ps, face_index);
+               if (slot) {
+                       if (slot != slot_last) {
+                               if (slot->uvname[0])
+                                       tf_base = 
CustomData_get_layer_named(&ps->dm->faceData, CD_MTFACE, slot->uvname);
+                               else
+                                       tf_base = 
CustomData_get_layer(&ps->dm->faceData, CD_MTFACE);
+                               *tf = tf_base + face_index;
+                       }
+                       else {
+                               *tf = tf_base + face_index;
+                       }
+
+                       /* tfbase here should be non-null! */
+                       if (ps->dm_mtface_stencil == tf_base || 
ps->dm_mtface_clone == tf_base)
+                               continue;
+               }
+
+               if (is_face_sel && ((slot && (tpage = slot->tex->ima)) || 
(tpage = project_paint_face_image(ps, face_index)))) {
                        float *v1coSS, *v2coSS, *v3coSS, *v4coSS = NULL;
 
                        v1coSS = ps->screenCoords[mf->v1];
@@ -3478,6 +3511,7 @@ static void project_paint_end(ProjPaintState *ps)
        MEM_freeN(ps->bucketRect);
        MEM_freeN(ps->bucketFaces);
        MEM_freeN(ps->bucketFlags);
+       MEM_freeN(ps->dm_mtface);
 
 #ifndef PROJ_DEBUG_NOSEAMBLEED
        if (ps->seam_bleed_px > 0.0f) {
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c 
b/source/blender/editors/sculpt_paint/paint_utils.c
index 8d5d443..c78263e 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -365,7 +365,7 @@ static Image *imapaint_face_image(DerivedMesh *dm, Scene 
*scene, Object *ob, int
        else {
                MFace *mf = dm_mface + face_index;
                Material *ma = give_current_material(ob, mf->mat_nr + 1);
-               ima = ma->texpaintima;
+               ima = ma->texpaintslot->tex->ima;
        }
 
        return ima;
diff --git a/source/blender/editors/space_view3d/drawmesh.c 
b/source/blender/editors/space_view3d/drawmesh.c
index 2550bc5..260b571 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -274,7 +274,7 @@ static bool set_draw_settings_cached(int clearcache, MTFace 
*texface, Material *
                        alphablend = GPU_BLEND_ALPHA;
        }
        else if (texpaint && ma) {
-               ima = ma->texpaintima;
+               ima = ma->texpaintslot->tex->ima;
        }
        else
                textured = 0;
@@ -295,7 +295,7 @@ static bool set_draw_settings_cached(int clearcache, MTFace 
*texface, Material *
                if (textured) {
                        if (texpaint) {
                                c_badtex = false;
-                               if(GPU_verify_image(ima, NULL, 0, 1, 0, false)) 
{
+                               if (GPU_verify_image(ima, NULL, 0, 1, 0, 
false)) {
                                        glEnable(GL_TEXTURE_2D);
                                }
                                else {
diff --git a/source/blender/makesdna/DNA_material_types.h 
b/source/blender/makesdna/DNA_material_types.h
index b9c262a..9612cf3 100644
--- a/source/blender/makesdna/DNA_material_types.h
+++ b/source/blender/makesdna/DNA_material_types.h
@@ -136,9 +136,9 @@ typedef struct Material {
        char mapflag;
 
        /* texture painting */
-       char texactpaint;
-       struct Image *texpaintima; /* cached image for painting. Make sure to 
recalculate before use
-                                   * with refresh_texpaint_image_cache */
+       char paint_active_slot;
+       struct MTex *texpaintslot; /* cached slot for painting. Make sure to 
recalculate before use
+                                   * with refresh_texpaint_image_slot */
 
        /* shaders */
        short diff_shader, spec_shader;
diff --git a/source/blender/makesrna/intern/rna_material.c 
b/source/blender/makesrna/intern/rna_material.c
index 457a58d..85c4dd1 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -194,7 +194,7 @@ static void 
rna_Material_active_paint_texture_index_update(Main *bmain, Scene *s
                        for (sl = sa->spacedata.first; sl; sl = sl->next) {
                                if (sl->spacetype == SPACE_IMAGE) {
                                                SpaceImage *sima = (SpaceImage 
*)sl;
-                                               ED_space_image_set(sima, scene, 
scene->obedit, ma->texpainti

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to