[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16835] trunk/blender/source/blender/ blenkernel/intern/particle.c: Fix for part of bug #17521: incorrect uv coordinates for particle

Brecht Van Lommel brecht at blender.org
Tue Sep 30 01:33:27 CEST 2008


Revision: 16835
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16835
Author:   blendix
Date:     2008-09-30 01:33:27 +0200 (Tue, 30 Sep 2008)

Log Message:
-----------
Fix for part of bug #17521: incorrect uv coordinates for particle
density controlled by a texture.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/particle.c

Modified: trunk/blender/source/blender/blenkernel/intern/particle.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle.c	2008-09-29 22:31:47 UTC (rev 16834)
+++ trunk/blender/source/blender/blenkernel/intern/particle.c	2008-09-29 23:33:27 UTC (rev 16835)
@@ -3191,6 +3191,47 @@
 /************************************************/
 /*			Textures							*/
 /************************************************/
+
+static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, float *fuv, char *name, float *texco)
+{
+	MFace *mf;
+	MTFace *tf;
+	int i;
+	
+	tf= CustomData_get_layer_named(&dm->faceData, CD_MTFACE, name);
+
+	if(tf == NULL)
+		tf= CustomData_get_layer(&dm->faceData, CD_MTFACE);
+
+	if(tf == NULL)
+		return 0;
+
+	if(pa) {
+		i= (pa->num_dmcache==DMCACHE_NOTFOUND)? pa->num: pa->num_dmcache;
+		if(i >= dm->getNumFaces(dm))
+			i = -1;
+	}
+	else
+		i= face_index;
+
+	if (i==-1) {
+		texco[0]= 0.0f;
+		texco[1]= 0.0f;
+		texco[2]= 0.0f;
+	}
+	else {
+		mf= dm->getFaceData(dm, i, CD_MFACE);
+
+		psys_interpolate_uvs(&tf[i], mf->v4, fuv, texco);
+
+		texco[0]= texco[0]*2.0f - 1.0f;
+		texco[1]= texco[1]*2.0f - 1.0f;
+		texco[2]= 0.0f;
+	}
+
+	return 1;
+}
+
 static void get_cpa_texture(DerivedMesh *dm, Material *ma, int face_index, float *fw, float *orco, ParticleTexture *ptex, int event)
 {
 	MTex *mtex;
@@ -3205,27 +3246,13 @@
 			short blend=mtex->blendtype;
 			short neg=mtex->pmaptoneg;
 
-			if(mtex->texco & TEXCO_UV && fw){
-				int uv_index=CustomData_get_named_layer_index(&dm->faceData,CD_MTFACE,mtex->uvname);
-				if(uv_index<0){
-					uv_index=CustomData_get_active_layer_index(&dm->faceData,CD_MTFACE);
-				}
-				if(uv_index>=0){
-					CustomDataLayer *layer=&dm->faceData.layers[uv_index];
-					MTFace *mtface= &((MTFace*)layer->data)[face_index];
-					MFace *mf=dm->getFaceData(dm,face_index,CD_MFACE);
-					psys_interpolate_uvs(mtface,mf->v4,fw,texco);
-					texco[0]*=2.0;
-					texco[1]*=2.0;
-					texco[0]-=1.0;
-					texco[1]-=1.0;
-				}
-				else
+			if((mtex->texco & TEXCO_UV) && fw) {
+				if(!get_particle_uv(dm, NULL, face_index, fw, mtex->uvname, texco))
 					VECCOPY(texco,orco);
 			}
-			else{
+			else
 				VECCOPY(texco,orco);
-			}
+
 			externtex(mtex, texco, &value, rgba, rgba+1, rgba+2, rgba+3);
 			if((event & mtex->pmapto) & MAP_PA_TIME){
 				if((setvars&MAP_PA_TIME)==0){
@@ -3265,33 +3292,16 @@
 			short blend=mtex->blendtype;
 			short neg=mtex->pmaptoneg;
 
-			if(mtex->texco & TEXCO_UV){
-				int uv_index=CustomData_get_named_layer_index(&psmd->dm->faceData,CD_MTFACE,mtex->uvname);
-				if(uv_index<0){
-					uv_index=CustomData_get_active_layer_index(&psmd->dm->faceData,CD_MTFACE);
+			if((mtex->texco & TEXCO_UV) && ELEM(psys->part->from, PART_FROM_FACE, PART_FROM_VOLUME)) {
+				if(!get_particle_uv(psmd->dm, pa, 0, pa->fuv, mtex->uvname, texco)) {
+					/* failed to get uv's, let's try orco's */
+					psys_particle_on_emitter(ob,psmd,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,0,0,0,texco, 0);
 				}
-				if(uv_index>=0){
-					CustomDataLayer *layer=&psmd->dm->faceData.layers[uv_index];
-					MTFace *mtface= &((MTFace*)layer->data)[pa->num];
-					MFace *mf=psmd->dm->getFaceData(psmd->dm,pa->num,CD_MFACE);
-					psys_interpolate_uvs(mtface,mf->v4,pa->fuv,texco);
-					texco[0]*=2.0;
-					texco[1]*=2.0;
-					texco[0]-=1.0;
-					texco[1]-=1.0;
-				}
-				else
-					//psys_particle_on_emitter(ob,psmd,psys->part->from,pa->num,pa->fuv,pa->foffset,texco,0,0,0);
-					/* <jahka> anyways I think it will be too small a difference to notice, so psys_get_texture should only know about the original mesh structure.. no dm needed anywhere */
-					/* <brecht> the code only does dm based lookup now, so passing num_dmcache anyway to avoid^
-					 * massive slowdown here */
-					psys_particle_on_emitter(ob,psmd,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,0,0,0,texco, 0);
 			}
-			else{
-				//psys_particle_on_emitter(ob,psmd,psys->part->from,pa->num,pa->fuv,pa->offset,texco,0,0,0);
-				/* ditto above */
+			else {
 				psys_particle_on_emitter(ob,psmd,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,0,0,0,texco, 0);
 			}
+
 			externtex(mtex, texco, &value, rgba, rgba+1, rgba+2, rgba+3);
 
 			if((event & mtex->pmapto) & MAP_PA_TIME){





More information about the Bf-blender-cvs mailing list