[Bf-blender-cvs] [acfdf08ea28] hair_guides: Simple operator for adding a single groom curve in edit mode.

Lukas Tönne noreply at git.blender.org
Fri Dec 22 12:02:28 CET 2017


Commit: acfdf08ea288d319042da828fff147158d840329
Author: Lukas Tönne
Date:   Fri Dec 22 11:02:08 2017 +0000
Branches: hair_guides
https://developer.blender.org/rBacfdf08ea288d319042da828fff147158d840329

Simple operator for adding a single groom curve in edit mode.

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

M	source/blender/blenkernel/intern/object_update.c
M	source/blender/editors/groom/CMakeLists.txt
A	source/blender/editors/groom/editgroom_region.c
M	source/blender/editors/groom/groom_intern.h
M	source/blender/editors/groom/groom_ops.c
M	source/blender/editors/include/ED_groom.h

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

diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 71d8c1981af..d745e629453 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -61,6 +61,7 @@
 #include "BKE_mball.h"
 #include "BKE_mesh.h"
 #include "BKE_image.h"
+#include "BKE_groom.h"
 
 #include "MEM_guardedalloc.h"
 #include "DEG_depsgraph.h"
@@ -324,6 +325,9 @@ void BKE_object_eval_uber_data(const EvaluationContext *eval_ctx,
 		case OB_MBALL:
 			BKE_mball_batch_cache_dirty(ob->data, BKE_MBALL_BATCH_DIRTY_ALL);
 			break;
+		case OB_GROOM:
+			BKE_groom_batch_cache_dirty(ob->data, BKE_GROOM_BATCH_DIRTY_ALL);
+			break;
 	}
 
 	if (DEG_depsgraph_use_copy_on_write()) {
@@ -429,6 +433,10 @@ void BKE_object_data_select_update(const EvaluationContext *UNUSED(eval_ctx),
 			BKE_lattice_batch_cache_dirty((struct Lattice *)object_data,
 			                              BKE_CURVE_BATCH_DIRTY_SELECT);
 			break;
+		case ID_GM:
+			BKE_groom_batch_cache_dirty((struct Groom *)object_data,
+			                              BKE_GROOM_BATCH_DIRTY_SELECT);
+			break;
 		default:
 			break;
 	}
diff --git a/source/blender/editors/groom/CMakeLists.txt b/source/blender/editors/groom/CMakeLists.txt
index 695b3846aaa..ef5e6d66580 100644
--- a/source/blender/editors/groom/CMakeLists.txt
+++ b/source/blender/editors/groom/CMakeLists.txt
@@ -36,6 +36,7 @@ set(INC_SYS
 set(SRC
 	groom_ops.c
 	editgroom.c
+	editgroom_region.c
 
 	groom_intern.h
 )
diff --git a/source/blender/editors/groom/editgroom_region.c b/source/blender/editors/groom/editgroom_region.c
new file mode 100644
index 00000000000..9ce1aa01fe6
--- /dev/null
+++ b/source/blender/editors/groom/editgroom_region.c
@@ -0,0 +1,121 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/curve/editgroom_region.c
+ *  \ingroup edgroom
+ */
+
+#include "DNA_groom_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+
+#include "BLT_translation.h"
+
+#include "BKE_context.h"
+#include "BKE_groom.h"
+#include "BKE_library.h"
+
+#include "DEG_depsgraph.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_object.h"
+#include "ED_screen.h"
+#include "ED_util.h"
+#include "ED_view3d.h"
+#include "ED_groom.h"
+
+#include "groom_intern.h"
+
+static GroomBundleSection* groom_add_bundle_section(float mat[4][4], float cparam)
+{
+	GroomBundleSection *section = MEM_callocN(sizeof(GroomBundleSection), "groom bundle section");
+	
+	madd_v3_v3v3fl(section->center, mat[3], mat[2], cparam);
+	copy_v3_v3(section->normal, mat[2]);
+	
+	return section;
+}
+
+static GroomBundle* groom_add_bundle(float mat[4][4])
+{
+	GroomBundle *bundle = MEM_callocN(sizeof(GroomBundle), "groom bundle");
+	
+	BLI_addtail(&bundle->sections, groom_add_bundle_section(mat, 0.0f));
+	BLI_addtail(&bundle->sections, groom_add_bundle_section(mat, 1.0f));
+	
+	return bundle;
+}
+
+static int region_add_exec(bContext *C, wmOperator *op)
+{
+	Object *obedit = CTX_data_edit_object(C);
+	Groom *groom = obedit->data;
+	EditGroom *editgroom = groom->editgroom;
+
+	WM_operator_view3d_unit_defaults(C, op);
+
+	float loc[3], rot[3];
+	unsigned int layer;
+	if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, &layer, NULL))
+		return OPERATOR_CANCELLED;
+
+	float mat[4][4];
+	ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
+
+	GroomBundle *bundle = groom_add_bundle(mat);
+	BLI_addtail(&editgroom->bundles, bundle);
+
+	WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit);
+
+	return OPERATOR_FINISHED;
+}
+
+void GROOM_OT_region_add(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Add Region";
+	ot->description = "Add a new region to the groom object";
+	ot->idname = "GROOM_OT_region_add";
+
+	/* api callbacks */
+	ot->exec = region_add_exec;
+	ot->poll = ED_operator_editgroom;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	ED_object_add_generic_props(ot, false);
+}
diff --git a/source/blender/editors/groom/groom_intern.h b/source/blender/editors/groom/groom_intern.h
index 336b82fb73e..193973c9b1d 100644
--- a/source/blender/editors/groom/groom_intern.h
+++ b/source/blender/editors/groom/groom_intern.h
@@ -33,5 +33,9 @@
 #ifndef __GROOM_INTERN_H__
 #define __GROOM_INTERN_H__
 
+struct wmOperatorType;
+
+/* editgroom_region.c */
+void GROOM_OT_region_add(struct wmOperatorType *ot);
 
 #endif /* __GROOM_INTERN_H__ */
diff --git a/source/blender/editors/groom/groom_ops.c b/source/blender/editors/groom/groom_ops.c
index 73a4f40c0ce..fbc0281285f 100644
--- a/source/blender/editors/groom/groom_ops.c
+++ b/source/blender/editors/groom/groom_ops.c
@@ -52,6 +52,7 @@
 
 void ED_operatortypes_groom(void)
 {
+	WM_operatortype_append(GROOM_OT_region_add);
 }
 
 void ED_operatormacros_groom(void)
diff --git a/source/blender/editors/include/ED_groom.h b/source/blender/editors/include/ED_groom.h
index ee6ae7b5d1e..500cde61728 100644
--- a/source/blender/editors/include/ED_groom.h
+++ b/source/blender/editors/include/ED_groom.h
@@ -46,7 +46,6 @@ void    ED_keymap_groom(struct wmKeyConfig *keyconf);
 
 /* editgroom.c */
 void    undo_push_groom(struct bContext *C, const char *name);
-ListBase *object_editgroom_get(struct Object *ob);
 
 void ED_groom_editgroom_load(struct Object *obedit);
 void ED_groom_editgroom_make(struct Object *obedit);



More information about the Bf-blender-cvs mailing list