Cleanup: Sculpt: Use return values, C++ types

This commit is contained in:
Hans Goudey
2024-05-19 23:11:00 -04:00
parent a72dbea01a
commit 5687072223
16 changed files with 97 additions and 140 deletions

View File

@@ -557,11 +557,10 @@ void BKE_pbvh_update_active_vcol(PBVH &pbvh, Mesh *mesh);
void BKE_pbvh_vertex_color_set(PBVH &pbvh,
blender::GroupedSpan<int> vert_to_face_map,
PBVHVertRef vertex,
const float color[4]);
void BKE_pbvh_vertex_color_get(const PBVH &pbvh,
blender::GroupedSpan<int> vert_to_face_map,
PBVHVertRef vertex,
float r_color[4]);
const blender::float4 &color);
blender::float4 BKE_pbvh_vertex_color_get(const PBVH &pbvh,
blender::GroupedSpan<int> vert_to_face_map,
PBVHVertRef vertex);
void BKE_pbvh_ensure_node_loops(PBVH &pbvh);
int BKE_pbvh_debug_draw_gen_get(PBVHNode &node);

View File

@@ -148,21 +148,22 @@ static void pbvh_vertex_color_set(PBVH &pbvh,
} // namespace blender::bke
void BKE_pbvh_vertex_color_get(const PBVH &pbvh,
const blender::GroupedSpan<int> vert_to_face_map,
PBVHVertRef vertex,
float r_color[4])
blender::float4 BKE_pbvh_vertex_color_get(const PBVH &pbvh,
const blender::GroupedSpan<int> vert_to_face_map,
PBVHVertRef vertex)
{
blender::float4 color;
blender::bke::to_static_color_type(eCustomDataType(pbvh.color_layer->type), [&](auto dummy) {
using T = decltype(dummy);
blender::bke::pbvh_vertex_color_get<T>(pbvh, vert_to_face_map, vertex, r_color);
blender::bke::pbvh_vertex_color_get<T>(pbvh, vert_to_face_map, vertex, color);
});
return color;
}
void BKE_pbvh_vertex_color_set(PBVH &pbvh,
const blender::GroupedSpan<int> vert_to_face_map,
const PBVHVertRef vertex,
const float color[4])
const blender::float4 &color)
{
blender::bke::to_static_color_type(eCustomDataType(pbvh.color_layer->type), [&](auto dummy) {
using T = decltype(dummy);

View File

@@ -592,9 +592,8 @@ static void gesture_apply_task(gesture::GestureData &gesture_data,
bool redraw = false;
BKE_pbvh_vertex_iter_begin (*gesture_data.ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
float vertex_normal[3];
const float *co = SCULPT_vertex_co_get(*gesture_data.ss, vd.vertex);
SCULPT_vertex_normal_get(*gesture_data.ss, vd.vertex, vertex_normal);
const float3 vertex_normal = SCULPT_vertex_normal_get(*gesture_data.ss, vd.vertex);
if (gesture::is_affected(gesture_data, co, vertex_normal)) {
float prevmask = vd.mask;

View File

@@ -220,38 +220,37 @@ bool SCULPT_has_colors(const SculptSession &ss)
return ss.vcol || ss.mcol;
}
void SCULPT_vertex_color_get(const SculptSession &ss, PBVHVertRef vertex, float r_color[4])
blender::float4 SCULPT_vertex_color_get(const SculptSession &ss, PBVHVertRef vertex)
{
BKE_pbvh_vertex_color_get(*ss.pbvh, ss.vert_to_face_map, vertex, r_color);
return BKE_pbvh_vertex_color_get(*ss.pbvh, ss.vert_to_face_map, vertex);
}
void SCULPT_vertex_color_set(SculptSession &ss, PBVHVertRef vertex, const float color[4])
void SCULPT_vertex_color_set(SculptSession &ss, PBVHVertRef vertex, const blender::float4 &color)
{
BKE_pbvh_vertex_color_set(*ss.pbvh, ss.vert_to_face_map, vertex, color);
}
void SCULPT_vertex_normal_get(const SculptSession &ss, PBVHVertRef vertex, float no[3])
const blender::float3 SCULPT_vertex_normal_get(const SculptSession &ss, PBVHVertRef vertex)
{
switch (BKE_pbvh_type(*ss.pbvh)) {
case PBVH_FACES: {
const Span<float3> vert_normals = BKE_pbvh_get_vert_normals(*ss.pbvh);
copy_v3_v3(no, vert_normals[vertex.i]);
break;
return vert_normals[vertex.i];
}
case PBVH_BMESH: {
BMVert *v = (BMVert *)vertex.i;
copy_v3_v3(no, v->no);
break;
return v->no;
}
case PBVH_GRIDS: {
const CCGKey *key = BKE_pbvh_get_grid_key(*ss.pbvh);
const int grid_index = vertex.i / key->grid_area;
const int index_in_grid = vertex.i - grid_index * key->grid_area;
CCGElem *elem = ss.subdiv_ccg->grids[grid_index];
copy_v3_v3(no, CCG_elem_no(key, CCG_elem_offset(key, elem, index_in_grid)));
break;
return CCG_elem_no(key, CCG_elem_offset(key, elem, index_in_grid));
}
}
BLI_assert_unreachable();
return {};
}
const float *SCULPT_vertex_persistent_co_get(const SculptSession &ss, PBVHVertRef vertex)
@@ -280,13 +279,12 @@ const float *SCULPT_vertex_co_for_grab_active_get(const SculptSession &ss, PBVHV
return SCULPT_vertex_co_get(ss, vertex);
}
void SCULPT_vertex_limit_surface_get(const SculptSession &ss, PBVHVertRef vertex, float r_co[3])
float3 SCULPT_vertex_limit_surface_get(const SculptSession &ss, PBVHVertRef vertex)
{
switch (BKE_pbvh_type(*ss.pbvh)) {
case PBVH_FACES:
case PBVH_BMESH:
copy_v3_v3(r_co, SCULPT_vertex_co_get(ss, vertex));
break;
return SCULPT_vertex_co_get(ss, vertex);
case PBVH_GRIDS: {
const CCGKey *key = BKE_pbvh_get_grid_key(*ss.pbvh);
const int grid_index = vertex.i / key->grid_area;
@@ -296,19 +294,21 @@ void SCULPT_vertex_limit_surface_get(const SculptSession &ss, PBVHVertRef vertex
coord.grid_index = grid_index;
coord.x = index_in_grid % key->grid_size;
coord.y = index_in_grid / key->grid_size;
BKE_subdiv_ccg_eval_limit_point(*ss.subdiv_ccg, coord, r_co);
break;
float3 tmp;
BKE_subdiv_ccg_eval_limit_point(*ss.subdiv_ccg, coord, tmp);
return tmp;
}
}
BLI_assert_unreachable();
return {};
}
void SCULPT_vertex_persistent_normal_get(const SculptSession &ss, PBVHVertRef vertex, float no[3])
float3 SCULPT_vertex_persistent_normal_get(const SculptSession &ss, PBVHVertRef vertex)
{
if (ss.attrs.persistent_no) {
copy_v3_v3(no, (const float *)SCULPT_vertex_attr_get(vertex, ss.attrs.persistent_no));
return;
return (const float *)SCULPT_vertex_attr_get(vertex, ss.attrs.persistent_no);
}
SCULPT_vertex_normal_get(ss, vertex, no);
return SCULPT_vertex_normal_get(ss, vertex);
}
float SCULPT_mask_get_at_grids_vert_index(const SubdivCCG &subdiv_ccg,
@@ -4171,10 +4171,7 @@ void SCULPT_cache_free(blender::ed::sculpt_paint::StrokeCache *cache)
MEM_SAFE_FREE(cache->dial);
MEM_SAFE_FREE(cache->surface_smooth_laplacian_disp);
MEM_SAFE_FREE(cache->layer_displacement_factor);
MEM_SAFE_FREE(cache->prev_colors);
MEM_SAFE_FREE(cache->detail_directions);
MEM_SAFE_FREE(cache->prev_displacement);
MEM_SAFE_FREE(cache->limit_surface_co);
for (int i = 0; i < PAINT_SYMM_AREAS; i++) {
if (cache->boundaries[i]) {

View File

@@ -127,7 +127,7 @@ static float normal_calc(const SculptSession &ss,
normal_v = automask_data.orig_data->no;
}
else {
SCULPT_vertex_normal_get(ss, vertex, normal_v);
normal_v = SCULPT_vertex_normal_get(ss, vertex);
}
float angle = safe_acosf(dot_v3v3(normal, normal_v));
@@ -338,10 +338,8 @@ static void calc_blurred_cavity(SculptSession &ss,
PBVHVertRef v = blurvert.vertex;
start = (start + 1) % queue.size();
float3 no;
const float *co = SCULPT_vertex_co_get(ss, v);
SCULPT_vertex_normal_get(ss, v, no);
const float3 no = SCULPT_vertex_normal_get(ss, v);
float centdist = len_v3v3(co, co1);
@@ -416,12 +414,12 @@ static void calc_blurred_cavity(SculptSession &ss,
normalize_v3(sno1);
if (dot_v3v3(sno1, sno1) == 0.0f) {
SCULPT_vertex_normal_get(ss, vertex, sno1);
sno1 = SCULPT_vertex_normal_get(ss, vertex);
}
normalize_v3(sno2);
if (dot_v3v3(sno2, sno2) == 0.0f) {
SCULPT_vertex_normal_get(ss, vertex, sno2);
sno2 = SCULPT_vertex_normal_get(ss, vertex);
}
float3 vec = sco1 - sco2;

View File

@@ -554,8 +554,7 @@ static void sculpt_boundary_bend_data_init(SculptSession &ss, SculptBoundary &bo
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(*ss.pbvh, i);
float dir[3];
float normal[3];
SCULPT_vertex_normal_get(ss, vertex, normal);
float3 normal = SCULPT_vertex_normal_get(ss, vertex);
sub_v3_v3v3(
dir,
SCULPT_vertex_co_get(

View File

@@ -1384,10 +1384,10 @@ static void do_layer_brush_task(Object &ob, const Sculpt &sd, const Brush &brush
*disp_factor = clamp_f(*disp_factor, -clamp_mask, clamp_mask);
float final_co[3];
float normal[3];
float3 normal;
if (use_persistent_base) {
SCULPT_vertex_persistent_normal_get(ss, vd.vertex, normal);
normal = SCULPT_vertex_persistent_normal_get(ss, vd.vertex);
mul_v3_fl(normal, brush.height);
madd_v3_v3v3fl(
final_co, SCULPT_vertex_persistent_co_get(ss, vd.vertex), normal, *disp_factor);
@@ -2164,13 +2164,13 @@ void relax_vertex(SculptSession &ss,
float plane[4];
float smooth_closest_plane[3];
float vno[3];
float3 vno;
if (is_boundary && avg_count == 2) {
normalize_v3_v3(vno, boundary_normal);
}
else {
SCULPT_vertex_normal_get(ss, vd->vertex, vno);
vno = SCULPT_vertex_normal_get(ss, vd->vertex);
}
if (is_zero_v3(vno)) {
@@ -2306,9 +2306,8 @@ static void do_displacement_eraser_brush_task(Object &ob, const Brush &brush, PB
thread_id,
&automask_data);
float limit_co[3];
float3 limit_co = SCULPT_vertex_limit_surface_get(ss, vd.vertex);
float disp[3];
SCULPT_vertex_limit_surface_get(ss, vd.vertex, limit_co);
sub_v3_v3v3(disp, limit_co, vd.co);
mul_v3_v3fl(proxy[vd.i], disp, fade);
}
@@ -2393,8 +2392,6 @@ static void do_displacement_smear_brush_task(Object &ob, const Brush &brush, PBV
SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vd.vertex, ni) {
float vertex_disp[3];
float vertex_disp_norm[3];
float neighbor_limit_co[3];
SCULPT_vertex_limit_surface_get(ss, ni.vertex, neighbor_limit_co);
sub_v3_v3v3(
vertex_disp, ss.cache->limit_surface_co[ni.index], ss.cache->limit_surface_co[vd.index]);
const float *neighbor_limit_surface_disp = ss.cache->prev_displacement[ni.index];
@@ -2440,15 +2437,13 @@ void SCULPT_do_displacement_smear_brush(const Sculpt &sd, Object &ob, Span<PBVHN
BKE_curvemapping_init(brush.curve);
const int totvert = SCULPT_vertex_count_get(ss);
if (!ss.cache->prev_displacement) {
ss.cache->prev_displacement = static_cast<float(*)[3]>(
MEM_malloc_arrayN(totvert, sizeof(float[3]), __func__));
ss.cache->limit_surface_co = static_cast<float(*)[3]>(
MEM_malloc_arrayN(totvert, sizeof(float[3]), __func__));
if (ss.cache->prev_displacement.is_empty()) {
ss.cache->prev_displacement = Array<float3>(totvert);
ss.cache->limit_surface_co = Array<float3>(totvert);
for (int i = 0; i < totvert; i++) {
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(*ss.pbvh, i);
SCULPT_vertex_limit_surface_get(ss, vertex, ss.cache->limit_surface_co[i]);
ss.cache->limit_surface_co[i] = SCULPT_vertex_limit_surface_get(ss, vertex);
sub_v3_v3v3(ss.cache->prev_displacement[i],
SCULPT_vertex_co_get(ss, vertex),
ss.cache->limit_surface_co[i]);

View File

@@ -1031,7 +1031,7 @@ SimulationData *brush_simulation_create(Object &ob,
cloth_sim->prev_pos = MEM_cnew_array<float[3]>(totverts, __func__);
cloth_sim->last_iteration_pos = MEM_cnew_array<float[3]>(totverts, __func__);
cloth_sim->init_pos = MEM_cnew_array<float[3]>(totverts, __func__);
cloth_sim->init_no = MEM_cnew_array<float[3]>(totverts, __func__);
cloth_sim->init_no = MEM_cnew_array<float3>(totverts, __func__);
cloth_sim->length_constraint_tweak = MEM_cnew_array<float>(totverts, __func__);
if (needs_deform_coords) {
@@ -1108,7 +1108,7 @@ void brush_simulation_init(const SculptSession &ss, SimulationData &cloth_sim)
copy_v3_v3(cloth_sim.last_iteration_pos[i], SCULPT_vertex_co_get(ss, vertex));
copy_v3_v3(cloth_sim.init_pos[i], SCULPT_vertex_co_get(ss, vertex));
SCULPT_vertex_normal_get(ss, vertex, cloth_sim.init_no[i]);
cloth_sim.init_no[i] = SCULPT_vertex_normal_get(ss, vertex);
copy_v3_v3(cloth_sim.prev_pos[i], SCULPT_vertex_co_get(ss, vertex));
if (has_deformation_pos) {
copy_v3_v3(cloth_sim.deformation_pos[i], SCULPT_vertex_co_get(ss, vertex));
@@ -1429,8 +1429,7 @@ static void cloth_filter_apply_forces_task(Object &ob,
filter::to_object_space(force, *ss.filter_cache);
break;
case CLOTH_FILTER_INFLATE: {
float normal[3];
SCULPT_vertex_normal_get(ss, vd.vertex, normal);
float3 normal = SCULPT_vertex_normal_get(ss, vd.vertex);
mul_v3_v3fl(force, normal, fade * filter_strength);
break;
}

View File

@@ -462,7 +462,7 @@ static Array<float> sculpt_expand_geodesic_falloff_create(Object &ob, const PBVH
* increasing the falloff value by 1 when visiting a new vertex.
*/
struct ExpandFloodFillData {
float original_normal[3];
float3 original_normal;
float edge_sensitivity;
MutableSpan<float> dists;
MutableSpan<float> edge_factor;
@@ -518,9 +518,8 @@ static bool mask_expand_normal_floodfill_cb(SculptSession &ss,
int to_v_i = BKE_pbvh_vertex_to_index(*ss.pbvh, to_v);
if (!is_duplicate) {
float current_normal[3], prev_normal[3];
SCULPT_vertex_normal_get(ss, to_v, current_normal);
SCULPT_vertex_normal_get(ss, from_v, prev_normal);
float3 current_normal = SCULPT_vertex_normal_get(ss, to_v);
float3 prev_normal = SCULPT_vertex_normal_get(ss, from_v);
const float from_edge_factor = data->edge_factor[from_v_i];
data->edge_factor[to_v_i] = dot_v3v3(current_normal, prev_normal) * from_edge_factor;
data->dists[to_v_i] = dot_v3v3(data->original_normal, current_normal) *
@@ -553,7 +552,7 @@ static Array<float> sculpt_expand_normal_falloff_create(Object &ob,
fdata.dists = dists;
fdata.edge_factor = edge_factor;
fdata.edge_sensitivity = edge_sensitivity;
SCULPT_vertex_normal_get(ss, v, fdata.original_normal);
fdata.original_normal = SCULPT_vertex_normal_get(ss, v);
flood_fill::execute(ss, flood, [&](PBVHVertRef from_v, PBVHVertRef to_v, bool is_duplicate) {
return mask_expand_normal_floodfill_cb(ss, from_v, to_v, is_duplicate, &fdata);
@@ -1122,7 +1121,6 @@ static void sculpt_expand_snap_initialize_from_enabled(SculptSession &ss, Cache
static void sculpt_expand_cache_data_free(Cache *expand_cache)
{
MEM_SAFE_FREE(expand_cache->face_falloff);
MEM_SAFE_FREE(expand_cache->original_colors);
MEM_delete<Cache>(expand_cache);
}
@@ -1344,8 +1342,7 @@ static void sculpt_expand_colors_update_task(SculptSession &ss, PBVHNode *node)
PBVHVertexIter vd;
BKE_pbvh_vertex_iter_begin (*ss.pbvh, node, vd, PBVH_ITER_ALL) {
float initial_color[4];
SCULPT_vertex_color_get(ss, vd.vertex, initial_color);
float4 initial_color = SCULPT_vertex_color_get(ss, vd.vertex);
const bool enabled = sculpt_expand_state_get(ss, expand_cache, vd.vertex);
float fade;
@@ -1398,12 +1395,10 @@ static void sculpt_expand_original_state_store(Object &ob, Cache *expand_cache)
}
if (expand_cache->target == SCULPT_EXPAND_TARGET_COLORS) {
expand_cache->original_colors = static_cast<float(*)[4]>(
MEM_malloc_arrayN(totvert, sizeof(float[4]), "initial colors"));
expand_cache->original_colors = Array<float4>(totvert);
for (int i = 0; i < totvert; i++) {
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(*ss.pbvh, i);
SCULPT_vertex_color_get(ss, vertex, expand_cache->original_colors[i]);
expand_cache->original_colors[i] = SCULPT_vertex_color_get(ss, vertex);
}
}
}

View File

@@ -187,8 +187,7 @@ static void color_filter_task(Object &ob,
fade = clamp_f(fade, -1.0f, 1.0f);
float4 smooth_color = smooth::neighbor_color_average(ss, vd.vertex);
float col[4];
SCULPT_vertex_color_get(ss, vd.vertex, col);
float4 col = SCULPT_vertex_color_get(ss, vd.vertex);
if (fade < 0.0f) {
interp_v4_v4v4(smooth_color, smooth_color, col, 0.5f);
@@ -230,14 +229,13 @@ static void sculpt_color_presmooth_init(SculptSession &ss)
{
int totvert = SCULPT_vertex_count_get(ss);
if (!ss.filter_cache->pre_smoothed_color) {
ss.filter_cache->pre_smoothed_color = static_cast<float(*)[4]>(
MEM_malloc_arrayN(totvert, sizeof(float[4]), __func__));
if (ss.filter_cache->pre_smoothed_color.is_empty()) {
ss.filter_cache->pre_smoothed_color = Array<float4>(totvert);
}
for (int i = 0; i < totvert; i++) {
SCULPT_vertex_color_get(
ss, BKE_pbvh_index_to_vertex(*ss.pbvh, i), ss.filter_cache->pre_smoothed_color[i]);
ss.filter_cache->pre_smoothed_color[i] = SCULPT_vertex_color_get(
ss, BKE_pbvh_index_to_vertex(*ss.pbvh, i));
}
for (int iteration = 0; iteration < 2; iteration++) {
@@ -278,7 +276,7 @@ static void sculpt_color_filter_apply(bContext *C, wmOperator *op, Object &ob)
RNA_float_get_array(op->ptr, "fill_color", fill_color);
IMB_colormanagement_srgb_to_scene_linear_v3(fill_color, fill_color);
if (filter_strength < 0.0 && !ss.filter_cache->pre_smoothed_color) {
if (filter_strength < 0.0 && ss.filter_cache->pre_smoothed_color.is_empty()) {
sculpt_color_presmooth_init(ss);
}

View File

@@ -223,8 +223,6 @@ void cache_free(SculptSession &ss)
MEM_SAFE_FREE(ss.filter_cache->surface_smooth_laplacian_disp);
MEM_SAFE_FREE(ss.filter_cache->sharpen_factor);
MEM_SAFE_FREE(ss.filter_cache->detail_directions);
MEM_SAFE_FREE(ss.filter_cache->limit_surface_co);
MEM_SAFE_FREE(ss.filter_cache->pre_smoothed_color);
MEM_delete(ss.filter_cache);
ss.filter_cache = nullptr;
}
@@ -555,12 +553,11 @@ static void mesh_filter_init_limit_surface_co(SculptSession &ss)
const int totvert = SCULPT_vertex_count_get(ss);
filter::Cache *filter_cache = ss.filter_cache;
filter_cache->limit_surface_co = static_cast<float(*)[3]>(
MEM_malloc_arrayN(totvert, sizeof(float[3]), __func__));
filter_cache->limit_surface_co = Array<float3>(totvert);
for (int i = 0; i < totvert; i++) {
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(*ss.pbvh, i);
SCULPT_vertex_limit_surface_get(ss, vertex, filter_cache->limit_surface_co[i]);
filter_cache->limit_surface_co[i] = SCULPT_vertex_limit_surface_get(ss, vertex);
}
}

View File

@@ -317,7 +317,7 @@ struct Cache {
float4x4 viewmat_inv;
/* Displacement eraser. */
float (*limit_surface_co)[3];
Array<float3> limit_surface_co;
/* unmasked nodes */
Vector<PBVHNode *> nodes;
@@ -347,7 +347,7 @@ struct Cache {
float3 view_normal;
/* Pre-smoothed colors used by sharpening. Colors are HSL. */
float (*pre_smoothed_color)[4];
Array<float4> pre_smoothed_color;
ViewContext vc;
float start_filter_strength;
@@ -401,12 +401,12 @@ struct StrokeCache {
/* Position of the mouse event in screen space, not modified by the stroke type. */
float2 mouse_event;
float (*prev_colors)[4];
Array<float4> prev_colors;
GArray<> prev_colors_vpaint;
/* Multires Displacement Smear. */
float (*prev_displacement)[3];
float (*limit_surface_co)[3];
Array<float3> prev_displacement;
Array<float3> limit_surface_co;
/* The rest is temporary storage that isn't saved as a property */
@@ -688,7 +688,7 @@ struct Cache {
/* Original data of the sculpt as it was before running the Expand operator. */
Array<float> original_mask;
Array<int> original_face_sets;
float (*original_colors)[4];
Array<float4> original_colors;
bool check_islands;
int normal_falloff_blur_steps;
@@ -847,13 +847,13 @@ int SCULPT_vertex_count_get(const SculptSession &ss);
const float *SCULPT_vertex_co_get(const SculptSession &ss, PBVHVertRef vertex);
/** Get the normal for a given sculpt vertex; do not modify the result */
void SCULPT_vertex_normal_get(const SculptSession &ss, PBVHVertRef vertex, float no[3]);
const blender::float3 SCULPT_vertex_normal_get(const SculptSession &ss, PBVHVertRef vertex);
float SCULPT_mask_get_at_grids_vert_index(const SubdivCCG &subdiv_ccg,
const CCGKey &key,
int vert_index);
void SCULPT_vertex_color_get(const SculptSession &ss, PBVHVertRef vertex, float r_color[4]);
void SCULPT_vertex_color_set(SculptSession &ss, PBVHVertRef vertex, const float color[4]);
blender::float4 SCULPT_vertex_color_get(const SculptSession &ss, PBVHVertRef vertex);
void SCULPT_vertex_color_set(SculptSession &ss, PBVHVertRef vertex, const blender::float4 &color);
bool SCULPT_vertex_is_occluded(SculptSession &ss, PBVHVertRef vertex, bool original);
@@ -864,7 +864,7 @@ bool SCULPT_has_colors(const SculptSession &ss);
bool SCULPT_has_loop_colors(const Object &ob);
const float *SCULPT_vertex_persistent_co_get(const SculptSession &ss, PBVHVertRef vertex);
void SCULPT_vertex_persistent_normal_get(const SculptSession &ss, PBVHVertRef vertex, float no[3]);
blender::float3 SCULPT_vertex_persistent_normal_get(const SculptSession &ss, PBVHVertRef vertex);
/**
* Coordinates used for manipulating the base mesh when Grab Active Vertex is enabled.
@@ -875,7 +875,7 @@ const float *SCULPT_vertex_co_for_grab_active_get(const SculptSession &ss, PBVHV
* Returns the info of the limit surface when multi-res is available,
* otherwise it returns the current coordinate of the vertex.
*/
void SCULPT_vertex_limit_surface_get(const SculptSession &ss, PBVHVertRef vertex, float r_co[3]);
blender::float3 SCULPT_vertex_limit_surface_get(const SculptSession &ss, PBVHVertRef vertex);
/**
* Returns the pointer to the coordinates that should be edited from a brush tool iterator
@@ -1461,7 +1461,7 @@ struct SimulationData {
float (*acceleration)[3];
float (*pos)[3];
float (*init_pos)[3];
float (*init_no)[3];
float3 *init_no;
float (*softbody_pos)[3];
float (*prev_pos)[3];
float (*last_iteration_pos)[3];

View File

@@ -107,8 +107,8 @@ static int sculpt_set_persistent_base_exec(bContext *C, wmOperator * /*op*/)
copy_v3_v3((float *)SCULPT_vertex_attr_get(vertex, ss->attrs.persistent_co),
SCULPT_vertex_co_get(*ss, vertex));
SCULPT_vertex_normal_get(
*ss, vertex, (float *)SCULPT_vertex_attr_get(vertex, ss->attrs.persistent_no));
*(float3 *)SCULPT_vertex_attr_get(vertex, ss->attrs.persistent_no) = SCULPT_vertex_normal_get(
*ss, vertex);
(*(float *)SCULPT_vertex_attr_get(vertex, ss->attrs.persistent_disp)) = 0.0f;
}
@@ -643,7 +643,7 @@ static int sculpt_sample_color_invoke(bContext *C, wmOperator *op, const wmEvent
Brush &brush = *BKE_paint_brush(&sd.paint);
SculptSession &ss = *ob.sculpt;
PBVHVertRef active_vertex = SCULPT_active_vertex_get(ss);
float active_vertex_color[4];
blender::float4 active_vertex_color;
if (!SCULPT_handles_colors_report(ss, op->reports)) {
return OPERATOR_CANCELLED;
@@ -662,7 +662,7 @@ static int sculpt_sample_color_invoke(bContext *C, wmOperator *op, const wmEvent
copy_v4_fl(active_vertex_color, 1.0f);
}
else {
SCULPT_vertex_color_get(ss, active_vertex, active_vertex_color);
active_vertex_color = SCULPT_vertex_color_get(ss, active_vertex);
}
float color_srgb[3];
@@ -789,9 +789,7 @@ static bool sculpt_mask_by_color_contiguous_floodfill(SculptSession &ss,
int from_v_i = BKE_pbvh_vertex_to_index(*ss.pbvh, from_v);
int to_v_i = BKE_pbvh_vertex_to_index(*ss.pbvh, to_v);
float current_color[4];
SCULPT_vertex_color_get(ss, to_v, current_color);
float4 current_color = SCULPT_vertex_color_get(ss, to_v);
float new_vertex_mask = sculpt_mask_by_color_delta_get(
current_color, data->initial_color, data->threshold, data->invert);
@@ -833,8 +831,7 @@ static void sculpt_mask_by_color_contiguous(Object &object,
ffd.invert = invert;
ffd.new_mask = new_mask;
float color[4];
SCULPT_vertex_color_get(ss, vertex, color);
float4 color = SCULPT_vertex_color_get(ss, vertex);
copy_v3_v3(ffd.initial_color, color);
@@ -869,14 +866,11 @@ static void do_mask_by_color_task(Object &ob,
undo::push_node(ob, node, undo::Type::Mask);
bool update_node = false;
float active_color[4];
SCULPT_vertex_color_get(ss, mask_by_color_vertex, active_color);
float4 active_color = SCULPT_vertex_color_get(ss, mask_by_color_vertex);
PBVHVertexIter vd;
BKE_pbvh_vertex_iter_begin (*ss.pbvh, node, vd, PBVH_ITER_UNIQUE) {
float col[4];
SCULPT_vertex_color_get(ss, vd.vertex, col);
float4 col = SCULPT_vertex_color_get(ss, vd.vertex);
const float current_mask = vd.mask;
const float new_mask = sculpt_mask_by_color_delta_get(active_color, col, threshold, invert);

View File

@@ -69,9 +69,7 @@ static void do_color_smooth_task(Object &ob, const Brush &brush, PBVHNode *node)
&automask_data);
const float4 smooth_color = smooth::neighbor_color_average(ss, vd.vertex);
float col[4];
SCULPT_vertex_color_get(ss, vd.vertex, col);
float4 col = SCULPT_vertex_color_get(ss, vd.vertex);
blend_color_interpolate_float(col, col, smooth_color, fade);
SCULPT_vertex_color_set(ss, vd.vertex, col);
}
@@ -192,8 +190,7 @@ static void do_paint_brush_task(Object &ob,
const float alpha = BKE_brush_alpha_get(ss.scene, &brush);
mul_v4_v4fl(buffer_color, color_buffer->color[vd.i], alpha * automasking);
float4 col;
SCULPT_vertex_color_get(ss, vd.vertex, col);
float4 col = SCULPT_vertex_color_get(ss, vd.vertex);
IMB_blend_color_float(col, orig_data.col, buffer_color, IMB_BlendMode(brush.blend));
col = math::clamp(col, 0.0f, 1.0f);
SCULPT_vertex_color_set(ss, vd.vertex, col);
@@ -225,8 +222,7 @@ static void do_sample_wet_paint_task(SculptSession &ss,
continue;
}
float col[4];
SCULPT_vertex_color_get(ss, vd.vertex, col);
float4 col = SCULPT_vertex_color_get(ss, vd.vertex);
add_v4_v4(swptd->color, col);
swptd->tot_samples++;
@@ -374,8 +370,7 @@ static void do_smear_brush_task(Object &ob, const Brush &brush, PBVHNode *node)
float current_disp[3];
float current_disp_norm[3];
float no[3];
SCULPT_vertex_normal_get(ss, vd.vertex, no);
float3 no = SCULPT_vertex_normal_get(ss, vd.vertex);
switch (brush.smear_deform_type) {
case BRUSH_SMEAR_DEFORM_DRAG:
@@ -465,21 +460,18 @@ static void do_smear_brush_task(Object &ob, const Brush &brush, PBVHNode *node)
mul_v4_fl(accum, 1.0f / totw);
}
float col[4];
SCULPT_vertex_color_get(ss, vd.vertex, col);
float4 col = SCULPT_vertex_color_get(ss, vd.vertex);
blend_color_interpolate_float(col, ss.cache->prev_colors[vd.index], accum, fade);
SCULPT_vertex_color_set(ss, vd.vertex, col);
}
BKE_pbvh_vertex_iter_end;
}
static void do_smear_store_prev_colors_task(SculptSession &ss,
PBVHNode *node,
float (*prev_colors)[4])
static void do_smear_store_prev_colors_task(SculptSession &ss, PBVHNode *node, float4 *prev_colors)
{
PBVHVertexIter vd;
BKE_pbvh_vertex_iter_begin (*ss.pbvh, node, vd, PBVH_ITER_UNIQUE) {
SCULPT_vertex_color_get(ss, vd.vertex, prev_colors[vd.index]);
prev_colors[vd.index] = SCULPT_vertex_color_get(ss, vd.vertex);
}
BKE_pbvh_vertex_iter_end;
}
@@ -495,12 +487,12 @@ void do_smear_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
const int totvert = SCULPT_vertex_count_get(ss);
if (!ss.cache->prev_colors) {
ss.cache->prev_colors = MEM_cnew_array<float[4]>(totvert, __func__);
if (ss.cache->prev_colors.is_empty()) {
ss.cache->prev_colors = Array<float4>(totvert);
for (int i = 0; i < totvert; i++) {
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(*ss.pbvh, i);
SCULPT_vertex_color_get(ss, vertex, ss.cache->prev_colors[i]);
ss.cache->prev_colors[i] = SCULPT_vertex_color_get(ss, vertex);
}
}
@@ -518,7 +510,7 @@ void do_smear_brush(const Sculpt &sd, Object &ob, Span<PBVHNode *> nodes)
/* Smear mode. */
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
for (const int i : range) {
do_smear_store_prev_colors_task(ss, nodes[i], ss.cache->prev_colors);
do_smear_store_prev_colors_task(ss, nodes[i], ss.cache->prev_colors.data());
}
});
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {

View File

@@ -38,10 +38,8 @@ static void apply_projection(gesture::GestureData &gesture_data, PBVHNode *node)
undo::push_node(*gesture_data.vc.obact, node, undo::Type::Position);
BKE_pbvh_vertex_iter_begin (*gesture_data.ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
float vertex_normal[3];
const float *co = SCULPT_vertex_co_get(*gesture_data.ss, vd.vertex);
SCULPT_vertex_normal_get(*gesture_data.ss, vd.vertex, vertex_normal);
float3 vertex_normal = SCULPT_vertex_normal_get(*gesture_data.ss, vd.vertex);
if (!gesture::is_affected(gesture_data, co, vertex_normal)) {
continue;
}

View File

@@ -171,9 +171,7 @@ float4 neighbor_color_average(SculptSession &ss, PBVHVertRef vertex)
SculptVertexNeighborIter ni;
SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vertex, ni) {
float tmp[4] = {0};
SCULPT_vertex_color_get(ss, ni.vertex, tmp);
float4 tmp = SCULPT_vertex_color_get(ss, ni.vertex);
avg += tmp;
total++;
@@ -183,9 +181,7 @@ float4 neighbor_color_average(SculptSession &ss, PBVHVertRef vertex)
if (total > 0) {
return avg / total;
}
float4 tmp;
SCULPT_vertex_color_get(ss, vertex, tmp);
return tmp;
return SCULPT_vertex_color_get(ss, vertex);
}
static void do_enhance_details_brush_task(Object &ob,