Texture painting:
authorAntony Riakiotakis <kalast@gmail.com>
Wed, 23 Jul 2014 18:06:29 +0000 (20:06 +0200)
committerAntony Riakiotakis <kalast@gmail.com>
Wed, 23 Jul 2014 18:06:41 +0000 (20:06 +0200)
Add ability to select UV layer from the layer panel.

release/scripts/startup/bl_ui/space_view3d_toolbar.py
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/material.c
source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/sculpt_paint/paint_utils.c
source/blender/editors/uvedit/uvedit_draw.c
source/blender/makesdna/DNA_material_types.h
source/blender/makesrna/intern/rna_internal.h
source/blender/makesrna/intern/rna_material.c

index e68ae62a57b254f4fbfc7fa9a6688d95a8ea40e5..6dd3ef27deb581f8f8264e4d1e1e1132d96d55e0 100644 (file)
@@ -1076,7 +1076,7 @@ class VIEW3D_PT_slots_projectpaint(View3DPanel, Panel):
         if mat:
             col.label("Available Paint Slots")
             col.template_list("TEXTURE_UL_texpaintslots", "",
-                              mat, "texture_paint_slots",
+                              mat, "texture_paint_images",
                               mat, "paint_active_slot", rows=2)
 
             if not mat.use_nodes:
@@ -1087,6 +1087,11 @@ class VIEW3D_PT_slots_projectpaint(View3DPanel, Panel):
                 row.prop(settings, "slot_yresolution_default")
                 col.prop(settings, "slot_color_default")
 
+                slot = mat.texture_paint_slots[mat.paint_active_slot]
+                col.separator()
+                col.label("UV Layer")
+                col.prop_search(slot, "uv_layer", ob.data, "uv_textures", text="")
+
 
 class VIEW3D_PT_tools_brush_overlay(Panel, View3DPaintPanel):
     bl_category = "Options"
index bdfaf9a1be9695cf21c71330b32935178756c097..c3e8d2a98af22c9dcf8bb36b131fc2ad29d0e8d2 100644 (file)
@@ -517,7 +517,7 @@ MTFace *DM_paint_uvlayer_active_get(DerivedMesh *dm, int mat_nr)
        BLI_assert(mat_nr < dm->totmat);
 
        if (dm->mat[mat_nr] && dm->mat[mat_nr]->texpaintslot &&
-           dm->mat[mat_nr]->texpaintslot[dm->mat[mat_nr]->paint_active_slot].uvname[0])
+           dm->mat[mat_nr]->texpaintslot[dm->mat[mat_nr]->paint_active_slot].uvname)
        {
                tf_base = CustomData_get_layer_named(&dm->faceData, CD_MTFACE,
                                                     dm->mat[mat_nr]->texpaintslot[dm->mat[mat_nr]->paint_active_slot].uvname);
index 27330fb8db3a0a5208e3e8429e29363701c60507..b4ab464838e774821d402a0cf4f33e22c86f98a0 100644 (file)
@@ -1388,7 +1388,7 @@ void BKE_texpaint_slot_refresh_cache(Material *ma, bool use_nodes)
                for (mtex = ma->mtex, i = 0; i < MAX_MTEX; i++, mtex++) {
                        if (get_mtex_slot_valid_texpaint(*mtex)) {
                                ma->texpaintslot[index].ima = (*mtex)->tex->ima;
-                               BLI_strncpy(ma->texpaintslot[index++].uvname, (*mtex)->uvname, 64);
+                               ma->texpaintslot[index++].uvname = (*mtex)->uvname;
                        }
                }
        }
index 1f0b2c80fc420b24bb83161c41a761209f723378..5c1af41e05d7de13527a513a9a04b36538852dc9 100644 (file)
@@ -3292,7 +3292,7 @@ static void project_paint_begin(ProjPaintState *ps)
                                continue;
 
                        if (slot != slot_last) {
-                               if (!slot->uvname[0] || !(tf_base = CustomData_get_layer_named(&ps->dm->faceData, CD_MTFACE, slot->uvname)))
+                               if (!slot->uvname || !(tf_base = CustomData_get_layer_named(&ps->dm->faceData, CD_MTFACE, slot->uvname)))
                                        tf_base = CustomData_get_layer(&ps->dm->faceData, CD_MTFACE);
                                slot_last = slot;
                        }
@@ -3313,7 +3313,7 @@ static void project_paint_begin(ProjPaintState *ps)
                        tf_clone = ps->dm_mtface_clone + face_index;
 
                        if (slot_clone != slot_last_clone) {
-                               if (!slot_clone->uvname[0] || !(tf_clone_base = CustomData_get_layer_named(&ps->dm->faceData, CD_MTFACE, slot_clone->uvname)))
+                               if (!slot->uvname || !(tf_clone_base = CustomData_get_layer_named(&ps->dm->faceData, CD_MTFACE, slot_clone->uvname)))
                                        tf_clone_base = CustomData_get_layer(&ps->dm->faceData, CD_MTFACE);
                                slot_last_clone = slot_clone;
                        }
index eaa4885572e1e5a48d212ef4e4eac5c0646635e2..0d463172f99146bc2e3b9b0f733d25dc054efd7f 100644 (file)
@@ -312,7 +312,7 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
                        if (mf.v4)
                                dm->getVert(dm, mf.v4, &mv[3]);
 
-                       if (!slot->uvname[0] || !(tf_base = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, slot->uvname)))
+                       if (!slot->uvname || !(tf_base = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, slot->uvname)))
                                tf_base = CustomData_get_layer(&dm->faceData, CD_MTFACE);
 
                        tf = &tf_base[a];
index 0f605429187c310150672ff995b9cb78040dcf8e..36c96a8d0117097fda609099a1160672f258c02f 100644 (file)
@@ -497,7 +497,7 @@ static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob)
                MPoly *mpoly = me->mpoly;
                MLoopUV *mloopuv, *mloopuv_base;
                int a, b;
-               if (!(ma && ma->texpaintslot && ma->texpaintslot[ma->paint_active_slot].uvname[0] &&
+               if (!(ma && ma->texpaintslot && ma->texpaintslot[ma->paint_active_slot].uvname &&
                      (mloopuv = CustomData_get_layer_named(&me->ldata, CD_MLOOPUV, ma->texpaintslot[ma->paint_active_slot].uvname))))
                {
                        mloopuv = me->mloopuv;
index 02d1103c08e7145af668dea9a9390936f8dceac2..ba617baa4e0c9fdce7db74ba079a51e111f0812c 100644 (file)
@@ -85,7 +85,7 @@ typedef struct GameSettings {
 
 typedef struct TexPaintSlot {
        struct Image *ima; /* image to be painted on */
-       char uvname[64]; /* customdata index for uv layer, MAX_NAME*/
+       char *uvname; /* customdata index for uv layer, MAX_NAME*/
 } TexPaintSlot;
 
 typedef struct Material {
index 9a1053b46662dfe165be27cc001015d1059a1ca2..e3179077cf4411e57c3c2e25b7b7bdae37c4e761 100644 (file)
@@ -202,7 +202,7 @@ void rna_def_texmat_common(struct StructRNA *srna, const char *texspace_editable
 void rna_def_mtex_common(struct BlenderRNA *brna, struct StructRNA *srna, const char *begin, const char *activeget,
                          const char *activeset, const char *activeeditable, const char *structname,
                          const char *structname_slots, const char *update, const char *update_index);
-void rna_def_mtex_texpaint(struct StructRNA *srna);
+void rna_def_texpaint_slots(struct BlenderRNA *brna, struct StructRNA *srna);
 void rna_def_render_layer_common(struct StructRNA *srna, int scene);
 
 void rna_def_actionbone_group_common(struct StructRNA *srna, int update_flag, const char *update_cb);
index 46c5cc770b8d2d55b2a37bbe9af21fb15ac9d664..bd870685a737662359fc0afaff1b0ca220c6fbd6 100644 (file)
@@ -2107,7 +2107,7 @@ void RNA_def_material(BlenderRNA *brna)
                            "rna_Material_active_texture_set", "rna_Material_active_texture_editable",
                            "MaterialTextureSlot", "MaterialTextureSlots", "rna_Material_update", "rna_Material_update");
 
-       rna_def_mtex_texpaint(srna);
+       rna_def_texpaint_slots(brna, srna);
 
        /* only material has this one */
        prop = RNA_def_property(srna, "use_textures", PROP_BOOLEAN, PROP_NONE);
@@ -2197,16 +2197,42 @@ void rna_def_mtex_common(BlenderRNA *brna, StructRNA *srna, const char *begin,
        RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, update_index);
 }
 
-void rna_def_mtex_texpaint(StructRNA *srna)
+static void rna_def_tex_slot(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+       srna = RNA_def_struct(brna, "TexPaintSlot", NULL);
+       RNA_def_struct_ui_text(srna, "Texture Paint Slot",
+                              "Slot that contains information about texture painting");
+
+       prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
+       RNA_def_property_string_maxlength(prop, 64); /* else it uses the pointer size! */
+       RNA_def_property_string_sdna(prop, NULL, "uvname");
+       RNA_def_property_ui_text(prop, "UV Map", "Name of UV map");
+       RNA_def_property_update(prop, 0, "rna_Material_update");
+}
+
+
+void rna_def_texpaint_slots(BlenderRNA *brna, StructRNA *srna)
 {
        PropertyRNA *prop;
 
+       rna_def_tex_slot(brna);
+
        /* mtex */
-       prop = RNA_def_property(srna, "texture_paint_slots", PROP_COLLECTION, PROP_NONE);
+       prop = RNA_def_property(srna, "texture_paint_images", PROP_COLLECTION, PROP_NONE);
+       RNA_def_property_collection_sdna(prop, NULL, "texpaintslot", NULL);
        RNA_def_property_collection_funcs(prop, "rna_Material_texpaint_begin", "rna_iterator_array_next", "rna_iterator_array_end",
                                          "rna_iterator_array_dereference_get", NULL, NULL, NULL, NULL);
        RNA_def_property_struct_type(prop, "Image");
-       RNA_def_property_ui_text(prop, "Textures", "Texture slots defining the mapping and influence of textures");
+       RNA_def_property_ui_text(prop, "Texture Slot Images", "Texture images used for texture painting");
+
+       prop = RNA_def_property(srna, "texture_paint_slots", PROP_COLLECTION, PROP_NONE);
+       RNA_def_property_collection_funcs(prop, "rna_Material_texpaint_begin", "rna_iterator_array_next", "rna_iterator_array_end",
+                                         "rna_iterator_array_get", NULL, NULL, NULL, NULL);
+       RNA_def_property_struct_type(prop, "TexPaintSlot");
+       RNA_def_property_ui_text(prop, "Texture Slots", "Texture slots defining the mapping and influence of textures");
 
        prop = RNA_def_property(srna, "paint_active_slot", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_range(prop, 0, INT_MAX);
@@ -2219,5 +2245,4 @@ void rna_def_mtex_texpaint(StructRNA *srna)
        RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, NULL);
 }
 
-
 #endif