[Bf-blender-cvs] [9fe6919] strand_gpu: Test operator for quickly initializing the strands data.
Lukas Tönne
noreply at git.blender.org
Tue Jul 5 09:56:58 CEST 2016
Commit: 9fe691934f7c283a1b66d8c77d224d113617e177
Author: Lukas Tönne
Date: Wed Jun 29 18:55:50 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB9fe691934f7c283a1b66d8c77d224d113617e177
Test operator for quickly initializing the strands data.
This is just a temporary test operator, to be removed later when
edit mode and other mechanisms exist to generate useful strands.
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/BKE_strands.h
M source/blender/blenkernel/intern/strands.c
M source/blender/editors/object/CMakeLists.txt
M source/blender/editors/object/object_intern.h
M source/blender/editors/object/object_ops.c
A source/blender/editors/object/object_strands.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 5634d49..eaaa43f 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -880,6 +880,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
row.prop(md, "material_offset_rim", text="Rim")
def STRANDS(self, layout, ob, md):
+ layout.operator("object.strands_test_init", text="Test Init")
+
split = layout.split()
col = split.column()
col.label(text="Display:")
diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index dac8548..539369b 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -45,6 +45,10 @@ struct Strands *BKE_strands_new(void);
struct Strands *BKE_strands_copy(struct Strands *strands);
void BKE_strands_free(struct Strands *strands);
+void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
+ int totcurves, int maxverts,
+ unsigned int seed);
+
struct StrandInfo *BKE_strands_scatter(struct DerivedMesh *scalp, unsigned int amount,
const StrandCurve *controls, unsigned int num_controls,
unsigned int seed);
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index ea4e929..2415fb6 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -68,9 +68,60 @@ void BKE_strands_free(Strands *strands)
if (strands->gpu_strands)
GPU_strands_free(strands->gpu_strands);
+ if (strands->curves)
+ MEM_freeN(strands->curves);
+ if (strands->verts)
+ MEM_freeN(strands->verts);
MEM_freeN(strands);
}
+void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
+ int totcurves, int maxverts,
+ unsigned int seed)
+{
+ const unsigned int totverts = totcurves * maxverts;
+
+ MeshSampleGenerator *gen = BKE_mesh_sample_gen_surface_random(scalp, seed);
+ unsigned int i, k;
+
+ StrandCurve *curves = MEM_mallocN(sizeof(StrandCurve) * totcurves, "StrandCurve buffer");
+ StrandVertex *verts = MEM_mallocN(sizeof(StrandVertex) * totverts, "StrandVertex buffer");
+
+ StrandCurve *c = curves;
+ StrandVertex *v = verts;
+ unsigned int verts_begin = 0;
+ for (i = 0; i < totcurves; ++i, ++c) {
+ if (BKE_mesh_sample_generate(gen, &c->root)) {
+ c->verts_begin = verts_begin;
+ c->num_verts = maxverts;
+
+ for (k = 0; k < c->num_verts; ++k, ++v) {
+ v->co[0] = 0.0f;
+ v->co[1] = 0.0f;
+ v->co[2] = (c->num_verts > 1) ? 1.0f / (c->num_verts - 1) : 0.0f;
+ }
+
+ verts_begin += c->num_verts;
+ }
+ else {
+ /* clear remaining samples */
+ memset(c, 0, sizeof(StrandCurve) * totcurves - i);
+ break;
+ }
+ }
+
+ BKE_mesh_sample_free_generator(gen);
+
+ if (strands->curves)
+ MEM_freeN(strands->curves);
+ if (strands->verts)
+ MEM_freeN(strands->verts);
+ strands->curves = curves;
+ strands->verts = verts;
+ strands->totcurves = totcurves;
+ strands->totverts = totverts;
+}
+
StrandInfo *BKE_strands_scatter(struct DerivedMesh *scalp, unsigned int amount,
const StrandCurve *controls, unsigned int num_controls,
unsigned int seed)
diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt
index b3d02d4..e58abe7 100644
--- a/source/blender/editors/object/CMakeLists.txt
+++ b/source/blender/editors/object/CMakeLists.txt
@@ -56,6 +56,7 @@ set(SRC
object_relations.c
object_select.c
object_shapekey.c
+ object_strands.c
object_data_transfer.c
object_transform.c
object_warp.c
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index 9710e4f..ac6c567 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -279,5 +279,8 @@ void TRANSFORM_OT_vertex_random(struct wmOperatorType *ot);
void OBJECT_OT_data_transfer(struct wmOperatorType *ot);
void OBJECT_OT_datalayout_transfer(struct wmOperatorType *ot);
+/* object_strands.c */
+void OBJECT_OT_strands_test_init(struct wmOperatorType *ot);
+
#endif /* __OBJECT_INTERN_H__ */
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 534e593..d54e9f0 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -255,6 +255,8 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_data_transfer);
WM_operatortype_append(OBJECT_OT_datalayout_transfer);
+
+ WM_operatortype_append(OBJECT_OT_strands_test_init);
}
void ED_operatormacros_object(void)
diff --git a/source/blender/editors/object/object_strands.c b/source/blender/editors/object/object_strands.c
new file mode 100644
index 0000000..ee4b562
--- /dev/null
+++ b/source/blender/editors/object/object_strands.c
@@ -0,0 +1,114 @@
+/*
+ * ***** 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/object/object_strands.c
+ * \ingroup edobj
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_strand_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_strands.h"
+
+#include "ED_object.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "object_intern.h"
+
+/************************ LaplacianDeform bind operator *********************/
+
+static int strands_test_init_poll(bContext *C)
+{
+ return edit_modifier_poll_generic(C, &RNA_StrandsModifier, 0);
+}
+
+static int strands_test_init_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = ED_object_active_context(C);
+ StrandsModifierData *smd = (StrandsModifierData *)edit_modifier_property_get(op, ob, eModifierType_Strands);
+
+ if (!smd)
+ return OPERATOR_CANCELLED;
+
+ CustomDataMask mask = CD_MASK_BAREMESH;
+ DerivedMesh *scalp = mesh_get_derived_final(scene, ob, mask);
+ if (!scalp)
+ return OPERATOR_CANCELLED;
+
+ int totcurves = RNA_int_get(op->ptr, "amount");
+ int maxverts = RNA_int_get(op->ptr, "maxverts");
+ unsigned int seed = RNA_int_get(op->ptr, "seed");
+ BKE_strands_test_init(smd->strands, scalp, totcurves, maxverts, seed);
+
+ DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+ return OPERATOR_FINISHED;
+}
+
+static int strands_test_init_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ if (edit_modifier_invoke_properties(C, op))
+ return WM_operator_props_popup_confirm(C, op, event);
+ else
+ return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_strands_test_init(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Strands Test Init";
+ ot->description = "Testing strand with randomized initialization of control curves";
+ ot->idname = "OBJECT_OT_strands_test_init";
+
+ /* api callbacks */
+ ot->poll = strands_test_init_poll;
+ ot->invoke = strands_test_init_invoke;
+ ot->exec = strands_test_init_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+ edit_modifier_properties(ot);
+
+ RNA_def_int(ot->srna, "amount", 100, 0, INT_MAX, "Amount", "Number of control curves to generate", 1, 10000);
+ RNA_def_int(ot->srna, "maxverts", 5, 0, INT_MAX, "Vertices", "Maximum number of vertices per strand", 1, 20);
+ RNA_def_int(ot->srna, "seed", 0, 0, INT_MAX, "Seed", "Seed value for randomization", 0, INT_MAX);
+}
More information about the Bf-blender-cvs
mailing list