[Bf-blender-cvs] [d50821f1455] blender2.8: Particle edit: Initial support of edit with copy-on-write

Sergey Sharybin noreply at git.blender.org
Fri May 11 12:49:39 CEST 2018


Commit: d50821f145550b60078ce1106edd21348476d960
Author: Sergey Sharybin
Date:   Fri May 11 12:44:43 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBd50821f145550b60078ce1106edd21348476d960

Particle edit: Initial support of edit with copy-on-write

The idea is that edit mode structure is owned by original object,
and used for drawing. This is a bit confusing, especially since
path cache is also in that structure and needs evaluated object
to calculate cache.

In the future we should split edit data from visualization data,
but that's bigger refactor.

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

M	source/blender/blenkernel/intern/particle.c
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_particles.c
M	source/blender/draw/modes/particle_mode.c
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/physics/particle_object.c
M	source/blender/editors/physics/physics_intern.h

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

diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index ae6028c742a..83484089a6a 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -2575,6 +2575,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
 }
 void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCacheEdit *edit, float cfra, const bool use_render_params)
 {
+	Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
 	ParticleCacheKey *ca, **cache = edit->pathcache;
 	ParticleEditSettings *pset = &scene->toolsettings->particle;
 	
@@ -2582,8 +2583,19 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCac
 	PTCacheEditKey *ekey = NULL;
 
 	ParticleSystem *psys = edit->psys;
+	ParticleSystem *psys_eval = NULL;
 	ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys);
-	ParticleData *pa = psys ? psys->particles : NULL;
+	ParticleSystemModifierData *psmd_eval = NULL;
+
+	BLI_assert((ob->id.tag & LIB_TAG_COPY_ON_WRITE) == 0);
+	BLI_assert(psmd != NULL);
+
+	if (psmd != NULL) {
+		psmd_eval = (ParticleSystemModifierData *)modifiers_findByName(ob_eval, psmd->modifier.name);
+		psys_eval = psmd_eval->psys;
+	}
+
+	ParticleData *pa = psys_eval ? psys_eval->particles : NULL;
 
 	ParticleInterpolationData pind;
 	ParticleKey result;
@@ -2612,7 +2624,7 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCac
 
 	/* frs_sec = (psys || edit->pid.flag & PTCACHE_VEL_PER_SEC) ? 25.0f : 1.0f; */ /* UNUSED */
 
-	const bool use_weight = (pset->brushtype == PE_BRUSH_WEIGHT) && (psys != NULL) && (psys->particles != NULL);
+	const bool use_weight = (pset->brushtype == PE_BRUSH_WEIGHT) && (psys_eval != NULL) && (psys_eval->particles != NULL);
 
 	if (use_weight) {
 		; /* use weight painting colors now... */
@@ -2657,10 +2669,10 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCac
 		cache[i]->segments = segments;
 
 		/*--get the first data points--*/
-		init_particle_interpolation(ob, psys, pa, &pind);
+		init_particle_interpolation(ob_eval, psys_eval, pa, &pind);
 
-		if (psys) {
-			psys_mat_hair_to_global(ob, psmd->dm_final, psys->part->from, pa, hairmat);
+		if (psys_eval) {
+			psys_mat_hair_to_global(ob_eval, psmd_eval->dm_final, psys->part->from, pa, hairmat);
 			copy_v3_v3(rotmat[0], hairmat[2]);
 			copy_v3_v3(rotmat[1], hairmat[1]);
 			copy_v3_v3(rotmat[2], hairmat[0]);
@@ -2679,7 +2691,7 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCac
 			time = (float)k / (float)segments;
 			t = birthtime + time * (dietime - birthtime);
 			result.time = -t;
-			do_particle_interpolation(psys, i, pa, t, &pind, &result);
+			do_particle_interpolation(psys_eval, i, pa, t, &pind, &result);
 			copy_v3_v3(ca->co, result.co);
 
 			/* non-hair points are already in global space */
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index b70ed1d053d..6c6e9a732b3 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -2886,19 +2886,19 @@ Gwn_Batch *DRW_cache_particles_get_dots(Object *object, ParticleSystem *psys)
 	return DRW_particles_batch_cache_get_dots(object, psys);
 }
 
-Gwn_Batch *DRW_cache_particles_get_edit_strands(struct PTCacheEdit *edit)
+Gwn_Batch *DRW_cache_particles_get_edit_strands(Object *object, struct PTCacheEdit *edit)
 {
-	return DRW_particles_batch_cache_get_edit_strands(edit);
+	return DRW_particles_batch_cache_get_edit_strands(object, edit);
 }
 
-Gwn_Batch *DRW_cache_particles_get_edit_inner_points(struct PTCacheEdit *edit)
+Gwn_Batch *DRW_cache_particles_get_edit_inner_points(Object *object, struct PTCacheEdit *edit)
 {
-	return DRW_particles_batch_cache_get_edit_inner_points(edit);
+	return DRW_particles_batch_cache_get_edit_inner_points(object, edit);
 }
 
-Gwn_Batch *DRW_cache_particles_get_edit_tip_points(struct PTCacheEdit *edit)
+Gwn_Batch *DRW_cache_particles_get_edit_tip_points(Object *object, struct PTCacheEdit *edit)
 {
-	return DRW_particles_batch_cache_get_edit_tip_points(edit);
+	return DRW_particles_batch_cache_get_edit_tip_points(object, edit);
 }
 
 Gwn_Batch *DRW_cache_particles_get_prim(int type)
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 66db405786d..2dc07e40c42 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -169,9 +169,9 @@ struct Gwn_Batch *DRW_cache_lattice_vert_overlay_get(struct Object *ob);
 /* Particles */
 struct Gwn_Batch *DRW_cache_particles_get_hair(struct ParticleSystem *psys, struct ModifierData *md);
 struct Gwn_Batch *DRW_cache_particles_get_dots(struct Object *object, struct ParticleSystem *psys);
-struct Gwn_Batch *DRW_cache_particles_get_edit_strands(struct PTCacheEdit *edit);
-struct Gwn_Batch *DRW_cache_particles_get_edit_inner_points(struct PTCacheEdit *edit);
-struct Gwn_Batch *DRW_cache_particles_get_edit_tip_points(struct PTCacheEdit *edit);
+struct Gwn_Batch *DRW_cache_particles_get_edit_strands(struct Object *object, struct PTCacheEdit *edit);
+struct Gwn_Batch *DRW_cache_particles_get_edit_inner_points(struct Object *object, struct PTCacheEdit *edit);
+struct Gwn_Batch *DRW_cache_particles_get_edit_tip_points(struct Object *object, struct PTCacheEdit *edit);
 struct Gwn_Batch *DRW_cache_particles_get_prim(int type);
 
 /* Metaball */
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 4e3c56eb427..9d9668f3ffc 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -125,8 +125,8 @@ void DRW_mesh_cache_sculpt_coords_ensure(struct Mesh *me);
 /* Particles */
 struct Gwn_Batch *DRW_particles_batch_cache_get_hair(struct ParticleSystem *psys, struct ModifierData *md);
 struct Gwn_Batch *DRW_particles_batch_cache_get_dots(struct Object *object, struct ParticleSystem *psys);
-struct Gwn_Batch *DRW_particles_batch_cache_get_edit_strands(struct PTCacheEdit *edit);
-struct Gwn_Batch *DRW_particles_batch_cache_get_edit_inner_points(struct PTCacheEdit *edit);
-struct Gwn_Batch *DRW_particles_batch_cache_get_edit_tip_points(struct PTCacheEdit *edit);
+struct Gwn_Batch *DRW_particles_batch_cache_get_edit_strands(struct Object *object, struct PTCacheEdit *edit);
+struct Gwn_Batch *DRW_particles_batch_cache_get_edit_inner_points(struct Object *object, struct PTCacheEdit *edit);
+struct Gwn_Batch *DRW_particles_batch_cache_get_edit_tip_points(struct Object *object, struct PTCacheEdit *edit);
 
 #endif /* __DRAW_CACHE_IMPL_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index 4102b72175f..f1ae9d6ef8c 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -597,10 +597,25 @@ Gwn_Batch *DRW_particles_batch_cache_get_dots(Object *object, ParticleSystem *ps
 	return cache->hairs;
 }
 
-Gwn_Batch *DRW_particles_batch_cache_get_edit_strands(PTCacheEdit *edit)
+/* TODO(sergey): Avoid linear lookup. */
+static ParticleBatchCache *particle_batch_cache_get_edit(Object *object, PTCacheEdit *edit)
+{
+	ParticleSystem *psys_orig = edit->psys;
+	for (ParticleSystem *psys_eval = object->particlesystem.first;
+	     psys_eval != NULL;
+	     psys_eval = psys_eval->next)
+	{
+		if (STREQ(psys_orig->name, psys_eval->name)) {
+			return particle_batch_cache_get(psys_eval);
+		}
+	}
+	return NULL;
+}
+
+Gwn_Batch *DRW_particles_batch_cache_get_edit_strands(Object *object, PTCacheEdit *edit)
 {
 	ParticleSystem *psys = edit->psys;
-	ParticleBatchCache *cache = particle_batch_cache_get(psys);
+	ParticleBatchCache *cache = particle_batch_cache_get_edit(object, edit);
 	if (cache->hairs != NULL) {
 		return cache->hairs;
 	}
@@ -676,10 +691,9 @@ static void particle_batch_cache_ensure_edit_inner_pos(
 	}
 }
 
-Gwn_Batch *DRW_particles_batch_cache_get_edit_inner_points(PTCacheEdit *edit)
+Gwn_Batch *DRW_particles_batch_cache_get_edit_inner_points(Object *object, PTCacheEdit *edit)
 {
-	ParticleSystem *psys = edit->psys;
-	ParticleBatchCache *cache = particle_batch_cache_get(psys);
+	ParticleBatchCache *cache = particle_batch_cache_get_edit(object, edit);
 	if (cache->edit_inner_points != NULL) {
 		return cache->edit_inner_points;
 	}
@@ -692,7 +706,7 @@ Gwn_Batch *DRW_particles_batch_cache_get_edit_inner_points(PTCacheEdit *edit)
 }
 
 static void ensure_edit_tip_points_count(const PTCacheEdit *edit,
-                                           ParticleBatchCache *cache)
+                                         ParticleBatchCache *cache)
 {
 	if (cache->edit_tip_pos != NULL) {
 		return;
@@ -738,10 +752,9 @@ static void particle_batch_cache_ensure_edit_tip_pos(
 	}
 }
 
-Gwn_Batch *DRW_particles_batch_cache_get_edit_tip_points(PTCacheEdit *edit)
+Gwn_Batch *DRW_particles_batch_cache_get_edit_tip_points(Object *object, PTCacheEdit *edit)
 {
-	ParticleSystem *psys = edit->psys;
-	ParticleBatchCache *cache = particle_batch_cache_get(psys);
+	ParticleBatchCache *cache = particle_batch_cache_get_edit(object, edit);
 	if (cache->edit_tip_points != NULL) {
 		return cache->edit_tip_points;
 	}
diff --git a/source/blender/draw/modes/particle_mode.c b/source/blender/draw/modes/particle_mode.c
index dc08ba63cb3..d9363a18054 100644
--- a/source/blender/draw/modes/particle_mode.c
+++ b/source/blender/draw/modes/particle_mode.c
@@ -139,18 +139,30 @@ static void particle_cache_init(void *vedata)
 	DRW_shgroup_uniform_float(stl->g_data->tip_points_group, "outlineWidth", &outline_width, 1);
 }
 
-static void draw_update_ptcache_edit(Object *object, PTCacheEdit *edit)
+/* TODO(sergey): Avoid linear lookup. */
+static void draw_update_ptcache_edit(Object *object_eval, PTCacheEdit *edit)
 {
-	if (edit->psys && edit->psys->flag & PSYS_HAIR_UPDATED) {
+	if (edit->psys == NULL) {
+		return;
+	}
+	ParticleSystem *psys_eval;
+	for (psys_eval = object_eval->particlesystem.first;
+	     psys_eval != NULL;
+	     psys_eval = psys_eval->next)
+	{
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list