[Bf-blender-cvs] [d045fd7] gooseberry: Apply hair shape keys to the particle base data when entering edit mode and when switching the active key during edit mode.

Lukas Tönne noreply at git.blender.org
Wed Jan 28 15:44:35 CET 2015


Commit: d045fd79d6177692065072703da52aa3fca99d4d
Author: Lukas Tönne
Date:   Wed Jan 28 15:42:12 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBd045fd79d6177692065072703da52aa3fca99d4d

Apply hair shape keys to the particle base data when entering edit mode
and when switching the active key during edit mode.

This is different from how shape key editing works on meshes: there the
edit data (BMEditMesh) stores customdata layers for shape keys, then
writes them back to the mesh. The hair edit mode is a lot more messy and
confusing, it has to update the base data immeditately (with potential
consequences for undo ...)

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

M	source/blender/blenkernel/intern/particle.c
M	source/blender/editors/include/ED_particle.h
M	source/blender/editors/physics/particle_edit.c
M	source/blender/makesrna/intern/rna_particle.c

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

diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index d776661..8b821bc 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -2481,7 +2481,6 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra)
 	ParticleCacheKey *ca, **cache;
 	const bool keyed = psys->flag & PSYS_KEYED;
 	const bool baked = psys->pointcache->mem_cache.first && psys->part->type != PART_HAIR;
-	const bool edit = psys->edit;
 
 	DerivedMesh *hair_dm = (psys->part->type == PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS) ? psys->hair_out_dm : NULL;
 	
@@ -2606,7 +2605,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra)
 			
 			for (k = 0, hkey = pa->hair; k < pa->totkey; ++k, ++hkey) {
 				float co[3];
-				if (edit && shapekey) {
+				if (shapekey) {
 					copy_v3_v3(co, shapekey);
 					shapekey += 3;
 				}
diff --git a/source/blender/editors/include/ED_particle.h b/source/blender/editors/include/ED_particle.h
index f9516f2..54244d6 100644
--- a/source/blender/editors/include/ED_particle.h
+++ b/source/blender/editors/include/ED_particle.h
@@ -45,6 +45,7 @@ struct Scene;
 /* particle edit mode */
 void PE_free_ptcache_edit(struct PTCacheEdit *edit);
 int PE_start_edit(struct PTCacheEdit *edit);
+bool PE_load(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
 
 /* access */
 struct PTCacheEdit *PE_get_current(struct Scene *scene, struct Object *ob);
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c
index d35b8fd..0d78f42 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -37,6 +37,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_key_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
@@ -56,6 +57,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
+#include "BKE_key.h"
 #include "BKE_object.h"
 #include "BKE_mesh.h"
 #include "BKE_modifier.h"
@@ -4553,6 +4555,25 @@ int PE_minmax(Scene *scene, float min[3], float max[3])
 
 /************************ particle edit toggle operator ************************/
 
+bool PE_load(Scene *UNUSED(scene), Object *ob, ParticleSystem *psys)
+{
+	const int mode_flag = OB_MODE_PARTICLE_EDIT;
+	const bool is_mode_set = (ob->mode & mode_flag) != 0;
+	
+	if (!is_mode_set)
+		return false;
+	
+	if (psys->edit) {
+		/* set the active shape key */
+		KeyBlock *actkb = BKE_keyblock_from_particles(psys);
+		
+		if (actkb)
+			BKE_keyblock_convert_to_hair_keys(actkb, ob, psys);
+	}
+	
+	return true;
+}
+
 /* initialize needed data for bake edit */
 void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, ParticleSystem *psys)
 {
@@ -4695,11 +4716,18 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
 		PTCacheEdit *edit;
 		ob->mode |= mode_flag;
 		edit= PE_create_current(scene, ob);
-	
+		
 		/* mesh may have changed since last entering editmode.
 		 * note, this may have run before if the edit data was just created, so could avoid this and speed up a little */
-		if (edit && edit->psys)
+		if (edit && edit->psys) {
+			/* set the active shape key */
+			KeyBlock *actkb = BKE_keyblock_from_particles(edit->psys);
+			
+			if (actkb)
+				BKE_keyblock_convert_to_hair_keys(actkb, ob, edit->psys);
+			
 			recalc_emitter_field(ob, edit->psys);
+		}
 		
 		toggle_particle_cursor(C, 1);
 		WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_PARTICLE, NULL);
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index 7f965aa..e612820 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -149,6 +149,8 @@ static EnumPropertyItem part_hair_ren_as_items[] = {
 
 #include "RNA_access.h"
 
+#include "ED_particle.h"
+
 /* use for object space hair get/set */
 static void rna_ParticleHairKey_location_object_info(PointerRNA *ptr, ParticleSystemModifierData **psmd_pt,
                                                      ParticleData **pa_pt)
@@ -774,31 +776,13 @@ static void rna_particle_settings_set(PointerRNA *ptr, PointerRNA value)
 
 static void rna_Particle_active_shape_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
+	Object *ob = ptr->id.data;
 	ParticleSystem *psys = ptr->data;
 	
-#if 0 /* XXX equivalent needed for particles? */
-	if (scene->obedit == ob) {
-		/* exit/enter editmode to get new shape */
-		switch (ob->type) {
-			case OB_MESH:
-				EDBM_mesh_load(ob);
-				EDBM_mesh_make(scene->toolsettings, ob);
-				EDBM_mesh_normals_update(((Mesh *)ob->data)->edit_btmesh);
-				BKE_editmesh_tessface_calc(((Mesh *)ob->data)->edit_btmesh);
-				break;
-			case OB_CURVE:
-			case OB_SURF:
-				load_editNurb(ob);
-				make_editNurb(ob);
-				break;
-			case OB_LATTICE:
-				load_editLatt(ob);
-				make_editLatt(ob);
-				break;
-		}
+	if (PE_load(scene, ob, psys)) {
+		WM_main_add_notifier(NC_SCENE | ND_PARTICLE | NS_MODE_PARTICLE, ptr->id.data);
 	}
-#endif
-	(void)psys;
+	
 	rna_Particle_redo(bmain, scene, ptr);
 }




More information about the Bf-blender-cvs mailing list