Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2018-01-28 17:32:50 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2018-01-28 17:32:50 +0300
commit9e56f6357fd1c49c1ae9a5ae72a1f7ac1213bec2 (patch)
tree46e74d42beb15608b6694742469b37d94623d4c1 /source
parent49c19ca679ea89209a18374d51377084f378f289 (diff)
New operator for distributing hair follicles for a groom object.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_groom.h5
-rw-r--r--source/blender/blenkernel/intern/groom.c11
-rw-r--r--source/blender/editors/groom/CMakeLists.txt1
-rw-r--r--source/blender/editors/groom/groom_hair.c110
-rw-r--r--source/blender/editors/groom/groom_intern.h3
-rw-r--r--source/blender/editors/groom/groom_ops.c2
6 files changed, 132 insertions, 0 deletions
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)