[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12493] branches/particles/source/blender: wip particle, function to update hair location when modifiers change, not working yet.

Campbell Barton cbarton at metavr.com
Tue Nov 6 12:36:01 CET 2007


Revision: 12493
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12493
Author:   campbellbarton
Date:     2007-11-06 12:36:01 +0100 (Tue, 06 Nov 2007)

Log Message:
-----------
wip particle, function to update hair location when modifiers change, not working yet.

Modified Paths:
--------------
    branches/particles/source/blender/blenkernel/intern/particle.c
    branches/particles/source/blender/blenkernel/intern/particle_system.c
    branches/particles/source/blender/blenlib/intern/arithb.c
    branches/particles/source/blender/src/editparticle.c

Modified: branches/particles/source/blender/blenkernel/intern/particle.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/particle.c	2007-11-06 11:25:48 UTC (rev 12492)
+++ branches/particles/source/blender/blenkernel/intern/particle.c	2007-11-06 11:36:01 UTC (rev 12493)
@@ -783,7 +783,7 @@
 int psys_particle_dm_face_lookup(DerivedMesh *dm, int index, float *fuv, struct LinkNode *node)
 {
 	MFace *mface=dm->getFaceData(dm,index,CD_MFACE);
-	int *origindex, *oi, totface, i;
+	int *origindex, *oi, totface, dmface_index;
 	OrigSpaceFace *osface=dm->getFaceDataArray(dm, CD_ORIGSPACE);
 	origindex = oi = dm->getFaceDataArray(dm, CD_ORIGINDEX);
 	totface = dm->getNumFaces(dm);
@@ -800,29 +800,28 @@
 	}
 	
 	if (node) { /* we have a linked list of faces that we use, faster! */
-		int node_index;
 		OrigSpaceFace *osface_node;
 		for(;node;node=node->next) {
-			node_index = (int *)node->link;
-			osface_node = osface + node_index;
+			dmface_index = (int *)node->link;
+			osface_node = osface + dmface_index;
 			if ( mface->v4 ) { /* check that this intersects - Its possible this misses :/ - could also check its not between */
 				if (IsectPQ2Df(fuv, osface_node->uv[0], osface_node->uv[1], osface_node->uv[2], osface_node->uv[3])) {
-					return node_index;
+					return dmface_index;
 				}
 			} else if (IsectPT2Df(fuv, osface_node->uv[0], osface_node->uv[1], osface_node->uv[2])) {
-				return node_index;
+				return dmface_index;
 			}
 		}
 	} else { /* if we have no node, try every face */
-		for (i=0; i<totface; i++, oi++, mface++, osface++) {
+		for (dmface_index=0; dmface_index<totface; dmface_index++, oi++, mface++, osface++) {
 					//printf("\tTesting dm_index:%i orig_index:%i looking for %i fuv(%f, %f)\n", i, *oi, index, fuv[0], fuv[1]);
 			if (*oi == index) {
 				if ( mface->v4 ) { /* check that this intersects - Its possible this misses :/ - could also check its not between */
 					if (IsectPQ2Df(fuv, osface->uv[0], osface->uv[1], osface->uv[2], osface->uv[3])) {
-						return i;
+						return dmface_index;
 					}
 				} else if (IsectPT2Df(fuv, osface->uv[0], osface->uv[1], osface->uv[2])) {
-					return i;
+					return dmface_index;
 				}
 			}
 		}
@@ -926,8 +925,12 @@
 			mtface= dm->getFaceData(dm, i, CD_MTFACE); 
 			osface= dm->getFaceData(dm, i, CD_ORIGSPACE);
 			
+			//printf("Before fuv_mod (%f %f)\n", fuv_mod[0], fuv_mod[1]);
 			PointInFace2DUV(mface->v4, osface->uv[0], osface->uv[1], osface->uv[2], osface->uv[3], fuv, fuv_mod);
+			//printf("After fuv_mod (%f %f)\n", fuv_mod[0], fuv_mod[1]);
+			
 			psys_interpolate_face(mvert,mface,mtface,fuv_mod,vec,nor,utan,vtan);
+			
 		} else {
 			/* TODO PARTICLE - support verts and volume */
 			PARTICLE_ERROR(nor, vec);
@@ -2251,8 +2254,6 @@
 	QuatMulVecf(q, vec);
 }
 
-
-
 void psys_vec_from_geometry(DerivedMesh *dm, ParticleData *pa, float *vec)
 {
 	float q[4], v1[3], v2[3], v3[3];

Modified: branches/particles/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/particle_system.c	2007-11-06 11:25:48 UTC (rev 12492)
+++ branches/particles/source/blender/blenkernel/intern/particle_system.c	2007-11-06 11:36:01 UTC (rev 12493)
@@ -159,7 +159,6 @@
 	node - the allocated links - total derived mesh face count 
 	node_array - is the array of nodes alligned with the base mesh's faces, so each original face can reference its derived faces
 	*/
-	LinkNode *node=NULL, *node_array=NULL;
 	Mesh *me = (Mesh *)ob->data;
 	int p;
 	ParticleData *pa=0;
@@ -220,6 +219,29 @@
 	}
 }
 
+/* when hair is being edited, and the mesh under it changes, we need to update the hair locations 
+TODO - this function dosnt do what it should yet */
+void psys_update_edithair_dmfaces(Object *ob, DerivedMesh *dm, ParticleSystem *psys)
+{
+	int p;
+	ParticleData *pa=0;
+	float loc0[3];
+	int deform_only = modifiers_isDeformedOnly(ob); /* needed for psys_particle_on_dm */
+	
+	if(psys->part->from!=PART_FROM_FACE || deform_only)
+		return;
+	
+	psys_calc_dmfaces(ob, dm, psys);
+	
+	for(p=0,pa=psys->particles; p<psys->totpart; p++,pa++) {
+		psys_particle_on_dm(dm,deform_only,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,loc0,0,0,0);
+		Mat4MulVecfl(ob->obmat,loc0);
+		/* TODO - update the hair location, this dosnt work at all right now */
+		//VECCOPY(pa->hair->co,loc0); 
+		//pa->fuv - fuv's are used too/
+	}
+}
+
 static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys)
 {
 	ParticleData *pa=0;
@@ -3981,6 +4003,8 @@
 	/* update particle mode things */
 	if(ob==OBACT && G.f & G_PARTICLEEDIT && psys->edit && psys->flag&PSYS_CURRENT){
 		/* PARTICLE TODO - recalc the uv's from fuv */
+		// This dosnt work...
+		//distribute_particles(ob,psys,psys->part->from);
 		
 		PE_iterate_lengths(psys);
 		PE_deflect_emitter(ob,psys);
@@ -4302,10 +4326,15 @@
 	if(psys->part->type==PART_HAIR && psys->soft)
 		psys_to_softbody(ob, psys, 0);
 
+	/* is the mesh changing under the edited particles? */
+	if((psys->flag & PSYS_EDITED) &&  psys->part->type==PART_HAIR && psys->recalc & PSYS_RECALC_HAIR) {
+		/* Just update the particles on the mesh */
+		psys_update_edithair_dmfaces(ob, psmd->dm, psys);
+	}
+	
 	if(psys->part->type==PART_HAIR && hair_needs_recalc(psys)){
 		float hcfra=0.0f;
 		int i;
-
 		free_hair(psys);
 
 		/* first step is negative so particles get killed and reset */

Modified: branches/particles/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/particles/source/blender/blenlib/intern/arithb.c	2007-11-06 11:25:48 UTC (rev 12492)
+++ branches/particles/source/blender/blenlib/intern/arithb.c	2007-11-06 11:36:01 UTC (rev 12493)
@@ -4009,6 +4009,7 @@
 		wtot = w1+w2;
 		uv[1] = w1/wtot;
 	}
+	/* may need to flip UV's here */
 }
 
 /* same as above but does tri's and quads, tri's are a bit of a hack :/ */
@@ -4032,8 +4033,8 @@
 		* 
 		* this method makes an imaginary triangle in 2d space using the UV's from the derived mesh face
 		* Then find new uv coords using the fuv and this face with LineIntersectsTriangleUV.
-		* .This means the new values will be correct in relation to the derived meshes face.
-				*/
+		* This means the new values will be correct in relation to the derived meshes face. 
+		*/
 		Vec2Copyf(v0_3d, v0);
 		Vec2Copyf(v1_3d, v1);
 		Vec2Copyf(v2_3d, v2);

Modified: branches/particles/source/blender/src/editparticle.c
===================================================================
--- branches/particles/source/blender/src/editparticle.c	2007-11-06 11:25:48 UTC (rev 12492)
+++ branches/particles/source/blender/src/editparticle.c	2007-11-06 11:36:01 UTC (rev 12493)
@@ -1720,6 +1720,7 @@
 	}
 }
 /* special brushes for particles */
+#define EXPEREMENTAL_DEFORM_ONLY_PAINTING 1
 static void brush_add(Object *ob, ParticleSystem *psys, short *mval, short number)
 {
 	ParticleData *add_pars = MEM_callocN(number*sizeof(ParticleData),"ParticleData add");
@@ -1734,7 +1735,9 @@
 	short size = edit->brushsize[PE_BRUSH_ADD];
 	short size2 = size*size;
 	int deform_only;
-
+#if EXPEREMENTAL_DEFORM_ONLY_PAINTING
+	DerivedMesh *dm=0;
+#endif
 	Mat4Invert(imat,ob->obmat);
 
 	BLI_srandom(psys->seed+mval[0]+mval[1]);
@@ -1742,7 +1745,7 @@
 	deform_only = modifiers_isDeformedOnly(ob);
 
 	/* painting onto the deformed mesh, could be an option? */
-#if 0
+#if EXPEREMENTAL_DEFORM_ONLY_PAINTING
 	if (deform_only)
 		dm = psmd->dm;
 	else
@@ -1791,6 +1794,12 @@
 		min_d=2.0;
 		
 		/* warning, returns the derived mesh face */
+#if EXPEREMENTAL_DEFORM_ONLY_PAINTING
+		if(psys_intersect_dm(ob,dm,0,co1,co2,&min_d,&add_pars[n].num,add_pars[n].fuv,0,0,0,0)) {
+			add_pars[n].fuv[2]=0.0;
+			n++;
+		}
+#else
 		if (deform_only) {
 			if(psys_intersect_dm(ob,psmd->dm,0,co1,co2,&min_d,&add_pars[n].num,add_pars[n].fuv,0,0,0,0)){
 				add_pars[n].fuv[2]=0.0;
@@ -1849,6 +1858,7 @@
 				n++;
 			}
 		}
+#endif
 	}
 	if(n){
 		int newtotpart=totpart+n;
@@ -1971,7 +1981,7 @@
 		MEM_freeN(add_pars);
 	
 /* painting onto the deformed mesh, could be an option? */
-#if 0
+#if EXPEREMENTAL_DEFORM_ONLY_PAINTING
 	if (!deform_only)
 		dm->release(dm);
 #endif





More information about the Bf-blender-cvs mailing list