[Bf-blender-cvs] [ad8d3c4] hair_immediate_fixes: New edit mode for hair.

Lukas Tönne noreply at git.blender.org
Tue Nov 25 14:44:53 CET 2014


Commit: ad8d3c4e42600c1fdcda5a5145bb1212c70bf95b
Author: Lukas Tönne
Date:   Mon Nov 24 20:55:26 2014 +0100
Branches: hair_immediate_fixes
https://developer.blender.org/rBad8d3c4e42600c1fdcda5a5145bb1212c70bf95b

New edit mode for hair.

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

M	source/blender/blenkernel/BKE_context.h
M	source/blender/blenkernel/intern/context.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/hair/hair_intern.h
M	source/blender/editors/hair/hair_ops.c
M	source/blender/editors/hair/hair_particles.c
M	source/blender/editors/include/ED_physics.h
M	source/blender/editors/object/object_edit.c
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/editors/space_view3d/view3d_header.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/windowmanager/WM_types.h

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

diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index ebc2466..bd0d8b2 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -105,6 +105,7 @@ enum {
 	CTX_MODE_PAINT_VERTEX,
 	CTX_MODE_PAINT_TEXTURE,
 	CTX_MODE_PARTICLE,
+	CTX_MODE_HAIR,
 	CTX_MODE_OBJECT
 };
 
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 66b1d00..86628ea 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -938,6 +938,7 @@ int CTX_data_mode_enum(const bContext *C)
 			else if (ob->mode & OB_MODE_VERTEX_PAINT) return CTX_MODE_PAINT_VERTEX;
 			else if (ob->mode & OB_MODE_TEXTURE_PAINT) return CTX_MODE_PAINT_TEXTURE;
 			else if (ob->mode & OB_MODE_PARTICLE_EDIT) return CTX_MODE_PARTICLE;
+			else if (ob->mode & OB_MODE_HAIR_EDIT) return CTX_MODE_HAIR;
 		}
 	}
 
@@ -961,6 +962,7 @@ static const char *data_mode_strings[] = {
 	"vertexpaint",
 	"imagepaint",
 	"particlemode",
+	"hairmode",
 	"objectmode",
 	NULL
 };
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 0b7aaf7..f87bccc 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3330,7 +3330,7 @@ void object_remove_particle_system(Scene *UNUSED(scene), Object *ob)
 	if (ob->particlesystem.first)
 		((ParticleSystem *) ob->particlesystem.first)->flag |= PSYS_CURRENT;
 	else
-		ob->mode &= ~OB_MODE_PARTICLE_EDIT;
+		ob->mode &= ~(OB_MODE_PARTICLE_EDIT | OB_MODE_HAIR_EDIT);
 
 	DAG_relations_tag_update(G.main);
 	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index ccdc613..7c520c4 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4935,7 +4935,7 @@ static void direct_link_object(FileData *fd, Object *ob)
 	 *
 	 * Also when linking in a file don't allow editmode: [#34776] */
 	if (fd->memfile || (ob->id.flag & (LIB_EXTERN | LIB_INDIRECT))) {
-		ob->mode &= ~(OB_MODE_EDIT | OB_MODE_PARTICLE_EDIT);
+		ob->mode &= ~(OB_MODE_EDIT | OB_MODE_PARTICLE_EDIT | OB_MODE_HAIR_EDIT);
 	}
 	
 	ob->adt = newdataadr(fd, ob->adt);
diff --git a/source/blender/editors/hair/hair_intern.h b/source/blender/editors/hair/hair_intern.h
index 4298810..d430760 100644
--- a/source/blender/editors/hair/hair_intern.h
+++ b/source/blender/editors/hair/hair_intern.h
@@ -70,4 +70,10 @@ void ED_hair_edit_reserve(struct HairEditData *hedit, int alloc_curves, int allo
 void hair_edit_from_particles(struct HairEditData *hedit, struct Object *ob, struct ParticleSystem *psys);
 void hair_edit_to_particles(struct HairEditData *hedit, struct Object *ob, struct ParticleSystem *psys);
 
+/* === operators === */
+
+struct wmOperatorType;
+
+void HAIR_OT_hair_edit_toggle(struct wmOperatorType *ot);
+
 #endif
diff --git a/source/blender/editors/hair/hair_ops.c b/source/blender/editors/hair/hair_ops.c
index d8f42d9..e8116c7 100644
--- a/source/blender/editors/hair/hair_ops.c
+++ b/source/blender/editors/hair/hair_ops.c
@@ -28,3 +28,131 @@
 /** \file blender/editors/hair/hair_ops.c
  *  \ingroup edhair
  */
+
+#include <stdlib.h>
+
+#include "BLI_utildefines.h"
+
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_object.h"
+#include "ED_physics.h"
+
+#include "hair_intern.h"
+
+/* ==== edit mode toggle ==== */
+
+static bool has_hair_data(Object *ob)
+{
+	ParticleSystem *psys;
+	
+	for (psys = ob->particlesystem.first; psys; psys = psys->next) {
+		if (psys->part->type == PART_HAIR)
+			return true;
+	}
+	
+	return false;
+}
+
+static bool init_hair_edit(Object *ob, HairEditData *hedit)
+{
+	ParticleSystem *psys;
+	
+	for (psys = ob->particlesystem.first; psys; psys = psys->next) {
+		if (psys->part->type == PART_HAIR) {
+			hair_edit_from_particles(hedit, ob, psys);
+			return true;
+		}
+	}
+	
+	return false;
+}
+
+static int hair_edit_toggle_poll(bContext *C)
+{
+	Object *ob = CTX_data_active_object(C);
+
+	if (ob == NULL)
+		return false;
+	if (!ob->data || ((ID *)ob->data)->lib)
+		return false;
+	if (CTX_data_edit_object(C))
+		return false;
+
+	return has_hair_data(ob);
+}
+
+static int hair_edit_toggle_exec(bContext *C, wmOperator *op)
+{
+	Object *ob = CTX_data_active_object(C);
+	const int mode_flag = OB_MODE_HAIR_EDIT;
+	const bool is_mode_set = (ob->mode & mode_flag) != 0;
+
+	if (!is_mode_set) {
+		if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
+			return OPERATOR_CANCELLED;
+		}
+	}
+
+	if (!is_mode_set) {
+		HairEditData *hedit = ED_hair_edit_create();
+		
+		ob->mode |= mode_flag;
+		init_hair_edit(ob, hedit);
+		
+//		toggle_particle_cursor(C, 1);
+		WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_HAIR, NULL);
+	}
+	else {
+//		hair_edit_to_particles();
+		ob->mode &= ~mode_flag;
+		
+//		toggle_particle_cursor(C, 0);
+		WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_HAIR, NULL);
+	}
+
+	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+
+	return OPERATOR_FINISHED;
+}
+
+void HAIR_OT_hair_edit_toggle(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Hair Edit Toggle";
+	ot->idname = "HAIR_OT_hair_edit_toggle";
+	ot->description = "Toggle hair edit mode";
+	
+	/* api callbacks */
+	ot->exec = hair_edit_toggle_exec;
+	ot->poll = hair_edit_toggle_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/* ==== register ==== */
+
+void ED_operatortypes_hair(void)
+{
+	WM_operatortype_append(HAIR_OT_hair_edit_toggle);
+}
+
+void ED_keymap_hair(wmKeyConfig *UNUSED(keyconf))
+{
+//	wmKeyMapItem *kmi;
+//	wmKeyMap *keymap;
+	
+//	keymap = WM_keymap_find(keyconf, "Hair", 0, 0);
+//	keymap->poll = PE_poll;
+}
diff --git a/source/blender/editors/hair/hair_particles.c b/source/blender/editors/hair/hair_particles.c
index fca0325..ef4fe5a 100644
--- a/source/blender/editors/hair/hair_particles.c
+++ b/source/blender/editors/hair/hair_particles.c
@@ -62,7 +62,7 @@ static void copy_edit_curve(HairEditData *hedit, HairEditCurve *curve, ParticleD
 	HairKey *hkey;
 	int k;
 	
-	BLI_assert(start + totverts < hedit->alloc_verts);
+	BLI_assert(start + totverts <= hedit->alloc_verts);
 	
 	curve->start = start;
 	curve->numverts = totverts;
diff --git a/source/blender/editors/include/ED_physics.h b/source/blender/editors/include/ED_physics.h
index 584e9a9..53eec0c 100644
--- a/source/blender/editors/include/ED_physics.h
+++ b/source/blender/editors/include/ED_physics.h
@@ -56,5 +56,9 @@ void ED_rigidbody_constraint_remove(struct Scene *scene, struct Object *ob);
 void ED_operatortypes_physics(void);
 void ED_keymap_physics(struct wmKeyConfig *keyconf);
 
+/* hair edit */
+void ED_operatortypes_hair(void);
+void ED_keymap_hair(struct wmKeyConfig *keyconf);
+
 #endif /* __ED_PHYSICS_H__ */
 
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 9395612..dcaf229 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1508,7 +1508,7 @@ static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *UNUSED(
 			    (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) ||
 			    (input->value == OB_MODE_PARTICLE_EDIT && use_mode_particle_edit) ||
 			    (ELEM(input->value, OB_MODE_SCULPT, OB_MODE_VERTEX_PAINT,
-			           OB_MODE_WEIGHT_PAINT, OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) ||
+			           OB_MODE_WEIGHT_PAINT, OB_MODE_TEXTURE_PAINT, OB_MODE_HAIR_EDIT) && (ob->type == OB_MESH)) ||
 			    (input->value == OB_MODE_OBJECT))
 			{
 				RNA_enum_item_add(&item, &totitem, input);
@@ -1542,6 +1542,8 @@ static const char *object_mode_op_string(int mode)
 		return "PAINT_OT_texture_paint_toggle";
 	if (mode == OB_MODE_PARTICLE_EDIT)
 		return "PARTICLE_OT_particle_edit_toggle";
+	if (mode == OB_MODE_HAIR_EDIT)
+		return "HAIR_OT_hair_edit_toggle";
 	if (mode == OB_MODE_POSE)
 		return "OBJECT_OT_posemode_toggle";
 	return NULL;
@@ -1559,7 +1561,7 @@ static bool object_mode_compat_test(Object *ob, ObjectMode mode)
 		switch (ob->type) {
 			case OB_MESH:
 				if (mode & (OB_MODE_EDIT | OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT |
-				            OB_MODE_TEXTURE_PAINT | OB_MODE_PARTICLE_EDIT))
+				            OB_MODE_TEXTURE_PAINT | OB_MODE_PARTICLE_EDIT | OB_MODE_HAIR_EDIT))
 				{
 					return true;
 				}
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index a8ad1e2..ecc902c 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -105,6 +105,7 @@ void ED_spacetypes_init(void)
 	ED_operatortypes_anim();
 	ED_operatortypes_animchannels();
 	ED_operatortypes_gpencil();
+	ED_operatortypes_hair();
 	ED_operatortypes_object();
 	ED_operatortypes_mesh();
 	ED_operatortypes_sculpt();
@@ -182,6 +183,7 @@ void ED_spacetypes_keymap(wmKeyConfig *keyconf)
 	ED_keymap_anim(keyconf);
 	ED_keymap_animchannels(keyconf);
 	ED_keymap_gpencil(keyconf);
+	ED_keymap_hair(keyconf);
 	ED_keymap_object(keyconf); /* defines lattice also */
 	ED_keymap_mesh(keyconf);
 	ED_keymap_uvedit(keyconf);
diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c
index 4c19f59..762989f 100644
--- a/source/blender/editors/space_view3d/view3d_header.c
+++ b/source/blender/editors/space_view3d/view3d_header.c
@@ -345,7 +345,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
 		}
 
 		/* Manipulators aren't used in paint modes */
-		if (!ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_PARTICLE_EDIT)) {
+		if (!ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_PARTICLE_EDIT, OB_MODE_HAIR_EDIT)) {
 			/* masks aren't used for sculpt and particle painting */
 			PointerRNA meshptr;
 
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 79e53ad

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list