[Bf-blender-cvs] [969e003] soc-2013-paint: First round of code review requests by Campbell

Antony Riakiotakis noreply at git.blender.org
Tue Apr 29 16:51:30 CEST 2014


Commit: 969e00386daaf2078ddbdfb56e053057750943f9
Author: Antony Riakiotakis
Date:   Tue Apr 29 17:51:22 2014 +0300
https://developer.blender.org/rB969e00386daaf2078ddbdfb56e053057750943f9

First round of code review requests by Campbell

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
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_ops.c
M	source/blender/editors/sculpt_paint/paint_utils.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_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index f73e32e..a433724 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1128,9 +1128,9 @@ class VIEW3D_PT_slots_projectpaint(View3DPanel, Panel):
                 col.operator_menu_enum("paint.add_texture_paint_slot", "type")
 
                 row = col.row(align=True)
-                row.prop(settings, "new_slot_xresolution")
-                row.prop(settings, "new_slot_yresolution")
-                col.prop(settings, "new_layer_color")
+                row.prop(settings, "slot_xresolution_default")
+                row.prop(settings, "slot_yresolution_default")
+                col.prop(settings, "slot_color_default")
                 
             if brush.image_tool == 'CLONE' and settings.use_clone_layer:
                 col.label("Clone Slot")
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 58acfd6..0077c6f 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1396,13 +1396,13 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob)
 		float color[4] = {0.0, 0.0, 0.0, 1.0};
 
 		/* 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;
+		if (imapaint->slot_xresolution_default == 0)
+			imapaint->slot_xresolution_default = 1024;
+		if (imapaint->slot_yresolution_default == 0)
+			imapaint->slot_yresolution_default = 1024;
 
-		width = imapaint->new_slot_xresolution;
-		height = imapaint->new_slot_yresolution;
+		width = imapaint->slot_xresolution_default;
+		height = imapaint->slot_yresolution_default;
 		imapaint->stencil = BKE_image_add_generated(bmain, width, height, "Stencil", 32, false, IMA_GENTYPE_BLANK, color);
 		imapaint->flag |= IMAGEPAINT_PROJECT_LAYER_STENCIL;
 	}
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 9c99007..15a40c0 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4794,13 +4794,13 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma)
 		return false;
 
 	/* 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;
+	if (imapaint->slot_xresolution_default == 0)
+		imapaint->slot_xresolution_default = 1024;
+	if (imapaint->slot_yresolution_default == 0)
+		imapaint->slot_yresolution_default = 1024;
 
-	width = imapaint->new_slot_xresolution;
-	height = imapaint->new_slot_yresolution;
+	width = imapaint->slot_xresolution_default;
+	height = imapaint->slot_yresolution_default;
 
 	if (!ma)
 		ma = give_current_material(ob, ob->actcol);
@@ -4835,7 +4835,7 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma)
 					float color[4];
 					bool use_float = type == MAP_NORM;
 
-					copy_v4_v4(color, imapaint->new_layer_col);
+					copy_v4_v4(color, imapaint->slot_color_default);
 					if (use_float) {
 						mul_v3_fl(color, color[3]);
 					}
@@ -4845,10 +4845,8 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma)
 						color[3] = 1.0;
 					}
 
-					BLI_strncpy(imagename, &ma->id.name[2], FILE_MAX);
-					BLI_strncat_utf8(imagename, "_", FILE_MAX);
-					BLI_strncat_utf8(imagename, name, FILE_MAX);
 					/* take the second letter to avoid the ID identifier */
+					BLI_snprintf(imagename, FILE_MAX, "%s_%s", &ma->id.name[2], name);
 
 					ima = mtex->tex->ima = BKE_image_add_generated(bmain, width, height, imagename, 32, use_float,
 					                                               IMA_GENTYPE_BLANK, color);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index aa34ca3..4ad1304 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -195,10 +195,6 @@ static int palette_color_add_exec(bContext *C, wmOperator *UNUSED(op))
 		zero_v3(color->rgb);
 		color->value = brush->weight;
 	}
-	else if (mode == PAINT_WEIGHT) {
-		zero_v3(color->rgb);
-		color->value = brush->alpha;
-	}
 
 	return OPERATOR_FINISHED;
 }
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index 1ae4c35..6990c3b 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -216,36 +216,27 @@ void paint_get_tex_pixel_col(MTex *mtex, float u, float v, float rgba[4], struct
 
 /* 3D Paint */
 
-static void imapaint_project(Object *ob, float model[4][4], float proj[4][4], const float co[3], float pco[4])
+static void imapaint_project(float matrix[4][4], const float co[3], float pco[4])
 {
 	copy_v3_v3(pco, co);
 	pco[3] = 1.0f;
 
-	mul_m4_v3(ob->obmat, pco);
-	mul_m4_v3(model, pco);
-	mul_m4_v4(proj, pco);
+	mul_m4_v4(matrix, pco);
 }
 
-static void imapaint_tri_weights(Object *ob,
+static void imapaint_tri_weights(float matrix[4][4], GLint view[4],
                                  const float v1[3], const float v2[3], const float v3[3],
                                  const float co[2], float w[3])
 {
 	float pv1[4], pv2[4], pv3[4], h[3], divw;
-	float model[4][4], proj[4][4], wmat[3][3], invwmat[3][3];
-	GLint view[4];
+	float wmat[3][3], invwmat[3][3];
 
 	/* compute barycentric coordinates */
 
-	/* get the needed opengl matrices */
-	glGetIntegerv(GL_VIEWPORT, view);
-	glGetFloatv(GL_MODELVIEW_MATRIX,  (float *)model);
-	glGetFloatv(GL_PROJECTION_MATRIX, (float *)proj);
-	view[0] = view[1] = 0;
-
 	/* project the verts */
-	imapaint_project(ob, model, proj, v1, pv1);
-	imapaint_project(ob, model, proj, v2, pv2);
-	imapaint_project(ob, model, proj, v3, pv3);
+	imapaint_project(matrix, v1, pv1);
+	imapaint_project(matrix, v2, pv2);
+	imapaint_project(matrix, v3, pv3);
 
 	/* do inverse view mapping, see gluProject man page */
 	h[0] = (co[0] - view[0]) * 2.0f / view[2] - 1;
@@ -280,6 +271,10 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
 	float p[2], w[3], absw, minabsw;
 	MFace mf;
 	MVert mv[4];
+	float matrix[4][4], proj[4][4];
+	GLint view[4];
+
+	/* compute barycentric coordinates */
 
 	/* double lookup */
 	const int *index_mf_to_mpoly = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
@@ -288,6 +283,14 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
 		index_mp_to_orig = NULL;
 	}
 
+	/* get the needed opengl matrices */
+	glGetIntegerv(GL_VIEWPORT, view);
+	glGetFloatv(GL_MODELVIEW_MATRIX,  (float *)matrix);
+	glGetFloatv(GL_PROJECTION_MATRIX, (float *)proj);
+	view[0] = view[1] = 0;
+	mul_m4_m4m4(matrix, matrix, ob->obmat);
+	mul_m4_m4m4(matrix, proj, matrix);
+
 	minabsw = 1e10;
 	uv[0] = uv[1] = 0.0;
 
@@ -312,7 +315,7 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
 			if (mf.v4) {
 				/* the triangle with the largest absolute values is the one
 				 * with the most negative weights */
-				imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[3].co, p, w);
+				imapaint_tri_weights(matrix, view, mv[0].co, mv[1].co, mv[3].co, p, w);
 				absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]);
 				if (absw < minabsw) {
 					uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[3][0] * w[2];
@@ -320,7 +323,7 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
 					minabsw = absw;
 				}
 
-				imapaint_tri_weights(ob, mv[1].co, mv[2].co, mv[3].co, p, w);
+				imapaint_tri_weights(matrix, view, mv[1].co, mv[2].co, mv[3].co, p, w);
 				absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]);
 				if (absw < minabsw) {
 					uv[0] = tf->uv[1][0] * w[0] + tf->uv[2][0] * w[1] + tf->uv[3][0] * w[2];
@@ -329,7 +332,7 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
 				}
 			}
 			else {
-				imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[2].co, p, w);
+				imapaint_tri_weights(matrix, view, mv[0].co, mv[1].co, mv[2].co, p, w);
 				absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]);
 				if (absw < minabsw) {
 					uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[2][0] * w[2];
@@ -489,9 +492,11 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr
 			glReadBuffer(GL_FRONT);
 			glReadPixels(x + ar->winrct.xmin, y + ar->winrct.ymin, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
 			glReadBuffer(GL_BACK);
-		} else
+		}
+		else
 			return;
-	} else {
+	}
+	else {
 		glReadBuffer(GL_FRONT);
 		glReadPixels(x + ar->winrct.xmin, y + ar->winrct.ymin, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
 		glReadBuffer(GL_BACK);
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 1e2a9ae..bed553e 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -798,14 +798,14 @@ typedef struct ImagePaintSettings {
 	short screen_grab_size[2]; /* capture size for re-projection */
 
 	/* new layer default resolution */
-	int new_slot_xresolution;
-	int new_slot_yresolution;
+	int slot_xresolution_default;
+	int slot_yresolution_default;
 
 	int pad1;
 
 	void *paintcursor;			/* wm handle */
 	struct Image *stencil;      /* workaround until we support true layer masks */
-	float new_layer_col[4];
+	float slot_color_default[4];
 	float stencil_col[3];
 	float pad2;
 } ImagePaintSettings;
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index 20d1c2d..59f1fa9 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -611,9 +611,8 @@ static void rna_def_image_paint(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Stencil Color", "Stencil color in the viewport

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list