[Bf-blender-cvs] [e3eaca976a3] blender2.8: Draw manager: De-duplicate calculation of parent UVs

Sergey Sharybin noreply at git.blender.org
Wed May 9 10:34:59 CEST 2018


Commit: e3eaca976a334c34f811d2f14227f82d4b6d4342
Author: Sergey Sharybin
Date:   Tue May 8 14:06:00 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBe3eaca976a334c34f811d2f14227f82d4b6d4342

Draw manager: De-duplicate calculation of parent UVs

===================================================================

M	source/blender/draw/intern/draw_cache_impl_particles.c

===================================================================

diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index 7082895e096..19b0949d7ea 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -177,6 +177,32 @@ static void ensure_seg_pt_count(ParticleSystem *psys, ParticleBatchCache *cache)
 	}
 }
 
+/* Used by parent particles and simple children. */
+static void particle_calculate_parent_uvs(ParticleSystem *psys,
+                                          ParticleSystemModifierData *psmd,
+                                          const int num_uv_layers,
+                                          const int parent_index,
+                                          /*const*/ MTFace **mtfaces,
+                                          float (*r_uv)[2])
+{
+	ParticleData *particle = &psys->particles[parent_index];
+	int num = particle->num_dmcache;
+	if (num == DMCACHE_NOTFOUND) {
+		if (particle->num < psmd->dm_final->getNumTessFaces(psmd->dm_final)) {
+			num = particle->num;
+		}
+	}
+	if (num != DMCACHE_NOTFOUND) {
+		MFace *mface = psmd->dm_final->getTessFaceData(psmd->dm_final, num, CD_MFACE);
+		for (int j = 0; j < num_uv_layers; j++) {
+			psys_interpolate_uvs(mtfaces[j] + num,
+			                     mface->v4,
+			                     particle->fuv,
+			                     r_uv[j]);
+		}
+	}
+}
+
 /* Gwn_Batch cache usage. */
 static void particle_batch_cache_ensure_pos_and_seg(ParticleSystem *psys, ModifierData *md, ParticleBatchCache *cache)
 {
@@ -256,19 +282,8 @@ static void particle_batch_cache_ensure_pos_and_seg(ParticleSystem *psys, Modifi
 				}
 			}
 			if (ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) {
-				ParticleData *particle = &psys->particles[i];
-				int num = particle->num_dmcache;
-				if (num == DMCACHE_NOTFOUND) {
-					if (particle->num < psmd->dm_final->getNumTessFaces(psmd->dm_final)) {
-						num = particle->num;
-					}
-				}
-				if (num != DMCACHE_NOTFOUND) {
-					MFace *mface = psmd->dm_final->getTessFaceData(psmd->dm_final, num, CD_MFACE);
-					for (int j = 0; j < num_uv_layers; j++) {
-						psys_interpolate_uvs(mtfaces[j] + num, mface->v4, particle->fuv, uv[j]);
-					}
-				}
+				particle_calculate_parent_uvs(
+				        psys, psmd, num_uv_layers, i, mtfaces, uv);
 			}
 			for (int j = 0; j < path->segments; j++) {
 				if (j == 0) {
@@ -342,19 +357,9 @@ static void particle_batch_cache_ensure_pos_and_seg(ParticleSystem *psys, Modifi
 					uv = parent_uvs[psys->child[i].parent] = MEM_callocN(sizeof(*uv) * num_uv_layers, "Particle UVs");
 				}
 				if (ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) {
-					ParticleData *particle = &psys->particles[psys->child[i].parent];
-					int num = particle->num_dmcache;
-					if (num == DMCACHE_NOTFOUND) {
-						if (particle->num < psmd->dm_final->getNumTessFaces(psmd->dm_final)) {
-							num = particle->num;
-						}
-					}
-					if (num != DMCACHE_NOTFOUND) {
-						MFace *mface = psmd->dm_final->getTessFaceData(psmd->dm_final, num, CD_MFACE);
-						for (int j = 0; j < num_uv_layers; j++) {
-							psys_interpolate_uvs(mtfaces[j] + num, mface->v4, particle->fuv, uv[j]);
-						}
-					}
+					const int parent_index = psys->child[i].parent;
+					particle_calculate_parent_uvs(
+					        psys, psmd, num_uv_layers, parent_index, mtfaces, uv);
 				}
 			}
 			for (int j = 0; j < path->segments; j++) {



More information about the Bf-blender-cvs mailing list