[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18612] branches/blender2.5/blender/source /blender: Brought back textures for sculpt mode.

Nicholas Bishop nicholasbishop at gmail.com
Wed Jan 21 21:03:42 CET 2009


Revision: 18612
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18612
Author:   nicholasbishop
Date:     2009-01-21 21:03:41 +0100 (Wed, 21 Jan 2009)

Log Message:
-----------
Brought back textures for sculpt mode. These are stored in Brush DNA now, as well as the three texture modes (drag/tile/3D).

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_brush_types.h
    branches/blender2.5/blender/source/blender/makesdna/DNA_scene_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c

Modified: branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-21 19:28:28 UTC (rev 18611)
+++ branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-21 20:03:41 UTC (rev 18612)
@@ -750,9 +750,9 @@
 	Brush *br = sd->brush;
 	float avg= 1;
 
-	if(br->texact==-1 || !br->mtex[sd->texact])
+	if(br->texact==-1 || !br->mtex[br->texact])
 		avg= 1;
-	else if(sd->texrept==SCULPTREPT_3D) {
+	else if(br->tex_mode==BRUSH_TEX_3D) {
 		/* Get strength by feeding the vertex location directly
 		   into a texture */
 		float jnk;
@@ -785,7 +785,7 @@
 
 		/* For Tile and Drag modes, get the 2D screen coordinates of the
 		   and scale them up or down to the texture size. */
-		if(sd->texrept==SCULPTREPT_TILE) {
+		if(br->tex_mode==BRUSH_TEX_TILE) {
 			const int sx= (const int)br->mtex[br->texact]->size[0];
 			const int sy= (const int)sd->texsep ? br->mtex[br->texact]->size[1] : sx;
 			
@@ -808,8 +808,8 @@
 				py %= sy-1;
 			avg= get_texcache_pixel_bilinear(ss, TC_SIZE*px/sx, TC_SIZE*py/sy);
 		} else {
-			float fx= (point_2d[0] - ss->cache->initial_mouse[0]) / bsize;
-			float fy= (point_2d[1] - ss->cache->initial_mouse[1]) / bsize;
+			float fx= (point_2d[0] - ss->cache->mouse[0]) / bsize;
+			float fy= (point_2d[1] - ss->cache->mouse[1]) / bsize;
 
 			float angle= atan2(fy, fx) - rot;
 			float flen= sqrtf(fx*fx + fy*fy);
@@ -1087,7 +1087,7 @@
 		ss->projverts[i].inside = 0;
 }
 
-static void sculptmode_update_tex(Sculpt *sd)
+static void sculpt_update_tex(Sculpt *sd)
 {
 	SculptSession *ss= sd->session;
 	Brush *br = sd->brush;
@@ -1099,7 +1099,7 @@
 	memset(&texres, 0, sizeof(TexResult));
 	
 	/* Skip Default brush shape and non-textures */
-	if(br->texact == -1 || !br->mtex[sd->texact]) return;
+	if(br->texact == -1 || !br->mtex[br->texact]) return;
 
 	if(ss->texcache) {
 		MEM_freeN(ss->texcache);
@@ -1274,7 +1274,7 @@
 	float *texdata= MEM_mallocN(sizeof(float)*tsz*tsz, "Brush preview");
 	GLuint tex;
 
-	if(sd->texrept!=SCULPTREPT_3D)
+	if(sd->tex_mode!=SCULPTREPT_3D)
 		sculptmode_update_tex();
 	for(i=0; i<tsz; ++i)
 		for(j=0; j<tsz; ++j) {
@@ -1729,6 +1729,11 @@
 
 	sculptmode_update_all_projverts(sd->session);
 
+	/* TODO: Shouldn't really have to do this at the start of every
+	   stroke, but sculpt would need some sort of notification when
+	   changes are made to the texture. */
+	sculpt_update_tex(sd);
+
 	/* add modal handler */
 	WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
 	
@@ -1805,6 +1810,7 @@
 
 	view3d_operator_needs_opengl(C);
 	sculpt_update_cache_invariants(sd, C, op);
+	sculpt_update_tex(sd);
 
 	RNA_BEGIN(op->ptr, itemptr, "stroke") {
 		sculpt_update_cache_variants(sd, &itemptr);
@@ -1899,6 +1905,8 @@
 		sculptsession_free(ts->sculpt);
 	}
 	else {
+		MTex *mtex; // XXX: temporary
+
 		/* Enter sculptmode */
 
 		G.f |= G_SCULPTMODE;
@@ -1910,6 +1918,15 @@
 
 		/* Needed for testing, if there's no brush then create one */
 		ts->sculpt->brush = add_brush("test brush");
+		/* Also for testing, set the brush texture to the first available one */
+		if(G.main->tex.first) {
+			mtex = MEM_callocN(sizeof(MTex), "test mtex");
+			ts->sculpt->brush->texact = 0;
+			ts->sculpt->brush->mtex[0] = mtex;
+			mtex->tex = G.main->tex.first;
+			mtex->size[0] = mtex->size[1] = mtex->size[2] = 50;
+		}
+		
 
 		/* Activate visible brush */
 		ts->sculpt->session->cursor =
@@ -1997,7 +2014,7 @@
 
 	/* Init texture
 	   FIXME: Shouldn't be doing this every time! */
-	if(sd->texrept!=SCULPTREPT_3D)
+	if(sd->tex_mode!=SCULPTREPT_3D)
 		sculptmode_update_tex(sd);
 
 	/*XXX: getmouseco_areawin(mouse); */

Modified: branches/blender2.5/blender/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesdna/DNA_brush_types.h	2009-01-21 19:28:28 UTC (rev 18611)
+++ branches/blender2.5/blender/source/blender/makesdna/DNA_brush_types.h	2009-01-21 20:03:41 UTC (rev 18612)
@@ -64,7 +64,8 @@
 	float alpha;				/* opacity */
 
 	short texact;				/* active texture */
-	char sculpt_tool, pad;			/* active tool */
+	char sculpt_tool;			/* active tool */
+	char tex_mode;
 } Brush;
 
 /* Brush.flag */
@@ -89,6 +90,11 @@
 #define BRUSH_BLEND_ERASE_ALPHA	6
 #define BRUSH_BLEND_ADD_ALPHA	7
 
+/* Brush.tex_mode */
+#define BRUSH_TEX_DRAG 0
+#define BRUSH_TEX_TILE 1
+#define BRUSH_TEX_3D   2
+
 /* Brush.sculpt_tool */
 #define SCULPT_TOOL_DRAW    1
 #define SCULPT_TOOL_SMOOTH  2

Modified: branches/blender2.5/blender/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesdna/DNA_scene_types.h	2009-01-21 19:28:28 UTC (rev 18611)
+++ branches/blender2.5/blender/source/blender/makesdna/DNA_scene_types.h	2009-01-21 20:03:41 UTC (rev 18612)
@@ -387,10 +387,10 @@
 	float pivot[3];
 	int flags;
 	/* For the Brush Shape */
-	short texact, texnr;
-	char texrept, texsep;
+	char texsep;
 	/* Control tablet input */
 	char tablet_size, tablet_strength;
+	char pad[5];
 } Sculpt;
 
 typedef struct VPaint {
@@ -810,10 +810,6 @@
 #define SCULPT_LOCK_X       64
 #define SCULPT_LOCK_Y      128
 #define SCULPT_LOCK_Z      256
-/* SculptData.texrept */
-#define SCULPTREPT_DRAG 1
-#define SCULPTREPT_TILE 2
-#define SCULPTREPT_3D   3
 
 /* toolsettings->imagepaint_flag */
 #define IMAGEPAINT_DRAWING				1

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c	2009-01-21 19:28:28 UTC (rev 18611)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c	2009-01-21 20:03:41 UTC (rev 18612)
@@ -62,6 +62,11 @@
 		{BRUSH_BLEND_ERASE_ALPHA, "ERASE_ALPHA", "Erase Alpha", "Erase alpha while painting."},
 		{BRUSH_BLEND_ADD_ALPHA, "ADD_ALPHA", "Add Alpha", "Add alpha while painting."},
 		{0, NULL, NULL, NULL}};
+	static EnumPropertyItem prop_texture_mode_items[] = {
+		{BRUSH_TEX_DRAG, "TEX_DRAG", "Drag", ""},
+		{BRUSH_TEX_TILE, "TEX_TILE", "Tile", ""},
+		{BRUSH_TEX_3D, "TEX_3D", "3D", ""},
+		{0, NULL, NULL, NULL}};
 	static EnumPropertyItem prop_sculpt_tool_items[] = {
 		{SCULPT_TOOL_DRAW, "DRAW", "Draw", ""},
 		{SCULPT_TOOL_SMOOTH, "SMOOTH", "Smooth", ""},
@@ -80,6 +85,11 @@
 	RNA_def_property_enum_items(prop, prop_blend_items);
 	RNA_def_property_ui_text(prop, "Blending mode", "Brush blending mode.");
 
+	prop= RNA_def_property(srna, "texture_mode", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "tex_mode");
+	RNA_def_property_enum_items(prop, prop_texture_mode_items);
+	RNA_def_property_ui_text(prop, "Texture Mode", "");
+
 	prop= RNA_def_property(srna, "sculpt_tool", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_items(prop, prop_sculpt_tool_items);
 	RNA_def_property_ui_text(prop, "Sculpt Tool", "");





More information about the Bf-blender-cvs mailing list