[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25988] trunk/blender/source/blender: particle weight brush back (mostly the same as in 2.4x), needed to control long hairs movement.

Campbell Barton ideasman42 at gmail.com
Thu Jan 14 09:53:11 CET 2010


Revision: 25988
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25988
Author:   campbellbarton
Date:     2010-01-14 09:53:10 +0100 (Thu, 14 Jan 2010)

Log Message:
-----------
particle weight brush back (mostly the same as in 2.4x), needed to control long hairs movement.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/particle.c
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/editors/physics/particle_edit.c
    trunk/blender/source/blender/editors/space_view3d/drawobject.c
    trunk/blender/source/blender/makesdna/DNA_scene_types.h
    trunk/blender/source/blender/makesrna/intern/rna_sculpt_paint.c

Modified: trunk/blender/source/blender/blenkernel/intern/particle.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle.c	2010-01-14 05:29:25 UTC (rev 25987)
+++ trunk/blender/source/blender/blenkernel/intern/particle.c	2010-01-14 08:53:10 UTC (rev 25988)
@@ -2983,12 +2983,21 @@
 
 	frs_sec = (psys || edit->pid.flag & PTCACHE_VEL_PER_SEC) ? 25.0f : 1.0f;
 
-	sel_col[0] = (float)edit->sel_col[0] / 255.0f;
-	sel_col[1] = (float)edit->sel_col[1] / 255.0f;
-	sel_col[2] = (float)edit->sel_col[2] / 255.0f;
-	nosel_col[0] = (float)edit->nosel_col[0] / 255.0f;
-	nosel_col[1] = (float)edit->nosel_col[1] / 255.0f;
-	nosel_col[2] = (float)edit->nosel_col[2] / 255.0f;
+	if(pset->brushtype == PE_BRUSH_WEIGHT){
+		/* use weight painting colors now... */
+#if 0
+		sel_col[0] = sel_col[1] = sel_col[2] = 1.0f;
+		nosel_col[0] = nosel_col[1] = nosel_col[2] = 0.0f;
+#endif
+	}
+	else{
+		sel_col[0] = (float)edit->sel_col[0] / 255.0f;
+		sel_col[1] = (float)edit->sel_col[1] / 255.0f;
+		sel_col[2] = (float)edit->sel_col[2] / 255.0f;
+		nosel_col[0] = (float)edit->nosel_col[0] / 255.0f;
+		nosel_col[1] = (float)edit->nosel_col[1] / 255.0f;
+		nosel_col[2] = (float)edit->nosel_col[2] / 255.0f;
+	}
 
 	/*---first main loop: create all actual particles' paths---*/
 	for(i=0; i<totpart; i++, pa+=pa?1:0, point++){
@@ -3003,6 +3012,14 @@
 		pind.bspline = psys ? (psys->part->flag & PART_HAIR_BSPLINE) : 0;
 		pind.dm = NULL;
 
+
+		/* should init_particle_interpolation set this ? */
+		if(pset->brushtype==PE_BRUSH_WEIGHT){
+			pind.hkey[0] = pa->hair;
+			pind.hkey[1] = pa->hair + 1;
+		}
+
+
 		memset(cache[i], 0, sizeof(*cache[i])*(steps+1));
 
 		cache[i]->steps = steps;
@@ -3035,6 +3052,12 @@
 
 			do_particle_interpolation(psys, i, pa, t, frs_sec, &pind, &result);
 
+			/* should init_particle_interpolation set this ? */
+			if(pset->brushtype==PE_BRUSH_WEIGHT){
+				pind.hkey[0] = pind.hkey[1];
+				pind.hkey[1]++;
+			}
+
 			 /* non-hair points are allready in global space */
 			if(psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
 				mul_m4_v3(hairmat, result.co);
@@ -3091,22 +3114,30 @@
 			ca->vel[1] = 1.0f;
 
 			/* selection coloring in edit mode */
-			if((ekey + (pind.ekey[0] - point->keys))->flag & PEK_SELECT){
-				if((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT){
-					VECCOPY(ca->col, sel_col);
-				}
-				else{
-					keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time));
-					interp_v3_v3v3(ca->col, sel_col, nosel_col, keytime);
-				}
+			if(pset->brushtype==PE_BRUSH_WEIGHT){
+				if(k==steps)
+					weight_to_rgb(pind.hkey[0]->weight, ca->col, ca->col+1, ca->col+2);
+				else
+					weight_to_rgb((1.0f - keytime) * pind.hkey[0]->weight + keytime * pind.hkey[1]->weight, ca->col, ca->col+1, ca->col+2);
 			}
-			else{
-				if((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT){
-					keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time));
-					interp_v3_v3v3(ca->col, nosel_col, sel_col, keytime);
+			else {
+				if((ekey + (pind.ekey[0] - point->keys))->flag & PEK_SELECT){
+					if((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT){
+						VECCOPY(ca->col, sel_col);
+					}
+					else{
+						keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time));
+						interp_v3_v3v3(ca->col, sel_col, nosel_col, keytime);
+					}
 				}
 				else{
-					VECCOPY(ca->col, nosel_col);
+					if((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT){
+						keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time));
+						interp_v3_v3v3(ca->col, nosel_col, sel_col, keytime);
+					}
+					else{
+						VECCOPY(ca->col, nosel_col);
+					}
 				}
 			}
 

Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c	2010-01-14 05:29:25 UTC (rev 25987)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c	2010-01-14 08:53:10 UTC (rev 25988)
@@ -3071,10 +3071,8 @@
 					dvert->dw = MEM_callocN (sizeof(MDeformWeight), "deformWeight");
 					dvert->totweight = 1;
 				}
-
-				/* no special reason for the 0.5 */
-				/* just seems like a nice value from experiments */
-				dvert->dw->weight = k ? 0.5f : 1.0f;
+				/* roots should be 1.0, the rest can be anything from 0.0 to 1.0 */
+				dvert->dw->weight = key->weight;
 				dvert++;
 			}
 		}

Modified: trunk/blender/source/blender/editors/physics/particle_edit.c
===================================================================
--- trunk/blender/source/blender/editors/physics/particle_edit.c	2010-01-14 05:29:25 UTC (rev 25987)
+++ trunk/blender/source/blender/editors/physics/particle_edit.c	2010-01-14 08:53:10 UTC (rev 25988)
@@ -2844,7 +2844,6 @@
 	PTCacheEditPoint *point = edit->points + point_index;
 	KEY_K;
 	float mat[4][4], imat[4][4];
-	float obmat[4][4], obimat[4][4];
 
 	float lastco[3], rootco[3] = {0.0f, 0.0f, 0.0f}, co[3], nor[3], kco[3], dco[3], ofs[3] = {0.0f, 0.0f, 0.0f}, fac=0.0f, length=0.0f;
 	int puff_volume = 0;
@@ -2865,22 +2864,19 @@
 		unit_m4(imat);
 	}
 
-	copy_m4_m4(obmat, data->ob->obmat);
-	invert_m4_m4(obimat, obmat);
-
 	LOOP_KEYS {
 		if(k==0) {
 			/* find root coordinate and normal on emitter */
 			VECCOPY(co, key->co);
 			mul_m4_v3(mat, co);
-			mul_v3_m4v3(kco, obimat, co); /* use 'kco' as the object space version of worldspace 'co' */
+			mul_v3_m4v3(kco, data->ob->imat, co); /* use 'kco' as the object space version of worldspace 'co', ob->imat is set before calling */
 
 			point_index= BLI_kdtree_find_nearest(edit->emitter_field, kco, NULL, NULL);
 			if(point_index == -1) return;
 
 			VECCOPY(rootco, co);
 			copy_v3_v3(nor, &edit->emitter_cosnos[point_index*6+3]);
-			mul_mat3_m4_v3(obmat, nor); /* normal into worldspace */
+			mul_mat3_m4_v3(data->ob->obmat, nor); /* normal into worldspace */
 
 			normalize_v3(nor);
 			length= 0.0f;
@@ -2949,6 +2945,21 @@
 		point->flag |= PEP_EDIT_RECALC;
 }
 
+
+static void brush_weight(PEData *data, float mat[][4], float imat[][4], int point_index, int key_index, PTCacheEditKey *key)
+{
+	/* roots have full weight allways */
+	if(key_index) {
+		PTCacheEdit *edit = data->edit;
+		ParticleSystem *psys = edit->psys;
+
+		ParticleData *pa= psys->particles + point_index;
+		pa->hair[key_index].weight = data->weightfac;
+
+		(data->edit->points + point_index)->flag |= PEP_EDIT_RECALC;
+	}
+}
+
 static void brush_smooth_get(PEData *data, float mat[][4], float imat[][4], int point_index, int key_index, PTCacheEditKey *key)
 {	
 	if(key_index) {
@@ -3396,6 +3407,23 @@
 
 				break;
 			}
+			case PE_BRUSH_WEIGHT:
+			{
+				PEData data;
+				PE_set_view3d_data(C, &data);
+
+				if(edit->psys) {
+					data.dm= psmd->dm;
+					data.mval= mval;
+					data.rad= (float)brush->size;
+
+					data.weightfac = (float)(brush->strength / 100.0f); /* note that this will never be zero */
+
+					foreach_mouse_hit_key(&data, brush_weight, selected);
+				}
+
+				break;
+			}
 		}
 		if((pset->flag & PE_KEEP_LENGTHS)==0)
 			recalc_lengths(edit);

Modified: trunk/blender/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/drawobject.c	2010-01-14 05:29:25 UTC (rev 25987)
+++ trunk/blender/source/blender/editors/space_view3d/drawobject.c	2010-01-14 08:53:10 UTC (rev 25988)
@@ -3812,6 +3812,12 @@
 	glEnable(GL_COLOR_MATERIAL);
 	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
 
+	if(pset->brushtype == PE_BRUSH_WEIGHT) {
+		glLineWidth(2.0f);
+		glDisable(GL_LIGHTING);
+		/* TODO, nice color blending */
+	}
+
 	cache=edit->pathcache;
 	for(i=0; i<totpoint; i++){
 		path = cache[i];

Modified: trunk/blender/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_scene_types.h	2010-01-14 05:29:25 UTC (rev 25987)
+++ trunk/blender/source/blender/makesdna/DNA_scene_types.h	2010-01-14 08:53:10 UTC (rev 25988)
@@ -1137,6 +1137,7 @@
 #define PE_BRUSH_PUFF		3
 #define PE_BRUSH_ADD		4
 #define PE_BRUSH_SMOOTH		5
+#define PE_BRUSH_WEIGHT		6
 
 /* this must equal ParticleEditSettings.brush array size */
 #define PE_TOT_BRUSH		6

Modified: trunk/blender/source/blender/makesrna/intern/rna_sculpt_paint.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_sculpt_paint.c	2010-01-14 05:29:25 UTC (rev 25987)
+++ trunk/blender/source/blender/makesrna/intern/rna_sculpt_paint.c	2010-01-14 08:53:10 UTC (rev 25988)
@@ -44,6 +44,7 @@
 	{PE_BRUSH_LENGTH, "LENGTH", 0, "Length", "Make hairs longer or shorter."},
 	{PE_BRUSH_PUFF, "PUFF", 0, "Puff", "Make hairs stand up."},
 	{PE_BRUSH_CUT, "CUT", 0, "Cut", "Cut hairs."},
+	{PE_BRUSH_WEIGHT, "WEIGHT", 0, "Weight", "Weight hair particles."},
 	{0, NULL, 0, NULL, NULL}};
 
 #ifdef RNA_RUNTIME





More information about the Bf-blender-cvs mailing list