[Bf-blender-cvs] [9e56f6357fd] hair_guides: New operator for distributing hair follicles for a groom object.
Lukas Tönne
noreply at git.blender.org
Sun Jan 28 15:42:13 CET 2018
Commit: 9e56f6357fd1c49c1ae9a5ae72a1f7ac1213bec2
Author: Lukas Tönne
Date: Sun Jan 28 14:32:50 2018 +0000
Branches: hair_guides
https://developer.blender.org/rB9e56f6357fd1c49c1ae9a5ae72a1f7ac1213bec2
New operator for distributing hair follicles for a groom object.
===================================================================
M release/scripts/startup/bl_ui/properties_data_groom.py
M source/blender/blenkernel/BKE_groom.h
M source/blender/blenkernel/intern/groom.c
M source/blender/editors/groom/CMakeLists.txt
A source/blender/editors/groom/groom_hair.c
M source/blender/editors/groom/groom_intern.h
M source/blender/editors/groom/groom_ops.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_groom.py b/release/scripts/startup/bl_ui/properties_data_groom.py
index 7c637794f07..2e6a9661714 100644
--- a/release/scripts/startup/bl_ui/properties_data_groom.py
+++ b/release/scripts/startup/bl_ui/properties_data_groom.py
@@ -57,7 +57,6 @@ class DATA_PT_context_groom(DataButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
-
ob = context.object
groom = context.groom
space = context.space_data
@@ -93,6 +92,16 @@ class DATA_PT_groom(DataButtonsPanel, Panel):
col.prop(groom, "curve_resolution", "Resolution")
+class DATA_PT_groom_hair(DataButtonsPanel, Panel):
+ bl_label = "Hair"
+
+ def draw(self, context):
+ layout = self.layout
+ groom = context.groom
+
+ layout.operator("groom.hair_distribute")
+
+
class DATA_PT_groom_draw_settings(DataButtonsPanel, Panel):
bl_label = "Draw Settings"
@@ -116,6 +125,7 @@ classes = (
GROOM_UL_bundles,
DATA_PT_context_groom,
DATA_PT_groom,
+ DATA_PT_groom_hair,
DATA_PT_groom_draw_settings,
DATA_PT_custom_props_groom,
)
diff --git a/source/blender/blenkernel/BKE_groom.h b/source/blender/blenkernel/BKE_groom.h
index 2b9c3213b7a..aa5b9fb53a0 100644
--- a/source/blender/blenkernel/BKE_groom.h
+++ b/source/blender/blenkernel/BKE_groom.h
@@ -69,6 +69,11 @@ bool BKE_groom_bundle_bind(struct Groom *groom, struct GroomBundle *bundle, bool
void BKE_groom_bundle_unbind(struct GroomBundle *bundle);
+/* === Hair System === */
+
+void BKE_groom_distribute_follicles(struct Groom *groom, unsigned int seed, int count);
+
+
/* === Depsgraph evaluation === */
void BKE_groom_eval_geometry(const struct EvaluationContext *eval_ctx, struct Groom *groom);
diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index 8d83a8d7b74..d2542fa89de 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -493,6 +493,17 @@ void BKE_groom_bundle_unbind(GroomBundle *bundle)
}
+/* === Hair System === */
+
+void BKE_groom_distribute_follicles(Groom *groom, unsigned int seed, int count)
+{
+ BLI_assert(groom->scalp_object);
+ DerivedMesh *scalp = object_get_derived_final(groom->scalp_object, false);
+
+ BKE_hair_generate_follicles(groom->hair_system, scalp, seed, count);
+}
+
+
/* === Curve cache === */
/* forward differencing method for cubic polynomial eval */
diff --git a/source/blender/editors/groom/CMakeLists.txt b/source/blender/editors/groom/CMakeLists.txt
index aa0d3dc3d7e..e145faf96fc 100644
--- a/source/blender/editors/groom/CMakeLists.txt
+++ b/source/blender/editors/groom/CMakeLists.txt
@@ -34,6 +34,7 @@ set(INC_SYS
)
set(SRC
+ groom_hair.c
groom_ops.c
editgroom.c
editgroom_region.c
diff --git a/source/blender/editors/groom/groom_hair.c b/source/blender/editors/groom/groom_hair.c
new file mode 100644
index 00000000000..503a8b9daef
--- /dev/null
+++ b/source/blender/editors/groom/groom_hair.c
@@ -0,0 +1,110 @@
+/*
+ * ***** 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/groom/groom_hair.c
+ * \ingroup groom
+ */
+
+#include "DNA_groom_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
+#include "BLT_translation.h"
+
+#include "BKE_context.h"
+#include "BKE_groom.h"
+#include "BKE_report.h"
+
+#include "DEG_depsgraph.h"
+
+#include "RNA_access.h"
+#include "RNA_define.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 int groom_object_poll(bContext *C)
+{
+ Object *ob = ED_object_context(C);
+ return ob->type == OB_GROOM;
+}
+
+/* GROOM_OT_hair_distribute */
+
+static int hair_distribute_exec(bContext *C, wmOperator *op)
+{
+ Object *ob = ED_object_context(C);
+ Groom *groom = ob->data;
+ int count = RNA_int_get(op->ptr, "count");
+ unsigned int seed = (unsigned int)RNA_int_get(op->ptr, "seed");
+
+ if (!groom->scalp_object)
+ {
+ BKE_reportf(op->reports, RPT_ERROR, "Scalp object needed for creating hair follicles");
+ return OPERATOR_CANCELLED;
+ }
+
+ BKE_groom_distribute_follicles(groom, seed, count);
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+
+ return OPERATOR_FINISHED;
+}
+
+void GROOM_OT_hair_distribute(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Distribute Hair";
+ ot->description = "Distribute hair follicles and guide curves on the scalp";
+ ot->idname = "GROOM_OT_hair_distribute";
+
+ /* api callbacks */
+ ot->exec = hair_distribute_exec;
+ ot->poll = groom_object_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ RNA_def_int(ot->srna, "count", 1000, 0, INT_MAX,
+ "Count", "Number of follicles to generate", 1, 1e6);
+ RNA_def_int(ot->srna, "seed", 0, 0, INT_MAX,
+ "Seed", "Seed value for randomized follicle distribution", 0, INT_MAX);
+}
diff --git a/source/blender/editors/groom/groom_intern.h b/source/blender/editors/groom/groom_intern.h
index 7738ff0bd59..b398408ffd2 100644
--- a/source/blender/editors/groom/groom_intern.h
+++ b/source/blender/editors/groom/groom_intern.h
@@ -42,4 +42,7 @@ void GROOM_OT_region_bind(struct wmOperatorType *ot);
/* editgroom_select.c */
void GROOM_OT_select_all(struct wmOperatorType *ot);
+/* groom_hair.c */
+void GROOM_OT_hair_distribute(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 840b437feab..f5ff8989a6b 100644
--- a/source/blender/editors/groom/groom_ops.c
+++ b/source/blender/editors/groom/groom_ops.c
@@ -56,6 +56,8 @@ void ED_operatortypes_groom(void)
WM_operatortype_append(GROOM_OT_region_bind);
WM_operatortype_append(GROOM_OT_select_all);
+
+ WM_operatortype_append(GROOM_OT_hair_distribute);
}
void ED_operatormacros_groom(void)
More information about the Bf-blender-cvs
mailing list