diff options
author | Luca Rood <dev@lucarood.com> | 2017-07-05 16:50:01 +0300 |
---|---|---|
committer | Luca Rood <dev@lucarood.com> | 2017-07-05 16:50:01 +0300 |
commit | bdeeb29482af2ab44e03e4681eb079bdcff82b21 (patch) | |
tree | 1bd0efa9a5e81fd93ef8af737605eb383fb6bf5d /source/blender/blenkernel/intern/particle.c | |
parent | f3764d51bd79a5b1eb7ea512817820da9d5150c5 (diff) | |
parent | fed853ea782211298c902759ec8cd8e455d8b41d (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenkernel/intern/particle.c')
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index dabade56490..f34a680b52d 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3379,7 +3379,8 @@ void BKE_particlesettings_make_local(Main *bmain, ParticleSettings *part, const /* Textures */ /************************************************/ -static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, const float fuv[4], char *name, float *texco) +static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int index, const float fuv[4], + char *name, float *texco, bool from_vert) { MFace *mf; MTFace *tf; @@ -3395,11 +3396,15 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co if (pa) { i = ELEM(pa->num_dmcache, DMCACHE_NOTFOUND, DMCACHE_ISCHILD) ? pa->num : pa->num_dmcache; - if (i >= dm->getNumTessFaces(dm)) + if ((!from_vert && i >= dm->getNumTessFaces(dm)) || + (from_vert && i >= dm->getNumVerts(dm))) + { i = -1; + } + } + else { + i = index; } - else - i = face_index; if (i == -1) { texco[0] = 0.0f; @@ -3407,7 +3412,19 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co texco[2] = 0.0f; } else { - mf = dm->getTessFaceData(dm, i, CD_MFACE); + if (from_vert) { + mf = dm->getTessFaceDataArray(dm, CD_MFACE); + + for (int j = 0; j < dm->getNumTessFaces(dm); j++, mf++) { + if (ELEM(i, mf->v1, mf->v2, mf->v3, mf->v4)) { + i = j; + break; + } + } + } + else { + mf = dm->getTessFaceData(dm, i, CD_MFACE); + } psys_interpolate_uvs(&tf[i], mf->v4, fuv, texco); @@ -3474,8 +3491,11 @@ static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSetti mul_m4_v3(mtex->object->imat, texvec); break; case TEXCO_UV: - if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname, texvec)) + if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname, + texvec, (part->from == PART_FROM_VERT))) + { break; + } /* no break, failed to get uv's, so let's try orco's */ ATTR_FALLTHROUGH; case TEXCO_ORCO: @@ -3547,8 +3567,11 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex mul_m4_v3(mtex->object->imat, texvec); break; case TEXCO_UV: - if (get_particle_uv(sim->psmd->dm_final, pa, 0, pa->fuv, mtex->uvname, texvec)) + if (get_particle_uv(sim->psmd->dm_final, pa, 0, pa->fuv, mtex->uvname, + texvec, (part->from == PART_FROM_VERT))) + { break; + } /* no break, failed to get uv's, so let's try orco's */ ATTR_FALLTHROUGH; case TEXCO_ORCO: |