[Bf-blender-cvs] [c81a922] soc-2013-paint: Refactor:

Antony Riakiotakis noreply at git.blender.org
Tue Apr 22 17:27:21 CEST 2014


Commit: c81a9223c40ec78630faa76ef66fb442b7af4620
Author: Antony Riakiotakis
Date:   Tue Apr 22 14:04:11 2014 +0300
https://developer.blender.org/rBc81a9223c40ec78630faa76ef66fb442b7af4620

Refactor:

Materials now include a generated texture paint cache. This solves
some irritating issues with calling synchronization functions too
often in many places. Synchronization only occurs in dependency graph
material updates and when we add layers.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/depsgraph.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/subsurf_ccg.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/gpu/intern/gpu_buffers.c
M	source/blender/makesdna/DNA_material_types.h
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_material.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index ee92542..5545692 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1075,12 +1075,11 @@ class TEXTURE_UL_texpaintslots(UIList):
     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
         # assert(isinstance(item, bpy.types.MaterialTextureSlot)
         ma = data
-        slot = item
-        tex = slot.texture if slot else None
+        ima = item
 
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
             # layout.label(text=tex.image.name, translate=False)
-            layout.label(text=tex.name, translate=False, icon_value=icon)
+            layout.label(text=ima.name, translate=False, icon_value=icon)
         elif self.layout_type in {'GRID'}:
             layout.alignment = 'CENTER'
             layout.label(text="")
@@ -1110,7 +1109,7 @@ class VIEW3D_PT_slots_projectpaint(View3DPanel, Panel):
         mat = ob.active_material;
         if mat:
             col.label("Available Paint Slots")
-            col.template_list("TEXTURE_UL_texpaintslots", "", mat, "texture_paint_slots", mat, "active_paint_texture_index", rows=2)
+            col.template_list("TEXTURE_UL_texpaintslots", "", mat, "texture_paint_slots", mat, "paint_active_slot", rows=2)
             #col.label("Only slots with UV mapping and image textures are available")
             
             col.operator_menu_enum("paint.add_texture_paint_slot", "type")
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 69483a3..b3c4dab 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -711,8 +711,12 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
 				if (mf->mat_nr != mat_nr_cache) {
 					if (dm->totmat > 1) {
 						int mat_i = mf->mat_nr;
-						if (dm->mat[mat_i] && dm->mat[mat_i]->texpaintslot && dm->mat[mat_i]->texpaintslot->uvname[0])
-							tf_base = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, dm->mat[mat_i]->texpaintslot->uvname);
+						if (dm->mat[mat_i] && dm->mat[mat_i]->texpaintslot &&
+						    dm->mat[mat_i]->texpaintslot[dm->mat[mat_i]->paint_active_slot].uvname[0])
+						{
+							tf_base = CustomData_get_layer_named(&dm->faceData, CD_MTFACE,
+							                                     dm->mat[mat_i]->texpaintslot[dm->mat[mat_i]->paint_active_slot].uvname);
+						}
 						else
 							tf_base = CustomData_get_layer(&dm->faceData, CD_MTFACE);
 					}
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index ba89e2c..d402a47 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -2477,6 +2477,7 @@ static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id)
 			for (obt = bmain->object.first; obt; obt = obt->id.next) {
 				if (obt->mode & OB_MODE_TEXTURE_PAINT) {
 					obt->recalc |= OB_RECALC_DATA;
+					refresh_object_texpaint_images(obt);
 					lib_id_recalc_data_tag(bmain, &obt->id);
 				}
 			}
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 8cb057e..59ee5d6 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -111,6 +111,11 @@ void BKE_material_free_ex(Material *ma, bool do_id_user)
 		MEM_freeN(ma->nodetree);
 	}
 
+	if (ma->texpaintslot) {
+		MEM_freeN(ma->texpaintslot);
+		ma->tot_slots = 0;
+	}
+
 	if (ma->gpumaterial.first)
 		GPU_material_free(ma);
 }
@@ -268,7 +273,9 @@ Material *localize_material(Material *ma)
 	
 	if (ma->ramp_col) man->ramp_col = MEM_dupallocN(ma->ramp_col);
 	if (ma->ramp_spec) man->ramp_spec = MEM_dupallocN(ma->ramp_spec);
-	
+
+	if (ma->texpaintslot) man->texpaintslot = MEM_dupallocN(man->texpaintslot);
+
 	man->preview = NULL;
 	
 	if (ma->nodetree)
@@ -1293,30 +1300,42 @@ bool get_mtex_slot_valid_texpaint(struct MTex *mtex)
 
 void refresh_texpaint_image_cache(Material *ma)
 {
-	MTex **mtex, *validmtex = NULL;
-
-	short index = 0, i = 0;
+	MTex **mtex;
+	short count = 0;
+	short index = 0, i;
 
 	if (!ma)
 		return;
 
-	ma->texpaintslot = NULL;
+	if (ma->texpaintslot) {
+		MEM_freeN (ma->texpaintslot);
+		ma->texpaintslot = NULL;
+	}
 
-	for(mtex = ma->mtex; i < MAX_MTEX; i++, mtex++) {
+	for(mtex = ma->mtex, i = 0; i < MAX_MTEX; i++, mtex++) {
 		if (get_mtex_slot_valid_texpaint(*mtex)) {
-			if (index++ == ma->paint_active_slot) {
-				ma->texpaintslot = (*mtex);
-				return;
-			}
+			count++;
+		}
+	}
 
-			validmtex = *mtex;
+	ma->tot_slots = count;
+
+	if (count == 0) {
+		ma->paint_active_slot = 0;
+		return;
+	}
+
+	ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
+
+	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);
 		}
 	}
 
-	/* possible to not have selected anything as active texture. Just set to a valid index */
-	if (index > 0) {
-		ma->paint_active_slot = index;
-		ma->texpaintslot = validmtex;
+	if (ma->paint_active_slot >= count) {
+	    ma->paint_active_slot = count - 1;
 	}
 
 	return;
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 31a7314..6a93b3d 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -2305,8 +2305,12 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
 		if (flag & DM_DRAW_USE_TEXPAINT_UV) {
 			if (mat_nr != mat_nr_cache) {
 				if (dm->totmat > 1) {
-					if (dm->mat[mat_nr] && dm->mat[mat_nr]->texpaintslot && dm->mat[mat_nr]->texpaintslot->uvname[0])
-						tf_base = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, dm->mat[mat_nr]->texpaintslot->uvname);
+					if (dm->mat[mat_nr] && dm->mat[mat_nr]->texpaintslot &&
+					    dm->mat[mat_nr]->texpaintslot[dm->mat[mat_nr]->paint_active_slot].uvname[0])
+					{
+						tf_base = CustomData_get_layer_named(&dm->faceData, CD_MTFACE,
+						                                     dm->mat[mat_nr]->texpaintslot[dm->mat[mat_nr]->paint_active_slot].uvname);
+					}
 					else
 						tf_base = CustomData_get_layer(&dm->faceData, CD_MTFACE);
 				}
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 6eab555..2c15a95 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1360,10 +1360,8 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob)
 			Material *ma = give_current_material(ob, i);
 			if (ma) {
 				has_material = true;
-				refresh_texpaint_image_cache(ma);
 				if (!ma->texpaintslot) {
 					proj_paint_add_slot(C, MAP_COL, ma);
-					refresh_texpaint_image_cache(ma);
 				}
 			}
 		}
@@ -1377,7 +1375,6 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob)
 		/* 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);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 851b1f4..77f44c5 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -360,13 +360,13 @@ 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->texpaintslot->tex->ima;
+		ima = ma->texpaintslot[ma->paint_active_slot].ima;
 	}
 
 	return ima;
 }
 
-static MTex *project_paint_face_paint_slot(const ProjPaintState *ps, int face_index)
+static TexPaintSlot *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;
@@ -374,7 +374,7 @@ static MTex *project_paint_face_paint_slot(const ProjPaintState *ps, int face_in
 	else {
 		MFace *mf = ps->dm_mface + face_index;
 		Material *ma = give_current_material(ps->ob, mf->mat_nr + 1);
-		return ma->texpaintslot;
+		return &ma->texpaintslot[ma->paint_active_slot];
 	}
 }
 
@@ -2960,7 +2960,7 @@ static void project_paint_begin(ProjPaintState *ps)
 
 	ProjPaintImage *projIma;
 	Image *tpage_last = NULL, *tpage;
-	MTex *slot_last = NULL, *slot;
+	TexPaintSlot *slot_last = NULL, *slot;
 
 	/* Face vars */
 	MPoly *mpoly_orig;
@@ -3365,7 +3365,7 @@ static void project_paint_begin(ProjPaintState *ps)
 		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)))) {
+		if (is_face_sel && ((slot && (tpage = slot->ima)) || (tpage = project_paint_face_image(ps, face_index)))) {
 			float *v1coSS, *v2coSS, *v3coSS, *v4coSS = NULL;
 
 			v1coSS = ps->screenCoords[mf->v1];
@@ -4833,8 +4833,6 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma)
 		if (mtex) {
 			char imagename[FILE_MAX];
 			char name[TEXNAME_MAX];
-			PointerRNA ptr, idptr;
-			PropertyRNA *prop;
 			Main *bmain = CTX_data_main(C);
 			Image *ima;
 
@@ -4850,19 +4848,6 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma)
 			mtex->mapto = type;
 
 			if (mtex->tex) {
-				/* hook into UI */
-				uiIDContextProperty(C, &ptr, &prop);
-
-				if (prop) {
-					/* when creating new ID blocks, use is already 1, but RNA
-					 * pointer se also increases user, so this compensates it */
-					mtex->tex->id.us--;
-
-					RNA_id_pointer_create(&mtex->tex->id, &idptr);
-					RNA_property_pointer_set(&ptr, prop, idptr);
-					RNA_property_update(C, &ptr, prop);
-				}
-
 				BLI_strncpy(imagename, &ma->id.name[2], FIL

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list