Sculpt: Enable persistent base for the cloth brush
The cloth brush builds the constraints when the stroke starts usign the current state of the mesh. This means that deformations profuced by the simulattion will accumulate after multiple strokes as it will always start from the previous deformed state. While this is useful in many cases, for other uses it is convenient to always simulate the same initial shape, but applying different forces to it. The persistent base options work like the persistent base in the layer brush and allows the cloth brush to not accumulate deformation after each stroke. When enabled, constraints are created for the shape stored in the persistent base instead of from the current state of the mesh. Reviewed By: sergey Differential Revision: https://developer.blender.org/D8428
This commit is contained in:
parent
27b643d27a
commit
49c1359b55
|
@ -196,7 +196,7 @@ void SCULPT_vertex_normal_get(SculptSession *ss, int index, float no[3])
|
|||
}
|
||||
}
|
||||
|
||||
static const float *sculpt_vertex_persistent_co_get(SculptSession *ss, int index)
|
||||
const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, int index)
|
||||
{
|
||||
if (ss->persistent_base) {
|
||||
return ss->persistent_base[index].co;
|
||||
|
@ -204,7 +204,7 @@ static const float *sculpt_vertex_persistent_co_get(SculptSession *ss, int index
|
|||
return SCULPT_vertex_co_get(ss, index);
|
||||
}
|
||||
|
||||
static void sculpt_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3])
|
||||
void SCULPT_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3])
|
||||
{
|
||||
if (ss->persistent_base) {
|
||||
copy_v3_v3(no, ss->persistent_base[index].no);
|
||||
|
@ -4341,9 +4341,9 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata,
|
|||
float normal[3];
|
||||
|
||||
if (use_persistent_base) {
|
||||
sculpt_vertex_persistent_normal_get(ss, vi, normal);
|
||||
SCULPT_vertex_persistent_normal_get(ss, vi, normal);
|
||||
mul_v3_fl(normal, brush->height);
|
||||
madd_v3_v3v3fl(final_co, sculpt_vertex_persistent_co_get(ss, vi), normal, *disp_factor);
|
||||
madd_v3_v3v3fl(final_co, SCULPT_vertex_persistent_co_get(ss, vi), normal, *disp_factor);
|
||||
}
|
||||
else {
|
||||
normal_short_to_float_v3(normal, orig_data.no);
|
||||
|
|
|
@ -126,7 +126,8 @@ static void cloth_brush_reallocate_constraints(SculptClothSimulation *cloth_sim)
|
|||
static void cloth_brush_add_length_constraint(SculptSession *ss,
|
||||
SculptClothSimulation *cloth_sim,
|
||||
const int v1,
|
||||
const int v2)
|
||||
const int v2,
|
||||
const bool use_persistent)
|
||||
{
|
||||
SculptClothLengthConstraint *length_constraint =
|
||||
&cloth_sim->length_constraints[cloth_sim->tot_length_constraints];
|
||||
|
@ -137,7 +138,14 @@ static void cloth_brush_add_length_constraint(SculptSession *ss,
|
|||
length_constraint->elem_position_a = cloth_sim->pos[v1];
|
||||
length_constraint->elem_position_b = cloth_sim->pos[v2];
|
||||
|
||||
length_constraint->length = len_v3v3(SCULPT_vertex_co_get(ss, v1), SCULPT_vertex_co_get(ss, v2));
|
||||
if (use_persistent) {
|
||||
length_constraint->length = len_v3v3(SCULPT_vertex_persistent_co_get(ss, v1),
|
||||
SCULPT_vertex_persistent_co_get(ss, v2));
|
||||
}
|
||||
else {
|
||||
length_constraint->length = len_v3v3(SCULPT_vertex_co_get(ss, v1),
|
||||
SCULPT_vertex_co_get(ss, v2));
|
||||
}
|
||||
length_constraint->strength = 1.0f;
|
||||
|
||||
cloth_sim->tot_length_constraints++;
|
||||
|
@ -180,6 +188,8 @@ static void do_cloth_brush_build_constraints_task_cb_ex(
|
|||
|
||||
PBVHVertexIter vd;
|
||||
|
||||
const bool use_persistent = brush != NULL && brush->flag & BRUSH_PERSISTENT;
|
||||
|
||||
BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
|
||||
{
|
||||
if (len_squared_v3v3(vd.co, data->cloth_sim_initial_location) <
|
||||
|
@ -211,7 +221,7 @@ static void do_cloth_brush_build_constraints_task_cb_ex(
|
|||
if (c_i != c_j && !cloth_brush_sim_has_length_constraint(
|
||||
data->cloth_sim, build_indices[c_i], build_indices[c_j])) {
|
||||
cloth_brush_add_length_constraint(
|
||||
ss, data->cloth_sim, build_indices[c_i], build_indices[c_j]);
|
||||
ss, data->cloth_sim, build_indices[c_i], build_indices[c_j], use_persistent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,9 @@ void SCULPT_vertex_normal_get(SculptSession *ss, int index, float no[3]);
|
|||
float SCULPT_vertex_mask_get(struct SculptSession *ss, int index);
|
||||
const float *SCULPT_vertex_color_get(SculptSession *ss, int index);
|
||||
|
||||
const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, int index);
|
||||
void SCULPT_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3]);
|
||||
|
||||
#define SCULPT_VERTEX_NEIGHBOR_FIXED_CAPACITY 256
|
||||
typedef struct SculptVertexNeighborIter {
|
||||
/* Storage */
|
||||
|
|
|
@ -365,7 +365,7 @@ static bool rna_BrushCapabilities_has_overlay_get(PointerRNA *ptr)
|
|||
static bool rna_BrushCapabilitiesSculpt_has_persistence_get(PointerRNA *ptr)
|
||||
{
|
||||
Brush *br = (Brush *)ptr->data;
|
||||
return br->sculpt_tool == SCULPT_TOOL_LAYER;
|
||||
return ELEM(br->sculpt_tool, SCULPT_TOOL_LAYER, SCULPT_TOOL_CLOTH);
|
||||
}
|
||||
|
||||
static bool rna_BrushCapabilitiesSculpt_has_pinch_factor_get(PointerRNA *ptr)
|
||||
|
|
Loading…
Reference in New Issue