diff options
Diffstat (limited to 'source/blender/blenkernel/intern/particle_system.c')
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 3db42f091d4..c0ffb7c62f8 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -780,6 +780,21 @@ void *exec_distribution(void *data) return 0; } +/* not thread safe, but qsort doesn't take userdata argument */ +static int *COMPARE_ORIG_INDEX = NULL; +static int compare_orig_index(const void *p1, const void *p2) +{ + int index1 = COMPARE_ORIG_INDEX[*(const int*)p1]; + int index2 = COMPARE_ORIG_INDEX[*(const int*)p2]; + + if(index1 < index2) + return -1; + else if(index1 == index2) + return 0; + else + return 1; +} + /* creates a distribution of coordinates on a DerivedMesh */ /* */ /* 1. lets check from what we are emitting */ @@ -1157,6 +1172,13 @@ int psys_threads_init_distribution(ParticleThread *threads, DerivedMesh *finaldm MEM_freeN(sum); + /* for hair, sort by origindex, allows optimizations in rendering */ + if(part->type == PART_HAIR) { + COMPARE_ORIG_INDEX= dm->getFaceDataArray(dm, CD_ORIGINDEX); + if(COMPARE_ORIG_INDEX) + qsort(index, totpart, sizeof(int), compare_orig_index); + } + /* weights are no longer used except for FROM_PARTICLE, which needs them zeroed for indexing */ if(from==PART_FROM_PARTICLE){ for(i=0; i<tot; i++) |