[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12731] trunk/blender/source/blender/ blenkernel/intern/particle_system.c:
Brecht Van Lommel
brechtvanlommel at pandora.be
Fri Nov 30 14:28:33 CET 2007
Revision: 12731
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12731
Author: blendix
Date: 2007-11-30 14:28:33 +0100 (Fri, 30 Nov 2007)
Log Message:
-----------
Bugfix:
Random particle distribution did not normalize weights properly,
could give particles on invalid faces.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/particle_system.c
Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c 2007-11-30 10:38:59 UTC (rev 12730)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c 2007-11-30 13:28:33 UTC (rev 12731)
@@ -494,7 +494,7 @@
//int *vertpart=0;
int jitlevel= 1, intersect, distr;
float *weight=0,*sum=0,*jitoff=0;
- float cur, maxweight=0.0,tweight;
+ float cur, maxweight=0.0, tweight, totweight;
float *v1, *v2, *v3, *v4, co[3], nor[3], co1[3], co2[3], nor1[3];
float cur_d, min_d;
DerivedMesh *dm= NULL;
@@ -756,9 +756,16 @@
}
/* 3. */
+ totweight= 0.0f;
+ for(i=0;i<tot; i++)
+ totweight += weight[i];
+
+ if(totweight > 0.0f)
+ totweight= 1.0f/totweight;
+
sum[0]= 0.0f;
for(i=0;i<tot; i++)
- sum[i+1]= sum[i]+weight[i];
+ sum[i+1]= sum[i]+weight[i]*totweight;
if(part->flag&PART_TRAND){
float pos;
@@ -766,6 +773,7 @@
for(p=0; p<totpart; p++) {
pos= BLI_frand();
index[p]= binary_search_distribution(sum, tot, pos);
+ index[p]= MIN2(tot-1, index[p]);
jitoff[index[p]]= pos;
}
}
More information about the Bf-blender-cvs
mailing list