Refactor: Sculpt: Remove PBVHVertRef usage in sculpt_expand.cc

Part of #118145

Also removes other now-unused functions & macros.

Pull Request: https://projects.blender.org/blender/blender/pulls/127821
This commit is contained in:
Sean Kim
2024-09-19 04:52:01 +02:00
committed by Sean Kim
parent fa1a3fbcce
commit 6a68a924fd
4 changed files with 26 additions and 27 deletions

View File

@@ -489,7 +489,6 @@ struct SculptSession : blender::NonCopyable, blender::NonMovable {
PBVHVertRef active_vert_ref() const;
ActiveVert active_vert() const;
PBVHVertRef last_active_vert_ref() const;
ActiveVert last_active_vert() const;
/**
@@ -502,6 +501,7 @@ struct SculptSession : blender::NonCopyable, blender::NonMovable {
* \returns -1 if there is no currently active vertex.
*/
int active_vert_index() const;
int last_active_vert_index() const;
/**
* Retrieves the active vertex position.

View File

@@ -281,13 +281,6 @@ struct PBVHFrustumPlanes {
int num_planes;
};
BLI_INLINE int BKE_pbvh_vertex_to_index(const blender::bke::pbvh::Tree &pbvh, PBVHVertRef v)
{
return (pbvh.type() == blender::bke::pbvh::Type::BMesh && v.i != PBVH_REF_NONE ?
BM_elem_index_get((BMVert *)(v.i)) :
(v.i));
}
/* Callbacks */
namespace blender::bke::pbvh {

View File

@@ -1768,22 +1768,6 @@ ActiveVert SculptSession::active_vert() const
return active_vert_;
}
PBVHVertRef SculptSession::last_active_vert_ref() const
{
if (std::holds_alternative<int>(last_active_vert_)) {
return {std::get<int>(last_active_vert_)};
}
if (std::holds_alternative<SubdivCCGCoord>(last_active_vert_)) {
const CCGKey key = BKE_subdiv_ccg_key_top_level(*this->subdiv_ccg);
const int index = std::get<SubdivCCGCoord>(last_active_vert_).to_index(key);
return {index};
}
if (std::holds_alternative<BMVert *>(last_active_vert_)) {
return {reinterpret_cast<intptr_t>(std::get<BMVert *>(last_active_vert_))};
}
return {PBVH_REF_NONE};
}
ActiveVert SculptSession::last_active_vert() const
{
return active_vert_;
@@ -1806,6 +1790,23 @@ int SculptSession::active_vert_index() const
return -1;
}
int SculptSession::last_active_vert_index() const
{
if (std::holds_alternative<int>(last_active_vert_)) {
return std::get<int>(last_active_vert_);
}
if (std::holds_alternative<SubdivCCGCoord>(last_active_vert_)) {
const SubdivCCGCoord coord = std::get<SubdivCCGCoord>(last_active_vert_);
return coord.to_index(BKE_subdiv_ccg_key_top_level(*this->subdiv_ccg));
}
if (std::holds_alternative<BMVert *>(last_active_vert_)) {
BMVert *bm_vert = std::get<BMVert *>(last_active_vert_);
return BM_elem_index_get(bm_vert);
}
return -1;
}
blender::float3 SculptSession::active_vert_position(const Depsgraph &depsgraph,
const Object &object) const
{

View File

@@ -2151,11 +2151,16 @@ static bool set_initial_components_for_mouse(bContext *C,
if (!initial_vert) {
/* Cursor not over the mesh, for creating valid initial falloffs, fallback to the last active
* vertex in the sculpt session. */
const PBVHVertRef last_active_vert = ss.last_active_vert_ref();
if (last_active_vert.i == PBVH_REF_NONE) {
const int last_active_vert_index = ss.last_active_vert_index();
/* It still may be the case that there is no last active vert in rare circumstances for
* everyday usage.
* (i.e. if the cursor has never been over the mesh at all. A solutoin to both this problem
* and needing to store this data is to figure out which is the nearest vertex to the current
* cursor position */
if (last_active_vert_index == -1) {
return false;
}
initial_vert = BKE_pbvh_vertex_to_index(*bke::object::pbvh_get(ob), ss.last_active_vert_ref());
initial_vert = last_active_vert_index;
}
copy_v2_v2(ss.expand_cache->initial_mouse, mval);