[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12475] branches/particles/source/blender: WIP commit, nor for general use still.

Campbell Barton cbarton at metavr.com
Sun Nov 4 21:56:21 CET 2007


Revision: 12475
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12475
Author:   campbellbarton
Date:     2007-11-04 21:56:21 +0100 (Sun, 04 Nov 2007)

Log Message:
-----------
WIP commit, nor for general use still.
when changingg subsurf levels hair was not updating the derived mesh faces it is attached to.
painting hair now has some experemental code to paint onto the original faces and assigne the (temporary) derived mesh face as well.

Modified Paths:
--------------
    branches/particles/source/blender/blenkernel/intern/particle.c
    branches/particles/source/blender/blenkernel/intern/particle_system.c
    branches/particles/source/blender/blenlib/BLI_arithb.h
    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-04 19:43:33 UTC (rev 12474)
+++ branches/particles/source/blender/blenkernel/intern/particle.c	2007-11-04 20:56:21 UTC (rev 12475)
@@ -893,16 +893,6 @@
 			 * since the fuv is the position on the face on the original mesh */
 			float fuv_mod[3] = {0.0,0.0,0.0};
 			
-			/* Not for quads, use for our abuse of LineIntersectsTriangleUV */
-			float p1[3], p2[3], v0[3], v1[3], v2[3], lambda;
-			
-			p1[0] = p2[0] = fuv[0];
-			p1[1] = p2[1] = fuv[1];
-			p1[2] = 1.0f;
-			p2[2] = -1.0f;
-			v0[2] = v1[2] = v2[2] = 0.0;
-			
-			
 			origindex = oi = dm->getFaceDataArray(dm, CD_ORIGINDEX);
 			totface = dm->getNumFaces(dm);
 			
@@ -936,25 +926,7 @@
 			mtface= dm->getFaceData(dm, i, CD_MTFACE); 
 			osface= dm->getFaceData(dm, i, CD_ORIGSPACE);
 			
-			if (mface->v4) {
-				PointInQuad2DUV(osface->uv[0], osface->uv[1], osface->uv[2], osface->uv[3], fuv, fuv_mod);
-			} else {
-				/* generate a new fuv, (this is possibly a non optimal solution,
-				* since we only need 2d calculation but use 3d func's)
-				* 
-				* 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.
-						*/
-				Vec2Copyf(v0, osface->uv[0]);
-				Vec2Copyf(v1, osface->uv[1]);
-				Vec2Copyf(v2, osface->uv[2]);
-						
-				/* Doing this in 3D is not nice */
-				LineIntersectsTriangleUV(p1, p2, v0, v1, v2, &lambda, fuv_mod);
-				//fuv_mod[1] = 1.0f-fuv_mod[1];
-				psys_interpolate_face(mvert,mface,mtface,fuv_mod,vec,nor,utan,vtan);
-			}
+			PointInFace2DUV(mface->v4, osface->uv[0], osface->uv[1], osface->uv[2], osface->uv[3], fuv, fuv_mod);
 			psys_interpolate_face(mvert,mface,mtface,fuv_mod,vec,nor,utan,vtan);
 		} else {
 			/* TODO PARTICLE - support verts and volume */

Modified: branches/particles/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/particle_system.c	2007-11-04 19:43:33 UTC (rev 12474)
+++ branches/particles/source/blender/blenkernel/intern/particle_system.c	2007-11-04 20:56:21 UTC (rev 12475)
@@ -4102,6 +4102,8 @@
 		vg_size=psys_cache_vgroup(psmd->dm,psys,PSYS_VG_SIZE);
 
 	if(part->type == PART_HAIR) {
+		/* need this for changing subsurf levels */
+		psys_calc_dmfaces(ob, psmd->dm, psys);
 		if(psys->flag & PSYS_HAIR_DONE) {
 			hair_step(ob, psmd, psys, cfra);
 			psys->cfra = cfra;
@@ -4199,8 +4201,9 @@
 
 	/* ok now we're all set so let's go */
 	if(psys->totpart) {
-		if(psys->part->from==PART_FROM_FACE)
+		if(psys->part->from==PART_FROM_FACE) {
 			psys_calc_dmfaces(ob, psmd->dm, psys);
+		}
 		dynamics_step(ob,psys,psmd,cfra,vg_vel,vg_tan,vg_rot,vg_size);
 	}
 	psys->recalc = 0;

Modified: branches/particles/source/blender/blenlib/BLI_arithb.h
===================================================================
--- branches/particles/source/blender/blenlib/BLI_arithb.h	2007-11-04 19:43:33 UTC (rev 12474)
+++ branches/particles/source/blender/blenlib/BLI_arithb.h	2007-11-04 20:56:21 UTC (rev 12475)
@@ -372,6 +372,7 @@
 int AabbIntersectAabb(float min1[3], float max1[3], float min2[3], float max2[3]);
 void VecfCubicInterpol(float *x1, float *v1, float *x2, float *v2, float t, float *x, float *v);
 void PointInQuad2DUV(float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv);
+void PointInFace2DUV(int isquad, float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv);
 int point_in_tri_prism(float p[3], float v1[3], float v2[3], float v3[3]);
 
 typedef struct DualQuat {

Modified: branches/particles/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/particles/source/blender/blenlib/intern/arithb.c	2007-11-04 19:43:33 UTC (rev 12474)
+++ branches/particles/source/blender/blenlib/intern/arithb.c	2007-11-04 20:56:21 UTC (rev 12475)
@@ -3918,7 +3918,7 @@
 	return(Inpf(u,h)/Inpf(u,u));
 }
 
-/* Similar to LineIntersectsTriangleUV, expect it operates on a quad and in 2d, assumes tri is in quad */
+/* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 2d, assumes point is in quad */
 void PointInQuad2DUV(float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv)
 {
 	float x0,y0, x1,y1, wtot, v2d[2], w1, w2;
@@ -4011,6 +4011,40 @@
 	}
 }
 
+/* same as above but does tri's and quads, tri's are a bit of a hack :/ */
+void PointInFace2DUV(int isquad, float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv)
+{
+	if (isquad) {
+		PointInQuad2DUV(v0, v1, v2, v3, pt, uv);
+	} else {
+		
+		/* Not for quads, use for our abuse of LineIntersectsTriangleUV */
+		float p1_3d[3], p2_3d[3], v0_3d[3], v1_3d[3], v2_3d[3], lambda;
+			
+		p1_3d[0] = p2_3d[0] = uv[0];
+		p1_3d[1] = p2_3d[1] = uv[1];
+		p1_3d[2] = 1.0f;
+		p2_3d[2] = -1.0f;
+		v0_3d[2] = v1_3d[2] = v2_3d[2] = 0.0;
+		
+		/* generate a new fuv, (this is possibly a non optimal solution,
+		* since we only need 2d calculation but use 3d func's)
+		* 
+		* 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.
+				*/
+		Vec2Copyf(v0_3d, v0);
+		Vec2Copyf(v1_3d, v1);
+		Vec2Copyf(v2_3d, v2);
+		
+		/* Doing this in 3D is not nice */
+		LineIntersectsTriangleUV(p1_3d, p2_3d, v0_3d, v1_3d, v2_3d, &lambda, uv);
+		//fuv_mod[1] = 1.0f-fuv_mod[1];
+	}
+}
+
+
 /* didn't find cubic interpolation anywhere else so here we go, this*/
 /* too can be moved to somewhere more apropriate if not needed		*/
 /* anywhere else than particle.c -jahka								*/

Modified: branches/particles/source/blender/src/editparticle.c
===================================================================
--- branches/particles/source/blender/src/editparticle.c	2007-11-04 19:43:33 UTC (rev 12474)
+++ branches/particles/source/blender/src/editparticle.c	2007-11-04 20:56:21 UTC (rev 12475)
@@ -1734,12 +1734,20 @@
 	short size = edit->brushsize[PE_BRUSH_ADD];
 	short size2 = size*size;
 	int deform_only;
+
 	Mat4Invert(imat,ob->obmat);
 
 	BLI_srandom(psys->seed+mval[0]+mval[1]);
 	
 	deform_only = modifiers_isDeformedOnly(ob);
-	
+
+	/* painting onto the deformed mesh, could be an option? */
+#if 0
+	if (deform_only)
+		dm = psmd->dm;
+	else
+		dm = mesh_get_derived_deform(ob, CD_MASK_BAREMESH);
+#endif
 	for(i=0; i<number; i++){
 		if(number>1){
 			dmx=dmy=size;
@@ -1783,29 +1791,63 @@
 		min_d=2.0;
 		
 		/* warning, returns the derived mesh face */
-		if(psys_intersect_dm(ob,psmd->dm,0,co1,co2,&min_d,&add_pars[n].num,add_pars[n].fuv,0,0,0,0)){
-			//mface=psmd->dm->getFaceData(psmd->dm,add_pars[n].num,CD_MFACE);
-			add_pars[n].fuv[2]=0.0;
-			
-			
-			if (!deform_only) {
+		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;
+				n++;
+			}
+		} else {
+			/* we need to test against the cage mesh, because 1) its faster and 2) then we can avoid converting the fuv back which is not simple */
+			if(psys_intersect_dm(ob,psmd->dm,0,co1,co2,&min_d,&add_pars[n].num,add_pars[n].fuv,0,0,0,0)){
 				float fuv_mod[3] = {0.0, 0.0, 0.0};
+				OrigSpaceFace *osface;
+				
+				mface= psmd->dm->getFaceData(psmd->dm,add_pars[n].num,CD_MFACE);
+				osface= psmd->dm->getFaceData(psmd->dm, add_pars[n].num, CD_ORIGSPACE);
+				
+				add_pars[n].fuv[2]=0.0;
+				
 				/* use the original index for num and the derived index for num_dmcache */
 				add_pars[n].num_dmcache = add_pars[n].num;
 				add_pars[n].num = *(int *)psmd->dm->getFaceData(psmd->dm, add_pars[n].num, CD_ORIGINDEX);
-				//printf("Test Paint %i:%i\n", add_pars[n].num, add_pars[n].num_dmcache);
 				
-				/* now convert the fuv mode back to the original face TODO PARTICLE */
-				/* Note, we COULD only paint onto the deformed mesh, would be less work */
-				/*add_pars[n].fuv*/
+				/* This is totally unaceptable code (fakeing mesh dara) but changing the target function isnt really nice either, do this temporarily */
+				if (1) { /* Evilness*/
+					MFace mface_fake;
+					MVert mvert_fake[4];
+					//int test1,test2;
+					//test1 = add_pars[n].num_dmcache;
+					//test2 = add_pars[n].num;
+					
+					mvert_fake[0].co[2] = mvert_fake[1].co[2] = mvert_fake[2].co[2] = mvert_fake[3].co[2] = 0.0;
+					
+					mface_fake.v1 = 0;
+					mface_fake.v2 = 1;
+					mface_fake.v3 = 2;
+					
+					if (mface->v4) {
+						mface_fake.v4 = 3;
+					} else {
+						mface_fake.v4 = 0;
+					}
+					
+					Vec2Copyf(mvert_fake[0].co, osface->uv[0]);
+					Vec2Copyf(mvert_fake[1].co, osface->uv[1]);
+					Vec2Copyf(mvert_fake[2].co, osface->uv[2]);
+					Vec2Copyf(mvert_fake[3].co, osface->uv[3]);
+					//printf("before %f %f %i %i\n", add_pars[n].fuv[0], add_pars[n].fuv[1], test1, test2);
+					psys_interpolate_face(&mvert_fake, &mface_fake, NULL, &add_pars[n].fuv, &fuv_mod, NULL, NULL, NULL);
+					
+					/* Apply as the UV */
+					Vec2Copyf(add_pars[n].fuv, fuv_mod);
+					//printf("after %f %f\n", add_pars[n].fuv[0], add_pars[n].fuv[1]);
+				}
+				/* Make a fake face, for calculating the derived face's fuv on the original face */
+				//PointInFace2DUV(mface->v4, osface->uv[0], osface->uv[1], osface->uv[2], osface->uv[3], add_pars[n].fuv, fuv_mod);
+				//Vec2Copyf(add_pars[n].fuv, fuv_mod);
 				
+				n++;
 			}
-			
-			//add_pars[n].verts[0]=mface->v1;
-			//add_pars[n].verts[1]=mface->v2;
-			//add_pars[n].verts[2]=mface->v3;
-
-			n++;
 		}
 	}
 	if(n){
@@ -1854,8 +1896,6 @@
 				ekey->co = hkey->co;
 				ekey->time = &hkey->time;
 			}
-
-			//mface = psmd->dm->getFaceData(psmd->dm,pa->num,CD_MFACE);
 			
 			initialize_particle(pa,i,ob,psys,psmd);
 			reset_particle(pa,psys,psmd,ob,deform_only,0.0,1.0,0,0,0);
@@ -1929,6 +1969,12 @@
 	}
 	if(add_pars)
 		MEM_freeN(add_pars);
+	
+/* painting onto the deformed mesh, could be an option? */
+#if 0
+	if (!deform_only)
+		dm->release(dm);
+#endif
 }

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list