[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34149] trunk/blender/source/blender/ blenkernel/intern/particle_system.c: Fix for [#25506] Hair showing up in places not assigned by a weightmap

Janne Karhu jhkarh at gmail.com
Fri Jan 7 11:13:31 CET 2011


Revision: 34149
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34149
Author:   jhk
Date:     2011-01-07 10:13:30 +0000 (Fri, 07 Jan 2011)
Log Message:
-----------
Fix for [#25506] Hair showing up in places not assigned by a weightmap
* Two separate bugs, with very similar symptoms.
* The distribution binary search didn't work correctly in cases where there were a lot of faces with 0 weights.
* Maximum distribution sum should have been exactly 1, but due to the wonderful nature of floats this wasn't the case at all.

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	2011-01-07 09:50:23 UTC (rev 34148)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c	2011-01-07 10:13:30 UTC (rev 34149)
@@ -616,15 +616,21 @@
 	}
 }
 
+/* Find the index in "sum" array before "value" is crossed. */
 static int binary_search_distribution(float *sum, int n, float value)
 {
 	int mid, low=0, high=n;
 
+	if(value == 0.f)
+		return 0;
+
 	while(low <= high) {
 		mid= (low + high)/2;
-		if(sum[mid] <= value && value <= sum[mid+1])
+		
+		if(sum[mid] < value && value <= sum[mid+1])
 			return mid;
-		else if(sum[mid] > value)
+		
+		if(sum[mid] >= value)
 			high= mid - 1;
 		else if(sum[mid] < value)
 			low= mid + 1;
@@ -1297,7 +1303,8 @@
 		float pos;
 
 		for(p=0; p<totpart; p++) {
-			pos= BLI_frand();
+			/* In theory sys[tot] should be 1.0, but due to float errors this is not necessarily always true, so scale pos accordingly. */
+			pos= BLI_frand() * sum[tot];
 			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