[Bf-blender-cvs] [f3e455a0f89] hair_object: Follicle selection flag and "select all" operator.
Lukas Tönne
noreply at git.blender.org
Sun Sep 23 15:14:26 CEST 2018
Commit: f3e455a0f89df914b95e5ee43b3c7cfd9b37a755
Author: Lukas Tönne
Date: Sun Sep 23 14:04:20 2018 +0100
Branches: hair_object
https://developer.blender.org/rBf3e455a0f89df914b95e5ee43b3c7cfd9b37a755
Follicle selection flag and "select all" operator.
===================================================================
M source/blender/draw/intern/draw_cache_impl_hair.c
M source/blender/editors/hair/CMakeLists.txt
A source/blender/editors/hair/edithair_select.c
M source/blender/editors/hair/hair_intern.h
M source/blender/editors/hair/hair_ops.c
M source/blender/makesdna/DNA_hair_types.h
===================================================================
diff --git a/source/blender/draw/intern/draw_cache_impl_hair.c b/source/blender/draw/intern/draw_cache_impl_hair.c
index 2673cc354f5..97c2b7b3f2a 100644
--- a/source/blender/draw/intern/draw_cache_impl_hair.c
+++ b/source/blender/draw/intern/draw_cache_impl_hair.c
@@ -768,7 +768,7 @@ static void hair_batch_cache_ensure_edit_follicle_pos(
if (format.attr_len == 0) {
/* initialize vertex format */
pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- data_id = GPU_vertformat_attr_add(&format, "data", GPU_COMP_U8, 1, GPU_FETCH_INT);
+ data_id = GPU_vertformat_attr_add(&format, "data", GPU_COMP_U32, 1, GPU_FETCH_INT);
}
cache->edit_follicle_pos = GPU_vertbuf_create_with_format(&format);
@@ -783,8 +783,7 @@ static void hair_batch_cache_ensure_edit_follicle_pos(
GPU_vertbuf_attr_set(cache->edit_follicle_pos, pos_id, point_index, loc);
- unsigned char flag = 0;
- GPU_vertbuf_attr_set(cache->edit_follicle_pos, data_id, point_index, &flag);
+ GPU_vertbuf_attr_set(cache->edit_follicle_pos, data_id, point_index, &follicle->flag);
}
}
diff --git a/source/blender/editors/hair/CMakeLists.txt b/source/blender/editors/hair/CMakeLists.txt
index 1477f1fb221..4f74c24734c 100644
--- a/source/blender/editors/hair/CMakeLists.txt
+++ b/source/blender/editors/hair/CMakeLists.txt
@@ -36,6 +36,7 @@ set(INC_SYS
set(SRC
hair_ops.c
edithair.c
+ edithair_select.c
edithair_test.c
hair_intern.h
diff --git a/source/blender/editors/hair/edithair_select.c b/source/blender/editors/hair/edithair_select.c
new file mode 100644
index 00000000000..c9d30caaf58
--- /dev/null
+++ b/source/blender/editors/hair/edithair_select.c
@@ -0,0 +1,168 @@
+/*
+ * ***** 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/hair/edithair_test.c
+ * \ingroup edhair
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "DNA_hair_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_context.h"
+#include "BKE_hair.h"
+#include "BKE_hair_iterators.h"
+#include "BKE_mesh_sample.h"
+
+#include "DEG_depsgraph.h"
+
+#include "ED_hair.h"
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "UI_resources.h"
+
+#include "BLT_translation.h"
+
+#include "hair_intern.h" /* own include */
+
+/************************ de select all operator ************************/
+
+static bool hair_has_selected_follicles(EditHair *edit)
+{
+ const HairFollicle *follicle;
+ HairIterator iter;
+ BKE_HAIR_ITER_FOLLICLES(follicle, &iter, edit->pattern) {
+ if (follicle->flag & HAIR_FOLLICLE_SELECT) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static void hair_follicle_select_action_apply(HairFollicle *follicle, int action)
+{
+ switch (action) {
+ case SEL_SELECT:
+ if (!(follicle->flag & HAIR_FOLLICLE_SELECT)) {
+ follicle->flag |= HAIR_FOLLICLE_SELECT;
+ }
+ break;
+ case SEL_DESELECT:
+ if (follicle->flag & HAIR_FOLLICLE_SELECT) {
+ follicle->flag &= ~HAIR_FOLLICLE_SELECT;
+ }
+ break;
+ case SEL_INVERT:
+ if (!(follicle->flag & HAIR_FOLLICLE_SELECT)) {
+ follicle->flag |= HAIR_FOLLICLE_SELECT;
+ }
+ else {
+ follicle->flag &= ~HAIR_FOLLICLE_SELECT;
+ }
+ break;
+ }
+}
+
+static int hair_select_all_exec(bContext *C, wmOperator *op)
+{
+ const ToolSettings *settings = CTX_data_tool_settings(C);
+ Object *obedit = CTX_data_edit_object(C);;
+ HairSystem *hsys = obedit->data;
+ EditHair *edit = hsys->edithair;
+ int action = RNA_enum_get(op->ptr, "action");
+
+ if (action == SEL_TOGGLE) {
+ switch (settings->hair_edit_settings.select_mode) {
+ case HAIR_SELECT_FOLLICLES: {
+ action = hair_has_selected_follicles(edit) ? SEL_DESELECT : SEL_SELECT;
+ break;
+ }
+ case HAIR_SELECT_VERTICES: {
+ BLI_assert(false);
+ break;
+ }
+ case HAIR_SELECT_TIPS: {
+ BLI_assert(false);
+ break;
+ }
+ }
+ }
+
+ switch (settings->hair_edit_settings.select_mode) {
+ case HAIR_SELECT_FOLLICLES: {
+ HairFollicle *follicle;
+ HairIterator iter;
+ BKE_HAIR_ITER_FOLLICLES(follicle, &iter, edit->pattern) {
+ hair_follicle_select_action_apply(follicle, action);
+ }
+ break;
+ }
+ case HAIR_SELECT_VERTICES: {
+ BLI_assert(false);
+ break;
+ }
+ case HAIR_SELECT_TIPS: {
+ BLI_assert(false);
+ break;
+ }
+ }
+
+ BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_SELECT);
+ DEG_id_tag_update(&obedit->id, DEG_TAG_SELECT_UPDATE);
+ WM_event_add_notifier(C, NC_OBJECT|ND_DATA|NA_SELECTED, obedit);
+
+ return OPERATOR_FINISHED;
+}
+
+void HAIR_OT_select_all(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "(De)select All";
+ ot->idname = "HAIR_OT_select_all";
+ ot->description = "(De)select all hair points";
+
+ /* api callbacks */
+ ot->exec = hair_select_all_exec;
+ ot->poll = ED_operator_edithair;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ WM_operator_properties_select_all(ot);
+}
diff --git a/source/blender/editors/hair/hair_intern.h b/source/blender/editors/hair/hair_intern.h
index 39f475f29eb..7fdc59a72f3 100644
--- a/source/blender/editors/hair/hair_intern.h
+++ b/source/blender/editors/hair/hair_intern.h
@@ -35,6 +35,8 @@
struct wmOperatorType;
+void HAIR_OT_select_all(struct wmOperatorType *ot);
+
void HAIR_OT_add_test_hair(struct wmOperatorType *ot);
#endif /* __HAIR_INTERN_H__ */
diff --git a/source/blender/editors/hair/hair_ops.c b/source/blender/editors/hair/hair_ops.c
index ca4cfb26caf..65b6241055b 100644
--- a/source/blender/editors/hair/hair_ops.c
+++ b/source/blender/editors/hair/hair_ops.c
@@ -52,6 +52,8 @@
void ED_operatortypes_hair(void)
{
+ WM_operatortype_append(HAIR_OT_select_all);
+
WM_operatortype_append(HAIR_OT_add_test_hair);
}
diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h
index 096d532ca31..e863deb9a2e 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -37,11 +37,16 @@
extern "C" {
#endif
+typedef enum HairFollicleFlag
+{
+ HAIR_FOLLICLE_SELECT = (1 << 0),
+} HairFollicleFlag;
+
/* Root point (follicle) of a hair on a surface */
typedef struct HairFollicle {
- MeshSample mesh_sample; /* Sample on the scalp mesh for the root vertex */
+ int flag;
unsigned int curve; /* Index of the curve used by the fiber */
- int pad;
+ MeshSample mesh_sample; /* Sample on the scalp mesh for the root vertex */
} HairFollicle;
/* Collection of hair roots on a surface */
More information about the Bf-blender-cvs
mailing list