Cleanup: Break apart paint_intern.hh

This commit moves the namespaced functions inside `paint_intern.hh` into
their own header files, specifically:
* `blender::ed::sculpt_paint::hide` to `paint_hide.hh`
* `blender::ed::sculpt_paint::mask` to `paint_mask.hh`

This commit also moves methods defined in `sculpt_hide.hh` into their
own file (`sculpt_hide.cc`) out from `sculpt.cc` and `paint_hide.cc`

Pull Request: https://projects.blender.org/blender/blender/pulls/126668
This commit is contained in:
Sean Kim
2024-08-23 21:54:18 +02:00
committed by Sean Kim
parent f08ade0523
commit 84615b0eac
19 changed files with 237 additions and 168 deletions

View File

@@ -104,6 +104,7 @@ set(SRC
sculpt_flood_fill.cc
sculpt_geodesic.cc
sculpt_gesture.cc
sculpt_hide.cc
sculpt_mask_init.cc
sculpt_ops.cc
sculpt_paint_color.cc

View File

@@ -24,6 +24,7 @@
#include "editors/sculpt_paint/mesh_brush_common.hh"
#include "editors/sculpt_paint/paint_intern.hh"
#include "editors/sculpt_paint/paint_mask.hh"
#include "editors/sculpt_paint/sculpt_intern.hh"
namespace blender::ed::sculpt_paint {

View File

@@ -20,6 +20,7 @@
#include "editors/sculpt_paint/mesh_brush_common.hh"
#include "editors/sculpt_paint/paint_intern.hh"
#include "editors/sculpt_paint/paint_mask.hh"
#include "editors/sculpt_paint/sculpt_intern.hh"
namespace blender::ed::sculpt_paint {

View File

@@ -15,6 +15,7 @@
#include "editors/sculpt_paint/mesh_brush_common.hh"
#include "editors/sculpt_paint/paint_intern.hh"
#include "editors/sculpt_paint/paint_mask.hh"
#include "editors/sculpt_paint/sculpt_boundary.hh"
#include "editors/sculpt_paint/sculpt_intern.hh"
#include "editors/sculpt_paint/sculpt_smooth.hh"

View File

@@ -6,7 +6,7 @@
* \ingroup edsculpt
* Implements the bke::pbvh::Tree node hiding operator.
*/
#include "sculpt_hide.hh"
#include "paint_hide.hh"
#include "MEM_guardedalloc.h"
@@ -55,25 +55,6 @@ namespace blender::ed::sculpt_paint::hide {
/** \name Public API
* \{ */
Span<int> node_visible_verts(const bke::pbvh::Node &node,
const Span<bool> hide_vert,
Vector<int> &indices)
{
if (BKE_pbvh_node_fully_hidden_get(node)) {
return {};
}
const Span<int> verts = bke::pbvh::node_unique_verts(node);
if (hide_vert.is_empty()) {
return verts;
}
indices.resize(verts.size());
const int *end = std::copy_if(verts.begin(), verts.end(), indices.begin(), [&](const int vert) {
return !hide_vert[vert];
});
indices.resize(end - indices.begin());
return indices;
}
void sync_all_from_faces(Object &object)
{
SculptSession &ss = *object.sculpt;

View File

@@ -0,0 +1,36 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edsculpt
*/
#pragma once
#include "BLI_span.hh"
struct bContext;
struct Depsgraph;
struct Object;
struct wmOperatorType;
namespace blender::bke::pbvh {
class Node;
}
namespace blender::ed::sculpt_paint::hide {
void sync_all_from_faces(Object &object);
void mesh_show_all(const Depsgraph &depsgraph, Object &object, Span<bke::pbvh::Node *> nodes);
void grids_show_all(Depsgraph &depsgraph, Object &object, Span<bke::pbvh::Node *> nodes);
void tag_update_visibility(const bContext &C);
void PAINT_OT_hide_show_masked(wmOperatorType *ot);
void PAINT_OT_hide_show_all(wmOperatorType *ot);
void PAINT_OT_hide_show(wmOperatorType *ot);
void PAINT_OT_hide_show_lasso_gesture(wmOperatorType *ot);
void PAINT_OT_hide_show_line_gesture(wmOperatorType *ot);
void PAINT_OT_hide_show_polyline_gesture(wmOperatorType *ot);
void PAINT_OT_visibility_invert(wmOperatorType *ot);
void PAINT_OT_visibility_filter(wmOperatorType *ot);
} // namespace blender::ed::sculpt_paint::hide

View File

@@ -483,75 +483,6 @@ enum BrushStrokeMode {
BRUSH_STROKE_ERASE,
};
/* paint_hide.cc */
namespace blender::ed::sculpt_paint::hide {
void sync_all_from_faces(Object &object);
void mesh_show_all(const Depsgraph &depsgraph, Object &object, Span<bke::pbvh::Node *> nodes);
void grids_show_all(Depsgraph &depsgraph, Object &object, Span<bke::pbvh::Node *> nodes);
void tag_update_visibility(const bContext &C);
void PAINT_OT_hide_show_masked(wmOperatorType *ot);
void PAINT_OT_hide_show_all(wmOperatorType *ot);
void PAINT_OT_hide_show(wmOperatorType *ot);
void PAINT_OT_hide_show_lasso_gesture(wmOperatorType *ot);
void PAINT_OT_hide_show_line_gesture(wmOperatorType *ot);
void PAINT_OT_hide_show_polyline_gesture(wmOperatorType *ot);
void PAINT_OT_visibility_invert(wmOperatorType *ot);
void PAINT_OT_visibility_filter(wmOperatorType *ot);
} // namespace blender::ed::sculpt_paint::hide
/* `paint_mask.cc` */
namespace blender::ed::sculpt_paint::mask {
Array<float> duplicate_mask(const Object &object);
void mix_new_masks(Span<float> new_masks, Span<float> factors, MutableSpan<float> masks);
void clamp_mask(MutableSpan<float> masks);
void gather_mask_grids(const SubdivCCG &subdiv_ccg, Span<int> grids, MutableSpan<float> r_mask);
void gather_mask_bmesh(const BMesh &bm, const Set<BMVert *, 0> &verts, MutableSpan<float> r_mask);
void scatter_mask_grids(Span<float> mask, SubdivCCG &subdiv_ccg, Span<int> grids);
void scatter_mask_bmesh(Span<float> mask, const BMesh &bm, const Set<BMVert *, 0> &verts);
void average_neighbor_mask_grids(const SubdivCCG &subdiv_ccg,
Span<int> grids,
MutableSpan<float> new_masks);
void average_neighbor_mask_bmesh(int mask_offset,
const Set<BMVert *, 0> &verts,
MutableSpan<float> new_masks);
/** Write to the mask attribute for each node, storing undo data. */
void write_mask_mesh(const Depsgraph &depsgraph,
Object &object,
Span<bke::pbvh::Node *> nodes,
FunctionRef<void(MutableSpan<float>, Span<int>)> write_fn);
/**
* Write to each node's mask data for visible vertices. Store undo data and mark for redraw only
* if the data is actually changed.
*/
void update_mask_mesh(const Depsgraph &depsgraph,
Object &object,
Span<bke::pbvh::Node *> nodes,
FunctionRef<void(MutableSpan<float>, Span<int>)> update_fn);
/** Check whether array data is the same as the stored mask for the referenced geometry. */
bool mask_equals_array_grids(Span<CCGElem *> elems,
const CCGKey &key,
Span<int> grids,
Span<float> values);
bool mask_equals_array_bmesh(int mask_offset, const Set<BMVert *, 0> &verts, Span<float> values);
void PAINT_OT_mask_flood_fill(wmOperatorType *ot);
void PAINT_OT_mask_lasso_gesture(wmOperatorType *ot);
void PAINT_OT_mask_box_gesture(wmOperatorType *ot);
void PAINT_OT_mask_line_gesture(wmOperatorType *ot);
void PAINT_OT_mask_polyline_gesture(wmOperatorType *ot);
} // namespace blender::ed::sculpt_paint::mask
/* `paint_curve.cc` */
void PAINTCURVE_OT_new(wmOperatorType *ot);

View File

@@ -5,6 +5,7 @@
/** \file
* \ingroup edsculpt
*/
#include "paint_mask.hh"
#include <cstdlib>

View File

@@ -0,0 +1,73 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edsculpt
*/
#pragma once
#include "BLI_array.hh"
#include "BLI_function_ref.hh"
#include "BLI_set.hh"
struct BMesh;
struct BMVert;
struct CCGElem;
struct CCGKey;
struct Depsgraph;
struct Object;
struct SubdivCCG;
struct wmOperatorType;
namespace blender::bke::pbvh {
class Node;
}
namespace blender::ed::sculpt_paint::mask {
Array<float> duplicate_mask(const Object &object);
void mix_new_masks(Span<float> new_masks, Span<float> factors, MutableSpan<float> masks);
void clamp_mask(MutableSpan<float> masks);
void gather_mask_grids(const SubdivCCG &subdiv_ccg, Span<int> grids, MutableSpan<float> r_mask);
void gather_mask_bmesh(const BMesh &bm, const Set<BMVert *, 0> &verts, MutableSpan<float> r_mask);
void scatter_mask_grids(Span<float> mask, SubdivCCG &subdiv_ccg, Span<int> grids);
void scatter_mask_bmesh(Span<float> mask, const BMesh &bm, const Set<BMVert *, 0> &verts);
void average_neighbor_mask_grids(const SubdivCCG &subdiv_ccg,
Span<int> grids,
MutableSpan<float> new_masks);
void average_neighbor_mask_bmesh(int mask_offset,
const Set<BMVert *, 0> &verts,
MutableSpan<float> new_masks);
/** Write to the mask attribute for each node, storing undo data. */
void write_mask_mesh(const Depsgraph &depsgraph,
Object &object,
Span<bke::pbvh::Node *> nodes,
FunctionRef<void(MutableSpan<float>, Span<int>)> write_fn);
/**
* Write to each node's mask data for visible vertices. Store undo data and mark for redraw only
* if the data is actually changed.
*/
void update_mask_mesh(const Depsgraph &depsgraph,
Object &object,
Span<bke::pbvh::Node *> nodes,
FunctionRef<void(MutableSpan<float>, Span<int>)> update_fn);
/** Check whether array data is the same as the stored mask for the referenced geometry. */
bool mask_equals_array_grids(Span<CCGElem *> elems,
const CCGKey &key,
Span<int> grids,
Span<float> values);
bool mask_equals_array_bmesh(int mask_offset, const Set<BMVert *, 0> &verts, Span<float> values);
void PAINT_OT_mask_flood_fill(wmOperatorType *ot);
void PAINT_OT_mask_lasso_gesture(wmOperatorType *ot);
void PAINT_OT_mask_box_gesture(wmOperatorType *ot);
void PAINT_OT_mask_line_gesture(wmOperatorType *ot);
void PAINT_OT_mask_polyline_gesture(wmOperatorType *ot);
} // namespace blender::ed::sculpt_paint::mask

View File

@@ -44,7 +44,9 @@
#include "RNA_define.hh"
#include "curves_sculpt_intern.hh"
#include "paint_hide.hh"
#include "paint_intern.hh"
#include "paint_mask.hh"
#include "sculpt_intern.hh"
static int brush_scale_size_exec(bContext *C, wmOperator *op)

View File

@@ -263,84 +263,6 @@ int active_face_set_get(const SculptSession &ss)
} // namespace face_set
namespace hide {
bool vert_visible_get(const Object &object, PBVHVertRef vertex)
{
const SculptSession &ss = *object.sculpt;
switch (ss.pbvh->type()) {
case bke::pbvh::Type::Mesh: {
const Mesh &mesh = *static_cast<const Mesh *>(object.data);
const bke::AttributeAccessor attributes = mesh.attributes();
const VArray hide_vert = *attributes.lookup_or_default<bool>(
".hide_vert", bke::AttrDomain::Point, false);
return !hide_vert[vertex.i];
}
case bke::pbvh::Type::BMesh:
return !BM_elem_flag_test((BMVert *)vertex.i, BM_ELEM_HIDDEN);
case bke::pbvh::Type::Grids: {
const CCGKey key = BKE_subdiv_ccg_key_top_level(*ss.subdiv_ccg);
const int grid_index = vertex.i / key.grid_area;
const int index_in_grid = vertex.i - grid_index * key.grid_area;
if (!ss.subdiv_ccg->grid_hidden.is_empty()) {
return !ss.subdiv_ccg->grid_hidden[grid_index][index_in_grid];
}
}
}
return true;
}
bool vert_all_faces_visible_get(const Span<bool> hide_poly,
const GroupedSpan<int> vert_to_face_map,
const int vert)
{
if (hide_poly.is_empty()) {
return true;
}
for (const int face : vert_to_face_map[vert]) {
if (hide_poly[face]) {
return false;
}
}
return true;
}
bool vert_all_faces_visible_get(const Span<bool> hide_poly,
const SubdivCCG &subdiv_ccg,
const SubdivCCGCoord vert)
{
const int face_index = BKE_subdiv_ccg_grid_to_face_index(subdiv_ccg, vert.grid_index);
return hide_poly[face_index];
}
bool vert_all_faces_visible_get(BMVert *vert)
{
BMEdge *edge = vert->e;
if (!edge) {
return true;
}
do {
BMLoop *loop = edge->l;
if (!loop) {
continue;
}
do {
if (BM_elem_flag_test(loop->f, BM_ELEM_HIDDEN)) {
return false;
}
} while ((loop = loop->radial_next) != edge->l);
} while ((edge = BM_DISK_EDGE_NEXT(edge, vert)) != vert->e);
return true;
}
} // namespace hide
namespace face_set {
int vert_face_set_get(const SculptSession &ss, PBVHVertRef vertex)

View File

@@ -45,6 +45,7 @@
#include "ED_sculpt.hh"
#include "paint_intern.hh"
#include "paint_mask.hh"
#include "sculpt_boundary.hh"
#include "sculpt_color.hh"
#include "sculpt_face_set.hh"

View File

@@ -53,7 +53,7 @@
#include "ED_sculpt.hh"
#include "mesh_brush_common.hh"
#include "paint_intern.hh"
#include "paint_hide.hh"
#include "sculpt_boundary.hh"
#include "sculpt_gesture.hh"
#include "sculpt_intern.hh"

View File

@@ -23,6 +23,7 @@
#include "mesh_brush_common.hh"
#include "paint_intern.hh"
#include "paint_mask.hh"
#include "sculpt_hide.hh"
#include "sculpt_intern.hh"
#include "sculpt_smooth.hh"

View File

@@ -0,0 +1,113 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edsculpt
*/
#include "sculpt_hide.hh"
#include "BKE_attribute.hh"
#include "BKE_paint.hh"
#include "BKE_pbvh_api.hh"
#include "BKE_subdiv_ccg.hh"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
namespace blender::ed::sculpt_paint::hide {
Span<int> node_visible_verts(const bke::pbvh::Node &node,
const Span<bool> hide_vert,
Vector<int> &indices)
{
if (BKE_pbvh_node_fully_hidden_get(node)) {
return {};
}
const Span<int> verts = bke::pbvh::node_unique_verts(node);
if (hide_vert.is_empty()) {
return verts;
}
indices.resize(verts.size());
const int *end = std::copy_if(verts.begin(), verts.end(), indices.begin(), [&](const int vert) {
return !hide_vert[vert];
});
indices.resize(end - indices.begin());
return indices;
}
bool vert_visible_get(const Object &object, PBVHVertRef vertex)
{
const SculptSession &ss = *object.sculpt;
switch (ss.pbvh->type()) {
case bke::pbvh::Type::Mesh: {
const Mesh &mesh = *static_cast<const Mesh *>(object.data);
const bke::AttributeAccessor attributes = mesh.attributes();
const VArray hide_vert = *attributes.lookup_or_default<bool>(
".hide_vert", bke::AttrDomain::Point, false);
return !hide_vert[vertex.i];
}
case bke::pbvh::Type::BMesh:
return !BM_elem_flag_test((BMVert *)vertex.i, BM_ELEM_HIDDEN);
case bke::pbvh::Type::Grids: {
const CCGKey key = BKE_subdiv_ccg_key_top_level(*ss.subdiv_ccg);
const int grid_index = vertex.i / key.grid_area;
const int index_in_grid = vertex.i - grid_index * key.grid_area;
if (!ss.subdiv_ccg->grid_hidden.is_empty()) {
return !ss.subdiv_ccg->grid_hidden[grid_index][index_in_grid];
}
}
}
return true;
}
bool vert_all_faces_visible_get(const Span<bool> hide_poly,
const GroupedSpan<int> vert_to_face_map,
const int vert)
{
if (hide_poly.is_empty()) {
return true;
}
for (const int face : vert_to_face_map[vert]) {
if (hide_poly[face]) {
return false;
}
}
return true;
}
bool vert_all_faces_visible_get(const Span<bool> hide_poly,
const SubdivCCG &subdiv_ccg,
const SubdivCCGCoord vert)
{
const int face_index = BKE_subdiv_ccg_grid_to_face_index(subdiv_ccg, vert.grid_index);
return hide_poly[face_index];
}
bool vert_all_faces_visible_get(BMVert *vert)
{
BMEdge *edge = vert->e;
if (!edge) {
return true;
}
do {
BMLoop *loop = edge->l;
if (!loop) {
continue;
}
do {
if (BM_elem_flag_test(loop->f, BM_ELEM_HIDDEN)) {
return false;
}
} while ((loop = loop->radial_next) != edge->l);
} while ((edge = BM_DISK_EDGE_NEXT(edge, vert)) != vert->e);
return true;
}
} // namespace blender::ed::sculpt_paint::hide

View File

@@ -31,6 +31,7 @@
#include "RNA_define.hh"
#include "paint_intern.hh"
#include "paint_mask.hh"
#include "sculpt_face_set.hh"
#include "sculpt_hide.hh"
#include "sculpt_intern.hh"

View File

@@ -57,6 +57,7 @@
#include "mesh_brush_common.hh"
#include "paint_intern.hh"
#include "paint_mask.hh"
#include "sculpt_automask.hh"
#include "sculpt_color.hh"
#include "sculpt_dyntopo.hh"

View File

@@ -35,6 +35,7 @@
#include "mesh_brush_common.hh"
#include "paint_intern.hh"
#include "paint_mask.hh"
#include "sculpt_filter.hh"
#include "sculpt_intern.hh"
#include "sculpt_undo.hh"

View File

@@ -76,6 +76,7 @@
#include "ED_undo.hh"
#include "bmesh.hh"
#include "paint_hide.hh"
#include "paint_intern.hh"
#include "sculpt_color.hh"
#include "sculpt_dyntopo.hh"