[Bf-blender-cvs] [485ea73b2bf] sculpt-mode-features: Mesh Filter: Init random displacement only once
Pablo Dobarro
noreply at git.blender.org
Tue May 14 23:43:11 CEST 2019
Commit: 485ea73b2bf849aae9077abb953f1f4b2f20e9f7
Author: Pablo Dobarro
Date: Tue May 14 23:42:54 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rB485ea73b2bf849aae9077abb953f1f4b2f20e9f7
Mesh Filter: Init random displacement only once
The random mesh filter should be much faster now, and it should not do
weird things when adjusting the strength.
===================================================================
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 2dc2bb5e18a..51c01f25929 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -7566,6 +7566,10 @@ EnumPropertyItem prop_mesh_filter_types[] = {
{0, NULL, 0, NULL, NULL},
};
+typedef struct MeshFilterData {
+ float *random_disp;
+} MeshFilterData;
+
static void mesh_filter_task_cb(void *__restrict userdata,
const int i,
const ParallelRangeTLS *__restrict UNUSED(tls))
@@ -7643,8 +7647,7 @@ static void mesh_filter_task_cb(void *__restrict userdata,
break;
case MESH_FILTER_RANDOM:
normal_short_to_float_v3(normal, vd.no);
- float random = (float)rand() / (float)(RAND_MAX);
- mul_v3_fl(normal, random - 0.5f);
+ mul_v3_fl(normal, data->random_disp[vd.vert_indices[vd.i]] - 0.5f);
mul_v3_v3fl(disp, normal, fade);
add_v3_v3v3(ss->mvert[vd.vert_indices[vd.i]].co, orig_co, disp);
break;
@@ -7668,6 +7671,7 @@ int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *event)
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
int mode = RNA_enum_get(op->ptr, "type");
float filter_strength = RNA_float_get(op->ptr, "strength");
+ MeshFilterData *mfd = op->customdata;
SculptSearchSphereData searchdata = {
.ss = ss,
@@ -7686,6 +7690,7 @@ int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *event)
.smooth_value = 0.5f,
.filter_type = mode,
.filter_strength = filter_strength,
+ .random_disp = mfd->random_disp,
};
ParallelRangeSettings settings;
@@ -7714,6 +7719,10 @@ int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *event)
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
if (event->type == 1 && event->val == 2) {
sculpt_undo_push_end();
+ if (mfd->random_disp) {
+ MEM_freeN(mfd->random_disp);
+ }
+ MEM_freeN(mfd);
return OPERATOR_FINISHED;
}
@@ -7740,13 +7749,25 @@ int sculpt_mesh_filter_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (BKE_pbvh_type(pbvh) == PBVH_FACES && needs_pmap && !ob->sculpt->pmap) {
return OPERATOR_CANCELLED;
}
+
+ MeshFilterData *mfd = MEM_callocN(sizeof(MeshFilterData), "mesh filter data");
if (ss->orco == NULL) {
ss->orco = MEM_mallocN(3 * ss->totvert * sizeof(float), "orco");
}
+
+ if (mode == MESH_FILTER_RANDOM && mfd->random_disp == NULL) {
+ mfd->random_disp = MEM_mallocN(ss->totvert * sizeof(float), "random_disp");
+ }
+
for (int i = 0; i < ss->totvert; i++) {
copy_v3_v3(ss->orco[i], ss->mvert[i].co);
+ if (mode == MESH_FILTER_RANDOM) {
+ mfd->random_disp[i] = (float)rand() / (float)(RAND_MAX);
+ }
}
+ op->customdata = mfd;
+
sculpt_undo_push_begin("mesh filter fill");
WM_event_add_modal_handler(C, op);
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 97122ebe1a5..7a5232d0dc3 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -209,6 +209,7 @@ typedef struct SculptThreadedTaskData {
float smooth_value;
float filter_strength;
int filter_type;
+ float *random_disp;
float *automask;
More information about the Bf-blender-cvs
mailing list