Merged changes in the trunk up to revision 51853.
[blender-staging.git] / source / blender / render / intern / source / convertblender.c
index 4aa30e6c4cf55a85c6eca2ec22c19563a7793982..4746e0f6b08a0d475252fab000d6f232871833d3 100644 (file)
@@ -1526,9 +1526,12 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
        int i, a, k, max_k=0, totpart, do_simplify = FALSE, do_surfacecache = FALSE, use_duplimat = FALSE;
        int totchild=0;
        int seed, path_nbr=0, orco1=0, num;
-       int totface, *origindex = 0;
+       int totface;
        char **uv_name=0;
 
+       const int *index_mf_to_mpoly = NULL;
+       const int *index_mp_to_orig = NULL;
+
 /* 1. check that everything is ok & updated */
        if (psys==NULL)
                return 0;
@@ -1698,9 +1701,13 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                                        do_surfacecache = TRUE;
 
                        totface= psmd->dm->getNumTessFaces(psmd->dm);
-                       origindex= psmd->dm->getTessFaceDataArray(psmd->dm, CD_ORIGINDEX);
+                       index_mf_to_mpoly = psmd->dm->getTessFaceDataArray(psmd->dm, CD_ORIGINDEX);
+                       index_mp_to_orig = psmd->dm->getPolyDataArray(psmd->dm, CD_ORIGINDEX);
+                       if ((index_mf_to_mpoly && index_mp_to_orig) == FALSE) {
+                               index_mf_to_mpoly = index_mp_to_orig = NULL;
+                       }
                        for (a=0; a<totface; a++)
-                               strandbuf->totbound= MAX2(strandbuf->totbound, (origindex)? origindex[a]: a);
+                               strandbuf->totbound = max_ii(strandbuf->totbound, (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, a): a);
 
                        strandbuf->totbound++;
                        strandbuf->bound= MEM_callocN(sizeof(StrandBound)*strandbuf->totbound, "StrandBound");
@@ -1811,7 +1818,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                        do_simplify = psys_render_simplify_params(psys, cpa, simplify);
 
                        if (strandbuf) {
-                               int orignum= (origindex)? origindex[cpa->num]: cpa->num;
+                               int orignum = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, cpa->num) : cpa->num;
 
                                if (orignum > sbound - strandbuf->bound) {
                                        sbound= strandbuf->bound + orignum;