diff options
author | Jacques Lucke <jacques@blender.org> | 2021-11-26 16:47:02 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-11-26 16:47:15 +0300 |
commit | f86331a0338dc2351e914b45ccbd743b6cccbb19 (patch) | |
tree | d67fb1d4baafd95e3b6fd97c9f707943b4d6746a /source/blender/blenkernel/intern/geometry_component_mesh.cc | |
parent | ef88047a97a10283cca21a3fe75c8d69d8fc40eb (diff) |
Geometry Nodes: deduplicate virtual array implementations
For some underlying data (e.g. spans) we had two virtual array
implementations. One for the mutable and one for the immutable
case. Now that most code does not deal with the virtual array
implementations directly anymore (since rBrBd4c868da9f97a),
we can get away with sharing one implementation for both cases.
This means that we have to do a `const_cast` in a few places, but
this is an implementation detail that does not leak into "user code"
(only when explicitly casting a `VArrayImpl` to a `VMutableArrayImpl`,
which should happen nowhere).
Diffstat (limited to 'source/blender/blenkernel/intern/geometry_component_mesh.cc')
-rw-r--r-- | source/blender/blenkernel/intern/geometry_component_mesh.cc | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index a258a66cdf3..e7d48670f73 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -996,57 +996,36 @@ static void set_crease(MEdge &edge, float value) edge.crease = round_fl_to_uchar_clamp(value * 255.0f); } -class VMutableArray_For_VertexWeights final : public VMutableArrayImpl<float> { +class VArrayImpl_For_VertexWeights final : public VMutableArrayImpl<float> { private: MDeformVert *dverts_; const int dvert_index_; public: - VMutableArray_For_VertexWeights(MDeformVert *dverts, const int totvert, const int dvert_index) + VArrayImpl_For_VertexWeights(MDeformVert *dverts, const int totvert, const int dvert_index) : VMutableArrayImpl<float>(totvert), dverts_(dverts), dvert_index_(dvert_index) { } float get(const int64_t index) const override { - return get_internal(dverts_, dvert_index_, index); - } - - void set(const int64_t index, const float value) override - { - MDeformWeight *weight = BKE_defvert_ensure_index(&dverts_[index], dvert_index_); - weight->weight = value; - } - - static float get_internal(const MDeformVert *dverts, const int dvert_index, const int64_t index) - { - if (dverts == nullptr) { + if (dverts_ == nullptr) { return 0.0f; } - const MDeformVert &dvert = dverts[index]; + const MDeformVert &dvert = dverts_[index]; for (const MDeformWeight &weight : Span(dvert.dw, dvert.totweight)) { - if (weight.def_nr == dvert_index) { + if (weight.def_nr == dvert_index_) { return weight.weight; } } return 0.0f; + ; } -}; -class VArray_For_VertexWeights final : public VArrayImpl<float> { - private: - const MDeformVert *dverts_; - const int dvert_index_; - - public: - VArray_For_VertexWeights(const MDeformVert *dverts, const int totvert, const int dvert_index) - : VArrayImpl<float>(totvert), dverts_(dverts), dvert_index_(dvert_index) - { - } - - float get(const int64_t index) const override + void set(const int64_t index, const float value) override { - return VMutableArray_For_VertexWeights::get_internal(dverts_, dvert_index_, index); + MDeformWeight *weight = BKE_defvert_ensure_index(&dverts_[index], dvert_index_); + weight->weight = value; } }; @@ -1077,7 +1056,7 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider { static const float default_value = 0.0f; return {VArray<float>::ForSingle(default_value, mesh->totvert), ATTR_DOMAIN_POINT}; } - return {VArray<float>::For<VArray_For_VertexWeights>( + return {VArray<float>::For<VArrayImpl_For_VertexWeights>( mesh->dvert, mesh->totvert, vertex_group_index), ATTR_DOMAIN_POINT}; } @@ -1109,7 +1088,7 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider { mesh->dvert = (MDeformVert *)CustomData_duplicate_referenced_layer( &mesh->vdata, CD_MDEFORMVERT, mesh->totvert); } - return {VMutableArray<float>::For<VMutableArray_For_VertexWeights>( + return {VMutableArray<float>::For<VArrayImpl_For_VertexWeights>( mesh->dvert, mesh->totvert, vertex_group_index), ATTR_DOMAIN_POINT}; } |