Sculpt: Cloth Brush simulation area property
This makes possible to choose between a local and a global simulation when the cloth brush is used. Local simulation is the current default. When global simulation is enabled, the cloth brush simulates the entire mesh without taking any simulation limits into account. This was possible before by setting the simulation limits to 10 (the current maximum value allowed) so the entire mesh was inside the limits, but this was a hack as the limits scale with the radius and there should not be any limitation on how big the simulated area can be to be able to simulate an entire object. This also allows to make a more clear distinction between cloth brush presets that are intended to be used in local areas to add details or globally to generate the base shape of the mesh. Reviewed By: sergey Differential Revision: https://developer.blender.org/D8481
This commit is contained in:
parent
97c56b7628
commit
d693d77fed
|
@ -656,9 +656,12 @@ def brush_settings(layout, context, brush, popover=False):
|
|||
|
||||
elif sculpt_tool == 'CLOTH':
|
||||
layout.separator()
|
||||
layout.prop(brush, "cloth_sim_limit")
|
||||
layout.prop(brush, "cloth_sim_falloff")
|
||||
layout.prop(brush, "use_cloth_pin_simulation_boundary")
|
||||
layout.prop(brush, "cloth_simulation_area_type")
|
||||
if brush.cloth_simulation_area_type == 'LOCAL':
|
||||
layout.prop(brush, "cloth_sim_limit")
|
||||
layout.prop(brush, "cloth_sim_falloff")
|
||||
layout.prop(brush, "use_cloth_pin_simulation_boundary")
|
||||
|
||||
layout.separator()
|
||||
layout.prop(brush, "cloth_deform_type")
|
||||
layout.prop(brush, "cloth_force_falloff_type")
|
||||
|
|
|
@ -1612,8 +1612,9 @@ static void paint_cursor_draw_3d_view_brush_cursor_inactive(PaintCursorContext *
|
|||
/* Main inactive cursor. */
|
||||
paint_cursor_draw_main_inactive_cursor(pcontext);
|
||||
|
||||
/* Cloth brush simulation areas. */
|
||||
if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
|
||||
/* Cloth brush local simulation areas. */
|
||||
if (brush->sculpt_tool == SCULPT_TOOL_CLOTH &&
|
||||
brush->cloth_simulation_area_type == BRUSH_CLOTH_SIMULATION_AREA_LOCAL) {
|
||||
const float white[3] = {1.0f, 1.0f, 1.0f};
|
||||
const float zero_v[3] = {0.0f};
|
||||
/* This functions sets its own drawing space in order to draw the simulation limits when the
|
||||
|
@ -1691,9 +1692,10 @@ static void paint_cursor_cursor_draw_3d_view_brush_cursor_active(PaintCursorCont
|
|||
SCULPT_cloth_plane_falloff_preview_draw(
|
||||
pcontext->pos, ss, pcontext->outline_col, pcontext->outline_alpha);
|
||||
}
|
||||
else if (brush->cloth_force_falloff_type == BRUSH_CLOTH_FORCE_FALLOFF_RADIAL) {
|
||||
else if (brush->cloth_force_falloff_type == BRUSH_CLOTH_FORCE_FALLOFF_RADIAL &&
|
||||
brush->cloth_simulation_area_type == BRUSH_CLOTH_SIMULATION_AREA_LOCAL) {
|
||||
/* Display the simulation limits if sculpting outside them. */
|
||||
/* This does not makes much sense of plane fallof as the fallof is infinte. */
|
||||
/* This does not makes much sense of plane fallof as the fallof is infinte or global. */
|
||||
|
||||
if (len_v3v3(ss->cache->true_location, ss->cache->true_initial_location) >
|
||||
ss->cache->radius * (1.0f + brush->cloth_sim_limit)) {
|
||||
|
|
|
@ -5513,15 +5513,21 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
|
|||
BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
|
||||
}
|
||||
else if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
|
||||
SculptSearchSphereData data = {
|
||||
.ss = ss,
|
||||
.sd = sd,
|
||||
.radius_squared = square_f(ss->cache->initial_radius * (1.0 + brush->cloth_sim_limit)),
|
||||
.original = false,
|
||||
.ignore_fully_ineffective = false,
|
||||
.center = ss->cache->initial_location,
|
||||
};
|
||||
BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, &totnode);
|
||||
if (brush->cloth_simulation_area_type == BRUSH_CLOTH_SIMULATION_AREA_LOCAL) {
|
||||
SculptSearchSphereData data = {
|
||||
.ss = ss,
|
||||
.sd = sd,
|
||||
.radius_squared = square_f(ss->cache->initial_radius * (1.0 + brush->cloth_sim_limit)),
|
||||
.original = false,
|
||||
.ignore_fully_ineffective = false,
|
||||
.center = ss->cache->initial_location,
|
||||
};
|
||||
BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, &totnode);
|
||||
}
|
||||
else {
|
||||
/* Gobal simulation, get all nodes. */
|
||||
BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? true :
|
||||
|
|
|
@ -108,6 +108,11 @@ static float cloth_brush_simulation_falloff_get(const Brush *brush,
|
|||
const float location[3],
|
||||
const float co[3])
|
||||
{
|
||||
/* Global simulation does not have any falloff as the entire mesh is being simulated. */
|
||||
if (brush->cloth_simulation_area_type == BRUSH_CLOTH_SIMULATION_AREA_GLOBAL) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
const float distance = len_v3v3(location, co);
|
||||
const float limit = radius + (radius * brush->cloth_sim_limit);
|
||||
const float falloff = radius + (radius * brush->cloth_sim_limit * brush->cloth_sim_falloff);
|
||||
|
@ -249,7 +254,11 @@ static void do_cloth_brush_build_constraints_task_cb_ex(
|
|||
radius_squared = ss->cache->initial_radius * ss->cache->initial_radius;
|
||||
}
|
||||
|
||||
const float cloth_sim_radius_squared = data->cloth_sim_radius * data->cloth_sim_radius;
|
||||
/* Only limit the contraint creation to a radius when the simulation is local. */
|
||||
const float cloth_sim_radius_squared = brush->cloth_simulation_area_type ==
|
||||
BRUSH_CLOTH_SIMULATION_AREA_LOCAL ?
|
||||
data->cloth_sim_radius * data->cloth_sim_radius :
|
||||
FLT_MAX;
|
||||
|
||||
BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
|
||||
{
|
||||
|
|
|
@ -351,6 +351,11 @@ typedef enum eBrushClothForceFalloffType {
|
|||
BRUSH_CLOTH_FORCE_FALLOFF_PLANE = 1,
|
||||
} eBrushClothForceFalloffType;
|
||||
|
||||
typedef enum eBrushClothSimulationAreaType {
|
||||
BRUSH_CLOTH_SIMULATION_AREA_LOCAL = 0,
|
||||
BRUSH_CLOTH_SIMULATION_AREA_GLOBAL = 1,
|
||||
} eBrushClothSimulationAreaType;
|
||||
|
||||
typedef enum eBrushPoseDeformType {
|
||||
BRUSH_POSE_DEFORM_ROTATE_TWIST = 0,
|
||||
BRUSH_POSE_DEFORM_SCALE_TRASLATE = 1,
|
||||
|
@ -546,7 +551,7 @@ typedef struct Brush {
|
|||
char gpencil_sculpt_tool;
|
||||
/** Active grease pencil weight tool. */
|
||||
char gpencil_weight_tool;
|
||||
char _pad1[6];
|
||||
char _pad1[2];
|
||||
|
||||
float autosmooth_factor;
|
||||
|
||||
|
@ -585,6 +590,7 @@ typedef struct Brush {
|
|||
/* cloth */
|
||||
int cloth_deform_type;
|
||||
int cloth_force_falloff_type;
|
||||
int cloth_simulation_area_type;
|
||||
|
||||
float cloth_mass;
|
||||
float cloth_damping;
|
||||
|
|
|
@ -1983,6 +1983,16 @@ static void rna_def_brush(BlenderRNA *brna)
|
|||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
static const EnumPropertyItem brush_cloth_simulation_area_type_items[] = {
|
||||
{BRUSH_CLOTH_SIMULATION_AREA_LOCAL,
|
||||
"LOCAL",
|
||||
0,
|
||||
"Local",
|
||||
"Simulates only a specific area arround the brush limited by a fixed radius"},
|
||||
{BRUSH_CLOTH_SIMULATION_AREA_GLOBAL, "GLOBAL", 0, "Global", "Simulates the entire mesh"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
static const EnumPropertyItem brush_smooth_deform_type_items[] = {
|
||||
{BRUSH_SMOOTH_DEFORM_LAPLACIAN,
|
||||
"LAPLACIAN",
|
||||
|
@ -2153,6 +2163,14 @@ static void rna_def_brush(BlenderRNA *brna)
|
|||
prop, "Force Falloff", "Shape used in the brush to apply force to the cloth");
|
||||
RNA_def_property_update(prop, 0, "rna_Brush_update");
|
||||
|
||||
prop = RNA_def_property(srna, "cloth_simulation_area_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_items(prop, brush_cloth_simulation_area_type_items);
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
"Simulation Area",
|
||||
"Part of the mesh that is going to be simulated when the stroke is active");
|
||||
RNA_def_property_update(prop, 0, "rna_Brush_update");
|
||||
|
||||
prop = RNA_def_property(srna, "smooth_deform_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_items(prop, brush_smooth_deform_type_items);
|
||||
RNA_def_property_ui_text(prop, "Deformation", "Deformation type that is used in the brush");
|
||||
|
|
Loading…
Reference in New Issue