Cleanup: Sculpt: Move sampling code to namespace, tweak arguments
Move the code to the proper namespace and change some arguments from the sculpt paint struct to just the brush.
This commit is contained in:
@@ -287,9 +287,9 @@ Vector<PBVHNode *> pbvh_gather_generic(Object &ob, const VPaint &wp, const Brush
|
||||
return node_in_sphere(node, ss.cache->location, ss.cache->radius_squared, true);
|
||||
});
|
||||
|
||||
ss.cache->sculpt_normal_symm =
|
||||
use_normal ? SCULPT_pbvh_calc_area_normal(brush, ob, nodes).value_or(float3(0)) :
|
||||
float3(0);
|
||||
ss.cache->sculpt_normal_symm = use_normal ?
|
||||
calc_area_normal(brush, ob, nodes).value_or(float3(0)) :
|
||||
float3(0);
|
||||
}
|
||||
else {
|
||||
const DistRayAABB_Precalc ray_dist_precalc = dist_squared_ray_to_aabb_v3_precalc(
|
||||
|
||||
@@ -1864,13 +1864,15 @@ static float calc_symmetry_feather(const Sculpt &sd,
|
||||
* (optionally using original coordinates).
|
||||
*
|
||||
* Functions are:
|
||||
* - #SCULPT_calc_area_center
|
||||
* - #SCULPT_calc_area_normal
|
||||
* - #SCULPT_calc_area_normal_and_center
|
||||
* - #calc_area_center
|
||||
* - #calc_area_normal
|
||||
* - #calc_area_normal_and_center
|
||||
*
|
||||
* \note These are all _very_ similar, when changing one, check others.
|
||||
* \{ */
|
||||
|
||||
namespace blender::ed::sculpt_paint {
|
||||
|
||||
struct AreaNormalCenterData {
|
||||
/* 0 = towards view, 1 = flipped */
|
||||
float area_cos[2][3];
|
||||
@@ -1888,8 +1890,6 @@ static void calc_area_normal_and_center_task(const Object &ob,
|
||||
AreaNormalCenterData *anctd,
|
||||
bool &r_any_vertex_sampled)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
const SculptSession &ss = *ob.sculpt;
|
||||
|
||||
PBVHVertexIter vd;
|
||||
@@ -2096,14 +2096,11 @@ static AreaNormalCenterData calc_area_normal_and_center_reduce(const AreaNormalC
|
||||
return joined;
|
||||
}
|
||||
|
||||
void SCULPT_calc_area_center(const Sculpt &sd,
|
||||
const Object &ob,
|
||||
Span<PBVHNode *> nodes,
|
||||
float r_area_co[3])
|
||||
void calc_area_center(const Brush &brush,
|
||||
const Object &ob,
|
||||
Span<PBVHNode *> nodes,
|
||||
float r_area_co[3])
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
const SculptSession &ss = *ob.sculpt;
|
||||
const bool has_bm_orco = ss.bm && dyntopo::stroke_is_dyntopo(ss, brush);
|
||||
int n;
|
||||
@@ -2144,18 +2141,8 @@ void SCULPT_calc_area_center(const Sculpt &sd,
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<float3> SCULPT_calc_area_normal(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
std::optional<float3> calc_area_normal(const Brush &brush, Object &ob, Span<PBVHNode *> nodes)
|
||||
{
|
||||
const Brush *brush = BKE_paint_brush_for_read(&sd.paint);
|
||||
return SCULPT_pbvh_calc_area_normal(*brush, ob, nodes);
|
||||
}
|
||||
|
||||
std::optional<float3> SCULPT_pbvh_calc_area_normal(const Brush &brush,
|
||||
Object &ob,
|
||||
Span<PBVHNode *> nodes)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const bool has_bm_orco = ss.bm && dyntopo::stroke_is_dyntopo(ss, brush);
|
||||
|
||||
@@ -2188,15 +2175,12 @@ std::optional<float3> SCULPT_pbvh_calc_area_normal(const Brush &brush,
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void SCULPT_calc_area_normal_and_center(const Sculpt &sd,
|
||||
const Object &ob,
|
||||
Span<PBVHNode *> nodes,
|
||||
float r_area_no[3],
|
||||
float r_area_co[3])
|
||||
void calc_area_normal_and_center(const Brush &brush,
|
||||
const Object &ob,
|
||||
Span<PBVHNode *> nodes,
|
||||
float r_area_no[3],
|
||||
float r_area_co[3])
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const bool has_bm_orco = ss.bm && dyntopo::stroke_is_dyntopo(ss, brush);
|
||||
int n;
|
||||
@@ -2244,6 +2228,8 @@ void SCULPT_calc_area_normal_and_center(const Sculpt &sd,
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blender::ed::sculpt_paint
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
@@ -2745,7 +2731,7 @@ static float3 calc_sculpt_normal(const Sculpt &sd, Object &ob, Span<PBVHNode *>
|
||||
const SculptSession &ss = *ob.sculpt;
|
||||
switch (brush.sculpt_plane) {
|
||||
case SCULPT_DISP_DIR_AREA:
|
||||
return SCULPT_calc_area_normal(sd, ob, nodes).value_or(float3(0));
|
||||
return calc_area_normal(brush, ob, nodes).value_or(float3(0));
|
||||
case SCULPT_DISP_DIR_VIEW:
|
||||
return ss.cache->true_view_normal;
|
||||
case SCULPT_DISP_DIR_X:
|
||||
@@ -3097,11 +3083,12 @@ bool SCULPT_tool_needs_all_pbvh_nodes(const Brush &brush)
|
||||
return false;
|
||||
}
|
||||
|
||||
void SCULPT_calc_brush_plane(
|
||||
const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes, float r_area_no[3], float r_area_co[3])
|
||||
namespace blender::ed::sculpt_paint {
|
||||
|
||||
void calc_brush_plane(
|
||||
const Brush &brush, Object &ob, Span<PBVHNode *> nodes, float r_area_no[3], float r_area_co[3])
|
||||
{
|
||||
const SculptSession &ss = *ob.sculpt;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
zero_v3(r_area_co);
|
||||
zero_v3(r_area_no);
|
||||
@@ -3128,7 +3115,7 @@ void SCULPT_calc_brush_plane(
|
||||
break;
|
||||
|
||||
case SCULPT_DISP_DIR_AREA:
|
||||
SCULPT_calc_area_normal_and_center(sd, ob, nodes, r_area_no, r_area_co);
|
||||
calc_area_normal_and_center(brush, ob, nodes, r_area_no, r_area_co);
|
||||
if (brush.falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
|
||||
project_plane_v3_v3v3(r_area_no, r_area_no, ss.cache->view_normal);
|
||||
normalize_v3(r_area_no);
|
||||
@@ -3142,7 +3129,7 @@ void SCULPT_calc_brush_plane(
|
||||
/* For flatten center. */
|
||||
/* Flatten center has not been calculated yet if we are not using the area normal. */
|
||||
if (brush.sculpt_plane != SCULPT_DISP_DIR_AREA) {
|
||||
SCULPT_calc_area_center(sd, ob, nodes, r_area_co);
|
||||
calc_area_center(brush, ob, nodes, r_area_co);
|
||||
}
|
||||
|
||||
/* For area normal. */
|
||||
@@ -3189,6 +3176,8 @@ void SCULPT_calc_brush_plane(
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blender::ed::sculpt_paint
|
||||
|
||||
int SCULPT_plane_trim(const blender::ed::sculpt_paint::StrokeCache &cache,
|
||||
const Brush &brush,
|
||||
const float val[3])
|
||||
@@ -5128,8 +5117,7 @@ bool SCULPT_cursor_geometry_info_update(bContext *C,
|
||||
}
|
||||
|
||||
/* Calculate the sampled normal. */
|
||||
if (const std::optional<float3> sampled_normal = SCULPT_pbvh_calc_area_normal(brush, ob, nodes))
|
||||
{
|
||||
if (const std::optional<float3> sampled_normal = calc_area_normal(brush, ob, nodes)) {
|
||||
copy_v3_v3(out->normal, *sampled_normal);
|
||||
copy_v3_v3(ss.cursor_sampled_normal, *sampled_normal);
|
||||
}
|
||||
|
||||
@@ -214,6 +214,7 @@ static void do_fill_brush_task(
|
||||
void SCULPT_do_fill_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
@@ -227,7 +228,7 @@ void SCULPT_do_fill_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
|
||||
float temp[3];
|
||||
|
||||
SCULPT_calc_brush_plane(sd, ob, nodes, area_no, area_co);
|
||||
calc_brush_plane(brush, ob, nodes, area_no, area_co);
|
||||
|
||||
SCULPT_tilt_apply_to_normal(area_no, ss.cache, brush.tilt_strength_factor);
|
||||
|
||||
@@ -302,6 +303,7 @@ static void do_scrape_brush_task(
|
||||
void SCULPT_do_scrape_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
@@ -315,7 +317,7 @@ void SCULPT_do_scrape_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes
|
||||
|
||||
float temp[3];
|
||||
|
||||
SCULPT_calc_brush_plane(sd, ob, nodes, area_no, area_co);
|
||||
calc_brush_plane(brush, ob, nodes, area_no, area_co);
|
||||
|
||||
SCULPT_tilt_apply_to_normal(area_no, ss.cache, brush.tilt_strength_factor);
|
||||
|
||||
@@ -423,6 +425,7 @@ float SCULPT_clay_thumb_get_stabilized_pressure(
|
||||
void SCULPT_do_clay_thumb_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
@@ -435,10 +438,10 @@ void SCULPT_do_clay_thumb_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> n
|
||||
float scale[4][4];
|
||||
float tmat[4][4];
|
||||
|
||||
SCULPT_calc_brush_plane(sd, ob, nodes, area_no_sp, area_co_tmp);
|
||||
calc_brush_plane(brush, ob, nodes, area_no_sp, area_co_tmp);
|
||||
|
||||
if (brush.sculpt_plane != SCULPT_DISP_DIR_AREA || (brush.flag & BRUSH_ORIGINAL_NORMAL)) {
|
||||
area_no = SCULPT_calc_area_normal(sd, ob, nodes).value_or(float3(0));
|
||||
area_no = calc_area_normal(brush, ob, nodes).value_or(float3(0));
|
||||
}
|
||||
else {
|
||||
area_no = area_no_sp;
|
||||
@@ -547,6 +550,7 @@ static void do_flatten_brush_task(
|
||||
void SCULPT_do_flatten_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
@@ -559,7 +563,7 @@ void SCULPT_do_flatten_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> node
|
||||
float displace;
|
||||
float temp[3];
|
||||
|
||||
SCULPT_calc_brush_plane(sd, ob, nodes, area_no, area_co);
|
||||
calc_brush_plane(brush, ob, nodes, area_no, area_co);
|
||||
|
||||
SCULPT_tilt_apply_to_normal(area_no, ss.cache, brush.tilt_strength_factor);
|
||||
|
||||
@@ -681,6 +685,7 @@ static void do_clay_brush_task(
|
||||
void SCULPT_do_clay_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
@@ -695,7 +700,7 @@ void SCULPT_do_clay_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
float area_co[3];
|
||||
float temp[3];
|
||||
|
||||
SCULPT_calc_brush_plane(sd, ob, nodes, area_no, area_co);
|
||||
calc_brush_plane(brush, ob, nodes, area_no, area_co);
|
||||
|
||||
ClaySampleData csd = threading::parallel_reduce(
|
||||
nodes.index_range(),
|
||||
@@ -795,6 +800,7 @@ static void do_clay_strips_brush_task(Object &ob,
|
||||
void SCULPT_do_clay_strips_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
@@ -815,11 +821,11 @@ void SCULPT_do_clay_strips_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *>
|
||||
float scale[4][4];
|
||||
float tmat[4][4];
|
||||
|
||||
SCULPT_calc_brush_plane(sd, ob, nodes, area_no_sp, area_co);
|
||||
calc_brush_plane(brush, ob, nodes, area_no_sp, area_co);
|
||||
SCULPT_tilt_apply_to_normal(area_no_sp, ss.cache, brush.tilt_strength_factor);
|
||||
|
||||
if (brush.sculpt_plane != SCULPT_DISP_DIR_AREA || (brush.flag & BRUSH_ORIGINAL_NORMAL)) {
|
||||
area_no = SCULPT_calc_area_normal(sd, ob, nodes).value_or(float3(0));
|
||||
area_no = calc_area_normal(brush, ob, nodes).value_or(float3(0));
|
||||
}
|
||||
else {
|
||||
area_no = area_no_sp;
|
||||
@@ -1548,6 +1554,7 @@ static void do_pinch_brush_task(Object &ob,
|
||||
void SCULPT_do_pinch_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
@@ -1555,7 +1562,7 @@ void SCULPT_do_pinch_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
|
||||
float area_co[3];
|
||||
|
||||
float mat[4][4];
|
||||
SCULPT_calc_brush_plane(sd, ob, nodes, area_no, area_co);
|
||||
calc_brush_plane(brush, ob, nodes, area_no, area_co);
|
||||
|
||||
/* delay the first daub because grab delta is not setup */
|
||||
if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(*ss.cache)) {
|
||||
|
||||
@@ -962,7 +962,7 @@ static void cloth_brush_apply_brush_foces(const Sculpt &sd, Object &ob, Span<PBV
|
||||
if (brush.cloth_deform_type == BRUSH_CLOTH_DEFORM_PINCH_PERPENDICULAR ||
|
||||
brush.cloth_force_falloff_type == BRUSH_CLOTH_FORCE_FALLOFF_PLANE)
|
||||
{
|
||||
SCULPT_calc_brush_plane(sd, ob, nodes, area_no, area_co);
|
||||
calc_brush_plane(brush, ob, nodes, area_no, area_co);
|
||||
|
||||
/* Initialize stroke local space matrix. */
|
||||
cross_v3_v3v3(mat[0], area_no, ss.cache->grab_delta_symmetry);
|
||||
|
||||
@@ -176,7 +176,7 @@ void cache_init(bContext *C,
|
||||
return !node_fully_masked_or_hidden(node) && node_in_sphere(node, co, radius_sq, true);
|
||||
});
|
||||
|
||||
const std::optional<float3> area_normal = SCULPT_pbvh_calc_area_normal(*brush, ob, nodes);
|
||||
const std::optional<float3> area_normal = calc_area_normal(*brush, ob, nodes);
|
||||
if (BKE_paint_brush_for_read(&sd.paint) && area_normal) {
|
||||
ss.filter_cache->initial_normal = *area_normal;
|
||||
ss.last_normal = ss.filter_cache->initial_normal;
|
||||
|
||||
@@ -1032,28 +1032,31 @@ void SCULPT_orig_vert_data_unode_init(SculptOrigVertData &data,
|
||||
|
||||
bool SCULPT_tool_needs_all_pbvh_nodes(const Brush &brush);
|
||||
|
||||
void SCULPT_calc_brush_plane(const Sculpt &sd,
|
||||
Object &ob,
|
||||
blender::Span<PBVHNode *> nodes,
|
||||
float r_area_no[3],
|
||||
float r_area_co[3]);
|
||||
namespace blender::ed::sculpt_paint {
|
||||
|
||||
void calc_brush_plane(const Brush &brush,
|
||||
Object &ob,
|
||||
Span<PBVHNode *> nodes,
|
||||
float r_area_no[3],
|
||||
float r_area_co[3]);
|
||||
|
||||
std::optional<float3> calc_area_normal(const Brush &brush, Object &ob, Span<PBVHNode *> nodes);
|
||||
|
||||
std::optional<blender::float3> SCULPT_calc_area_normal(const Sculpt &sd,
|
||||
Object &ob,
|
||||
blender::Span<PBVHNode *> nodes);
|
||||
/**
|
||||
* This calculates flatten center and area normal together,
|
||||
* amortizing the memory bandwidth and loop overhead to calculate both at the same time.
|
||||
*/
|
||||
void SCULPT_calc_area_normal_and_center(const Sculpt &sd,
|
||||
const Object &ob,
|
||||
blender::Span<PBVHNode *> nodes,
|
||||
float r_area_no[3],
|
||||
float r_area_co[3]);
|
||||
void SCULPT_calc_area_center(const Sculpt &sd,
|
||||
const Object &ob,
|
||||
blender::Span<PBVHNode *> nodes,
|
||||
float r_area_co[3]);
|
||||
void calc_area_normal_and_center(const Brush &brush,
|
||||
const Object &ob,
|
||||
Span<PBVHNode *> nodes,
|
||||
float r_area_no[3],
|
||||
float r_area_co[3]);
|
||||
void calc_area_center(const Brush &brush,
|
||||
const Object &ob,
|
||||
Span<PBVHNode *> nodes,
|
||||
float r_area_co[3]);
|
||||
|
||||
}
|
||||
|
||||
PBVHVertRef SCULPT_nearest_vertex_get(const Object &ob,
|
||||
const float co[3],
|
||||
@@ -1621,13 +1624,6 @@ void relax_vertex(SculptSession &ss,
|
||||
|
||||
/** \} */
|
||||
|
||||
/**
|
||||
* Expose 'calc_area_normal' externally (just for vertex paint).
|
||||
*/
|
||||
std::optional<blender::float3> SCULPT_pbvh_calc_area_normal(const Brush &brush,
|
||||
Object &ob,
|
||||
blender::Span<PBVHNode *> nodes);
|
||||
|
||||
/**
|
||||
* Flip all the edit-data across the axis/axes specified by \a symm.
|
||||
* Used to calculate multiple modifications to the mesh when symmetry is enabled.
|
||||
|
||||
@@ -192,6 +192,7 @@ void SCULPT_do_multiplane_scrape_brush(const Sculpt &sd,
|
||||
blender::Span<PBVHNode *> nodes)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint;
|
||||
SculptSession &ss = *ob.sculpt;
|
||||
const Brush &brush = *BKE_paint_brush_for_read(&sd.paint);
|
||||
|
||||
@@ -210,10 +211,10 @@ void SCULPT_do_multiplane_scrape_brush(const Sculpt &sd,
|
||||
float temp[3];
|
||||
float4x4 mat;
|
||||
|
||||
SCULPT_calc_brush_plane(sd, ob, nodes, area_no_sp, area_co);
|
||||
calc_brush_plane(brush, ob, nodes, area_no_sp, area_co);
|
||||
|
||||
if (brush.sculpt_plane != SCULPT_DISP_DIR_AREA || (brush.flag & BRUSH_ORIGINAL_NORMAL)) {
|
||||
area_no = SCULPT_calc_area_normal(sd, ob, nodes).value_or(float3(0));
|
||||
area_no = calc_area_normal(brush, ob, nodes).value_or(float3(0));
|
||||
}
|
||||
else {
|
||||
area_no = area_no_sp;
|
||||
|
||||
Reference in New Issue
Block a user