[Bf-blender-cvs] [068aa21] strand_gpu: Generate a number of "roots" for render hairs on the mesh surface.
Lukas Tönne
noreply at git.blender.org
Tue Jul 5 09:57:04 CEST 2016
Commit: 068aa21e12c4a58d5f75420ea320041b70483252
Author: Lukas Tönne
Date: Fri Jul 1 10:00:07 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB068aa21e12c4a58d5f75420ea320041b70483252
Generate a number of "roots" for render hairs on the mesh surface.
These root points will be used as input for the strand shader to generate
the interpolated render 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/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/editors/object/object_strands.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesdna/DNA_strand_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_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 eaaa43f..cf5b39e 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -884,6 +884,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
split = layout.split()
col = split.column()
+ col.prop(md, "seed")
+ col.prop(md, "num_roots")
+
+ col = split.column()
col.label(text="Display:")
col.prop(md, "show_control_strands", text="Control Strands")
diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index f73294f..79005cf 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -63,21 +63,35 @@ typedef struct StrandCurveData {
float mat[4][4];
} StrandCurveData;
+typedef struct StrandRootData {
+ /* Position */
+ float co[3];
+ /* Indices of control strands for interpolation */
+ unsigned int control_index[4];
+ /* Weights of control strands for interpolation */
+ float control_weights[4];
+} StrandRootData;
+
typedef struct StrandData {
/* Array of vertices */
StrandVertexData *verts;
/* Array of curves */
StrandCurveData *curves;
+ /* Array of root points */
+ StrandRootData *roots;
/* Total number of vertices */
int totverts;
/* Total number of curves */
int totcurves;
+ /* Total number of root points */
+ int totroots;
struct GPUDrawStrands *gpu_buffer;
} StrandData;
-struct StrandData *BKE_strand_data_calc(struct Strands *strands, struct DerivedMesh *scalp);
+struct StrandData *BKE_strand_data_calc(struct Strands *strands, struct DerivedMesh *scalp,
+ StrandRoot *roots, int num_roots);
void BKE_strand_data_free(struct StrandData *data);
/* ------------------------------------------------------------------------- */
@@ -87,8 +101,8 @@ void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
unsigned int seed);
-struct StrandInfo *BKE_strands_scatter(struct DerivedMesh *scalp, unsigned int amount,
- const StrandCurve *controls, unsigned int num_controls,
+struct StrandRoot *BKE_strands_scatter(struct Strands *strands,
+ struct DerivedMesh *scalp, unsigned int amount,
unsigned int seed);
#if 0
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index e07b09a..aab0d9f 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -84,14 +84,17 @@ void BKE_strands_free(Strands *strands)
/* ------------------------------------------------------------------------- */
-StrandData *BKE_strand_data_calc(Strands *strands, DerivedMesh *scalp)
+StrandData *BKE_strand_data_calc(Strands *strands, DerivedMesh *scalp,
+ StrandRoot *roots, int num_roots)
{
StrandData *data = MEM_callocN(sizeof(StrandData), "StrandData");
data->totverts = strands->totverts;
data->totcurves = strands->totcurves;
+ data->totroots = num_roots;
data->verts = MEM_mallocN(sizeof(StrandVertexData) * data->totverts, "StrandVertexData");
data->curves = MEM_mallocN(sizeof(StrandCurveData) * data->totcurves, "StrandCurveData");
+ data->roots = MEM_mallocN(sizeof(StrandRootData) * data->totroots, "StrandRootData");
int c;
StrandCurve *scurve = strands->curves;
@@ -111,6 +114,20 @@ StrandData *BKE_strand_data_calc(Strands *strands, DerivedMesh *scalp)
}
}
+ int i;
+ StrandRoot *sroot = roots;
+ StrandRootData *root = data->roots;
+ for (i = 0; i < data->totroots; ++i) {
+ float nor[3], tang[3];
+ BKE_mesh_sample_eval(scalp, &sroot->root, root->co, nor, tang);
+
+ int k;
+ for (k = 0; k < 4; ++k) {
+ root->control_index[k] = sroot->control_index[k];
+ root->control_weights[k] = sroot->control_weights[k];
+ }
+ }
+
return data;
}
@@ -123,6 +140,8 @@ void BKE_strand_data_free(StrandData *data)
MEM_freeN(data->verts);
if (data->curves)
MEM_freeN(data->curves);
+ if (data->roots)
+ MEM_freeN(data->roots);
MEM_freeN(data);
}
}
@@ -176,36 +195,36 @@ void BKE_strands_test_init(struct Strands *strands, struct DerivedMesh *scalp,
strands->totverts = totverts;
}
-StrandInfo *BKE_strands_scatter(struct DerivedMesh *scalp, unsigned int amount,
- const StrandCurve *controls, unsigned int num_controls,
+StrandRoot *BKE_strands_scatter(Strands *strands,
+ struct DerivedMesh *scalp, unsigned int amount,
unsigned int seed)
{
MeshSampleGenerator *gen = BKE_mesh_sample_gen_surface_random(scalp, seed);
unsigned int i;
- StrandInfo *strands = MEM_mallocN(sizeof(StrandInfo) * amount, "strands");
- StrandInfo *s;
+ StrandRoot *roots = MEM_mallocN(sizeof(StrandRoot) * amount, "StrandRoot");
+ StrandRoot *root;
- UNUSED_VARS(controls, num_controls);
- for (i = 0, s = strands; i < amount; ++i, ++s) {
- if (BKE_mesh_sample_generate(gen, &s->root)) {
+ UNUSED_VARS(strands);
+ for (i = 0, root = roots; i < amount; ++i, ++root) {
+ if (BKE_mesh_sample_generate(gen, &root->root)) {
int k;
/* TODO find weights to "nearest" control strands */
for (k = 0; k < 4; ++k) {
- s->control_index[k] = STRAND_INDEX_NONE;
- s->control_weights[k] = 0.0f;
+ root->control_index[k] = STRAND_INDEX_NONE;
+ root->control_weights[k] = 0.0f;
}
}
else {
/* clear remaining samples */
- memset(s, 0, sizeof(StrandInfo) * amount - i);
+ memset(root, 0, sizeof(StrandRoot) * amount - i);
break;
}
}
BKE_mesh_sample_free_generator(gen);
- return strands;
+ return roots;
}
#if 0
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9d05178..ae7cb61 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5282,6 +5282,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
smd->strands = newdataadr(fd, smd->strands);
direct_link_strands(fd, smd->strands);
}
+ smd->roots = newdataadr(fd, smd->roots);
}
}
}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index e22fe6f..c4219b7 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1690,6 +1690,9 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
if (smd->strands) {
write_strands(wd, smd->strands);
}
+ if (smd->roots) {
+ writestruct(wd, DATA, "StrandRoot", smd->num_roots, smd->roots);
+ }
}
}
}
diff --git a/source/blender/editors/object/object_strands.c b/source/blender/editors/object/object_strands.c
index ee4b562..f96439e 100644
--- a/source/blender/editors/object/object_strands.c
+++ b/source/blender/editors/object/object_strands.c
@@ -77,8 +77,15 @@ static int strands_test_init_exec(bContext *C, wmOperator *op)
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);
+ /* invalidate roots */
+ if (smd->roots) {
+ MEM_freeN(smd->roots);
+ smd->roots = NULL;
+ }
+
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index c186713..241433a 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1549,9 +1549,12 @@ typedef struct StrandsModifierData {
ModifierData modifier;
int flag;
+ int num_roots;
+ int seed;
int pad;
struct Strands *strands;
+ struct StrandRoot *roots;
} StrandsModifierData;
/* StrandsModifierData.flag */
diff --git a/source/blender/makesdna/DNA_strand_types.h b/source/blender/makesdna/DNA_strand_types.h
index 88c42f6..52fdc97 100644
--- a/source/blender/makesdna/DNA_strand_types.h
+++ b/source/blender/makesdna/DNA_strand_types.h
@@ -51,14 +51,14 @@ typedef struct StrandCurve {
unsigned int num_verts;
} StrandCurve;
-typedef struct StrandInfo {
+typedef struct StrandRoot {
/* Sample on the scalp mesh for the root vertex */
MeshSample root;
/* Indices of control strands for interpolation */
unsigned int control_index[4];
/* Weights of control strands for interpolation */
float control_weights[4];
-} StrandInfo;
+} StrandRoot;
typedef struct Strands {
/* Array of vertices */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index ac54fe8..f9058f8 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -288,6 +288,7 @@ EnumPropertyItem rna_enum_axis_flag_xyz_items[] = {
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "BKE_particle.h"
+#include "BKE_strands.h"
static void rna_UVProject_projectors_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
@@ -1123,6 +1124,32 @@ static int rna_CorrectiveSmoothModifier_is_bind_get(PointerRNA *ptr)
return (csmd->bind_coords != NULL);
}
+static void rna_StrandsModifier_seed_set(PointerRNA *ptr, int value)
+{
+ StrandsModifierData *smd = (StrandsModifierData *)ptr->data;
+
+ /* Note: roots array is regenerated by the modifier */
+ if (smd->roots && smd->seed != value) {
+ MEM_freeN(smd->roots);
+ smd->roots = NULL;
+ }
+
+ smd->seed = value;
+}
+
+static void rna_StrandsModifier_num_roots_set(PointerRNA *ptr, int value)
+{
+ StrandsModifierData *smd = (StrandsModifierData *)ptr->data;
+
+ /* Note: roots array is regenerated by the modifier */
+ if (smd->roots && smd->num_roots != value) {
+ MEM_freeN(smd->roots);
+ smd->roots = NULL;
+ }
+
+ smd->num_roots = value;
+}
+
#else
static P
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list