[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12602] branches/particles/source/blender: Brecht's 15.11.

Janne Karhu jhkarh at utu.fi
Fri Nov 16 01:37:29 CET 2007


Revision: 12602
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12602
Author:   jhk
Date:     2007-11-16 01:37:28 +0100 (Fri, 16 Nov 2007)

Log Message:
-----------
Brecht's 15.11. buglist fixed and some others..

- Jittered distribution didn't allow individual coordinates for all particles on face.
- Adding particles in particle mode by interpolation crashed.
- Hair normals weren't created properly so hair wasn't shaded properly in 3d view. Still left to figure out how to shade coloured strands in edit mode.
- Canceling a transform on hair keys didn't reset the keys properly. Now they are reset correctly, but the cost is that we have to create transdata for all keys of particles that have selected keys.
- Subsurf render levels didn't get through to particles. Still left to figure out proper way to update particles again straight after render with view levels.	
- Added "emit locations / face" variable to ui for jittered face emission.
- Hopefully faster and more accurate cut-brush algorithm. (the old one had a bug too :)

Modified Paths:
--------------
    branches/particles/source/blender/blenkernel/intern/particle.c
    branches/particles/source/blender/blenkernel/intern/particle_system.c
    branches/particles/source/blender/include/transform.h
    branches/particles/source/blender/makesdna/DNA_particle_types.h
    branches/particles/source/blender/render/intern/source/convertblender.c
    branches/particles/source/blender/src/buttons_object.c
    branches/particles/source/blender/src/editparticle.c
    branches/particles/source/blender/src/transform.c
    branches/particles/source/blender/src/transform_conversions.c
    branches/particles/source/blender/src/transform_generics.c

Modified: branches/particles/source/blender/blenkernel/intern/particle.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/particle.c	2007-11-15 19:02:31 UTC (rev 12601)
+++ branches/particles/source/blender/blenkernel/intern/particle.c	2007-11-16 00:37:28 UTC (rev 12602)
@@ -2079,9 +2079,17 @@
 			}
 
 			VECCOPY(ca->co, result.co);
-			VECCOPY(ca->vel, result.vel);
+			
+			if(k){
+				VECSUB(ca->vel, ca->co, (ca-1)->co);
 
+				if(k==1) {
+					VECCOPY((ca-1)->vel, ca->vel);
+				}
 
+			}
+
+
 			/* selection coloring in edit mode */
 			if(edit){
 				if(pset->brushtype==PE_BRUSH_WEIGHT){

Modified: branches/particles/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/particle_system.c	2007-11-15 19:02:31 UTC (rev 12601)
+++ branches/particles/source/blender/blenkernel/intern/particle_system.c	2007-11-16 00:37:28 UTC (rev 12602)
@@ -747,7 +747,7 @@
 			jitlevel= totpart/tot;
 			if(part->flag & PART_EDISTR) jitlevel*= 2;	/* looks better in general, not very scietific */
 			if(jitlevel<3) jitlevel= 3;
-			if(jitlevel>100) jitlevel= 100;
+			//if(jitlevel>100) jitlevel= 100;
 		}
 		
 		jit= MEM_callocN(2+ jitlevel*2*sizeof(float), "jit");
@@ -784,14 +784,16 @@
 			case PART_FROM_VOLUME:
 			{
 				MFace *mface;
-				pa->num=i=index[p];
+				pa->num = i = index[p];
 				mface = dm->getFaceData(dm,i,CD_MFACE);
 				
 				switch(distr){
 				case PART_DISTR_JIT:
+					sum[i] = fmod(sum[i],(float)jitlevel);
 					pa->fuv[0] = jit[2*(int)sum[i]];
 					pa->fuv[1] = jit[2*(int)sum[i]+1];
-					sum[i]=(float)fmod(sum[i]+maxweight/weight[i],(float)jitlevel);
+					sum[i]++;
+					//sum[i]=(float)fmod(sum[i]+maxweight/weight[i],(float)jitlevel);
 					break;
 				case PART_DISTR_RAND:
 					pa->fuv[0] = BLI_frand();

Modified: branches/particles/source/blender/include/transform.h
===================================================================
--- branches/particles/source/blender/include/transform.h	2007-11-15 19:02:31 UTC (rev 12601)
+++ branches/particles/source/blender/include/transform.h	2007-11-16 00:37:28 UTC (rev 12602)
@@ -271,6 +271,7 @@
 #define TD_TIMEONLY			128
 #define TD_NOCENTER			256
 #define TD_NO_EXT			512	/* ext abused for particle key timing */
+#define TD_SKIP				1024 /* don't transform this data */
 
 /* transsnap->status */
 #define SNAP_ON			1

Modified: branches/particles/source/blender/makesdna/DNA_particle_types.h
===================================================================
--- branches/particles/source/blender/makesdna/DNA_particle_types.h	2007-11-15 19:02:31 UTC (rev 12601)
+++ branches/particles/source/blender/makesdna/DNA_particle_types.h	2007-11-16 00:37:28 UTC (rev 12602)
@@ -383,7 +383,7 @@
 #define PARS_UNEXIST		1
 #define PARS_NO_DISP		2
 #define PARS_STICKY			4
-//#define PARS_DONE			8 /* not used anymore */
+#define PARS_SELECTED_KEYS	8
 #define PARS_HIDE			16
 #define PARS_REMOVE			32
 #define PARS_REKEY			64

Modified: branches/particles/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/particles/source/blender/render/intern/source/convertblender.c	2007-11-15 19:02:31 UTC (rev 12601)
+++ branches/particles/source/blender/render/intern/source/convertblender.c	2007-11-16 00:37:28 UTC (rev 12602)
@@ -3696,16 +3696,16 @@
 
 	ob->flag |= OB_DONE;
 
+	/* the emitter has to be processed first (render levels of modifiers) */
+	/* so here we only check if the emitter should be rendered */
 	if(ob->particlesystem.first) {
-		ParticleSystem *psys=ob->particlesystem.first;
-		int showe= 0;
-		for(; psys; psys=psys->next) {
-			render_new_particle_system(re, ob, psys);
-			showe+=psys->part->draw & PART_DRAW_EMITTER;
-		}
+		ParticleSystem *psys = ob->particlesystem.first;
+		int showe = 0;
+		for(; psys; psys=psys->next)
+			showe += psys->part->draw & PART_DRAW_EMITTER;
 
 		/* if no psys has "show emitter" selected don't render emitter */
-		if(showe==0) allow_render=0;
+		if(showe==0) allow_render = 0;
 	}
 
 	if(allow_render) {
@@ -3724,6 +3724,21 @@
 			MTC_Mat4Invert(ob->imat, mat);
 		}
 	}
+
+	if(ob->particlesystem.first) {
+		ParticleSystem *psys = ob->particlesystem.first;
+		DerivedMesh *dm = 0;
+
+		/* the emitter mesh wasn't rendered so the modifier stack wasn't evaluated with render settings */
+		if(allow_render==0 && ob->type==OB_MESH && G.rendering)
+			dm = mesh_create_derived_render(ob,	CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL);
+
+		for(; psys; psys=psys->next)
+			render_new_particle_system(re, ob, psys);
+
+		if(dm)
+			dm->release(dm);
+	}
 	
 	/* generic post process here */
 	if(startvert!=re->totvert) {

Modified: branches/particles/source/blender/src/buttons_object.c
===================================================================
--- branches/particles/source/blender/src/buttons_object.c	2007-11-15 19:02:31 UTC (rev 12601)
+++ branches/particles/source/blender/src/buttons_object.c	2007-11-16 00:37:28 UTC (rev 12602)
@@ -4405,8 +4405,10 @@
 	if(ELEM(part->from,PART_FROM_FACE,PART_FROM_VOLUME)) {
 		uiDefButBitI(block, TOG, PART_EDISTR, B_PART_DISTR, "Even",butx,(buty-=buth),butw/2,buth, &part->flag, 0, 0, 0, 0, "Use even distribution from faces based on face areas or edge lengths");
 		uiDefButS(block, MENU, B_PART_DISTR, "Distribution %t|Grid%x2|Random%x1|Jittered%x0", butx+butw/2,buty,butw/2,buth, &part->distr, 14.0, 0.0, 0, 0, "How to distribute particles on selected element");
-		if(part->distr==PART_DISTR_JIT)
-			uiDefButF(block, NUM, B_PART_DISTR, "Amount:",		butx,(buty-=buth),butw,buth, &part->jitfac, 0, 2.0, 1, 1, "Specify the mass of the particles");
+		if(part->distr==PART_DISTR_JIT) {
+			uiDefButF(block, NUM, B_PART_DISTR, "Amount:",		butx,(buty-=buth),butw,buth, &part->jitfac, 0, 2.0, 1, 1, "Amount of jitter applied to the sampling");
+			uiDefButI(block, NUM, B_PART_DISTR, "P/F:",		butx,(buty-=buth),butw,buth, &part->userjit, 0, 1000.0, 1, 1, "Emission locations / face (0 = automatic)");
+		}
 		if(part->distr==PART_DISTR_GRID){
 			uiDefButBitI(block, TOG, PART_GRID_INVERT, B_PART_DISTR, "Invert",butx,(buty-=buth),butw,buth, &part->flag, 0, 0, 0, 0, "Invert what is considered object and what is not.");				
 		}

Modified: branches/particles/source/blender/src/editparticle.c
===================================================================
--- branches/particles/source/blender/src/editparticle.c	2007-11-15 19:02:31 UTC (rev 12601)
+++ branches/particles/source/blender/src/editparticle.c	2007-11-16 00:37:28 UTC (rev 12602)
@@ -1485,7 +1485,7 @@
 	
 	/* interpolate new keys from old ones (roots stay the same) */
 	for(k=1, key++; k < pa->totkey; k++, key++) {
-		state.time = path_time * (float)k / (float)pa->totkey;
+		state.time = path_time * (float)k / (float)(pa->totkey-1);
 		psys_get_particle_on_path(ob, psys, index, &state, 0);
 		VECCOPY(key->co, state.co);
 	}
@@ -1708,15 +1708,6 @@
 /************************************************/
 /*			Edit Brushes						*/
 /************************************************/
-/* if usefull elsewhere please move to arithb.c */
-static float lambda_cp_line_2d(float p[2], float l1[2], float l2[2])
-{
-	float h[3],u[3];
-	
-	Vec2Subf(u, l2, l1);
-	Vec2Subf(h, p, l1);
-	return(Inp2f(u,h)/Inp2f(u,u));
-}
 static void brush_comb(ParticleSystem *psys, float mat[][4], float imat[][4], int pa_index, int key_index, void *userData)
 {
 	struct {Object *ob; short *mval; float rad; rcti* rect; float dist; float *dvec; float combfac;} *data = userData;
@@ -1739,66 +1730,74 @@
 	struct { short *mval; float rad; rcti* rect; int selected; float cutfac;} *data = userData;
 	ParticleData *pa= &psys->particles[index];
 	ParticleCacheKey *key = psys->pathcache[index];
-	float lambda, length, rad, rad2, dist, cut_time = 1.0;
-	float vertcof1[2], vertcof2[2], mvalf[2], dvec[2];
+	float rad2, cut_time = 1.0;
+	float x0, x1, v0, v1, o0, o1, xo0, xo1, d, dv;
 	int k, cut, keys = (int)pow(2.0, (double)psys->part->draw_step);
-	short vertco1[2], vertco2[2];
+	short vertco[2];
 
 	/* blunt scissors */
 	if(BLI_frand() > data->cutfac) return;
 
-	project_short_noclip(key->co, vertco1);
-	vertcof1[0] = (float)vertco1[0];
-	vertcof1[1] = (float)vertco1[1];
-	mvalf[0] = (float)data->mval[0];
-	mvalf[1] = (float)data->mval[1];
-	rad = data->rad;
-	rad2 = rad * rad;
+	rad2 = data->rad * data->rad;
 
 	cut=0;
 
-	/* calculate path time closest to root that was inside the circle */
-	for(k=1, key++; k<=keys; k++, key++){
-		project_short_noclip(key->co, vertco2);
-		vertcof2[0] = (float)vertco2[0];
-		vertcof2[1] = (float)vertco2[1];
+	project_short_noclip(key->co, vertco);
+	x0 = (float)vertco[0];
+	x1 = (float)vertco[1];
 
-		lambda = lambda_cp_line_2d(mvalf, vertcof1, vertcof2);
+	o0 = (float)data->mval[0];
+	o1 = (float)data->mval[1];
+	
+	xo0 = x0 - o0;
+	xo1 = x1 - o1;
 
-		if(lambda >= 0.0f){
-			if(lambda < 1.0){
-				Vec2Subf(dvec, vertcof2, vertcof1);
-				Vec2Mulf(dvec, lambda);
-				Vec2Addf(dvec, vertcof1, dvec);
+	/* check if root is inside circle */
+	if(xo0*xo0 + xo1*xo1 < rad2) {
+		cut_time = -1.0f;
+		cut = 1;
+	}
+	else {
+		/* calculate path time closest to root that was inside the circle */
+		for(k=1, key++; k<=keys; k++, key++){
+			project_short_noclip(key->co, vertco);
 
-				dist = Vec2Lenf(dvec, mvalf);
-				if(dist <= rad){
-					length = Vec2Lenf(vertcof1, vertcof2);
-					lambda = (lambda * length - (float)sqrt((double)(rad2 - dist * dist))) / length;
+			v0 = (float)vertco[0] - x0;
+			v1 = (float)vertco[1] - x1;
 
-					cut_time = ((float)(k - 1) + lambda) / (float)keys;
-					cut = 1;
-					break;
+			dv = v0*v0 + v1*v1;
+
+			d = (v0*xo1 - v1*xo0);
+			
+			d = dv * rad2 - d*d;
+
+			if(d > 0.0f) {
+				d = sqrt(d);
+
+				cut_time = -(v0*xo0 + v1*xo1 + d);
+
+				if(cut_time > 0.0f) {
+					cut_time /= dv;
+
+					if(cut_time < 1.0f) {
+						cut_time += (float)(k-1);
+						cut_time /= (float)keys;
+						cut = 1;
+						break;
+					}
 				}
 			}
-			else{
-				dist = Vec2Lenf(vertcof2, mvalf);
 
-				if(dist <= rad){
-					length = Vec2Lenf(vertcof1, vertcof2);
-					lambda = (length + dist - rad) / length;
-					cut_time = ((float)(k - 1) + lambda) / (float)keys;
-					cut = 1;
-					break;
-				}
-			}
+			x0 = (float)vertco[0];
+			x1 = (float)vertco[1];
+
+			xo0 = x0 - o0;
+			xo1 = x1 - o1;
 		}

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list