svn merge ^/trunk/blender -r42521:42550
[blender.git] / source / blender / blenkernel / intern / particle.c
index 000df5e721d3ad8486d1742aeab5833036b90e3a..b84d06d78e955e8116925a798c7d15d840075f77 100644 (file)
@@ -55,6 +55,8 @@
 #include "BLI_threads.h"
 #include "BLI_linklist.h"
 #include "BLI_bpath.h"
+#include "BLI_cellalloc.h"
+#include "BLI_math.h"
 
 #include "BKE_anim.h"
 #include "BKE_animsys.h"
@@ -696,7 +698,7 @@ void psys_render_set(Object *ob, ParticleSystem *psys, float viewmat[][4], float
        data->totchildcache= psys->totchildcache;
 
        if(psmd->dm)
-               data->dm= CDDM_copy(psmd->dm);
+               data->dm= CDDM_copy(psmd->dm, 0);
        data->totdmvert= psmd->totdmvert;
        data->totdmedge= psmd->totdmedge;
        data->totdmface= psmd->totdmface;
@@ -799,9 +801,9 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot)
                return tot;
 
        mvert= dm->getVertArray(dm);
-       mface= dm->getFaceArray(dm);
-       origindex= dm->getFaceDataArray(dm, CD_ORIGINDEX);
-       totface= dm->getNumFaces(dm);
+       mface= dm->getTessFaceArray(dm);
+       origindex= dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
+       totface= dm->getNumTessFaces(dm);
        totorigface= me->totface;
 
        if(totface == 0 || totorigface == 0)
@@ -1540,7 +1542,7 @@ static float psys_interpolate_value_from_verts(DerivedMesh *dm, short from, int
                case PART_FROM_FACE:
                case PART_FROM_VOLUME:
                {
-                       MFace *mf=dm->getFaceData(dm,index,CD_MFACE);
+                       MFace *mf=dm->getTessFaceData(dm,index,CD_MFACE);
                        return interpolate_particle_value(values[mf->v1],values[mf->v2],values[mf->v3],values[mf->v4],fw,mf->v4);
                }
                        
@@ -1588,11 +1590,11 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, const f
        int quad, findex, totface;
        float uv[2], (*faceuv)[2];
 
-       mface = dm->getFaceDataArray(dm, CD_MFACE);
-       origindex = dm->getFaceDataArray(dm, CD_ORIGINDEX);
-       osface = dm->getFaceDataArray(dm, CD_ORIGSPACE);
+       mface = dm->getTessFaceDataArray(dm, CD_MFACE);
+       origindex = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
+       osface = dm->getTessFaceDataArray(dm, CD_ORIGSPACE);
 
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
        
        if(osface==NULL || origindex==NULL) {
                /* Assume we dont need osface data */
@@ -1661,7 +1663,7 @@ static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_
                        *mapindex = index;
                }
                else  { /* FROM_FACE/FROM_VOLUME */
-                       if(index >= dm->getNumFaces(dm))
+                       if(index >= dm->getNumTessFaces(dm))
                                return 0;
 
                        *mapindex = index;
@@ -1685,15 +1687,15 @@ static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_
 
                        i = index_dmcache;
 
-                       if(i== DMCACHE_NOTFOUND || i >= dm->getNumFaces(dm))
+                       if(i== DMCACHE_NOTFOUND || i >= dm->getNumTessFaces(dm))
                                return 0;
 
                        *mapindex = i;
 
                        /* modify the original weights to become
                         * weights for the derived mesh face */
-                       osface= dm->getFaceDataArray(dm, CD_ORIGSPACE);
-                       mface= dm->getFaceData(dm, i, CD_MFACE);
+                       osface= dm->getTessFaceDataArray(dm, CD_ORIGSPACE);
+                       mface= dm->getTessFaceData(dm, i, CD_MFACE);
 
                        if(osface == NULL)
                                mapfw[0]= mapfw[1]= mapfw[2]= mapfw[3]= 0.0f;
@@ -1751,7 +1753,7 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache
                MTFace *mtface;
                MVert *mvert;
 
-               mface=dm->getFaceData(dm,mapindex,CD_MFACE);
+               mface=dm->getTessFaceData(dm,mapindex,CD_MFACE);
                mvert=dm->getVertDataArray(dm,CD_MVERT);
                mtface=CustomData_get_layer(&dm->faceData,CD_MTFACE);
 
@@ -3313,10 +3315,10 @@ static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float m
 
        int i = pa->num_dmcache==DMCACHE_NOTFOUND ? pa->num : pa->num_dmcache;
        
-       if (i==-1 || i >= dm->getNumFaces(dm)) { unit_m4(mat); return; }
+       if (i==-1 || i >= dm->getNumTessFaces(dm)) { unit_m4(mat); return; }
 
-       mface=dm->getFaceData(dm,i,CD_MFACE);
-       osface=dm->getFaceData(dm,i,CD_ORIGSPACE);
+       mface=dm->getTessFaceData(dm,i,CD_MFACE);
+       osface=dm->getTessFaceData(dm,i,CD_ORIGSPACE);
        
        if(orco && (orcodata=dm->getVertDataArray(dm, CD_ORCO))) {
                copy_v3_v3(v[0], orcodata[mface->v1]);
@@ -3631,7 +3633,6 @@ void make_local_particlesettings(ParticleSettings *part)
        }
        else if(is_local && is_lib) {
                ParticleSettings *part_new= psys_copy_settings(part);
-
                part_new->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
@@ -3671,7 +3672,7 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co
 
        if(pa) {
                i= (pa->num_dmcache==DMCACHE_NOTFOUND)? pa->num: pa->num_dmcache;
-               if(i >= dm->getNumFaces(dm))
+               if(i >= dm->getNumTessFaces(dm))
                        i = -1;
        }
        else
@@ -3683,7 +3684,7 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co
                texco[2]= 0.0f;
        }
        else {
-               mf= dm->getFaceData(dm, i, CD_MFACE);
+               mf= dm->getTessFaceData(dm, i, CD_MFACE);
 
                psys_interpolate_uvs(&tf[i], mf->v4, fuv, texco);
 
@@ -4328,7 +4329,7 @@ void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part, Partic
                if(part->childtype == PART_CHILD_FACES) {
                        mtface= CustomData_get_layer(&psmd->dm->faceData, CD_MTFACE);
                        if(mtface) {
-                               mface= psmd->dm->getFaceData(psmd->dm, cpa->num, CD_MFACE);
+                               mface= psmd->dm->getTessFaceData(psmd->dm, cpa->num, CD_MFACE);
                                mtface += cpa->num;
                                psys_interpolate_uvs(mtface, mface->v4, cpa->fuv, uv);
                        }
@@ -4348,14 +4349,14 @@ void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part, Partic
                if(num == DMCACHE_NOTFOUND)
                        num= pa->num;
 
-               if (num >= psmd->dm->getNumFaces(psmd->dm)) {
+               if (num >= psmd->dm->getNumTessFaces(psmd->dm)) {
                        /* happens when simplify is enabled
                                * gives invalid coords but would crash otherwise */
                        num= DMCACHE_NOTFOUND;
                }
 
                if(mtface && num != DMCACHE_NOTFOUND) {
-                       mface= psmd->dm->getFaceData(psmd->dm, num, CD_MFACE);
+                       mface= psmd->dm->getTessFaceData(psmd->dm, num, CD_MFACE);
                        mtface += num;
                        psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv);
                }
@@ -4514,7 +4515,6 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3]
        madd_v3_v3fl(center, yvec, bb->offset[1]);
 }
 
-
 void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) {
        ParticleSimulationData sim= {0};
        sim.scene= scene;