Commit: ec81d2bd1d0c382b239251ac068512b71d1b30de
Author: Antony Riakiotakis
Date:   Wed Mar 12 14:47:28 2014 +0200
https://developer.blender.org/rBec81d2bd1d0c382b239251ac068512b71d1b30de

* Correct icon for strength space attenuation.
* Finish data ensurance code for texture paint. On entering projective texture
paint mode, a uv layer, material and diffuse slot will be generated to paint
on if they are missing.

I am not totally happy with how the paint images are cached on the material.
It may be better to store in a per object paint session or toolsetting imapaint
struct. Still this works.

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

M       release/scripts/startup/bl_ui/space_image.py
M       release/scripts/startup/bl_ui/space_view3d_toolbar.py
M       source/blender/blenkernel/BKE_blender.h
M       source/blender/blenkernel/intern/material.c
M       source/blender/blenloader/intern/versioning_270.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_intern.h
M       source/blender/editors/sculpt_paint/paint_ops.c
M       source/blender/makesdna/DNA_scene_types.h
M       source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/scripts/startup/bl_ui/space_image.py 
b/release/scripts/startup/bl_ui/space_image.py
index 69852ae..c21b737 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -763,10 +763,7 @@ class IMAGE_PT_paint(Panel, ImagePaintPanel):
             row = col.row(align=True)
 
             if capabilities.has_space_attenuation:
-                if brush.use_space_attenuation:
-                    row.prop(brush, "use_space_attenuation", toggle=True, 
text="", icon='LOCKED')
-                else:
-                    row.prop(brush, "use_space_attenuation", toggle=True, 
text="", icon='UNLOCKED')
+                row.prop(brush, "use_space_attenuation", toggle=True, 
icon_only=True)
 
             self.prop_unified_strength(row, context, brush, "strength", 
slider=True, text="Strength")
             self.prop_unified_strength(row, context, brush, 
"use_pressure_strength")
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py 
b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 518dfcd..b97f950 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -955,10 +955,7 @@ class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
             row = col.row(align=True)
             
             if capabilities.has_space_attenuation:
-                if brush.use_space_attenuation:
-                    row.prop(brush, "use_space_attenuation", toggle=True, 
text="", icon='LOCKED')
-                else:
-                    row.prop(brush, "use_space_attenuation", toggle=True, 
text="", icon='UNLOCKED')
+                row.prop(brush, "use_space_attenuation", toggle=True, 
icon_only=True)
 
             self.prop_unified_strength(row, context, brush, "strength", 
text="Strength")
             self.prop_unified_strength(row, context, brush, 
"use_pressure_strength")
@@ -1057,11 +1054,11 @@ class VIEW3D_PT_layers_projectpaint(View3DPanel, Panel):
             col.template_list("TEXTURE_UL_texpaintslots", "", mat, 
"texture_paint_slots", mat, "active_paint_texture_index", rows=2)
             #col.label("Only slots with UV mapping and image textures are 
available")
             
-            col.operator_menu_enum("paint.add_layer", "type")
+            col.operator_menu_enum("paint.add_texture_paint_slot", "type")
         
         row = col.row(align=True)
-        row.prop(settings, "new_layer_xresolution")
-        row.prop(settings, "new_layer_yresolution")
+        row.prop(settings, "new_slot_xresolution")
+        row.prop(settings, "new_slot_yresolution")
 
 
 class VIEW3D_PT_tools_brush_overlay(Panel, View3DPaintPanel):
diff --git a/source/blender/blenkernel/BKE_blender.h 
b/source/blender/blenkernel/BKE_blender.h
index 415a912..3eb2fab 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         270
-#define BLENDER_SUBVERSION      0
+#define BLENDER_SUBVERSION      1
 /* 262 was the last editmesh release but it has compatibility code for bmesh 
data */
 #define BLENDER_MINVERSION      262
 #define BLENDER_MINSUBVERSION   0
diff --git a/source/blender/blenkernel/intern/material.c 
b/source/blender/blenkernel/intern/material.c
index 85ba444..9ee2c83 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1306,6 +1306,8 @@ void refresh_texpaint_image_cache(Material *ma)
        if (!ma)
                return;
 
+       ma->texpaintima = NULL;
+
        for(mtex = ma->mtex; i < MAX_MTEX; i++, mtex++) {
                if (get_mtex_slot_valid_texpaint(*mtex)) {
                        if (index++ == ma->texactpaint) {
diff --git a/source/blender/blenloader/intern/versioning_270.c 
b/source/blender/blenloader/intern/versioning_270.c
index 30d8bf4..6ddd0d2 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -109,4 +109,12 @@ void blo_do_versions_270(FileData *fd, Library 
*UNUSED(lib), Main *main)
                        }
                }
        }
+
+       if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
+               Scene *sce;
+               for (sce = main->scene.first; sce; sce = sce->id.next) {
+                       sce->toolsettings->imapaint.new_slot_xresolution = 1024;
+                       sce->toolsettings->imapaint.new_slot_yresolution = 1024;
+               }
+       }
 }
diff --git a/source/blender/editors/sculpt_paint/paint_image.c 
b/source/blender/editors/sculpt_paint/paint_image.c
index de53186..5f6cdb9 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1388,13 +1388,61 @@ static int texture_paint_toggle_poll(bContext *C)
        return 1;
 }
 
+
+/* Make sure that active object has a material, and assign UVs and image 
layers (TODO) if they do not exist */
+void paint_proj_mesh_data_ensure(bContext *C, Object *ob)
+{
+       Mesh *me;
+       int layernum;
+       bool add_material = false;
+
+       /* no material, add one */
+       if (ob->totcol == 0) {
+               add_material = true;
+       }
+       else {
+               /* there may be material slots but they may be empty, check */
+               bool has_material = false;
+               int i;
+
+               for (i = 1; i < ob->totcol + 1; i++) {
+                       Material *ma = give_current_material(ob, i);
+                       if (ma) {
+                               has_material = true;
+                               refresh_texpaint_image_cache(ma);
+                               if (!ma->texpaintima) {
+                                       proj_paint_add_slot(C, MAP_COL, ma);
+                                       refresh_texpaint_image_cache(ma);
+                               }
+                       }
+               }
+
+               if (!has_material)
+                       add_material = true;
+       }
+
+       if (add_material) {
+               Material *ma = BKE_material_add(CTX_data_main(C), "Material");
+               /* no material found, just assign to first slot */
+               assign_material(ob, ma, 1, BKE_MAT_ASSIGN_USERPREF);
+               proj_paint_add_slot(C, MAP_COL, ma);
+               refresh_texpaint_image_cache(ma);
+       }
+
+       me = BKE_mesh_from_object(ob);
+       layernum = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
+
+       if (layernum == 0) {
+               ED_mesh_uv_texture_add(me, "UVMap", true);
+       }
+}
+
 static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
        Object *ob = CTX_data_active_object(C);
        const int mode_flag = OB_MODE_TEXTURE_PAINT;
        const bool is_mode_set = (ob->mode & mode_flag) != 0;
-       Mesh *me;
 
        if (!is_mode_set) {
                if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
@@ -1402,8 +1450,6 @@ static int texture_paint_toggle_exec(bContext *C, 
wmOperator *op)
                }
        }
 
-       me = BKE_mesh_from_object(ob);
-
        if (ob->mode & mode_flag) {
                ob->mode &= ~mode_flag;
 
@@ -1414,20 +1460,10 @@ static int texture_paint_toggle_exec(bContext *C, 
wmOperator *op)
                toggle_paint_cursor(C, 0);
        }
        else {
-               /* Make sure that active object has a material, and assign UVs 
and image layers (TODO) if they do not exist */
-
-               /* no material, add one */
-               if (ob->totcol == 0) {
-                       Material *ma = BKE_material_add(CTX_data_main(C), 
"Material");
-                       assign_material(ob, ma, 1, BKE_MAT_ASSIGN_USERPREF);
-               }
+               paint_proj_mesh_data_ensure(C, ob);
 
                ob->mode |= mode_flag;
 
-               if (me->mtface == NULL)
-                       me->mtface = CustomData_add_layer(&me->fdata, 
CD_MTFACE, CD_DEFAULT,
-                                                         NULL, me->totface);
-
                BKE_paint_init(&scene->toolsettings->imapaint.paint, 
PAINT_CURSOR_TEXTURE_PAINT);
 
                if (U.glreslimit != 0)
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c 
b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 60ffee1..711b25e 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4448,7 +4448,9 @@ static void project_state_init(bContext *C, Object *ob, 
ProjPaintState *ps, int
 void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int 
mode)
 {
        ProjPaintState *ps = MEM_callocN(sizeof(ProjPaintState), 
"ProjectionPaintState");
-       refresh_object_texpaint_images(ob);
+
+       paint_proj_mesh_data_ensure(C, ob);
+
        project_state_init(C, ob, ps, mode);
 
        if (ps->tool == PAINT_TOOL_CLONE && mode == BRUSH_STROKE_INVERT) {
@@ -4746,28 +4748,29 @@ static EnumPropertyItem layer_type_items[] = {
        {0, NULL, 0, NULL, NULL}
 };
 
-static int texture_paint_add_layer_exec(bContext *C, wmOperator *op)
+bool proj_paint_add_slot(bContext *C, int type, Material *ma)
 {
-       Material *ma;
        Object *ob = CTX_data_active_object(C);
        float color[4] = {0.0, 0.0, 0.0, 1.0};
        int i;
        ImagePaintSettings *imapaint = &CTX_data_tool_settings(C)->imapaint;
-       int width = imapaint->new_layer_xresolution;
-       int height = imapaint->new_layer_yresolution;
-
-       int type = RNA_enum_get(op->ptr, "type");
+       int width;
+       int height;
 
        if (!ob)
-               return OPERATOR_CANCELLED;
+               return false;
 
-       /* unlikely, but just in case */
-       if (width * height == 0) {
-               BKE_report(op->reports, RPT_ERROR, "New layer dimensions need 
to be greater than 0");
-               return OPERATOR_CANCELLED;
-       }
+       /* should not be allowed, but just in case */
+       if (imapaint->new_slot_xresolution == 0)
+               imapaint->new_slot_xresolution = 1024;
+       if (imapaint->new_slot_yresolution == 0)
+               imapaint->new_slot_yresolution = 1024;
 
-       ma = give_current_material(ob, ob->actcol);
+       width = imapaint->new_slot_xresolution;
+       height = imapaint->new_slot_yresolution;
+
+       if (!ma)
+               ma = give_current_material(ob, ob->actcol);
 
        if (ma) {
                MTex *mtex = add_mtex_id(&ma->id, -1);
@@ -4798,7 +4801,7 @@ static int texture_paint_add_layer_exec(bContext *C, 
wmOperator *op)
 
                                if (prop) {
                                        /* when creating new ID blocks, use is 
already 1, but RNA
-                                    * pointer se also increases user, so this 
compensates it */
+                                        * pointer se also increases user, so 
this compensates it */
                                        mtex->tex->id.us--;
 
                                        RNA_id_pointer_create(&mtex->tex->id, 
&idptr);
@@ -4817,7 +4820,7 @@ static int texture_paint_add_layer_exec(bContext *C, 
wmOperator *op)
 
                                if (prop) {
                                        /* when creating new ID blocks, use is 
already 1, but RNA
-                                    * pointer se also increases user, so this 
compensates it */
+                                        * pointer se also increases user, so 
this compensates it */
                                        ima->id.us--;
 
                                        RNA_id_pointer_create(&ima->id, &idptr);
@@ -4830,22 +4833,29 @@ static int texture_paint_add_layer_exec(b

@@ 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