From ae068ad23cb0ada53c68284a5412df73a7c738a9 Mon Sep 17 00:00:00 2001 From: illua1 Date: Tue, 7 Feb 2023 23:41:23 +0300 Subject: [PATCH 01/17] re init --- release/datafiles/locale | 2 +- release/scripts/addons | 2 +- release/scripts/addons_contrib | 2 +- .../nodes/node_geo_accumulate_field.cc | 161 ++++++++++-------- source/tools | 2 +- 5 files changed, 95 insertions(+), 74 deletions(-) diff --git a/release/datafiles/locale b/release/datafiles/locale index 4331c8e76c2..547a54b294f 160000 --- a/release/datafiles/locale +++ b/release/datafiles/locale @@ -1 +1 @@ -Subproject commit 4331c8e76c2f42b9fd903716c333d6cdeaa5cebd +Subproject commit 547a54b294f32ee11bce73273c6f183d8b235f92 diff --git a/release/scripts/addons b/release/scripts/addons index b3f0ffc587d..78b0fc30b6b 160000 --- a/release/scripts/addons +++ b/release/scripts/addons @@ -1 +1 @@ -Subproject commit b3f0ffc587d197b37eac9a1566d1d24b7bee7d9a +Subproject commit 78b0fc30b6b6e610ef897fc7d26e812da348f2ff diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib index 14ab9273409..65ff08e325d 160000 --- a/release/scripts/addons_contrib +++ b/release/scripts/addons_contrib @@ -1 +1 @@ -Subproject commit 14ab9273409ea0231d08ba6e86fdc73d4e459e99 +Subproject commit 65ff08e325d54a58b47fb3219ec7dbf417f20f18 diff --git a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc index f7a8496868e..f2e7134e22c 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc @@ -2,6 +2,10 @@ #include "BKE_attribute_math.hh" +#include "BLI_array.hh" +#include "BLI_generic_virtual_array.hh" +#include "BLI_virtual_array.hh" + #include "NOD_socket_search_link.hh" #include "node_geometry_util.hh" @@ -192,19 +196,19 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } } -template class AccumulateFieldInput final : public bke::GeometryFieldInput { +class AccumulateFieldInput final : public bke::GeometryFieldInput { private: - Field input_; + GField input_; Field group_index_; eAttrDomain source_domain_; AccumulationMode accumulation_mode_; public: AccumulateFieldInput(const eAttrDomain source_domain, - Field input, + GField input, Field group_index, AccumulationMode accumulation_mode) - : bke::GeometryFieldInput(CPPType::get(), "Accumulation"), + : bke::GeometryFieldInput(input.cpp_type(), "Accumulation"), input_(input), group_index_(group_index), source_domain_(source_domain), @@ -216,7 +220,7 @@ template class AccumulateFieldInput final : public bke::GeometryFiel const IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int domain_size = attributes.domain_size(source_domain_); + const int64_t domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -227,46 +231,55 @@ template class AccumulateFieldInput final : public bke::GeometryFiel evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const VArray values = evaluator.get_evaluated(0); + const GVArraySpan g_values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - Array accumulations_out(domain_size); + GVArray g_output; - if (group_indices.is_single()) { - T accumulation = T(); - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; - accumulations_out[i] = accumulation; - } - } - else { - for (const int i : values.index_range()) { - accumulations_out[i] = accumulation; - accumulation = values[i] + accumulation; - } - } - } - else { - Map accumulations; - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - accumulation_value += values[i]; - accumulations_out[i] = accumulation_value; - } - } - else { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - accumulations_out[i] = accumulation_value; - accumulation_value += values[i]; - } - } - } + attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { + using T = decltype(dummy); + if constexpr (is_same_any_v) { + Array outputs(domain_size); + const Span values = g_values.typed(); - return attributes.adapt_domain( - VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); + if (group_indices.is_single()) { + T accumulation = T(); + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; + outputs[i] = accumulation; + } + } + else { + for (const int i : values.index_range()) { + outputs[i] = accumulation; + accumulation = values[i] + accumulation; + } + } + } + else { + Map accumulations; + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + accumulation_value += values[i]; + outputs[i] = accumulation_value; + } + } + else { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + outputs[i] = accumulation_value; + accumulation_value += values[i]; + } + } + } + + g_output = VArray::ForContainer(std::move(outputs)); + } + }); + + return attributes.adapt_domain(std::move(g_output), source_domain_, context.domain()); } uint64_t hash() const override @@ -293,15 +306,15 @@ template class AccumulateFieldInput final : public bke::GeometryFiel } }; -template class TotalFieldInput final : public bke::GeometryFieldInput { +class TotalFieldInput final : public bke::GeometryFieldInput { private: - Field input_; + GField input_; Field group_index_; eAttrDomain source_domain_; public: - TotalFieldInput(const eAttrDomain source_domain, Field input, Field group_index) - : bke::GeometryFieldInput(CPPType::get(), "Total Value"), + TotalFieldInput(const eAttrDomain source_domain, GField input, Field group_index) + : bke::GeometryFieldInput(input.cpp_type(), "Total Value"), input_(input), group_index_(group_index), source_domain_(source_domain) @@ -312,7 +325,7 @@ template class TotalFieldInput final : public bke::GeometryFieldInpu IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int domain_size = attributes.domain_size(source_domain_); + const int64_t domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -323,29 +336,38 @@ template class TotalFieldInput final : public bke::GeometryFieldInpu evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const VArray values = evaluator.get_evaluated(0); + const GVArraySpan g_values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - if (group_indices.is_single()) { - T accumulation = T(); - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; + GVArray g_outputs; + + attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { + using T = decltype(dummy); + if constexpr (is_same_any_v) { + const Span values = g_values.typed(); + if (group_indices.is_single()) { + T accumulation = {}; + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; + } + g_outputs = VArray::ForSingle(accumulation, domain_size); + } + else { + Map accumulations; + for (const int i : values.index_range()) { + T &value = accumulations.lookup_or_add_default(group_indices[i]); + value = value + values[i]; + } + Array outputs(domain_size); + for (const int i : values.index_range()) { + outputs[i] = accumulations.lookup(group_indices[i]); + } + g_outputs = VArray::ForContainer(std::move(outputs)); + } } - return VArray::ForSingle(accumulation, domain_size); - } + }); - Array accumulations_out(domain_size); - Map accumulations; - for (const int i : values.index_range()) { - T &value = accumulations.lookup_or_add_default(group_indices[i]); - value = value + values[i]; - } - for (const int i : values.index_range()) { - accumulations_out[i] = accumulations.lookup(group_indices[i]); - } - - return attributes.adapt_domain( - VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); + return attributes.adapt_domain(std::move(g_outputs), source_domain_, context.domain()); } uint64_t hash() const override @@ -391,25 +413,24 @@ static void node_geo_exec(GeoNodeExecParams params) Field group_index_field = params.extract_input>("Group Index"); attribute_math::convert_to_static_type(data_type, [&](auto dummy) { using T = decltype(dummy); - if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v) { + if constexpr (is_same_any_v) { const std::string suffix = " " + identifier_suffix(); Field input_field = params.extract_input>("Value" + suffix); if (params.output_is_required("Leading" + suffix)) { params.set_output( "Leading" + suffix, - Field{std::make_shared>( + Field{std::make_shared( source_domain, input_field, group_index_field, AccumulationMode::Leading)}); } if (params.output_is_required("Trailing" + suffix)) { params.set_output( "Trailing" + suffix, - Field{std::make_shared>( + Field{std::make_shared( source_domain, input_field, group_index_field, AccumulationMode::Trailing)}); } if (params.output_is_required("Total" + suffix)) { params.set_output("Total" + suffix, - Field{std::make_shared>( + Field{std::make_shared( source_domain, input_field, group_index_field)}); } } diff --git a/source/tools b/source/tools index e133fc08cd3..979bfe2504e 160000 --- a/source/tools +++ b/source/tools @@ -1 +1 @@ -Subproject commit e133fc08cd3254bb3d3bd1345028c8486700bca4 +Subproject commit 979bfe2504eb2f446639ab5768aac9b80b1f4864 -- 2.30.2 From a5500c2e47542b55bab69085d04aa851ffcfccbb Mon Sep 17 00:00:00 2001 From: illua1 Date: Wed, 8 Feb 2023 16:52:52 +0300 Subject: [PATCH 02/17] changes based on comments --- .../nodes/node_geo_accumulate_field.cc | 161 ++++++++++-------- 1 file changed, 91 insertions(+), 70 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc index f7a8496868e..5ce67779384 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc @@ -2,6 +2,10 @@ #include "BKE_attribute_math.hh" +#include "BLI_array.hh" +#include "BLI_generic_virtual_array.hh" +#include "BLI_virtual_array.hh" + #include "NOD_socket_search_link.hh" #include "node_geometry_util.hh" @@ -192,19 +196,19 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } } -template class AccumulateFieldInput final : public bke::GeometryFieldInput { +class AccumulateFieldInput final : public bke::GeometryFieldInput { private: - Field input_; + GField input_; Field group_index_; eAttrDomain source_domain_; AccumulationMode accumulation_mode_; public: AccumulateFieldInput(const eAttrDomain source_domain, - Field input, + GField input, Field group_index, AccumulationMode accumulation_mode) - : bke::GeometryFieldInput(CPPType::get(), "Accumulation"), + : bke::GeometryFieldInput(input.cpp_type(), "Accumulation"), input_(input), group_index_(group_index), source_domain_(source_domain), @@ -216,7 +220,7 @@ template class AccumulateFieldInput final : public bke::GeometryFiel const IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int domain_size = attributes.domain_size(source_domain_); + const int64_t domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -227,46 +231,55 @@ template class AccumulateFieldInput final : public bke::GeometryFiel evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const VArray values = evaluator.get_evaluated(0); + const GVArray g_values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - Array accumulations_out(domain_size); + GVArray g_output; - if (group_indices.is_single()) { - T accumulation = T(); - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; - accumulations_out[i] = accumulation; - } - } - else { - for (const int i : values.index_range()) { - accumulations_out[i] = accumulation; - accumulation = values[i] + accumulation; - } - } - } - else { - Map accumulations; - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - accumulation_value += values[i]; - accumulations_out[i] = accumulation_value; - } - } - else { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - accumulations_out[i] = accumulation_value; - accumulation_value += values[i]; - } - } - } + attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { + using T = decltype(dummy); + if constexpr (is_same_any_v) { + Array outputs(domain_size); + const VArray values = g_values.typed(); - return attributes.adapt_domain( - VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); + if (group_indices.is_single()) { + T accumulation = T(); + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; + outputs[i] = accumulation; + } + } + else { + for (const int i : values.index_range()) { + outputs[i] = accumulation; + accumulation = values[i] + accumulation; + } + } + } + else { + Map accumulations; + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + accumulation_value += values[i]; + outputs[i] = accumulation_value; + } + } + else { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + outputs[i] = accumulation_value; + accumulation_value += values[i]; + } + } + } + + g_output = VArray::ForContainer(std::move(outputs)); + } + }); + + return attributes.adapt_domain(std::move(g_output), source_domain_, context.domain()); } uint64_t hash() const override @@ -293,15 +306,15 @@ template class AccumulateFieldInput final : public bke::GeometryFiel } }; -template class TotalFieldInput final : public bke::GeometryFieldInput { +class TotalFieldInput final : public bke::GeometryFieldInput { private: - Field input_; + GField input_; Field group_index_; eAttrDomain source_domain_; public: - TotalFieldInput(const eAttrDomain source_domain, Field input, Field group_index) - : bke::GeometryFieldInput(CPPType::get(), "Total Value"), + TotalFieldInput(const eAttrDomain source_domain, GField input, Field group_index) + : bke::GeometryFieldInput(input.cpp_type(), "Total Value"), input_(input), group_index_(group_index), source_domain_(source_domain) @@ -312,7 +325,7 @@ template class TotalFieldInput final : public bke::GeometryFieldInpu IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int domain_size = attributes.domain_size(source_domain_); + const int64_t domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -323,29 +336,38 @@ template class TotalFieldInput final : public bke::GeometryFieldInpu evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const VArray values = evaluator.get_evaluated(0); + const GVArray g_values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - if (group_indices.is_single()) { - T accumulation = T(); - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; + GVArray g_outputs; + + attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { + using T = decltype(dummy); + if constexpr (is_same_any_v) { + const VArray values = g_values.typed(); + if (group_indices.is_single()) { + T accumulation = {}; + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; + } + g_outputs = VArray::ForSingle(accumulation, domain_size); + } + else { + Map accumulations; + for (const int i : values.index_range()) { + T &value = accumulations.lookup_or_add_default(group_indices[i]); + value = value + values[i]; + } + Array outputs(domain_size); + for (const int i : values.index_range()) { + outputs[i] = accumulations.lookup(group_indices[i]); + } + g_outputs = VArray::ForContainer(std::move(outputs)); + } } - return VArray::ForSingle(accumulation, domain_size); - } + }); - Array accumulations_out(domain_size); - Map accumulations; - for (const int i : values.index_range()) { - T &value = accumulations.lookup_or_add_default(group_indices[i]); - value = value + values[i]; - } - for (const int i : values.index_range()) { - accumulations_out[i] = accumulations.lookup(group_indices[i]); - } - - return attributes.adapt_domain( - VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); + return attributes.adapt_domain(std::move(g_outputs), source_domain_, context.domain()); } uint64_t hash() const override @@ -391,25 +413,24 @@ static void node_geo_exec(GeoNodeExecParams params) Field group_index_field = params.extract_input>("Group Index"); attribute_math::convert_to_static_type(data_type, [&](auto dummy) { using T = decltype(dummy); - if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v) { + if constexpr (is_same_any_v) { const std::string suffix = " " + identifier_suffix(); Field input_field = params.extract_input>("Value" + suffix); if (params.output_is_required("Leading" + suffix)) { params.set_output( "Leading" + suffix, - Field{std::make_shared>( + Field{std::make_shared( source_domain, input_field, group_index_field, AccumulationMode::Leading)}); } if (params.output_is_required("Trailing" + suffix)) { params.set_output( "Trailing" + suffix, - Field{std::make_shared>( + Field{std::make_shared( source_domain, input_field, group_index_field, AccumulationMode::Trailing)}); } if (params.output_is_required("Total" + suffix)) { params.set_output("Total" + suffix, - Field{std::make_shared>( + Field{std::make_shared( source_domain, input_field, group_index_field)}); } } -- 2.30.2 From 9621f361cbcb7680b440d780e7e6dff83b12c14e Mon Sep 17 00:00:00 2001 From: illua1 Date: Wed, 8 Feb 2023 16:59:57 +0300 Subject: [PATCH 03/17] undo changes in wrong branch --- .../nodes/node_geo_accumulate_field.cc | 157 ++++++++---------- 1 file changed, 68 insertions(+), 89 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc index 5ce67779384..f7a8496868e 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc @@ -2,10 +2,6 @@ #include "BKE_attribute_math.hh" -#include "BLI_array.hh" -#include "BLI_generic_virtual_array.hh" -#include "BLI_virtual_array.hh" - #include "NOD_socket_search_link.hh" #include "node_geometry_util.hh" @@ -196,19 +192,19 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } } -class AccumulateFieldInput final : public bke::GeometryFieldInput { +template class AccumulateFieldInput final : public bke::GeometryFieldInput { private: - GField input_; + Field input_; Field group_index_; eAttrDomain source_domain_; AccumulationMode accumulation_mode_; public: AccumulateFieldInput(const eAttrDomain source_domain, - GField input, + Field input, Field group_index, AccumulationMode accumulation_mode) - : bke::GeometryFieldInput(input.cpp_type(), "Accumulation"), + : bke::GeometryFieldInput(CPPType::get(), "Accumulation"), input_(input), group_index_(group_index), source_domain_(source_domain), @@ -220,7 +216,7 @@ class AccumulateFieldInput final : public bke::GeometryFieldInput { const IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int64_t domain_size = attributes.domain_size(source_domain_); + const int domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -231,55 +227,46 @@ class AccumulateFieldInput final : public bke::GeometryFieldInput { evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const GVArray g_values = evaluator.get_evaluated(0); + const VArray values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - GVArray g_output; + Array accumulations_out(domain_size); - attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { - using T = decltype(dummy); - if constexpr (is_same_any_v) { - Array outputs(domain_size); - const VArray values = g_values.typed(); - - if (group_indices.is_single()) { - T accumulation = T(); - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; - outputs[i] = accumulation; - } - } - else { - for (const int i : values.index_range()) { - outputs[i] = accumulation; - accumulation = values[i] + accumulation; - } - } + if (group_indices.is_single()) { + T accumulation = T(); + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; + accumulations_out[i] = accumulation; } - else { - Map accumulations; - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - accumulation_value += values[i]; - outputs[i] = accumulation_value; - } - } - else { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - outputs[i] = accumulation_value; - accumulation_value += values[i]; - } - } - } - - g_output = VArray::ForContainer(std::move(outputs)); } - }); + else { + for (const int i : values.index_range()) { + accumulations_out[i] = accumulation; + accumulation = values[i] + accumulation; + } + } + } + else { + Map accumulations; + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + accumulation_value += values[i]; + accumulations_out[i] = accumulation_value; + } + } + else { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + accumulations_out[i] = accumulation_value; + accumulation_value += values[i]; + } + } + } - return attributes.adapt_domain(std::move(g_output), source_domain_, context.domain()); + return attributes.adapt_domain( + VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); } uint64_t hash() const override @@ -306,15 +293,15 @@ class AccumulateFieldInput final : public bke::GeometryFieldInput { } }; -class TotalFieldInput final : public bke::GeometryFieldInput { +template class TotalFieldInput final : public bke::GeometryFieldInput { private: - GField input_; + Field input_; Field group_index_; eAttrDomain source_domain_; public: - TotalFieldInput(const eAttrDomain source_domain, GField input, Field group_index) - : bke::GeometryFieldInput(input.cpp_type(), "Total Value"), + TotalFieldInput(const eAttrDomain source_domain, Field input, Field group_index) + : bke::GeometryFieldInput(CPPType::get(), "Total Value"), input_(input), group_index_(group_index), source_domain_(source_domain) @@ -325,7 +312,7 @@ class TotalFieldInput final : public bke::GeometryFieldInput { IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int64_t domain_size = attributes.domain_size(source_domain_); + const int domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -336,38 +323,29 @@ class TotalFieldInput final : public bke::GeometryFieldInput { evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const GVArray g_values = evaluator.get_evaluated(0); + const VArray values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - GVArray g_outputs; - - attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { - using T = decltype(dummy); - if constexpr (is_same_any_v) { - const VArray values = g_values.typed(); - if (group_indices.is_single()) { - T accumulation = {}; - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; - } - g_outputs = VArray::ForSingle(accumulation, domain_size); - } - else { - Map accumulations; - for (const int i : values.index_range()) { - T &value = accumulations.lookup_or_add_default(group_indices[i]); - value = value + values[i]; - } - Array outputs(domain_size); - for (const int i : values.index_range()) { - outputs[i] = accumulations.lookup(group_indices[i]); - } - g_outputs = VArray::ForContainer(std::move(outputs)); - } + if (group_indices.is_single()) { + T accumulation = T(); + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; } - }); + return VArray::ForSingle(accumulation, domain_size); + } - return attributes.adapt_domain(std::move(g_outputs), source_domain_, context.domain()); + Array accumulations_out(domain_size); + Map accumulations; + for (const int i : values.index_range()) { + T &value = accumulations.lookup_or_add_default(group_indices[i]); + value = value + values[i]; + } + for (const int i : values.index_range()) { + accumulations_out[i] = accumulations.lookup(group_indices[i]); + } + + return attributes.adapt_domain( + VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); } uint64_t hash() const override @@ -413,24 +391,25 @@ static void node_geo_exec(GeoNodeExecParams params) Field group_index_field = params.extract_input>("Group Index"); attribute_math::convert_to_static_type(data_type, [&](auto dummy) { using T = decltype(dummy); - if constexpr (is_same_any_v) { + if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v) { const std::string suffix = " " + identifier_suffix(); Field input_field = params.extract_input>("Value" + suffix); if (params.output_is_required("Leading" + suffix)) { params.set_output( "Leading" + suffix, - Field{std::make_shared( + Field{std::make_shared>( source_domain, input_field, group_index_field, AccumulationMode::Leading)}); } if (params.output_is_required("Trailing" + suffix)) { params.set_output( "Trailing" + suffix, - Field{std::make_shared( + Field{std::make_shared>( source_domain, input_field, group_index_field, AccumulationMode::Trailing)}); } if (params.output_is_required("Total" + suffix)) { params.set_output("Total" + suffix, - Field{std::make_shared( + Field{std::make_shared>( source_domain, input_field, group_index_field)}); } } -- 2.30.2 From dc46826007515334344ec9815bf0e03167d65bb0 Mon Sep 17 00:00:00 2001 From: illua1 Date: Wed, 8 Feb 2023 17:01:02 +0300 Subject: [PATCH 04/17] changes based on comments --- .../nodes/geometry/nodes/node_geo_accumulate_field.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc index f2e7134e22c..5ce67779384 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc @@ -231,7 +231,7 @@ class AccumulateFieldInput final : public bke::GeometryFieldInput { evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const GVArraySpan g_values = evaluator.get_evaluated(0); + const GVArray g_values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); GVArray g_output; @@ -240,7 +240,7 @@ class AccumulateFieldInput final : public bke::GeometryFieldInput { using T = decltype(dummy); if constexpr (is_same_any_v) { Array outputs(domain_size); - const Span values = g_values.typed(); + const VArray values = g_values.typed(); if (group_indices.is_single()) { T accumulation = T(); @@ -336,7 +336,7 @@ class TotalFieldInput final : public bke::GeometryFieldInput { evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const GVArraySpan g_values = evaluator.get_evaluated(0); + const GVArray g_values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); GVArray g_outputs; @@ -344,7 +344,7 @@ class TotalFieldInput final : public bke::GeometryFieldInput { attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { using T = decltype(dummy); if constexpr (is_same_any_v) { - const Span values = g_values.typed(); + const VArray values = g_values.typed(); if (group_indices.is_single()) { T accumulation = {}; for (const int i : values.index_range()) { -- 2.30.2 From 8c614debeed6449729ec61bcd656267792776acd Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 12 Jan 2023 15:00:52 +0100 Subject: [PATCH 05/17] Release: support generating LTS release notes from Gitea Now a single script to generate both links and release notes. It also includes the issue ID for the LTS releases, so only the release version needs to be specified. Pull Request #104402 --- release/lts/README.md | 47 ++--- release/lts/create_release_notes.py | 195 ++++-------------- ...reate_download_urls.py => lts_download.py} | 20 +- release/lts/lts_issue.py | 168 +++++++++++++++ release/lts/requirements.txt | 2 +- 5 files changed, 219 insertions(+), 213 deletions(-) rename release/lts/{create_download_urls.py => lts_download.py} (69%) mode change 100755 => 100644 create mode 100644 release/lts/lts_issue.py diff --git a/release/lts/README.md b/release/lts/README.md index 8f7b6f0b87a..c95aecabe18 100644 --- a/release/lts/README.md +++ b/release/lts/README.md @@ -1,41 +1,18 @@ -This folder contains several scripts to smoothen the Blender LTS releases. +This folder contains a script to generate release notes and download URLs +for Blender LTS releases. -create_download_urls.py -======================= +Ensure required Python modules are installed before running: -This python script is used to generate the download urls which we can -copy-paste directly into the CMS of www.blender.org. + pip3 install -r ./requirements.txt -Usage: create_download_urls.py --version 2.83.7 +Then run for example: -Arguments: - --version VERSION Version string in the form of {major}.{minor}.{build} - (eg 2.83.7) + ./create_release_notes.py --version 3.3.2 --format=html -The resulting html will be printed to the console. +Available arguments: -create_release_notes.py -======================= - -This python script is used to generate the release notes which we can -copy-paste directly into the CMS of www.blender.org and stores. - -Usage: ./create_release_notes.py --task=T77348 --version=2.83.7 - -Arguments: - --version VERSION Version string in the form of {major}.{minor}.{build} - (e.g. 2.83.7) - --task TASK Phabricator ticket that is contains the release notes - information (e.g. T77348) - --format FORMAT Format the result in `text`, `steam`, `wiki` or `html` - -Requirements -============ - -* Python 3.8 or later -* Python phabricator client version 0.7.0 - https://pypi.org/project/phabricator/ - -For convenience the python modules can be installed using pip - - pip3 install -r ./requirements.txt \ No newline at end of file + --version VERSION Version string in the form of {major}.{minor}.{build} + (e.g. 3.3.2) + --issue ISSUE Gitea issue that is contains the release notes + information (e.g. #77348) + --format FORMAT Format the result in `text`, `steam`, `wiki` or `html` diff --git a/release/lts/create_release_notes.py b/release/lts/create_release_notes.py index a51721057bb..cfab24c94ae 100755 --- a/release/lts/create_release_notes.py +++ b/release/lts/create_release_notes.py @@ -1,169 +1,46 @@ +#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-or-later -#!/usr/bin/env python3 - import argparse -import phabricator +import lts_issue +import lts_download -DESCRIPTION = ("This python script is used to generate the release notes " - "which we can copy-paste directly into the CMS of " +DESCRIPTION = ("This python script is used to generate the release notes and " + "download URLs which we can copy-paste directly into the CMS of " "www.blender.org and stores.") -USAGE = "./create_release_notes.py --task=T77348 --version=2.83.7" +# Parse arguments +parser = argparse.ArgumentParser(description=DESCRIPTION) +parser.add_argument( + "--version", + required=True, + help="Version string in the form of {major}.{minor}.{patch} (e.g. 3.3.2)") +parser.add_argument( + "--issue", + help="Task that is contains the release notes information (e.g. #77348)") +parser.add_argument( + "--format", + help="Format the result in `text`, `steam`, `wiki` or `html`", + default="text") +args = parser.parse_args() -class ReleaseLogLine: - """ - Class containing the information of a single line of the release log +# Determine issue number +version = args.version +issue = args.issue +if not issue: + if version.startswith("2.83."): + issue = "#77348" + elif version.startswith("2.93."): + issue = "#88449" + elif version.startswith("3.3."): + issue = "#100749" + else: + raise ValueError("Specify --issue or update script to include issue number for this version") - Instance attributes: +# Print +if args.format == "html": + lts_download.print_urls(version=version) + print("") - * line: (str) the original line used to create this log line - * task_id: (int or None) the extracted task id associated with this log - line. Can be None if the log line isn't associated with a task. - * commit_id: (str or None) the extracted commit id associated with this log - line. Only filled when no `task_id` could be found. - * ref: (str) `task_id` or `commit_id` of this line, including `T` for tasks - or `D` for diffs. - * title: (str) title of this log line. When constructed this attribute is - an empty string. The called needs to retrieve the title from the - backend. - * url: (str) url of the ticket task or commit. - """ - - def __init__(self, line: str): - self.line = line - items = line.split("|") - self.task_id = None - self.commit_id = None - try: - task_id = int(items[1].strip()[1:]) - self.task_id = task_id - self.ref = f"T{self.task_id}" - except ValueError: - # no task - commit_string = items[3].strip() - commits = commit_string.split(",") - commit_id = commits[0] - commit_id = commit_id.replace("{", "").replace("}", "") - if not commit_id.startswith("rB"): - commit_id = f"rB{commit_id}" - self.commit_id = commit_id - - self.ref = f"{self.commit_id}" - - self.title = "" - self.url = f"https://developer.blender.org/{self.ref}" - - def __format_as_html(self) -> str: - return f"
  • {self.title} [{self.ref}]
  • " - - def __format_as_text(self) -> str: - return f"* {self.title} [{self.ref}]" - - def __format_as_steam(self) -> str: - return f"* {self.title} ([url={self.url}]{self.ref}[/url])" - - def __format_as_wiki(self) -> str: - if self.task_id: - return f"* {self.title} [{{{{BugReport|{self.task_id}}}}}]" - else: - return f"* {self.title} [{{{{GitCommit|{self.commit_id[2:]}}}}}]" - - def format(self, format: str) -> str: - """ - Format this line - - :attr format: the desired format. Possible values are 'text', 'steam' or 'html' - :type string: - """ - if format == 'html': - return self.__format_as_html() - elif format == 'steam': - return self.__format_as_steam() - elif format == 'wiki': - return self.__format_as_wiki() - else: - return self.__format_as_text() - - -def format_title(title: str) -> str: - title = title.strip() - if not title.endswith("."): - title = title + "." - return title - - -def extract_release_notes(version: str, task_id: int): - """ - Extract all release notes logs - - # Process - - 1. Retrieval of description of the given `task_id`. - 2. Find rows for the given `version` and convert to `ReleaseLogLine`. - 3. based on the associated task or commit retrieves the title of the log - line. - """ - phab = phabricator.Phabricator() - phab.update_interfaces() - task = phab.maniphest.info(task_id=task_id) - description = task["description"] - lines = description.split("\n") - start_index = lines.index(f"## Blender {version} ##") - lines = lines[start_index + 1:] - for line in lines: - if not line.strip(): - continue - if line.startswith("| **Report**"): - continue - if line.startswith("## Blender"): - break - - log_line = ReleaseLogLine(line) - if log_line.task_id: - issue_task = phab.maniphest.info(task_id=log_line.task_id) - log_line.title = format_title(issue_task.title) - yield log_line - elif log_line.commit_id: - commits = phab.diffusion.commit.search(constraints={"identifiers": [log_line.commit_id]}) - commit = commits.data[0] - commit_message = commit['fields']['message'] - commit_title = commit_message.split("\n")[0] - log_line.title = format_title(commit_title) - yield log_line - - -def print_release_notes(version: str, format: str, task_id: int): - """ - Generate and print the release notes to the console. - """ - if format == 'html': - print("
      ") - if format == 'steam': - print("[ul]") - for log_item in extract_release_notes(version=version, task_id=task_id): - print(log_item.format(format=format)) - if format == 'html': - print("
    ") - if format == 'steam': - print("[/ul]") - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description=DESCRIPTION, usage=USAGE) - parser.add_argument( - "--version", - required=True, - help="Version string in the form of {major}.{minor}.{build} (e.g. 2.83.7)") - parser.add_argument( - "--task", - required=True, - help="Phabricator ticket that is contains the release notes information (e.g. T77348)") - parser.add_argument( - "--format", - help="Format the result in `text`, `steam`, `wiki` or `html`", - default="text") - args = parser.parse_args() - - print_release_notes(version=args.version, format=args.format, task_id=int(args.task[1:])) +lts_issue.print_notes(version=version, format=args.format, issue=issue) diff --git a/release/lts/create_download_urls.py b/release/lts/lts_download.py old mode 100755 new mode 100644 similarity index 69% rename from release/lts/create_download_urls.py rename to release/lts/lts_download.py index c6b01acdf60..6d0dd81397b --- a/release/lts/create_download_urls.py +++ b/release/lts/lts_download.py @@ -1,14 +1,9 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-or-later -import argparse import datetime -DESCRIPTION = ("This python script is used to generate the download urls " - "which we can copy-paste directly into the CMS of " - "www.blender.org") -USAGE = "create_download_urls --version=2.83.7" # Used date format: "September 30, 2020" DATE_FORMAT = "%B %d, %Y" @@ -62,19 +57,8 @@ def generate_html(version: Version) -> str: return "\n".join(lines) -def print_download_urls(version: Version): +def print_urls(version: str): """ Generate the download urls and print them to the console. """ - print(generate_html(version)) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description=DESCRIPTION, usage=USAGE) - parser.add_argument("--version", - required=True, - help=("Version string in the form of {major}.{minor}." - "{build} (eg 2.83.7)")) - args = parser.parse_args() - - print_download_urls(version=Version(args.version)) + print(generate_html(Version(version))) diff --git a/release/lts/lts_issue.py b/release/lts/lts_issue.py new file mode 100644 index 00000000000..f84cfb29b15 --- /dev/null +++ b/release/lts/lts_issue.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later + +import requests + +class ReleaseLogLine: + """ + Class containing the information of a single line of the release log + + Instance attributes: + + * line: (str) the original line used to create this log line + * issue_id: (int or None) the extracted issue id associated with this log + line. Can be None if the log line isn't associated with a issue. + * commit_id: (str or None) the extracted commit id associated with this log + line. Only filled when no `issue_id` could be found. + * ref: (str) `issue_id` or `commit_id` of this line, including `T` for issues + or `D` for diffs. + * title: (str) title of this log line. When constructed this attribute is + an empty string. The called needs to retrieve the title from the + backend. + * url: (str) url of the ticket issue or commit. + """ + + def __init__(self, line: str): + self.line = line + items = line.split("|") + self.issue_id = None + self.issue_repo = None + self.commit_id = None + self.commit_repo = None + base_url = "https://projects.blender.org" + try: + issue_tokens = items[1].strip().split("#") + if len(issue_tokens[0]) > 0: + self.issue_repo = issue_tokens[0] + self.issue_id = issue_tokens[1] + else: + self.issue_repo = "blender/blender" + self.issue_id = issue_tokens[1] + + self.ref = f"#{self.issue_id}" + self.url = f"{base_url}/{self.issue_repo}/issues/{self.issue_id}" + except IndexError: + # no issue + commit_string = items[3].strip() + commit_string = commit_string.split(",")[0] + commit_string = commit_string.split("]")[0] + commit_string = commit_string.replace("[", "") + + commit_tokens = commit_string.split("@") + if len(commit_tokens) > 1: + self.commit_repo = commit_tokens[0] + self.commit_id = commit_tokens[1] + else: + self.commit_repo = "blender/blender" + self.commit_id = commit_tokens[0] + + self.ref = f"{self.commit_id}" + self.url = f"{base_url}/{self.commit_repo}/commit/{self.commit_id}" + + self.title = "" + + def __format_as_html(self) -> str: + return f"
  • {self.title} [{self.ref}]
  • " + + def __format_as_text(self) -> str: + return f"* {self.title} [{self.ref}]" + + def __format_as_steam(self) -> str: + return f"* {self.title} ([url={self.url}]{self.ref}[/url])" + + def __format_as_wiki(self) -> str: + if self.issue_id: + return f"* {self.title} [{{{{BugReport|{self.issue_id}}}}}]" + else: + return f"* {self.title} [{{{{GitCommit|{self.commit_id[2:]}}}}}]" + + def format(self, format: str) -> str: + """ + Format this line + + :attr format: the desired format. Possible values are 'text', 'steam' or 'html' + :type string: + """ + if format == 'html': + return self.__format_as_html() + elif format == 'steam': + return self.__format_as_steam() + elif format == 'wiki': + return self.__format_as_wiki() + else: + return self.__format_as_text() + + +def format_title(title: str) -> str: + title = title.strip() + if not title.endswith("."): + title = title + "." + return title + + +def extract_release_notes(version: str, issue: str): + """ + Extract all release notes logs + + # Process + + 1. Retrieval of description of the given `issue_id`. + 2. Find rows for the given `version` and convert to `ReleaseLogLine`. + 3. based on the associated issue or commit retrieves the title of the log + line. + """ + base_url = "https://projects.blender.org/api/v1/repos" + issues_url = base_url + "/blender/blender/issues/" + headers = {'accept': 'application/json'} + + response = requests.get(issues_url + issue[1:], headers=headers) + description = response.json()["body"] + + lines = description.split("\n") + start_index = lines.index(f"## Blender {version}") + lines = lines[start_index + 1:] + for line in lines: + if not line.strip(): + continue + if line.startswith("| **Report**"): + continue + if line.startswith("## Blender"): + break + if line.find("| -- |") != -1: + continue + + log_line = ReleaseLogLine(line) + if log_line.issue_id: + issue_url = f"{base_url}/{log_line.issue_repo}/issues/{log_line.issue_id}" + response = requests.get(issue_url, headers=headers) + if response.status_code != 200: + raise ValueError("Issue not found: " + str(log_line.issue_id)) + + log_line.title = format_title(response.json()["title"]) + yield log_line + elif log_line.commit_id: + commit_url = f"{base_url}/{log_line.commit_repo}/git/commits/{log_line.commit_id}" + response = requests.get(commit_url, headers=headers) + if response.status_code != 200: + raise ValueError("Commit not found: " + log_line.commit_id) + + commit_message = response.json()['commit']['message'] + commit_title = commit_message.split("\n")[0] + log_line.title = format_title(commit_title) + yield log_line + + +def print_notes(version: str, format: str, issue: str): + """ + Generate and print the release notes to the console. + """ + if format == 'html': + print("
      ") + if format == 'steam': + print("[ul]") + for log_item in extract_release_notes(version=version, issue=issue): + print(log_item.format(format=format)) + if format == 'html': + print("
    ") + if format == 'steam': + print("[/ul]") diff --git a/release/lts/requirements.txt b/release/lts/requirements.txt index dc91ba85b01..f2293605cf1 100644 --- a/release/lts/requirements.txt +++ b/release/lts/requirements.txt @@ -1 +1 @@ -phabricator==0.7.0 \ No newline at end of file +requests -- 2.30.2 From 497cf6ca74e7a4cd10481c3d103a2d9342380dea Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 7 Feb 2023 21:56:45 +0100 Subject: [PATCH 06/17] Cleanup: Move 18 sculpt files to C++ To allow further mesh data structure refactoring. See #103343 Pull Request #104436 --- source/blender/blenkernel/BKE_shrinkwrap.h | 2 +- source/blender/blenkernel/intern/brush.cc | 2 +- source/blender/editors/include/ED_sculpt.h | 2 +- source/blender/editors/mesh/CMakeLists.txt | 2 +- ...ask_extract.c => editmesh_mask_extract.cc} | 134 +++--- source/blender/editors/mesh/mesh_intern.h | 2 +- .../editors/sculpt_paint/CMakeLists.txt | 30 +- source/blender/editors/sculpt_paint/sculpt.cc | 4 +- .../{sculpt_boundary.c => sculpt_boundary.cc} | 131 +++--- ...pt_brush_types.c => sculpt_brush_types.cc} | 433 +++++++++--------- .../{sculpt_cloth.c => sculpt_cloth.cc} | 228 +++++---- .../{sculpt_detail.c => sculpt_detail.cc} | 79 ++-- ..._filter_color.c => sculpt_filter_color.cc} | 45 +- ...pt_filter_mask.c => sculpt_filter_mask.cc} | 48 +- ...pt_filter_mesh.c => sculpt_filter_mesh.cc} | 132 +++--- .../editors/sculpt_paint/sculpt_intern.h | 10 +- ...pt_mask_expand.c => sculpt_mask_expand.cc} | 96 ++-- ...sculpt_mask_init.c => sculpt_mask_init.cc} | 27 +- ...e_scrape.c => sculpt_multiplane_scrape.cc} | 59 ++- .../{sculpt_ops.c => sculpt_ops.cc} | 170 +++---- ...pt_paint_color.c => sculpt_paint_color.cc} | 86 ++-- .../{sculpt_pose.c => sculpt_pose.cc} | 180 ++++---- .../{sculpt_smooth.c => sculpt_smooth.cc} | 55 ++- ...sculpt_transform.c => sculpt_transform.cc} | 61 ++- .../blender/editors/transform/CMakeLists.txt | 4 +- .../editors/transform/transform_convert.h | 2 +- ...t_sculpt.c => transform_convert_sculpt.cc} | 10 +- ...sform_gizmo_3d.c => transform_gizmo_3d.cc} | 332 +++++++------- source/blender/makesdna/DNA_brush_types.h | 3 + source/blender/makesdna/DNA_scene_types.h | 8 + 30 files changed, 1150 insertions(+), 1227 deletions(-) rename source/blender/editors/mesh/{editmesh_mask_extract.c => editmesh_mask_extract.cc} (81%) rename source/blender/editors/sculpt_paint/{sculpt_boundary.c => sculpt_boundary.cc} (92%) rename source/blender/editors/sculpt_paint/{sculpt_brush_types.c => sculpt_brush_types.cc} (93%) rename source/blender/editors/sculpt_paint/{sculpt_cloth.c => sculpt_cloth.cc} (90%) rename source/blender/editors/sculpt_paint/{sculpt_detail.c => sculpt_detail.cc} (92%) rename source/blender/editors/sculpt_paint/{sculpt_filter_color.c => sculpt_filter_color.cc} (93%) rename source/blender/editors/sculpt_paint/{sculpt_filter_mask.c => sculpt_filter_mask.cc} (90%) rename source/blender/editors/sculpt_paint/{sculpt_filter_mesh.c => sculpt_filter_mesh.cc} (89%) rename source/blender/editors/sculpt_paint/{sculpt_mask_expand.c => sculpt_mask_expand.cc} (86%) rename source/blender/editors/sculpt_paint/{sculpt_mask_init.c => sculpt_mask_init.cc} (90%) rename source/blender/editors/sculpt_paint/{sculpt_multiplane_scrape.c => sculpt_multiplane_scrape.cc} (92%) rename source/blender/editors/sculpt_paint/{sculpt_ops.c => sculpt_ops.cc} (91%) rename source/blender/editors/sculpt_paint/{sculpt_paint_color.c => sculpt_paint_color.cc} (91%) rename source/blender/editors/sculpt_paint/{sculpt_pose.c => sculpt_pose.cc} (90%) rename source/blender/editors/sculpt_paint/{sculpt_smooth.c => sculpt_smooth.cc} (94%) rename source/blender/editors/sculpt_paint/{sculpt_transform.c => sculpt_transform.cc} (92%) rename source/blender/editors/transform/{transform_convert_sculpt.c => transform_convert_sculpt.cc} (93%) rename source/blender/editors/transform/{transform_gizmo_3d.c => transform_gizmo_3d.cc} (90%) diff --git a/source/blender/blenkernel/BKE_shrinkwrap.h b/source/blender/blenkernel/BKE_shrinkwrap.h index b13a1cbd034..448a8938bd3 100644 --- a/source/blender/blenkernel/BKE_shrinkwrap.h +++ b/source/blender/blenkernel/BKE_shrinkwrap.h @@ -120,7 +120,7 @@ void shrinkwrapGpencilModifier_deform(struct ShrinkwrapGpencilModifierData *mmd, int numVerts); /** - * Used in `editmesh_mask_extract.c` to shrink-wrap the extracted mesh to the sculpt. + * Used in `editmesh_mask_extract.cc` to shrink-wrap the extracted mesh to the sculpt. */ void BKE_shrinkwrap_mesh_nearest_surface_deform(struct bContext *C, struct Object *ob_source, diff --git a/source/blender/blenkernel/intern/brush.cc b/source/blender/blenkernel/intern/brush.cc index a8482f905d1..8d5737e940d 100644 --- a/source/blender/blenkernel/intern/brush.cc +++ b/source/blender/blenkernel/intern/brush.cc @@ -1598,7 +1598,7 @@ struct Brush *BKE_brush_first_search(struct Main *bmain, const eObjectMode ob_mo void BKE_brush_debug_print_state(Brush *br) { /* create a fake brush and set it to the defaults */ - Brush def = {{nullptr}}; + Brush def = blender::dna::shallow_zero_initialize(); brush_defaults(&def); #define BR_TEST(field, t) \ diff --git a/source/blender/editors/include/ED_sculpt.h b/source/blender/editors/include/ED_sculpt.h index 4e356499a1f..10f20054840 100644 --- a/source/blender/editors/include/ED_sculpt.h +++ b/source/blender/editors/include/ED_sculpt.h @@ -28,7 +28,7 @@ bool ED_sculpt_mask_box_select(struct bContext *C, const struct rcti *rect, bool select); -/* sculpt_transform.c */ +/* sculpt_transform.cc */ void ED_sculpt_update_modal_transform(struct bContext *C, struct Object *ob); void ED_sculpt_init_transform(struct bContext *C, diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index 283969cee47..a0769fbaa5f 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -39,7 +39,7 @@ set(SRC editmesh_knife.c editmesh_knife_project.c editmesh_loopcut.c - editmesh_mask_extract.c + editmesh_mask_extract.cc editmesh_path.c editmesh_polybuild.c editmesh_preselect_edgering.c diff --git a/source/blender/editors/mesh/editmesh_mask_extract.c b/source/blender/editors/mesh/editmesh_mask_extract.cc similarity index 81% rename from source/blender/editors/mesh/editmesh_mask_extract.c rename to source/blender/editors/mesh/editmesh_mask_extract.cc index 969a5cf52ed..cea882b0db7 100644 --- a/source/blender/editors/mesh/editmesh_mask_extract.c +++ b/source/blender/editors/mesh/editmesh_mask_extract.cc @@ -49,7 +49,7 @@ static bool geometry_extract_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - if (ob != NULL && ob->mode == OB_MODE_SCULPT) { + if (ob != nullptr && ob->mode == OB_MODE_SCULPT) { if (ob->sculpt->bm) { CTX_wm_operator_poll_msg_set(C, "The geometry can not be extracted with dyntopo activated"); return false; @@ -59,7 +59,7 @@ static bool geometry_extract_poll(bContext *C) return false; } -typedef struct GeometryExtactParams { +struct GeometryExtractParams { /* For extracting Face Sets. */ int active_face_set; @@ -71,17 +71,17 @@ typedef struct GeometryExtactParams { int num_smooth_iterations; bool apply_shrinkwrap; bool add_solidify; -} GeometryExtractParams; +}; /* Function that tags in BMesh the faces that should be deleted in the extracted object. */ -typedef void(GeometryExtractTagMeshFunc)(struct BMesh *, GeometryExtractParams *); +using GeometryExtractTagMeshFunc = void(BMesh *, GeometryExtractParams *); static int geometry_extract_apply(bContext *C, wmOperator *op, GeometryExtractTagMeshFunc *tag_fn, GeometryExtractParams *params) { - struct Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); Object *ob = CTX_data_active_object(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); @@ -89,28 +89,24 @@ static int geometry_extract_apply(bContext *C, ED_object_sculptmode_exit(C, depsgraph); - BKE_sculpt_mask_layers_ensure(depsgraph, bmain, ob, NULL); + BKE_sculpt_mask_layers_ensure(depsgraph, bmain, ob, nullptr); /* Ensures that deformation from sculpt mode is taken into account before duplicating the mesh to * extract the geometry. */ CTX_data_ensure_evaluated_depsgraph(C); - Mesh *mesh = ob->data; + Mesh *mesh = static_cast(ob->data); Mesh *new_mesh = (Mesh *)BKE_id_copy(bmain, &mesh->id); const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(new_mesh); - BMesh *bm; - bm = BM_mesh_create(&allocsize, - &((struct BMeshCreateParams){ - .use_toolflags = true, - })); + BMeshCreateParams bm_create_params{}; + bm_create_params.use_toolflags = true; + BMesh *bm = BM_mesh_create(&allocsize, &bm_create_params); - BM_mesh_bm_from_me(bm, - new_mesh, - (&(struct BMeshFromMeshParams){ - .calc_face_normal = true, - .calc_vert_normal = true, - })); + BMeshFromMeshParams mesh_to_bm_params{}; + mesh_to_bm_params.calc_face_normal = true; + mesh_to_bm_params.calc_vert_normal = true; + BM_mesh_bm_from_me(bm, new_mesh, &mesh_to_bm_params); BMEditMesh *em = BKE_editmesh_create(bm); @@ -186,11 +182,9 @@ static int geometry_extract_apply(bContext *C, BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false); BKE_id_free(bmain, new_mesh); - new_mesh = BKE_mesh_from_bmesh_nomain(bm, - (&(struct BMeshToMeshParams){ - .calc_object_remap = false, - }), - mesh); + BMeshToMeshParams bm_to_mesh_params{}; + bm_to_mesh_params.calc_object_remap = false; + new_mesh = BKE_mesh_from_bmesh_nomain(bm, &bm_to_mesh_params, mesh); BKE_editmesh_free_data(em); MEM_freeN(em); @@ -204,12 +198,13 @@ static int geometry_extract_apply(bContext *C, if (v3d && v3d->localvd) { local_view_bits = v3d->local_view_uuid; } - Object *new_ob = ED_object_add_type(C, OB_MESH, NULL, ob->loc, ob->rot, false, local_view_bits); - BKE_mesh_nomain_to_mesh(new_mesh, new_ob->data, new_ob); + Object *new_ob = ED_object_add_type( + C, OB_MESH, nullptr, ob->loc, ob->rot, false, local_view_bits); + BKE_mesh_nomain_to_mesh(new_mesh, static_cast(new_ob->data), new_ob); /* Remove the Face Sets as they need to be recreated when entering Sculpt Mode in the new object. * TODO(pablodobarro): In the future we can try to preserve them from the original mesh. */ - Mesh *new_ob_mesh = new_ob->data; + Mesh *new_ob_mesh = static_cast(new_ob->data); CustomData_free_layer_named(&new_ob_mesh->pdata, ".sculpt_face_set", new_ob_mesh->totpoly); /* Remove the mask from the new object so it can be sculpted directly after extracting. */ @@ -232,7 +227,7 @@ static int geometry_extract_apply(bContext *C, } WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, new_ob); - BKE_mesh_batch_cache_dirty_tag(new_ob->data, BKE_MESH_BATCH_DIRTY_ALL); + BKE_mesh_batch_cache_dirty_tag(static_cast(new_ob->data), BKE_MESH_BATCH_DIRTY_ALL); DEG_relations_tag_update(bmain); DEG_id_tag_update(&new_ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_GEOM | ND_DATA, new_ob->data); @@ -363,7 +358,7 @@ void MESH_OT_paint_mask_extract(wmOperatorType *ot) geometry_extract_props(ot->srna); } -static int face_set_extract_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e)) +static int face_set_extract_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { ED_workspace_status_text(C, TIP_("Click on the mesh to select a Face Set")); WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_EYEDROPPER); @@ -377,7 +372,7 @@ static int face_set_extract_modal(bContext *C, wmOperator *op, const wmEvent *ev case LEFTMOUSE: if (event->val == KM_PRESS) { WM_cursor_modal_restore(CTX_wm_window(C)); - ED_workspace_status_text(C, NULL); + ED_workspace_status_text(C, nullptr); /* This modal operator uses and eyedropper to pick a Face Set from the mesh. This ensures * that the mouse clicked in a viewport region and its coordinates can be used to ray-cast @@ -389,8 +384,8 @@ static int face_set_extract_modal(bContext *C, wmOperator *op, const wmEvent *ev return OPERATOR_CANCELLED; } - const float mval[2] = {event->xy[0] - region->winrct.xmin, - event->xy[1] - region->winrct.ymin}; + const float mval[2] = {float(event->xy[0] - region->winrct.xmin), + float(event->xy[1] - region->winrct.ymin)}; Object *ob = CTX_data_active_object(C); const int face_set_id = ED_sculpt_face_sets_active_update_and_get(C, ob, mval); @@ -410,7 +405,7 @@ static int face_set_extract_modal(bContext *C, wmOperator *op, const wmEvent *ev case EVT_ESCKEY: case RIGHTMOUSE: { WM_cursor_modal_restore(CTX_wm_window(C)); - ED_workspace_status_text(C, NULL); + ED_workspace_status_text(C, nullptr); return OPERATOR_CANCELLED; } @@ -488,40 +483,34 @@ static void slice_paint_mask(BMesh *bm, bool invert, bool fill_holes, float mask static int paint_mask_slice_exec(bContext *C, wmOperator *op) { - struct Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); Object *ob = CTX_data_active_object(C); View3D *v3d = CTX_wm_view3d(C); - BKE_sculpt_mask_layers_ensure(NULL, NULL, ob, NULL); + BKE_sculpt_mask_layers_ensure(nullptr, nullptr, ob, nullptr); - Mesh *mesh = ob->data; + Mesh *mesh = static_cast(ob->data); Mesh *new_mesh = (Mesh *)BKE_id_copy(bmain, &mesh->id); if (ob->mode == OB_MODE_SCULPT) { ED_sculpt_undo_geometry_begin(ob, op); } - BMesh *bm; const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(new_mesh); - bm = BM_mesh_create(&allocsize, - &((struct BMeshCreateParams){ - .use_toolflags = true, - })); + BMeshCreateParams bm_create_params{}; + bm_create_params.use_toolflags = true; + BMesh *bm = BM_mesh_create(&allocsize, &bm_create_params); - BM_mesh_bm_from_me(bm, - new_mesh, - (&(struct BMeshFromMeshParams){ - .calc_face_normal = true, - })); + BMeshFromMeshParams mesh_to_bm_params{}; + mesh_to_bm_params.calc_face_normal = true; + BM_mesh_bm_from_me(bm, new_mesh, &mesh_to_bm_params); slice_paint_mask( bm, false, RNA_boolean_get(op->ptr, "fill_holes"), RNA_float_get(op->ptr, "mask_threshold")); BKE_id_free(bmain, new_mesh); - new_mesh = BKE_mesh_from_bmesh_nomain(bm, - (&(struct BMeshToMeshParams){ - .calc_object_remap = false, - }), - mesh); + BMeshToMeshParams bm_to_mesh_params{}; + bm_to_mesh_params.calc_object_remap = false; + new_mesh = BKE_mesh_from_bmesh_nomain(bm, &bm_to_mesh_params, mesh); BM_mesh_free(bm); if (RNA_boolean_get(op->ptr, "new_object")) { @@ -530,64 +519,53 @@ static int paint_mask_slice_exec(bContext *C, wmOperator *op) local_view_bits = v3d->local_view_uuid; } Object *new_ob = ED_object_add_type( - C, OB_MESH, NULL, ob->loc, ob->rot, false, local_view_bits); + C, OB_MESH, nullptr, ob->loc, ob->rot, false, local_view_bits); Mesh *new_ob_mesh = (Mesh *)BKE_id_copy(bmain, &mesh->id); const BMAllocTemplate allocsize_new_ob = BMALLOC_TEMPLATE_FROM_ME(new_ob_mesh); - bm = BM_mesh_create(&allocsize_new_ob, - &((struct BMeshCreateParams){ - .use_toolflags = true, - })); + bm = BM_mesh_create(&allocsize_new_ob, &bm_create_params); - BM_mesh_bm_from_me(bm, - new_ob_mesh, - (&(struct BMeshFromMeshParams){ - .calc_face_normal = true, - })); + BM_mesh_bm_from_me(bm, new_ob_mesh, &mesh_to_bm_params); slice_paint_mask(bm, true, RNA_boolean_get(op->ptr, "fill_holes"), RNA_float_get(op->ptr, "mask_threshold")); BKE_id_free(bmain, new_ob_mesh); - new_ob_mesh = BKE_mesh_from_bmesh_nomain(bm, - (&(struct BMeshToMeshParams){ - .calc_object_remap = false, - }), - mesh); + new_ob_mesh = BKE_mesh_from_bmesh_nomain(bm, &bm_to_mesh_params, mesh); BM_mesh_free(bm); /* Remove the mask from the new object so it can be sculpted directly after slicing. */ CustomData_free_layers(&new_ob_mesh->vdata, CD_PAINT_MASK, new_ob_mesh->totvert); - BKE_mesh_nomain_to_mesh(new_ob_mesh, new_ob->data, new_ob); - BKE_mesh_copy_parameters_for_eval(new_ob->data, mesh); + Mesh *new_mesh = static_cast(new_ob->data); + BKE_mesh_nomain_to_mesh(new_ob_mesh, new_mesh, new_ob); + BKE_mesh_copy_parameters_for_eval(new_mesh, mesh); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, new_ob); - BKE_mesh_batch_cache_dirty_tag(new_ob->data, BKE_MESH_BATCH_DIRTY_ALL); + BKE_mesh_batch_cache_dirty_tag(new_mesh, BKE_MESH_BATCH_DIRTY_ALL); DEG_relations_tag_update(bmain); DEG_id_tag_update(&new_ob->id, ID_RECALC_GEOMETRY); - WM_event_add_notifier(C, NC_GEOM | ND_DATA, new_ob->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, new_mesh); } - BKE_mesh_nomain_to_mesh(new_mesh, ob->data, ob); + mesh = static_cast(ob->data); + BKE_mesh_nomain_to_mesh(new_mesh, mesh, ob); if (ob->mode == OB_MODE_SCULPT) { SculptSession *ss = ob->sculpt; - ss->face_sets = CustomData_get_layer_named_for_write(&((Mesh *)ob->data)->pdata, - CD_PROP_INT32, - ".sculpt_face_set", - ((Mesh *)ob->data)->totpoly); + ss->face_sets = static_cast(CustomData_get_layer_named_for_write( + &mesh->pdata, CD_PROP_INT32, ".sculpt_face_set", mesh->totpoly)); if (ss->face_sets) { /* Assign a new Face Set ID to the new faces created by the slice operation. */ - const int next_face_set_id = ED_sculpt_face_sets_find_next_available_id(ob->data); - ED_sculpt_face_sets_initialize_none_to_id(ob->data, next_face_set_id); + const int next_face_set_id = ED_sculpt_face_sets_find_next_available_id(mesh); + ED_sculpt_face_sets_initialize_none_to_id(mesh, next_face_set_id); } ED_sculpt_undo_geometry_end(ob); } - BKE_mesh_batch_cache_dirty_tag(ob->data, BKE_MESH_BATCH_DIRTY_ALL); + BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); - WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 7386fe69b6c..856918fa365 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -296,7 +296,7 @@ void MESH_OT_smooth_normals(struct wmOperatorType *ot); void MESH_OT_mod_weighted_strength(struct wmOperatorType *ot); void MESH_OT_flip_quad_tessellation(struct wmOperatorType *ot); -/* *** editmesh_mask_extract.c *** */ +/* *** editmesh_mask_extract.cc *** */ void MESH_OT_paint_mask_extract(struct wmOperatorType *ot); void MESH_OT_face_set_extract(struct wmOperatorType *ot); diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt index a165bbaf5ef..16a86564c27 100644 --- a/source/blender/editors/sculpt_paint/CMakeLists.txt +++ b/source/blender/editors/sculpt_paint/CMakeLists.txt @@ -62,26 +62,26 @@ set(SRC paint_vertex_weight_utils.c sculpt.cc sculpt_automasking.cc - sculpt_boundary.c - sculpt_brush_types.c - sculpt_cloth.c - sculpt_detail.c + sculpt_boundary.cc + sculpt_brush_types.cc + sculpt_cloth.cc + sculpt_detail.cc sculpt_dyntopo.cc sculpt_expand.cc sculpt_face_set.cc - sculpt_filter_color.c - sculpt_filter_mask.c - sculpt_filter_mesh.c + sculpt_filter_color.cc + sculpt_filter_mask.cc + sculpt_filter_mesh.cc sculpt_geodesic.cc - sculpt_mask_expand.c - sculpt_mask_init.c - sculpt_multiplane_scrape.c - sculpt_ops.c - sculpt_paint_color.c + sculpt_mask_expand.cc + sculpt_mask_init.cc + sculpt_multiplane_scrape.cc + sculpt_ops.cc + sculpt_paint_color.cc sculpt_paint_image.cc - sculpt_pose.c - sculpt_smooth.c - sculpt_transform.c + sculpt_pose.cc + sculpt_smooth.cc + sculpt_transform.cc sculpt_undo.cc sculpt_uv.c diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index b5d3e53b00c..014bc7c56ce 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -325,10 +325,10 @@ float *SCULPT_brush_deform_target_vertex_co_get(SculptSession *ss, return iter->co; } -char SCULPT_mesh_symmetry_xyz_get(Object *object) +ePaintSymmetryFlags SCULPT_mesh_symmetry_xyz_get(Object *object) { const Mesh *mesh = BKE_mesh_from_object(object); - return mesh->symmetry; + return ePaintSymmetryFlags(mesh->symmetry); } /* Sculpt Face Sets and Visibility. */ diff --git a/source/blender/editors/sculpt_paint/sculpt_boundary.c b/source/blender/editors/sculpt_paint/sculpt_boundary.cc similarity index 92% rename from source/blender/editors/sculpt_paint/sculpt_boundary.c rename to source/blender/editors/sculpt_paint/sculpt_boundary.cc index 967a4331ecd..ff925daf1f9 100644 --- a/source/blender/editors/sculpt_paint/sculpt_boundary.c +++ b/source/blender/editors/sculpt_paint/sculpt_boundary.cc @@ -28,13 +28,13 @@ #include "GPU_immediate.h" #include "GPU_state.h" -#include -#include +#include +#include #define BOUNDARY_VERTEX_NONE -1 #define BOUNDARY_STEPS_NONE -1 -typedef struct BoundaryInitialVertexFloodFillData { +struct BoundaryInitialVertexFloodFillData { PBVHVertRef initial_vertex; int initial_vertex_i; int boundary_initial_vertex_steps; @@ -42,12 +42,13 @@ typedef struct BoundaryInitialVertexFloodFillData { int boundary_initial_vertex_i; int *floodfill_steps; float radius_sq; -} BoundaryInitialVertexFloodFillData; +}; static bool boundary_initial_vertex_floodfill_cb( SculptSession *ss, PBVHVertRef from_v, PBVHVertRef to_v, bool is_duplicate, void *userdata) { - BoundaryInitialVertexFloodFillData *data = userdata; + BoundaryInitialVertexFloodFillData *data = static_cast( + userdata); 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); @@ -91,15 +92,13 @@ static PBVHVertRef sculpt_boundary_get_closest_boundary_vertex(SculptSession *ss SCULPT_floodfill_init(ss, &flood); SCULPT_floodfill_add_initial(&flood, initial_vertex); - BoundaryInitialVertexFloodFillData fdata = { - .initial_vertex = initial_vertex, - .boundary_initial_vertex = {BOUNDARY_VERTEX_NONE}, - .boundary_initial_vertex_steps = INT_MAX, - .radius_sq = radius * radius, - }; + BoundaryInitialVertexFloodFillData fdata{}; + fdata.initial_vertex = initial_vertex; + fdata.boundary_initial_vertex = {BOUNDARY_VERTEX_NONE}; + fdata.boundary_initial_vertex_steps = INT_MAX; + fdata.radius_sq = radius * radius; - fdata.floodfill_steps = MEM_calloc_arrayN( - SCULPT_vertex_count_get(ss), sizeof(int), "floodfill steps"); + fdata.floodfill_steps = MEM_cnew_array(SCULPT_vertex_count_get(ss), __func__); SCULPT_floodfill_execute(ss, &flood, boundary_initial_vertex_floodfill_cb, &fdata); SCULPT_floodfill_free(&flood); @@ -131,8 +130,8 @@ static void sculpt_boundary_index_add(SculptBoundary *boundary, boundary->verts_num++; if (boundary->verts_num >= boundary->verts_capacity) { boundary->verts_capacity += BOUNDARY_INDICES_BLOCK_SIZE; - boundary->verts = MEM_reallocN_id( - boundary->verts, boundary->verts_capacity * sizeof(PBVHVertRef), "boundary indices"); + boundary->verts = static_cast(MEM_reallocN_id( + boundary->verts, boundary->verts_capacity * sizeof(PBVHVertRef), "boundary indices")); } }; @@ -147,9 +146,10 @@ static void sculpt_boundary_preview_edge_add(SculptBoundary *boundary, if (boundary->edges_num >= boundary->edges_capacity) { boundary->edges_capacity += BOUNDARY_INDICES_BLOCK_SIZE; - boundary->edges = MEM_reallocN_id(boundary->edges, - boundary->edges_capacity * sizeof(SculptBoundaryPreviewEdge), - "boundary edges"); + boundary->edges = static_cast( + MEM_reallocN_id(boundary->edges, + boundary->edges_capacity * sizeof(SculptBoundaryPreviewEdge), + "boundary edges")); } }; @@ -196,14 +196,13 @@ static bool sculpt_boundary_is_vertex_in_editable_boundary(SculptSession *ss, /* Flood fill that adds to the boundary data all the vertices from a boundary and its duplicates. */ -typedef struct BoundaryFloodFillData { +struct BoundaryFloodFillData { SculptBoundary *boundary; GSet *included_verts; EdgeSet *preview_edges; PBVHVertRef last_visited_vertex; - -} BoundaryFloodFillData; +}; static bool boundary_floodfill_cb( SculptSession *ss, PBVHVertRef from_v, PBVHVertRef to_v, bool is_duplicate, void *userdata) @@ -211,7 +210,7 @@ static bool boundary_floodfill_cb( 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); - BoundaryFloodFillData *data = userdata; + BoundaryFloodFillData *data = static_cast(userdata); SculptBoundary *boundary = data->boundary; if (!SCULPT_vertex_is_boundary(ss, to_v)) { return false; @@ -236,14 +235,14 @@ static void sculpt_boundary_indices_init(SculptSession *ss, { const int totvert = SCULPT_vertex_count_get(ss); - boundary->verts = MEM_malloc_arrayN( - BOUNDARY_INDICES_BLOCK_SIZE, sizeof(PBVHVertRef), "boundary indices"); + boundary->verts = static_cast( + MEM_malloc_arrayN(BOUNDARY_INDICES_BLOCK_SIZE, sizeof(PBVHVertRef), __func__)); if (init_boundary_distances) { - boundary->distance = MEM_calloc_arrayN(totvert, sizeof(float), "boundary distances"); + boundary->distance = static_cast(MEM_calloc_arrayN(totvert, sizeof(float), __func__)); } - boundary->edges = MEM_malloc_arrayN( - BOUNDARY_INDICES_BLOCK_SIZE, sizeof(SculptBoundaryPreviewEdge), "boundary edges"); + boundary->edges = static_cast( + MEM_malloc_arrayN(BOUNDARY_INDICES_BLOCK_SIZE, sizeof(SculptBoundaryPreviewEdge), __func__)); GSet *included_verts = BLI_gset_int_new_ex("included verts", BOUNDARY_INDICES_BLOCK_SIZE); SculptFloodFill flood; @@ -260,12 +259,10 @@ static void sculpt_boundary_indices_init(SculptSession *ss, boundary, initial_boundary_vertex, initial_boundary_index, 0.0f, included_verts); SCULPT_floodfill_add_initial(&flood, boundary->initial_vertex); - BoundaryFloodFillData fdata = { - .boundary = boundary, - .included_verts = included_verts, - .last_visited_vertex = {BOUNDARY_VERTEX_NONE}, - - }; + BoundaryFloodFillData fdata{}; + fdata.boundary = boundary; + fdata.included_verts = included_verts; + fdata.last_visited_vertex = {BOUNDARY_VERTEX_NONE}; SCULPT_floodfill_execute(ss, &flood, boundary_floodfill_cb, &fdata); SCULPT_floodfill_free(&flood); @@ -284,7 +281,7 @@ static void sculpt_boundary_indices_init(SculptSession *ss, SCULPT_VERTEX_NEIGHBORS_ITER_END(ni); } - BLI_gset_free(included_verts, NULL); + BLI_gset_free(included_verts, nullptr); } /** @@ -302,8 +299,8 @@ static void sculpt_boundary_edit_data_init(SculptSession *ss, const bool has_duplicates = BKE_pbvh_type(ss->pbvh) == PBVH_GRIDS; - boundary->edit_info = MEM_malloc_arrayN( - totvert, sizeof(SculptBoundaryEditInfo), "Boundary edit info"); + boundary->edit_info = static_cast( + MEM_malloc_arrayN(totvert, sizeof(SculptBoundaryEditInfo), __func__)); for (int i = 0; i < totvert; i++) { boundary->edit_info[i].original_vertex_i = BOUNDARY_VERTEX_NONE; @@ -496,7 +493,7 @@ SculptBoundary *SCULPT_boundary_data_init(Object *object, SculptSession *ss = object->sculpt; if (initial_vertex.i == PBVH_REF_NONE) { - return NULL; + return nullptr; } SCULPT_vertex_random_access_ensure(ss); @@ -506,16 +503,16 @@ SculptBoundary *SCULPT_boundary_data_init(Object *object, ss, initial_vertex, radius); if (boundary_initial_vertex.i == BOUNDARY_VERTEX_NONE) { - return NULL; + return nullptr; } - /* Starting from a vertex that is the limit of a boundary is ambiguous, so return NULL instead of - * forcing a random active boundary from a corner. */ + /* Starting from a vertex that is the limit of a boundary is ambiguous, so return nullptr instead + * of forcing a random active boundary from a corner. */ if (!sculpt_boundary_is_vertex_in_editable_boundary(ss, initial_vertex)) { - return NULL; + return nullptr; } - SculptBoundary *boundary = MEM_callocN(sizeof(SculptBoundary), "Boundary edit data"); + SculptBoundary *boundary = MEM_cnew(__func__); const bool init_boundary_distances = brush ? brush->boundary_falloff_type != BRUSH_BOUNDARY_FALLOFF_CONSTANT : @@ -548,9 +545,10 @@ void SCULPT_boundary_data_free(SculptBoundary *boundary) static void sculpt_boundary_bend_data_init(SculptSession *ss, SculptBoundary *boundary) { const int totvert = SCULPT_vertex_count_get(ss); - boundary->bend.pivot_rotation_axis = MEM_calloc_arrayN( - totvert, sizeof(float[3]), "pivot rotation axis"); - boundary->bend.pivot_positions = MEM_calloc_arrayN(totvert, sizeof(float[3]), "pivot positions"); + boundary->bend.pivot_rotation_axis = static_cast( + MEM_calloc_arrayN(totvert, sizeof(float[3]), __func__)); + boundary->bend.pivot_positions = static_cast( + MEM_calloc_arrayN(totvert, sizeof(float[3]), __func__)); for (int i = 0; i < totvert; i++) { if (boundary->edit_info[i].propagation_steps_num != boundary->max_propagation_steps) { @@ -588,7 +586,8 @@ static void sculpt_boundary_bend_data_init(SculptSession *ss, SculptBoundary *bo static void sculpt_boundary_slide_data_init(SculptSession *ss, SculptBoundary *boundary) { const int totvert = SCULPT_vertex_count_get(ss); - boundary->slide.directions = MEM_calloc_arrayN(totvert, sizeof(float[3]), "slide directions"); + boundary->slide.directions = static_cast( + MEM_calloc_arrayN(totvert, sizeof(float[3]), "slide directions")); for (int i = 0; i < totvert; i++) { if (boundary->edit_info[i].propagation_steps_num != boundary->max_propagation_steps) { @@ -614,7 +613,8 @@ static void sculpt_boundary_slide_data_init(SculptSession *ss, SculptBoundary *b static void sculpt_boundary_twist_data_init(SculptSession *ss, SculptBoundary *boundary) { zero_v3(boundary->twist.pivot_position); - float(*poly_verts)[3] = MEM_malloc_arrayN(boundary->verts_num, sizeof(float[3]), "poly verts"); + float(*poly_verts)[3] = static_cast( + MEM_malloc_arrayN(boundary->verts_num, sizeof(float[3]), "poly verts")); for (int i = 0; i < boundary->verts_num; i++) { add_v3_v3(boundary->twist.pivot_position, SCULPT_vertex_co_get(ss, boundary->verts[i])); copy_v3_v3(poly_verts[i], SCULPT_vertex_co_get(ss, boundary->verts[i])); @@ -648,9 +648,9 @@ static float sculpt_boundary_displacement_from_grab_delta_get(SculptSession *ss, /* Deformation tasks callbacks. */ static void do_boundary_brush_bend_task_cb_ex(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; @@ -707,9 +707,9 @@ static void do_boundary_brush_bend_task_cb_ex(void *__restrict userdata, static void do_boundary_brush_slide_task_cb_ex(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; @@ -758,9 +758,9 @@ static void do_boundary_brush_slide_task_cb_ex(void *__restrict userdata, static void do_boundary_brush_inflate_task_cb_ex(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; @@ -809,9 +809,9 @@ static void do_boundary_brush_inflate_task_cb_ex(void *__restrict userdata, static void do_boundary_brush_grab_task_cb_ex(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; @@ -857,9 +857,9 @@ static void do_boundary_brush_grab_task_cb_ex(void *__restrict userdata, static void do_boundary_brush_twist_task_cb_ex(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; @@ -916,9 +916,9 @@ static void do_boundary_brush_twist_task_cb_ex(void *__restrict userdata, static void do_boundary_brush_smooth_task_cb_ex(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const int symmetry_pass = ss->cache->mirror_symmetry_pass; const SculptBoundary *boundary = ss->cache->boundaries[symmetry_pass]; @@ -978,7 +978,7 @@ void SCULPT_do_boundary_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totn SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); - const int symm_area = ss->cache->mirror_symmetry_pass; + const ePaintSymmetryFlags symm_area = ss->cache->mirror_symmetry_pass; if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache)) { PBVHVertRef initial_vertex; @@ -1024,12 +1024,11 @@ void SCULPT_do_boundary_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totn return; } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); diff --git a/source/blender/editors/sculpt_paint/sculpt_brush_types.c b/source/blender/editors/sculpt_paint/sculpt_brush_types.cc similarity index 93% rename from source/blender/editors/sculpt_paint/sculpt_brush_types.c rename to source/blender/editors/sculpt_paint/sculpt_brush_types.cc index c24bdba662a..777da9a0bca 100644 --- a/source/blender/editors/sculpt_paint/sculpt_brush_types.c +++ b/source/blender/editors/sculpt_paint/sculpt_brush_types.cc @@ -35,9 +35,9 @@ #include "bmesh.h" -#include -#include -#include +#include +#include +#include /* -------------------------------------------------------------------- */ /** \name SculptProjectVector @@ -45,13 +45,12 @@ * Fast-path for #project_plane_v3_v3v3 * \{ */ -typedef struct SculptProjectVector { +struct SculptProjectVector { float plane[3]; float len_sq; float len_sq_inv_neg; bool is_valid; - -} SculptProjectVector; +}; static bool plane_point_side_flip(const float co[3], const float plane[4], const bool flip) { @@ -239,7 +238,7 @@ static void do_draw_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *offset = data->offset; @@ -305,13 +304,12 @@ void SCULPT_do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) BKE_curvemapping_init(brush->curve); /* Threaded loop over nodes. */ - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .offset = offset, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.offset = offset; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -328,7 +326,7 @@ static void do_fill_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *area_no = data->area_no; @@ -416,14 +414,13 @@ void SCULPT_do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) mul_v3_fl(temp, displace); add_v3_v3(area_co, temp); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .area_no = area_no, - .area_co = area_co, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.area_no = area_no; + data.area_co = area_co; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -434,7 +431,7 @@ static void do_scrape_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *area_no = data->area_no; @@ -521,14 +518,13 @@ void SCULPT_do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod mul_v3_fl(temp, displace); add_v3_v3(area_co, temp); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .area_no = area_no, - .area_co = area_co, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.area_no = area_no; + data.area_co = area_co; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -545,7 +541,7 @@ static void do_clay_thumb_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; float(*mat)[4] = data->mat; @@ -700,16 +696,15 @@ void SCULPT_do_clay_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to float clay_strength = ss->cache->bstrength * SCULPT_clay_thumb_get_stabilized_pressure(ss->cache); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .area_no_sp = area_no_sp, - .area_co = ss->cache->location, - .mat = mat, - .clay_strength = clay_strength, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.area_no_sp = area_no_sp; + data.area_co = ss->cache->location; + data.mat = mat; + data.clay_strength = clay_strength; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -726,7 +721,7 @@ static void do_flatten_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *area_no = data->area_no; @@ -808,14 +803,13 @@ void SCULPT_do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno mul_v3_fl(temp, displace); add_v3_v3(area_co, temp); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .area_no = area_no, - .area_co = area_co, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.area_no = area_no; + data.area_co = area_co; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -828,18 +822,18 @@ void SCULPT_do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno /** \name Sculpt Clay Brush * \{ */ -typedef struct ClaySampleData { +struct ClaySampleData { float plane_dist[2]; -} ClaySampleData; +}; static void calc_clay_surface_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; - ClaySampleData *csd = tls->userdata_chunk; + ClaySampleData *csd = static_cast(tls->userdata_chunk); const float *area_no = data->area_no; const float *area_co = data->area_co; float plane[4]; @@ -877,12 +871,12 @@ static void calc_clay_surface_task_cb(void *__restrict userdata, } } -static void calc_clay_surface_reduce(const void *__restrict UNUSED(userdata), +static void calc_clay_surface_reduce(const void *__restrict /*userdata*/, void *__restrict chunk_join, void *__restrict chunk) { - ClaySampleData *join = chunk_join; - ClaySampleData *csd = chunk; + ClaySampleData *join = static_cast(chunk_join); + ClaySampleData *csd = static_cast(chunk); join->plane_dist[0] = MIN2(csd->plane_dist[0], join->plane_dist[0]); join->plane_dist[1] = MIN2(csd->plane_dist[1], join->plane_dist[1]); } @@ -891,7 +885,7 @@ static void do_clay_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *area_no = data->area_no; @@ -965,15 +959,14 @@ void SCULPT_do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no, area_co); - SculptThreadedTaskData sample_data = { - .sd = NULL, - .ob = ob, - .brush = brush, - .nodes = nodes, - .totnode = totnode, - .area_no = area_no, - .area_co = ss->cache->location, - }; + SculptThreadedTaskData sample_data{}; + sample_data.sd = nullptr; + sample_data.ob = ob; + sample_data.brush = brush; + sample_data.nodes = nodes; + sample_data.totnode = totnode; + sample_data.area_no = area_no; + sample_data.area_co = ss->cache->location; ClaySampleData csd = {{0}}; @@ -999,14 +992,13 @@ void SCULPT_do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) copy_v3_v3(area_co, ss->cache->location); add_v3_v3(area_co, temp); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .area_no = area_no, - .area_co = area_co, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.area_no = area_no; + data.area_co = area_co; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -1017,7 +1009,7 @@ static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; float(*mat)[4] = data->mat; @@ -1159,15 +1151,14 @@ void SCULPT_do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t invert_m4_m4(mat, tmat); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .area_no_sp = area_no_sp, - .area_co = area_co, - .mat = mat, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.area_no_sp = area_no_sp; + data.area_co = area_co; + data.mat = mat; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -1178,7 +1169,7 @@ static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; SculptProjectVector *spvc = data->spvc; @@ -1314,14 +1305,13 @@ void SCULPT_do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to sculpt_project_v3_cache_init(&spvc, grab_delta); } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .spvc = &spvc, - .grab_delta = grab_delta, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.spvc = &spvc; + data.grab_delta = grab_delta; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -1332,7 +1322,7 @@ static void do_thumb_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *cono = data->cono; @@ -1368,7 +1358,7 @@ static void do_thumb_brush_task_cb_ex(void *__restrict userdata, orig_data.co, sqrtf(test.dist), orig_data.no, - NULL, + nullptr, vd.mask ? *vd.mask : 0.0f, vd.vertex, thread_id, @@ -1395,13 +1385,12 @@ void SCULPT_do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta); cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .cono = cono, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.cono = cono; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -1412,7 +1401,7 @@ static void do_rotate_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float angle = data->angle; @@ -1450,7 +1439,7 @@ static void do_rotate_brush_task_cb_ex(void *__restrict userdata, orig_data.co, sqrtf(test.dist), orig_data.no, - NULL, + nullptr, vd.mask ? *vd.mask : 0.0f, vd.vertex, thread_id, @@ -1477,13 +1466,12 @@ void SCULPT_do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod static const int flip[8] = {1, -1, -1, 1, -1, 1, 1, -1}; const float angle = ss->cache->vertex_rotation * flip[ss->cache->mirror_symmetry_pass]; - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .angle = angle, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.angle = angle; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -1494,7 +1482,7 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; const Brush *brush = data->brush; @@ -1598,17 +1586,16 @@ void SCULPT_do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); - if (ss->cache->layer_displacement_factor == NULL) { - ss->cache->layer_displacement_factor = MEM_callocN(sizeof(float) * SCULPT_vertex_count_get(ss), - "layer displacement factor"); + if (ss->cache->layer_displacement_factor == nullptr) { + ss->cache->layer_displacement_factor = MEM_cnew_array(SCULPT_vertex_count_get(ss), + __func__); } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -1619,7 +1606,7 @@ static void do_inflate_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; @@ -1677,12 +1664,11 @@ void SCULPT_do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno { Brush *brush = BKE_paint_brush(&sd->paint); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -1693,7 +1679,7 @@ static void do_nudge_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *cono = data->cono; @@ -1751,13 +1737,12 @@ void SCULPT_do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta); cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .cono = cono, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.cono = cono; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -1777,7 +1762,7 @@ static void do_crease_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; SculptProjectVector *spvc = data->spvc; @@ -1878,15 +1863,14 @@ void SCULPT_do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod sculpt_project_v3_cache_init(&spvc, ss->cache->sculpt_normal_symm); /* Threaded loop over nodes. */ - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .spvc = &spvc, - .offset = offset, - .flippedbstrength = flippedbstrength, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.spvc = &spvc; + data.offset = offset; + data.flippedbstrength = flippedbstrength; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -1897,7 +1881,7 @@ static void do_pinch_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; float(*stroke_xz)[3] = data->stroke_xz; @@ -2001,13 +1985,12 @@ void SCULPT_do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode normalize_v3_v3(stroke_xz[0], mat[0]); normalize_v3_v3(stroke_xz[1], mat[2]); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .stroke_xz = stroke_xz, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.stroke_xz = stroke_xz; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -2018,7 +2001,7 @@ static void do_grab_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *grab_delta = data->grab_delta; @@ -2056,7 +2039,7 @@ static void do_grab_brush_task_cb_ex(void *__restrict userdata, orig_data.co, sqrtf(test.dist), orig_data.no, - NULL, + nullptr, vd.mask ? *vd.mask : 0.0f, vd.vertex, thread_id, @@ -2094,13 +2077,12 @@ void SCULPT_do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta); } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .grab_delta = grab_delta, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.grab_delta = grab_delta; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -2109,9 +2091,9 @@ void SCULPT_do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) static void do_elastic_deform_brush_task_cb_ex(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *grab_delta = data->grab_delta; @@ -2209,13 +2191,12 @@ void SCULPT_do_elastic_deform_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, in sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta); } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .grab_delta = grab_delta, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.grab_delta = grab_delta; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -2232,7 +2213,7 @@ static void do_draw_sharp_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *offset = data->offset; @@ -2267,7 +2248,7 @@ static void do_draw_sharp_brush_task_cb_ex(void *__restrict userdata, orig_data.co, sqrtf(test.dist), orig_data.no, - NULL, + nullptr, vd.mask ? *vd.mask : 0.0f, vd.vertex, thread_id, @@ -2301,13 +2282,12 @@ void SCULPT_do_draw_sharp_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to BKE_curvemapping_init(brush->curve); /* Threaded loop over nodes. */ - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .offset = offset, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.offset = offset; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -2324,7 +2304,7 @@ static void do_topology_slide_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; @@ -2357,7 +2337,7 @@ static void do_topology_slide_task_cb_ex(void *__restrict userdata, orig_data.co, sqrtf(test.dist), orig_data.no, - NULL, + nullptr, vd.mask ? *vd.mask : 0.0f, vd.vertex, thread_id, @@ -2488,7 +2468,7 @@ static void do_topology_relax_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = ss->cache->bstrength; @@ -2521,7 +2501,7 @@ static void do_topology_relax_task_cb_ex(void *__restrict userdata, orig_data.co, sqrtf(test.dist), orig_data.no, - NULL, + nullptr, vd.mask ? *vd.mask : 0.0f, vd.vertex, thread_id, @@ -2546,12 +2526,11 @@ void SCULPT_do_slide_relax_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t BKE_curvemapping_init(brush->curve); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -2576,7 +2555,7 @@ static void do_displacement_eraser_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = clamp_f(ss->cache->bstrength, 0.0f, 1.0f); @@ -2629,12 +2608,11 @@ void SCULPT_do_displacement_eraser_brush(Sculpt *sd, Object *ob, PBVHNode **node BKE_curvemapping_init(brush->curve); /* Threaded loop over nodes. */ - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -2651,7 +2629,7 @@ static void do_displacement_smear_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = clamp_f(ss->cache->bstrength, 0.0f, 1.0f); @@ -2743,9 +2721,9 @@ static void do_displacement_smear_brush_task_cb_ex(void *__restrict userdata, } static void do_displacement_smear_store_prev_disp_task_cb_ex( - void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int n, const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHVertexIter vd; @@ -2766,9 +2744,10 @@ void SCULPT_do_displacement_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes const int totvert = SCULPT_vertex_count_get(ss); if (!ss->cache->prev_displacement) { - ss->cache->prev_displacement = MEM_malloc_arrayN( - totvert, sizeof(float[3]), "prev displacement"); - ss->cache->limit_surface_co = MEM_malloc_arrayN(totvert, sizeof(float[3]), "limit surface co"); + ss->cache->prev_displacement = static_cast( + MEM_malloc_arrayN(totvert, sizeof(float[3]), __func__)); + ss->cache->limit_surface_co = static_cast( + MEM_malloc_arrayN(totvert, sizeof(float[3]), __func__)); for (int i = 0; i < totvert; i++) { PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); @@ -2779,12 +2758,11 @@ void SCULPT_do_displacement_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes } } /* Threaded loop over nodes. */ - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -2803,7 +2781,7 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; const Brush *brush = data->brush; @@ -2885,13 +2863,13 @@ void SCULPT_bmesh_topology_rake( for (iteration = 0; iteration <= count; iteration++) { - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .strength = factor, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.strength = factor; + TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -2909,7 +2887,7 @@ static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = ss->cache->bstrength; @@ -2958,12 +2936,11 @@ void SCULPT_do_mask_brush_draw(Sculpt *sd, Object *ob, PBVHNode **nodes, int tot Brush *brush = BKE_paint_brush(&sd->paint); /* Threaded loop over nodes. */ - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.cc similarity index 90% rename from source/blender/editors/sculpt_paint/sculpt_cloth.c rename to source/blender/editors/sculpt_paint/sculpt_cloth.cc index a5c469ca3a0..a59e4768f02 100644 --- a/source/blender/editors/sculpt_paint/sculpt_cloth.c +++ b/source/blender/editors/sculpt_paint/sculpt_cloth.cc @@ -49,9 +49,9 @@ #include "bmesh.h" -#include -#include -#include +#include +#include +#include static void cloth_brush_simulation_location_get(SculptSession *ss, const Brush *brush, @@ -75,30 +75,28 @@ PBVHNode **SCULPT_cloth_brush_affected_nodes_gather(SculptSession *ss, { BLI_assert(ss->cache); BLI_assert(brush->sculpt_tool == SCULPT_TOOL_CLOTH); - PBVHNode **nodes = NULL; + PBVHNode **nodes = nullptr; switch (brush->cloth_simulation_area_type) { case BRUSH_CLOTH_SIMULATION_AREA_LOCAL: { - SculptSearchSphereData data = { - .ss = ss, - .radius_squared = square_f(ss->cache->initial_radius * (1.0 + brush->cloth_sim_limit)), - .original = false, - .ignore_fully_ineffective = false, - .center = ss->cache->initial_location, - }; + SculptSearchSphereData data{}; + data.ss = ss; + data.radius_squared = square_f(ss->cache->initial_radius * (1.0 + brush->cloth_sim_limit)); + data.original = false; + data.ignore_fully_ineffective = false; + data.center = ss->cache->initial_location; BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, r_totnode); } break; case BRUSH_CLOTH_SIMULATION_AREA_GLOBAL: - BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, r_totnode); + BKE_pbvh_search_gather(ss->pbvh, nullptr, nullptr, &nodes, r_totnode); break; case BRUSH_CLOTH_SIMULATION_AREA_DYNAMIC: { - SculptSearchSphereData data = { - .ss = ss, - .radius_squared = square_f(ss->cache->radius * (1.0 + brush->cloth_sim_limit)), - .original = false, - .ignore_fully_ineffective = false, - .center = ss->cache->location, - }; + SculptSearchSphereData data{}; + data.ss = ss; + data.radius_squared = square_f(ss->cache->radius * (1.0 + brush->cloth_sim_limit)); + data.original = false; + data.ignore_fully_ineffective = false; + data.center = ss->cache->location; BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, r_totnode); } break; } @@ -159,10 +157,10 @@ static void cloth_brush_reallocate_constraints(SculptClothSimulation *cloth_sim) { if (cloth_sim->tot_length_constraints >= cloth_sim->capacity_length_constraints) { cloth_sim->capacity_length_constraints += CLOTH_LENGTH_CONSTRAINTS_BLOCK; - cloth_sim->length_constraints = MEM_reallocN_id(cloth_sim->length_constraints, - cloth_sim->capacity_length_constraints * - sizeof(SculptClothLengthConstraint), - "length constraints"); + cloth_sim->length_constraints = static_cast(MEM_reallocN_id( + cloth_sim->length_constraints, + cloth_sim->capacity_length_constraints * sizeof(SculptClothLengthConstraint), + "length constraints")); } } @@ -289,10 +287,11 @@ static void cloth_brush_add_deformation_constraint(SculptClothSimulation *cloth_ cloth_brush_reallocate_constraints(cloth_sim); } -static void do_cloth_brush_build_constraints_task_cb_ex( - void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) +static void do_cloth_brush_build_constraints_task_cb_ex(void *__restrict userdata, + const int n, + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; PBVHNode *node = data->nodes[n]; @@ -305,16 +304,16 @@ static void do_cloth_brush_build_constraints_task_cb_ex( PBVHVertexIter vd; - const bool pin_simulation_boundary = ss->cache != NULL && brush != NULL && + const bool pin_simulation_boundary = ss->cache != nullptr && brush != nullptr && brush->flag2 & BRUSH_CLOTH_PIN_SIMULATION_BOUNDARY && brush->cloth_simulation_area_type != BRUSH_CLOTH_SIMULATION_AREA_DYNAMIC; - const bool use_persistent = brush != NULL && brush->flag & BRUSH_PERSISTENT; + const bool use_persistent = brush != nullptr && brush->flag & BRUSH_PERSISTENT; - /* Brush can be NULL in tools that use the solver without relying of constraints with deformation - * positions. */ - const bool cloth_is_deform_brush = ss->cache != NULL && brush != NULL && + /* Brush can be nullptr in tools that use the solver without relying of constraints with + * deformation positions. */ + const bool cloth_is_deform_brush = ss->cache != nullptr && brush != nullptr && SCULPT_is_cloth_deform_brush(brush); const bool use_falloff_plane = brush->cloth_force_falloff_type == @@ -417,7 +416,7 @@ static void do_cloth_brush_build_constraints_task_cb_ex( BKE_pbvh_vertex_iter_end; } -static void cloth_brush_apply_force_to_vertex(SculptSession *UNUSED(ss), +static void cloth_brush_apply_force_to_vertex(SculptSession * /*ss*/, SculptClothSimulation *cloth_sim, const float force[3], const int vertex_index) @@ -429,7 +428,7 @@ static void do_cloth_brush_apply_forces_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; SculptClothSimulation *cloth_sim = ss->cache->cloth_sim; @@ -589,7 +588,7 @@ static void do_cloth_brush_apply_forces_task_cb_ex(void *__restrict userdata, static ListBase *cloth_brush_collider_cache_create(Object *object, Depsgraph *depsgraph) { - ListBase *cache = NULL; + ListBase *cache = nullptr; DEGObjectIterSettings deg_iter_settings = {0}; deg_iter_settings.depsgraph = depsgraph; deg_iter_settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE | @@ -608,11 +607,11 @@ static ListBase *cloth_brush_collider_cache_create(Object *object, Depsgraph *de if (!cmd->bvhtree) { continue; } - if (cache == NULL) { - cache = MEM_callocN(sizeof(ListBase), "ColliderCache array"); + if (cache == nullptr) { + cache = MEM_cnew(__func__); } - ColliderCache *col = MEM_callocN(sizeof(ColliderCache), "ColliderCache"); + ColliderCache *col = MEM_cnew(__func__); col->ob = ob; col->collmd = cmd; collision_move_object(cmd, 1.0, 0.0, true); @@ -622,10 +621,10 @@ static ListBase *cloth_brush_collider_cache_create(Object *object, Depsgraph *de return cache; } -typedef struct ClothBrushCollision { +struct ClothBrushCollision { CollisionModifierData *col_data; - struct IsectRayPrecalc isect_precalc; -} ClothBrushCollision; + IsectRayPrecalc isect_precalc; +}; static void cloth_brush_collision_cb(void *userdata, int index, @@ -644,7 +643,7 @@ static void cloth_brush_collision_cb(void *userdata, float dist = 0.0f; bool tri_hit = isect_ray_tri_watertight_v3( - ray->origin, &col->isect_precalc, UNPACK3(tri), &dist, NULL); + ray->origin, &col->isect_precalc, UNPACK3(tri), &dist, nullptr); normal_tri_v3(no, UNPACK3(tri)); madd_v3_v3v3fl(co, ray->origin, ray->direction, dist); @@ -669,7 +668,8 @@ static void cloth_brush_solve_collision(Object *object, float obmat_inv[4][4]; invert_m4_m4(obmat_inv, object->object_to_world); - for (collider_cache = cloth_sim->collider_list->first; collider_cache; + for (collider_cache = static_cast(cloth_sim->collider_list->first); + collider_cache; collider_cache = collider_cache->next) { float ray_start[3], ray_normal[3]; float pos_world_space[3], prev_pos_world_space[3]; @@ -720,10 +720,11 @@ static void cloth_brush_solve_collision(Object *object, } } -static void do_cloth_brush_solve_simulation_task_cb_ex( - void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) +static void do_cloth_brush_solve_simulation_task_cb_ex(void *__restrict userdata, + const int n, + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; @@ -771,7 +772,7 @@ static void do_cloth_brush_solve_simulation_task_cb_ex( madd_v3_v3fl(cloth_sim->pos[i], pos_diff, mask_v); madd_v3_v3fl(cloth_sim->pos[i], cloth_sim->acceleration[i], mask_v); - if (cloth_sim->collider_list != NULL) { + if (cloth_sim->collider_list != nullptr) { cloth_brush_solve_collision(data->ob, cloth_sim, i); } @@ -910,14 +911,13 @@ void SCULPT_cloth_brush_do_simulation_step( cloth_brush_satisfy_constraints(ss, brush, cloth_sim); /* Solve the simulation and write the final step to the mesh. */ - SculptThreadedTaskData solve_simulation_data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .cloth_time_step = CLOTH_SIMULATION_TIME_STEP, - .cloth_sim = cloth_sim, - }; + SculptThreadedTaskData solve_simulation_data{}; + solve_simulation_data.sd = sd; + solve_simulation_data.ob = ob; + solve_simulation_data.brush = brush; + solve_simulation_data.nodes = nodes; + solve_simulation_data.cloth_time_step = CLOTH_SIMULATION_TIME_STEP; + solve_simulation_data.cloth_sim = cloth_sim; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -937,15 +937,14 @@ static void cloth_brush_apply_brush_foces(Sculpt *sd, Object *ob, PBVHNode **nod float imat[4][4]; float offset[3]; - SculptThreadedTaskData apply_forces_data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .area_no = area_no, - .area_co = area_co, - .mat = imat, - }; + SculptThreadedTaskData apply_forces_data{}; + apply_forces_data.sd = sd; + apply_forces_data.ob = ob; + apply_forces_data.brush = brush; + apply_forces_data.nodes = nodes; + apply_forces_data.area_no = area_no; + apply_forces_data.area_co = area_co; + apply_forces_data.mat = imat; BKE_curvemapping_init(brush->curve); @@ -1016,10 +1015,10 @@ static void cloth_sim_initialize_default_node_state(SculptSession *ss, { PBVHNode **nodes; int totnode; - BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); + BKE_pbvh_search_gather(ss->pbvh, nullptr, nullptr, &nodes, &totnode); - cloth_sim->node_state = MEM_malloc_arrayN( - totnode, sizeof(eSculptClothNodeSimState), "node sim state"); + cloth_sim->node_state = static_cast( + MEM_malloc_arrayN(totnode, sizeof(eSculptClothNodeSimState), "node sim state")); cloth_sim->node_state_index = BLI_ghash_ptr_new("node sim state indices"); for (int i = 0; i < totnode; i++) { cloth_sim->node_state[i] = SCULPT_CLOTH_NODE_UNINITIALIZED; @@ -1039,34 +1038,27 @@ SculptClothSimulation *SCULPT_cloth_brush_simulation_create(Object *ob, const int totverts = SCULPT_vertex_count_get(ss); SculptClothSimulation *cloth_sim; - cloth_sim = MEM_callocN(sizeof(SculptClothSimulation), "cloth constraints"); + cloth_sim = MEM_cnew(__func__); - cloth_sim->length_constraints = MEM_callocN(sizeof(SculptClothLengthConstraint) * - CLOTH_LENGTH_CONSTRAINTS_BLOCK, - "cloth length constraints"); + cloth_sim->length_constraints = MEM_cnew_array( + CLOTH_LENGTH_CONSTRAINTS_BLOCK, __func__); cloth_sim->capacity_length_constraints = CLOTH_LENGTH_CONSTRAINTS_BLOCK; - cloth_sim->acceleration = MEM_calloc_arrayN( - totverts, sizeof(float[3]), "cloth sim acceleration"); - cloth_sim->pos = MEM_calloc_arrayN(totverts, sizeof(float[3]), "cloth sim pos"); - cloth_sim->prev_pos = MEM_calloc_arrayN(totverts, sizeof(float[3]), "cloth sim prev pos"); - cloth_sim->last_iteration_pos = MEM_calloc_arrayN( - totverts, sizeof(float[3]), "cloth sim last iteration pos"); - cloth_sim->init_pos = MEM_calloc_arrayN(totverts, sizeof(float[3]), "cloth sim init pos"); - cloth_sim->init_no = MEM_calloc_arrayN(totverts, sizeof(float[3]), "cloth sim init normals"); - cloth_sim->length_constraint_tweak = MEM_calloc_arrayN( - totverts, sizeof(float), "cloth sim length tweak"); + cloth_sim->acceleration = MEM_cnew_array(totverts, __func__); + cloth_sim->pos = MEM_cnew_array(totverts, __func__); + cloth_sim->prev_pos = MEM_cnew_array(totverts, __func__); + cloth_sim->last_iteration_pos = MEM_cnew_array(totverts, __func__); + cloth_sim->init_pos = MEM_cnew_array(totverts, __func__); + cloth_sim->init_no = MEM_cnew_array(totverts, __func__); + cloth_sim->length_constraint_tweak = MEM_cnew_array(totverts, __func__); if (needs_deform_coords) { - cloth_sim->deformation_pos = MEM_calloc_arrayN( - totverts, sizeof(float[3]), "cloth sim deformation positions"); - cloth_sim->deformation_strength = MEM_calloc_arrayN( - totverts, sizeof(float), "cloth sim deformation strength"); + cloth_sim->deformation_pos = MEM_cnew_array(totverts, __func__); + cloth_sim->deformation_strength = MEM_cnew_array(totverts, __func__); } if (cloth_softbody_strength > 0.0f) { - cloth_sim->softbody_pos = MEM_calloc_arrayN( - totverts, sizeof(float[3]), "cloth sim softbody pos"); + cloth_sim->softbody_pos = MEM_cnew_array(totverts, __func__); } cloth_sim->mass = cloth_mass; @@ -1104,15 +1096,15 @@ void SCULPT_cloth_brush_ensure_nodes_constraints( cloth_sim->created_length_constraints = BLI_edgeset_new("created length constraints"); - SculptThreadedTaskData build_constraints_data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .cloth_sim = cloth_sim, - .cloth_sim_initial_location = initial_location, - .cloth_sim_radius = radius, - }; + SculptThreadedTaskData build_constraints_data{}; + build_constraints_data.sd = sd; + build_constraints_data.ob = ob; + build_constraints_data.brush = brush; + build_constraints_data.nodes = nodes; + build_constraints_data.cloth_sim = cloth_sim; + build_constraints_data.cloth_sim_initial_location = initial_location; + build_constraints_data.cloth_sim_radius = radius; + BLI_task_parallel_range( 0, totnode, &build_constraints_data, do_cloth_brush_build_constraints_task_cb_ex, &settings); @@ -1122,8 +1114,8 @@ void SCULPT_cloth_brush_ensure_nodes_constraints( void SCULPT_cloth_brush_simulation_init(SculptSession *ss, SculptClothSimulation *cloth_sim) { const int totverts = SCULPT_vertex_count_get(ss); - const bool has_deformation_pos = cloth_sim->deformation_pos != NULL; - const bool has_softbody_pos = cloth_sim->softbody_pos != NULL; + const bool has_deformation_pos = cloth_sim->deformation_pos != nullptr; + const bool has_softbody_pos = cloth_sim->softbody_pos != nullptr; for (int i = 0; i < totverts; i++) { PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); @@ -1232,7 +1224,7 @@ void SCULPT_do_cloth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode SCULPT_cloth_brush_do_simulation_step(sd, ob, ss->cache->cloth_sim, nodes, totnode); } -void SCULPT_cloth_simulation_free(struct SculptClothSimulation *cloth_sim) +void SCULPT_cloth_simulation_free(SculptClothSimulation *cloth_sim) { MEM_SAFE_FREE(cloth_sim->pos); MEM_SAFE_FREE(cloth_sim->last_iteration_pos); @@ -1246,7 +1238,7 @@ void SCULPT_cloth_simulation_free(struct SculptClothSimulation *cloth_sim) MEM_SAFE_FREE(cloth_sim->init_no); MEM_SAFE_FREE(cloth_sim->deformation_strength); MEM_SAFE_FREE(cloth_sim->node_state); - BLI_ghash_free(cloth_sim->node_state_index, NULL, NULL); + BLI_ghash_free(cloth_sim->node_state_index, nullptr, nullptr); if (cloth_sim->collider_list) { BKE_collider_cache_free(&cloth_sim->collider_list); } @@ -1339,7 +1331,7 @@ static EnumPropertyItem prop_cloth_filter_type[] = { 0, "Scale", "Scales the mesh as a soft body using the origin of the object as scale"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static EnumPropertyItem prop_cloth_filter_orientation_items[] = { @@ -1358,7 +1350,7 @@ static EnumPropertyItem prop_cloth_filter_orientation_items[] = { 0, "View", "Use the view axis to limit the force and set the gravity direction"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; typedef enum eClothFilterForceAxis { @@ -1371,7 +1363,7 @@ static EnumPropertyItem prop_cloth_filter_force_axis_items[] = { {CLOTH_FILTER_FORCE_X, "X", 0, "X", "Apply force in the X axis"}, {CLOTH_FILTER_FORCE_Y, "Y", 0, "Y", "Apply force in the Y axis"}, {CLOTH_FILTER_FORCE_Z, "Z", 0, "Z", "Apply force in the Z axis"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static bool cloth_filter_is_deformation_filter(eSculptClothFilterType filter_type) @@ -1400,21 +1392,21 @@ static void cloth_filter_apply_forces_to_vertices(const int v_index, copy_v3_v3(final_force, force); SCULPT_filter_zero_disabled_axis_components(final_force, filter_cache); add_v3_v3(final_force, gravity); - cloth_brush_apply_force_to_vertex(NULL, filter_cache->cloth_sim, final_force, v_index); + cloth_brush_apply_force_to_vertex(nullptr, filter_cache->cloth_sim, final_force, v_index); } static void cloth_filter_apply_forces_task_cb(void *__restrict userdata, const int i, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); Sculpt *sd = data->sd; SculptSession *ss = data->ob->sculpt; PBVHNode *node = data->nodes[i]; SculptClothSimulation *cloth_sim = ss->filter_cache->cloth_sim; - const eSculptClothFilterType filter_type = data->filter_type; + const eSculptClothFilterType filter_type = eSculptClothFilterType(data->filter_type); const bool is_deformation_filter = cloth_filter_is_deformation_filter(filter_type); float sculpt_gravity[3] = {0.0f}; @@ -1530,13 +1522,12 @@ static int sculpt_cloth_filter_modal(bContext *C, wmOperator *op, const wmEvent copy_v3_v3(ss->filter_cache->cloth_sim->pos[i], SCULPT_vertex_co_get(ss, vertex)); } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = ss->filter_cache->nodes, - .filter_type = filter_type, - .filter_strength = filter_strength, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = ss->filter_cache->nodes; + data.filter_type = filter_type; + data.filter_strength = filter_strength; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->totnode); @@ -1565,10 +1556,10 @@ static int sculpt_cloth_filter_invoke(bContext *C, wmOperator *op, const wmEvent Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = ob->sculpt; - const eSculptClothFilterType filter_type = RNA_enum_get(op->ptr, "type"); + const eSculptClothFilterType filter_type = eSculptClothFilterType(RNA_enum_get(op->ptr, "type")); /* Update the active vertex */ - float mval_fl[2] = {UNPACK2(event->mval)}; + float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])}; SculptCursorGeometryInfo sgi; SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false); @@ -1583,7 +1574,7 @@ static int sculpt_cloth_filter_invoke(bContext *C, wmOperator *op, const wmEvent SCULPT_filter_cache_init( C, ob, sd, SCULPT_UNDO_COORDS, event->mval, RNA_float_get(op->ptr, "area_normal_radius")); - ss->filter_cache->automasking = SCULPT_automasking_cache_init(sd, NULL, ob); + ss->filter_cache->automasking = SCULPT_automasking_cache_init(sd, nullptr, ob); const float cloth_mass = RNA_float_get(op->ptr, "cloth_mass"); const float cloth_damping = RNA_float_get(op->ptr, "cloth_damping"); @@ -1622,14 +1613,15 @@ static int sculpt_cloth_filter_invoke(bContext *C, wmOperator *op, const wmEvent ss->filter_cache->enabled_force_axis[1] = force_axis & CLOTH_FILTER_FORCE_Y; ss->filter_cache->enabled_force_axis[2] = force_axis & CLOTH_FILTER_FORCE_Z; - SculptFilterOrientation orientation = RNA_enum_get(op->ptr, "orientation"); + SculptFilterOrientation orientation = SculptFilterOrientation( + RNA_enum_get(op->ptr, "orientation")); ss->filter_cache->orientation = orientation; WM_event_add_modal_handler(C, op); return OPERATOR_RUNNING_MODAL; } -void SCULPT_OT_cloth_filter(struct wmOperatorType *ot) +void SCULPT_OT_cloth_filter(wmOperatorType *ot) { /* Identifiers. */ ot->name = "Filter Cloth"; diff --git a/source/blender/editors/sculpt_paint/sculpt_detail.c b/source/blender/editors/sculpt_paint/sculpt_detail.cc similarity index 92% rename from source/blender/editors/sculpt_paint/sculpt_detail.c rename to source/blender/editors/sculpt_paint/sculpt_detail.cc index 0e46fd50f3b..f631eb890a8 100644 --- a/source/blender/editors/sculpt_paint/sculpt_detail.c +++ b/source/blender/editors/sculpt_paint/sculpt_detail.cc @@ -37,21 +37,21 @@ #include "RNA_access.h" #include "RNA_define.h" -#include -#include +#include +#include /* -------------------------------------------------------------------- */ /** \name Internal Utilities * \{ */ -typedef struct { +struct SculptDetailRaycastData { const float *ray_start; bool hit; float depth; float edge_length; - struct IsectRayPrecalc isect_precalc; -} SculptDetailRaycastData; + IsectRayPrecalc isect_precalc; +}; static bool sculpt_and_constant_or_manual_detail_poll(bContext *C) { @@ -85,7 +85,7 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op) int totnodes; PBVHNode **nodes; - BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnodes); + BKE_pbvh_search_gather(ss->pbvh, nullptr, nullptr, &nodes, &totnodes); if (!totnodes) { return OPERATOR_CANCELLED; @@ -107,10 +107,10 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *op) BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail); SCULPT_undo_push_begin(ob, op); - SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_COORDS); + SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_COORDS); while (BKE_pbvh_bmesh_update_topology( - ss->pbvh, PBVH_Collapse | PBVH_Subdivide, center, NULL, size, false, false)) { + ss->pbvh, PBVH_Collapse | PBVH_Subdivide, center, nullptr, size, false, false)) { for (int i = 0; i < totnodes; i++) { BKE_pbvh_node_mark_topology_update(nodes[i]); } @@ -155,21 +155,21 @@ typedef enum eSculptSampleDetailModeTypes { static EnumPropertyItem prop_sculpt_sample_detail_mode_types[] = { {SAMPLE_DETAIL_DYNTOPO, "DYNTOPO", 0, "Dyntopo", "Sample dyntopo detail"}, {SAMPLE_DETAIL_VOXEL, "VOXEL", 0, "Voxel", "Sample mesh voxel size"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static void sample_detail_voxel(bContext *C, ViewContext *vc, const int mval[2]) { Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Object *ob = vc->obact; - Mesh *mesh = ob->data; + Mesh *mesh = static_cast(ob->data); SculptSession *ss = ob->sculpt; SculptCursorGeometryInfo sgi; SCULPT_vertex_random_access_ensure(ss); /* Update the active vertex. */ - const float mval_fl[2] = {UNPACK2(mval)}; + const float mval_fl[2] = {float(mval[0]), float(mval[1])}; SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false); BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, false); @@ -185,14 +185,14 @@ static void sample_detail_voxel(bContext *C, ViewContext *vc, const int mval[2]) } SCULPT_VERTEX_NEIGHBORS_ITER_END(ni); if (tot > 0) { - mesh->remesh_voxel_size = edge_length / (float)tot; + mesh->remesh_voxel_size = edge_length / float(tot); } } static void sculpt_raycast_detail_cb(PBVHNode *node, void *data_v, float *tmin) { if (BKE_pbvh_node_get_tmin(node) < *tmin) { - SculptDetailRaycastData *srd = data_v; + SculptDetailRaycastData *srd = static_cast(data_v); if (BKE_pbvh_bmesh_node_raycast_detail( node, srd->ray_start, &srd->isect_precalc, &srd->depth, &srd->edge_length)) { srd->hit = true; @@ -209,7 +209,7 @@ static void sample_detail_dyntopo(bContext *C, ViewContext *vc, const int mval[2 SCULPT_stroke_modifiers_check(C, ob, brush); - const float mval_fl[2] = {UNPACK2(mval)}; + const float mval_fl[2] = {float(mval[0]), float(mval[1])}; float ray_start[3], ray_end[3], ray_normal[3]; float depth = SCULPT_raycast_init(vc, mval_fl, ray_start, ray_end, ray_normal, false); @@ -233,8 +233,8 @@ static int sample_detail(bContext *C, const int event_xy[2], int mode) /* Find 3D view to pick from. */ bScreen *screen = CTX_wm_screen(C); ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_VIEW3D, event_xy); - ARegion *region = (area) ? BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, event_xy) : NULL; - if (region == NULL) { + ARegion *region = (area) ? BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, event_xy) : nullptr; + if (region == nullptr) { return OPERATOR_CANCELLED; } @@ -249,7 +249,7 @@ static int sample_detail(bContext *C, const int event_xy[2], int mode) ED_view3d_viewcontext_init(C, &vc, depsgraph); Object *ob = vc.obact; - if (ob == NULL) { + if (ob == nullptr) { return OPERATOR_CANCELLED; } @@ -298,7 +298,7 @@ static int sculpt_sample_detail_size_exec(bContext *C, wmOperator *op) return sample_detail(C, ss_co, mode); } -static int sculpt_sample_detail_size_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e)) +static int sculpt_sample_detail_size_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { ED_workspace_status_text(C, TIP_("Click on the mesh to set the detail")); WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_EYEDROPPER); @@ -316,8 +316,8 @@ static int sculpt_sample_detail_size_modal(bContext *C, wmOperator *op, const wm RNA_int_set_array(op->ptr, "location", event->xy); WM_cursor_modal_restore(CTX_wm_window(C)); - ED_workspace_status_text(C, NULL); - WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL); + ED_workspace_status_text(C, nullptr); + WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, nullptr); return OPERATOR_FINISHED; } @@ -325,7 +325,7 @@ static int sculpt_sample_detail_size_modal(bContext *C, wmOperator *op, const wm case EVT_ESCKEY: case RIGHTMOUSE: { WM_cursor_modal_restore(CTX_wm_window(C)); - ED_workspace_status_text(C, NULL); + ED_workspace_status_text(C, nullptr); return OPERATOR_CANCELLED; } @@ -352,7 +352,7 @@ void SCULPT_OT_sample_detail_size(wmOperatorType *ot) RNA_def_int_array(ot->srna, "location", 2, - NULL, + nullptr, 0, SHRT_MAX, "Location", @@ -409,12 +409,12 @@ static void sculpt_detail_size_set_radial_control(bContext *C) RNA_string_set(&props_ptr, "data_path_primary", "tool_settings.sculpt.detail_size"); } - WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, NULL); + WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, nullptr); WM_operator_properties_free(&props_ptr); } -static int sculpt_set_detail_size_exec(bContext *C, wmOperator *UNUSED(op)) +static int sculpt_set_detail_size_exec(bContext *C, wmOperator * /*op*/) { sculpt_detail_size_set_radial_control(C); @@ -446,7 +446,7 @@ void SCULPT_OT_set_detail_size(wmOperatorType *ot) #define DETAIL_SIZE_DELTA_SPEED 0.08f #define DETAIL_SIZE_DELTA_ACCURATE_SPEED 0.004f -typedef struct DyntopoDetailSizeEditCustomData { +struct DyntopoDetailSizeEditCustomData { void *draw_handle; Object *active_object; @@ -465,7 +465,7 @@ typedef struct DyntopoDetailSizeEditCustomData { float preview_tri[3][3]; float gizmo_mat[4][4]; -} DyntopoDetailSizeEditCustomData; +}; static void dyntopo_detail_size_parallel_lines_draw(uint pos3d, DyntopoDetailSizeEditCustomData *cd, @@ -485,7 +485,7 @@ static void dyntopo_detail_size_parallel_lines_draw(uint pos3d, object_space_constant_detail *= 0.7f; const float total_len = len_v3v3(cd->preview_tri[0], cd->preview_tri[1]); - const int tot_lines = (int)(total_len / object_space_constant_detail) + 1; + const int tot_lines = int(total_len / object_space_constant_detail) + 1; const float tot_lines_fl = total_len / object_space_constant_detail; float spacing_disp[3]; sub_v3_v3v3(spacing_disp, end_co, start_co); @@ -499,10 +499,10 @@ static void dyntopo_detail_size_parallel_lines_draw(uint pos3d, for (int i = 0; i < tot_lines; i++) { float line_length; if (flip) { - line_length = total_len * ((float)i / (float)tot_lines_fl); + line_length = total_len * (float(i) / float(tot_lines_fl)); } else { - line_length = total_len * (1.0f - ((float)i / (float)tot_lines_fl)); + line_length = total_len * (1.0f - (float(i) / float(tot_lines_fl))); } float line_start[3]; copy_v3_v3(line_start, start_co); @@ -515,11 +515,9 @@ static void dyntopo_detail_size_parallel_lines_draw(uint pos3d, immEnd(); } -static void dyntopo_detail_size_edit_draw(const bContext *UNUSED(C), - ARegion *UNUSED(ar), - void *arg) +static void dyntopo_detail_size_edit_draw(const bContext * /*C*/, ARegion * /*region*/, void *arg) { - DyntopoDetailSizeEditCustomData *cd = arg; + DyntopoDetailSizeEditCustomData *cd = static_cast(arg); GPU_blend(GPU_BLEND_ALPHA); GPU_line_smooth(true); @@ -567,11 +565,12 @@ static void dyntopo_detail_size_edit_cancel(bContext *C, wmOperator *op) Object *active_object = CTX_data_active_object(C); SculptSession *ss = active_object->sculpt; ARegion *region = CTX_wm_region(C); - DyntopoDetailSizeEditCustomData *cd = op->customdata; + DyntopoDetailSizeEditCustomData *cd = static_cast( + op->customdata); ED_region_draw_cb_exit(region->type, cd->draw_handle); ss->draw_faded_cursor = false; MEM_freeN(op->customdata); - ED_workspace_status_text(C, NULL); + ED_workspace_status_text(C, nullptr); } static void dyntopo_detail_size_sample_from_surface(Object *ob, @@ -602,7 +601,7 @@ static void dyntopo_detail_size_sample_from_surface(Object *ob, static void dyntopo_detail_size_update_from_mouse_delta(DyntopoDetailSizeEditCustomData *cd, const wmEvent *event) { - const float mval[2] = {event->mval[0], event->mval[1]}; + const float mval[2] = {float(event->mval[0]), float(event->mval[1])}; float detail_size_delta; if (cd->accurate_mode) { @@ -633,7 +632,8 @@ static int dyntopo_detail_size_edit_modal(bContext *C, wmOperator *op, const wmE Object *active_object = CTX_data_active_object(C); SculptSession *ss = active_object->sculpt; ARegion *region = CTX_wm_region(C); - DyntopoDetailSizeEditCustomData *cd = op->customdata; + DyntopoDetailSizeEditCustomData *cd = static_cast( + op->customdata); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; /* Cancel modal operator */ @@ -653,7 +653,7 @@ static int dyntopo_detail_size_edit_modal(bContext *C, wmOperator *op, const wmE ss->draw_faded_cursor = false; MEM_freeN(op->customdata); ED_region_tag_redraw(region); - ED_workspace_status_text(C, NULL); + ED_workspace_status_text(C, nullptr); return OPERATOR_FINISHED; } @@ -696,8 +696,7 @@ static int dyntopo_detail_size_edit_invoke(bContext *C, wmOperator *op, const wm Object *active_object = CTX_data_active_object(C); Brush *brush = BKE_paint_brush(&sd->paint); - DyntopoDetailSizeEditCustomData *cd = MEM_callocN(sizeof(DyntopoDetailSizeEditCustomData), - "Dyntopo Detail Size Edit OP Custom Data"); + DyntopoDetailSizeEditCustomData *cd = MEM_cnew(__func__); /* Initial operator Custom Data setup. */ cd->draw_handle = ED_region_draw_cb_activate( diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_color.c b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc similarity index 93% rename from source/blender/editors/sculpt_paint/sculpt_filter_color.c rename to source/blender/editors/sculpt_paint/sculpt_filter_color.cc index 0c0194da4e2..628ad0ff0fc 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_color.c +++ b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc @@ -30,10 +30,10 @@ #include "RNA_access.h" #include "RNA_define.h" -#include -#include +#include +#include -typedef enum eSculptColorFilterTypes { +enum eSculptColorFilterTypes { COLOR_FILTER_FILL, COLOR_FILTER_HUE, COLOR_FILTER_SATURATION, @@ -44,7 +44,7 @@ typedef enum eSculptColorFilterTypes { COLOR_FILTER_GREEN, COLOR_FILTER_BLUE, COLOR_FILTER_SMOOTH, -} eSculptColorFilterTypes; +}; static EnumPropertyItem prop_color_filter_types[] = { {COLOR_FILTER_FILL, "FILL", 0, "Fill", "Fill with a specific color"}, @@ -60,14 +60,14 @@ static EnumPropertyItem prop_color_filter_types[] = { {COLOR_FILTER_RED, "RED", 0, "Red", "Change red channel"}, {COLOR_FILTER_GREEN, "GREEN", 0, "Green", "Change green channel"}, {COLOR_FILTER_BLUE, "BLUE", 0, "Blue", "Change blue channel"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static void color_filter_task_cb(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const int mode = data->filter_type; @@ -222,8 +222,8 @@ 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 = MEM_malloc_arrayN( - totvert, sizeof(float) * 4, "ss->filter_cache->pre_smoothed_color"); + ss->filter_cache->pre_smoothed_color = static_cast( + MEM_malloc_arrayN(totvert, sizeof(float[4]), __func__)); } for (int i = 0; i < totvert; i++) { @@ -248,7 +248,7 @@ static void sculpt_color_presmooth_init(SculptSession *ss) SCULPT_VERTEX_NEIGHBORS_ITER_END(ni); if (total > 0) { - mul_v4_fl(avg, 1.0f / (float)total); + mul_v4_fl(avg, 1.0f / float(total)); interp_v4_v4v4(ss->filter_cache->pre_smoothed_color[i], ss->filter_cache->pre_smoothed_color[i], avg, @@ -288,14 +288,13 @@ static int sculpt_color_filter_modal(bContext *C, wmOperator *op, const wmEvent sculpt_color_presmooth_init(ss); } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = ss->filter_cache->nodes, - .filter_type = mode, - .filter_strength = filter_strength, - .filter_fill_color = fill_color, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = ss->filter_cache->nodes; + data.filter_type = mode; + data.filter_strength = filter_strength; + data.filter_fill_color = fill_color; TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); @@ -319,14 +318,14 @@ static int sculpt_color_filter_invoke(bContext *C, wmOperator *op, const wmEvent v3d->shading.color_type = V3D_SHADING_VERTEX_COLOR; } - const bool use_automasking = SCULPT_is_automasking_enabled(sd, ss, NULL); + const bool use_automasking = SCULPT_is_automasking_enabled(sd, ss, nullptr); if (use_automasking) { /* Increment stroke id for auto-masking system. */ SCULPT_stroke_id_next(ob); /* Update the active face set manually as the paint cursor is not enabled when using the Mesh * Filter Tool. */ - float mval_fl[2] = {UNPACK2(event->mval)}; + float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])}; SculptCursorGeometryInfo sgi; SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false); } @@ -352,14 +351,14 @@ static int sculpt_color_filter_invoke(bContext *C, wmOperator *op, const wmEvent C, ob, sd, SCULPT_UNDO_COLOR, event->mval, RNA_float_get(op->ptr, "area_normal_radius")); FilterCache *filter_cache = ss->filter_cache; filter_cache->active_face_set = SCULPT_FACE_SET_NONE; - filter_cache->automasking = SCULPT_automasking_cache_init(sd, NULL, ob); + filter_cache->automasking = SCULPT_automasking_cache_init(sd, nullptr, ob); ED_paint_tool_update_sticky_shading_color(C, ob); WM_event_add_modal_handler(C, op); return OPERATOR_RUNNING_MODAL; } -void SCULPT_OT_color_filter(struct wmOperatorType *ot) +void SCULPT_OT_color_filter(wmOperatorType *ot) { /* identifiers */ ot->name = "Filter Color"; @@ -379,6 +378,6 @@ void SCULPT_OT_color_filter(struct wmOperatorType *ot) RNA_def_enum(ot->srna, "type", prop_color_filter_types, COLOR_FILTER_HUE, "Filter Type", ""); PropertyRNA *prop = RNA_def_float_color( - ot->srna, "fill_color", 3, NULL, 0.0f, FLT_MAX, "Fill Color", "", 0.0f, 1.0f); + ot->srna, "fill_color", 3, nullptr, 0.0f, FLT_MAX, "Fill Color", "", 0.0f, 1.0f); RNA_def_property_subtype(prop, PROP_COLOR_GAMMA); } diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mask.c b/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc similarity index 90% rename from source/blender/editors/sculpt_paint/sculpt_filter_mask.c rename to source/blender/editors/sculpt_paint/sculpt_filter_mask.cc index 8e199a72858..3ffc69f9366 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mask.c +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mask.cc @@ -30,17 +30,17 @@ #include "bmesh.h" -#include -#include +#include +#include -typedef enum eSculptMaskFilterTypes { +enum eSculptMaskFilterTypes { MASK_FILTER_SMOOTH = 0, MASK_FILTER_SHARPEN = 1, MASK_FILTER_GROW = 2, MASK_FILTER_SHRINK = 3, MASK_FILTER_CONTRAST_INCREASE = 5, MASK_FILTER_CONTRAST_DECREASE = 6, -} eSculptMaskFilterTypes; +}; static EnumPropertyItem prop_mask_filter_types[] = { {MASK_FILTER_SMOOTH, "SMOOTH", 0, "Smooth Mask", "Smooth mask"}, @@ -57,14 +57,14 @@ static EnumPropertyItem prop_mask_filter_types[] = { 0, "Decrease Contrast", "Decrease the contrast of the paint mask"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static void mask_filter_task_cb(void *__restrict userdata, const int i, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHNode *node = data->nodes[i]; bool update = false; @@ -182,14 +182,14 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op) int num_verts = SCULPT_vertex_count_get(ss); - BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); + BKE_pbvh_search_gather(pbvh, nullptr, nullptr, &nodes, &totnode); SCULPT_undo_push_begin(ob, op); for (int i = 0; i < totnode; i++) { SCULPT_undo_push_node(ob, nodes[i], SCULPT_UNDO_MASK); } - float *prev_mask = NULL; + float *prev_mask = nullptr; int iterations = RNA_int_get(op->ptr, "iterations"); /* Auto iteration count calculates the number of iteration based on the vertices of the mesh to @@ -197,25 +197,24 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op) * One iteration per 50000 vertices in the mesh should be fine in most cases. * Maybe we want this to be configurable. */ if (RNA_boolean_get(op->ptr, "auto_iteration_count")) { - iterations = (int)(num_verts / 50000.0f) + 1; + iterations = int(num_verts / 50000.0f) + 1; } for (int i = 0; i < iterations; i++) { if (ELEM(filter_type, MASK_FILTER_GROW, MASK_FILTER_SHRINK)) { - prev_mask = MEM_mallocN(num_verts * sizeof(float), "prevmask"); + prev_mask = static_cast(MEM_mallocN(num_verts * sizeof(float), __func__)); for (int j = 0; j < num_verts; j++) { PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, j); prev_mask[j] = SCULPT_vertex_mask_get(ss, vertex); } } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = nodes, - .filter_type = filter_type, - .prev_mask = prev_mask, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = nodes; + data.filter_type = filter_type; + data.prev_mask = prev_mask; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -238,12 +237,11 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op) void SCULPT_mask_filter_smooth_apply( Sculpt *sd, Object *ob, PBVHNode **nodes, const int totnode, const int smooth_iterations) { - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = nodes, - .filter_type = MASK_FILTER_SMOOTH, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = nodes; + data.filter_type = MASK_FILTER_SMOOTH; for (int i = 0; i < smooth_iterations; i++) { TaskParallelSettings settings; @@ -252,7 +250,7 @@ void SCULPT_mask_filter_smooth_apply( } } -void SCULPT_OT_mask_filter(struct wmOperatorType *ot) +void SCULPT_OT_mask_filter(wmOperatorType *ot) { /* Identifiers. */ ot->name = "Mask Filter"; diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc similarity index 89% rename from source/blender/editors/sculpt_paint/sculpt_filter_mesh.c rename to source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc index 4367189c997..27a1b90ba8b 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc @@ -35,10 +35,10 @@ #include "bmesh.h" -#include -#include +#include +#include -void SCULPT_filter_to_orientation_space(float r_v[3], struct FilterCache *filter_cache) +void SCULPT_filter_to_orientation_space(float r_v[3], FilterCache *filter_cache) { switch (filter_cache->orientation) { case SCULPT_FILTER_ORIENTATION_LOCAL: @@ -54,7 +54,7 @@ void SCULPT_filter_to_orientation_space(float r_v[3], struct FilterCache *filter } } -void SCULPT_filter_to_object_space(float r_v[3], struct FilterCache *filter_cache) +void SCULPT_filter_to_object_space(float r_v[3], FilterCache *filter_cache) { switch (filter_cache->orientation) { case SCULPT_FILTER_ORIENTATION_LOCAL: @@ -70,7 +70,7 @@ void SCULPT_filter_to_object_space(float r_v[3], struct FilterCache *filter_cach } } -void SCULPT_filter_zero_disabled_axis_components(float r_v[3], struct FilterCache *filter_cache) +void SCULPT_filter_zero_disabled_axis_components(float r_v[3], FilterCache *filter_cache) { SCULPT_filter_to_orientation_space(r_v, filter_cache); for (int axis = 0; axis < 3; axis++) { @@ -83,12 +83,12 @@ void SCULPT_filter_zero_disabled_axis_components(float r_v[3], struct FilterCach static void filter_cache_init_task_cb(void *__restrict userdata, const int i, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); PBVHNode *node = data->nodes[i]; - SCULPT_undo_push_node(data->ob, node, data->filter_undo_type); + SCULPT_undo_push_node(data->ob, node, SculptUndoType(data->filter_undo_type)); } void SCULPT_filter_cache_init(bContext *C, @@ -101,7 +101,7 @@ void SCULPT_filter_cache_init(bContext *C, SculptSession *ss = ob->sculpt; PBVH *pbvh = ob->sculpt->pbvh; - ss->filter_cache = MEM_callocN(sizeof(FilterCache), "filter cache"); + ss->filter_cache = MEM_cnew(__func__); ss->filter_cache->random_seed = rand(); @@ -110,13 +110,12 @@ void SCULPT_filter_cache_init(bContext *C, } const float center[3] = {0.0f}; - SculptSearchSphereData search_data = { - .original = true, - .center = center, - .radius_squared = FLT_MAX, - .ignore_fully_ineffective = true, + SculptSearchSphereData search_data{}; + search_data.original = true; + search_data.center = center; + search_data.radius_squared = FLT_MAX; + search_data.ignore_fully_ineffective = true; - }; BKE_pbvh_search_gather(pbvh, SCULPT_search_sphere_cb, &search_data, @@ -130,15 +129,14 @@ void SCULPT_filter_cache_init(bContext *C, /* `mesh->runtime.subdiv_ccg` is not available. Updating of the normals is done during drawing. * Filters can't use normals in multi-resolution. */ if (BKE_pbvh_type(ss->pbvh) != PBVH_GRIDS) { - BKE_pbvh_update_normals(ss->pbvh, NULL); + BKE_pbvh_update_normals(ss->pbvh, nullptr); } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = ss->filter_cache->nodes, - .filter_undo_type = undo_type, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = ss->filter_cache->nodes; + data.filter_undo_type = undo_type; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->totnode); @@ -161,7 +159,7 @@ void SCULPT_filter_cache_init(bContext *C, UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; float co[3]; - float mval_fl[2] = {(float)mval[0], (float)mval[1]}; + float mval_fl[2] = {float(mval[0]), float(mval[1])}; if (SCULPT_stroke_get_location(C, co, mval_fl, false)) { PBVHNode **nodes; @@ -174,22 +172,21 @@ void SCULPT_filter_cache_init(bContext *C, if (brush) { if (BKE_brush_use_locked_size(scene, brush)) { radius = paint_calc_object_space_radius( - &vc, co, (float)BKE_brush_size_get(scene, brush) * area_normal_radius); + &vc, co, float(BKE_brush_size_get(scene, brush) * area_normal_radius)); } else { radius = BKE_brush_unprojected_radius_get(scene, brush) * area_normal_radius; } } else { - radius = paint_calc_object_space_radius(&vc, co, (float)ups->size * area_normal_radius); + radius = paint_calc_object_space_radius(&vc, co, float(ups->size) * area_normal_radius); } - SculptSearchSphereData search_data2 = { - .original = true, - .center = co, - .radius_squared = radius * radius, - .ignore_fully_ineffective = true, - }; + SculptSearchSphereData search_data2{}; + search_data2.original = true; + search_data2.center = co; + search_data2.radius_squared = radius * radius; + search_data2.ignore_fully_ineffective = true; BKE_pbvh_search_gather(pbvh, SCULPT_search_sphere_cb, &search_data2, &nodes, &totnode); @@ -295,7 +292,7 @@ static EnumPropertyItem prop_mesh_filter_types[] = { 0, "Erase Displacement", "Deletes the displacement of the Multires Modifier"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; typedef enum eMeshFilterDeformAxis { @@ -308,7 +305,7 @@ static EnumPropertyItem prop_mesh_filter_deform_axis_items[] = { {MESH_FILTER_DEFORM_X, "X", 0, "X", "Deform in the X axis"}, {MESH_FILTER_DEFORM_Y, "Y", 0, "Y", "Deform in the Y axis"}, {MESH_FILTER_DEFORM_Z, "Z", 0, "Z", "Deform in the Z axis"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static EnumPropertyItem prop_mesh_filter_orientation_items[] = { @@ -327,7 +324,7 @@ static EnumPropertyItem prop_mesh_filter_orientation_items[] = { 0, "View", "Use the view axis to limit the displacement"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static bool sculpt_mesh_filter_needs_pmap(eSculptMeshFilterType filter_type) @@ -343,13 +340,13 @@ static bool sculpt_mesh_filter_needs_pmap(eSculptMeshFilterType filter_type) static void mesh_filter_task_cb(void *__restrict userdata, const int i, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHNode *node = data->nodes[i]; - const eSculptMeshFilterType filter_type = data->filter_type; + const eSculptMeshFilterType filter_type = eSculptMeshFilterType(data->filter_type); SculptOrigVertData orig_data; SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[i], SCULPT_UNDO_COORDS); @@ -442,7 +439,7 @@ static void mesh_filter_task_cb(void *__restrict userdata, const uint *hash_co = (const uint *)orig_co; const uint hash = BLI_hash_int_2d(hash_co[0], hash_co[1]) ^ BLI_hash_int_2d(hash_co[2], ss->filter_cache->random_seed); - mul_v3_fl(normal, hash * (1.0f / (float)0xFFFFFFFF) - 0.5f); + mul_v3_fl(normal, hash * (1.0f / float(0xFFFFFFFF)) - 0.5f); mul_v3_v3fl(disp, normal, fade); break; } @@ -546,8 +543,8 @@ static void mesh_filter_enhance_details_init_directions(SculptSession *ss) const int totvert = SCULPT_vertex_count_get(ss); FilterCache *filter_cache = ss->filter_cache; - filter_cache->detail_directions = MEM_malloc_arrayN( - totvert, sizeof(float[3]), "detail directions"); + filter_cache->detail_directions = static_cast( + MEM_malloc_arrayN(totvert, sizeof(float[3]), __func__)); for (int i = 0; i < totvert; i++) { PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); @@ -564,8 +561,8 @@ static void mesh_filter_surface_smooth_init(SculptSession *ss, const int totvert = SCULPT_vertex_count_get(ss); FilterCache *filter_cache = ss->filter_cache; - filter_cache->surface_smooth_laplacian_disp = MEM_malloc_arrayN( - totvert, sizeof(float[3]), "surface smooth displacement"); + filter_cache->surface_smooth_laplacian_disp = static_cast( + MEM_malloc_arrayN(totvert, sizeof(float[3]), __func__)); filter_cache->surface_smooth_shape_preservation = shape_preservation; filter_cache->surface_smooth_current_vertex = current_vertex_displacement; } @@ -575,8 +572,8 @@ static void mesh_filter_init_limit_surface_co(SculptSession *ss) const int totvert = SCULPT_vertex_count_get(ss); FilterCache *filter_cache = ss->filter_cache; - filter_cache->limit_surface_co = MEM_malloc_arrayN( - totvert, sizeof(float[3]), "limit surface co"); + filter_cache->limit_surface_co = static_cast( + MEM_malloc_arrayN(totvert, sizeof(float[3]), __func__)); for (int i = 0; i < totvert; i++) { PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); @@ -595,9 +592,10 @@ static void mesh_filter_sharpen_init(SculptSession *ss, filter_cache->sharpen_smooth_ratio = smooth_ratio; filter_cache->sharpen_intensify_detail_strength = intensify_detail_strength; filter_cache->sharpen_curvature_smooth_iterations = curvature_smooth_iterations; - filter_cache->sharpen_factor = MEM_malloc_arrayN(totvert, sizeof(float), "sharpen factor"); - filter_cache->detail_directions = MEM_malloc_arrayN( - totvert, sizeof(float[3]), "sharpen detail direction"); + filter_cache->sharpen_factor = static_cast( + MEM_malloc_arrayN(totvert, sizeof(float), __func__)); + filter_cache->detail_directions = static_cast( + MEM_malloc_arrayN(totvert, sizeof(float[3]), __func__)); for (int i = 0; i < totvert; i++) { PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); @@ -648,10 +646,11 @@ static void mesh_filter_sharpen_init(SculptSession *ss, } } -static void mesh_filter_surface_smooth_displace_task_cb( - void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) +static void mesh_filter_surface_smooth_displace_task_cb(void *__restrict userdata, + const int i, + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHNode *node = data->nodes[i]; PBVHVertexIter vd; @@ -688,7 +687,7 @@ static int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent * Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); SculptSession *ss = ob->sculpt; Sculpt *sd = CTX_data_tool_settings(C)->sculpt; - eSculptMeshFilterType filter_type = RNA_enum_get(op->ptr, "type"); + eSculptMeshFilterType filter_type = eSculptMeshFilterType(RNA_enum_get(op->ptr, "type")); float filter_strength = RNA_float_get(op->ptr, "strength"); if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { @@ -710,13 +709,12 @@ static int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent * bool needs_pmap = sculpt_mesh_filter_needs_pmap(filter_type); BKE_sculpt_update_object_for_edit(depsgraph, ob, needs_pmap, false, false); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = ss->filter_cache->nodes, - .filter_type = filter_type, - .filter_strength = filter_strength, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = ss->filter_cache->nodes; + data.filter_type = filter_type; + data.filter_strength = filter_strength; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->totnode); @@ -753,9 +751,10 @@ static int sculpt_mesh_filter_invoke(bContext *C, wmOperator *op, const wmEvent Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = ob->sculpt; - const eMeshFilterDeformAxis deform_axis = RNA_enum_get(op->ptr, "deform_axis"); - const eSculptMeshFilterType filter_type = RNA_enum_get(op->ptr, "type"); - const bool use_automasking = SCULPT_is_automasking_enabled(sd, ss, NULL); + const eMeshFilterDeformAxis deform_axis = eMeshFilterDeformAxis( + RNA_enum_get(op->ptr, "deform_axis")); + const eSculptMeshFilterType filter_type = eSculptMeshFilterType(RNA_enum_get(op->ptr, "type")); + const bool use_automasking = SCULPT_is_automasking_enabled(sd, ss, nullptr); const bool needs_topology_info = sculpt_mesh_filter_needs_pmap(filter_type) || use_automasking; if (deform_axis == 0) { @@ -769,7 +768,7 @@ static int sculpt_mesh_filter_invoke(bContext *C, wmOperator *op, const wmEvent /* Update the active face set manually as the paint cursor is not enabled when using the Mesh * Filter Tool. */ - float mval_fl[2] = {UNPACK2(event->mval)}; + float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])}; SculptCursorGeometryInfo sgi; SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false); } @@ -787,7 +786,7 @@ static int sculpt_mesh_filter_invoke(bContext *C, wmOperator *op, const wmEvent FilterCache *filter_cache = ss->filter_cache; filter_cache->active_face_set = SCULPT_FACE_SET_NONE; - filter_cache->automasking = SCULPT_automasking_cache_init(sd, NULL, ob); + filter_cache->automasking = SCULPT_automasking_cache_init(sd, nullptr, ob); switch (filter_type) { case MESH_FILTER_SURFACE_SMOOTH: { @@ -823,14 +822,15 @@ static int sculpt_mesh_filter_invoke(bContext *C, wmOperator *op, const wmEvent ss->filter_cache->enabled_axis[1] = deform_axis & MESH_FILTER_DEFORM_Y; ss->filter_cache->enabled_axis[2] = deform_axis & MESH_FILTER_DEFORM_Z; - SculptFilterOrientation orientation = RNA_enum_get(op->ptr, "orientation"); + SculptFilterOrientation orientation = SculptFilterOrientation( + RNA_enum_get(op->ptr, "orientation")); ss->filter_cache->orientation = orientation; WM_event_add_modal_handler(C, op); return OPERATOR_RUNNING_MODAL; } -void SCULPT_mesh_filter_properties(struct wmOperatorType *ot) +void SCULPT_mesh_filter_properties(wmOperatorType *ot) { RNA_def_float( ot->srna, @@ -846,7 +846,7 @@ void SCULPT_mesh_filter_properties(struct wmOperatorType *ot) ot->srna, "strength", 1.0f, -10.0f, 10.0f, "Strength", "Filter strength", -10.0f, 10.0f); } -void SCULPT_OT_mesh_filter(struct wmOperatorType *ot) +void SCULPT_OT_mesh_filter(wmOperatorType *ot) { /* Identifiers. */ ot->name = "Filter Mesh"; diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 154e9a7decc..c173a695caf 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -908,7 +908,7 @@ float SCULPT_raycast_init(struct ViewContext *vc, bool original); /* Symmetry */ -char SCULPT_mesh_symmetry_xyz_get(Object *object); +ePaintSymmetryFlags SCULPT_mesh_symmetry_xyz_get(Object *object); /** * Returns true when the step belongs to the stroke that is directly performed by the brush and @@ -1711,7 +1711,7 @@ void SCULPT_OT_dyntopo_detail_size_edit(struct wmOperatorType *ot); void SCULPT_OT_dynamic_topology_toggle(struct wmOperatorType *ot); -/* sculpt_brush_types.c */ +/* sculpt_brush_types.cc */ /* -------------------------------------------------------------------- */ /** \name Brushes @@ -1918,13 +1918,13 @@ void SCULPT_do_mask_brush(struct Sculpt *sd, void SCULPT_bmesh_topology_rake( struct Sculpt *sd, struct Object *ob, struct PBVHNode **nodes, int totnode, float bstrength); -/* end sculpt_brush_types.c */ +/* end sculpt_brush_types.cc */ -/* sculpt_ops.c */ +/* sculpt_ops.cc */ void SCULPT_OT_brush_stroke(struct wmOperatorType *ot); -/* end sculpt_ops.c */ +/* end sculpt_ops.cc */ BLI_INLINE bool SCULPT_tool_is_paint(int tool) { diff --git a/source/blender/editors/sculpt_paint/sculpt_mask_expand.c b/source/blender/editors/sculpt_paint/sculpt_mask_expand.cc similarity index 86% rename from source/blender/editors/sculpt_paint/sculpt_mask_expand.c rename to source/blender/editors/sculpt_paint/sculpt_mask_expand.cc index 74b3ca95389..1f4dd80ebf5 100644 --- a/source/blender/editors/sculpt_paint/sculpt_mask_expand.c +++ b/source/blender/editors/sculpt_paint/sculpt_mask_expand.cc @@ -35,8 +35,8 @@ #include "bmesh.h" -#include -#include +#include +#include static void sculpt_mask_expand_cancel(bContext *C, wmOperator *op) { @@ -70,14 +70,14 @@ static void sculpt_mask_expand_cancel(bContext *C, wmOperator *op) SCULPT_filter_cache_free(ss); SCULPT_undo_push_end(ob); SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK); - ED_workspace_status_text(C, NULL); + ED_workspace_status_text(C, nullptr); } static void sculpt_expand_task_cb(void *__restrict userdata, const int i, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHNode *node = data->nodes[i]; PBVHVertexIter vd; @@ -148,9 +148,9 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent * Sculpt *sd = CTX_data_tool_settings(C)->sculpt; ARegion *region = CTX_wm_region(C); float prev_click_f[2]; - copy_v2_v2(prev_click_f, op->customdata); - const int prev_click[2] = {(int)prev_click_f[0], (int)prev_click_f[1]}; - int len = (int)len_v2v2_int(prev_click, event->mval); + copy_v2_v2(prev_click_f, static_cast(op->customdata)); + const int prev_click[2] = {int(prev_click_f[0]), int(prev_click_f[1])}; + int len = int(len_v2v2_int(prev_click, event->mval)); len = abs(len); int mask_speed = RNA_int_get(op->ptr, "mask_speed"); int mask_expand_update_it = len / mask_speed; @@ -161,7 +161,7 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent * if (RNA_boolean_get(op->ptr, "use_cursor")) { SculptCursorGeometryInfo sgi; - const float mval_fl[2] = {UNPACK2(event->mval)}; + const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])}; if (SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false)) { int active_vertex_i = BKE_pbvh_vertex_to_index(ss->pbvh, SCULPT_active_vertex_get(ss)); @@ -233,7 +233,7 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent * SCULPT_undo_push_end(ob); SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK); - ED_workspace_status_text(C, NULL); + ED_workspace_status_text(C, nullptr); return OPERATOR_FINISHED; } @@ -259,16 +259,16 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent * ss->face_sets[i] = ss->filter_cache->prev_face_set[i]; } } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = ss->filter_cache->nodes, - .mask_expand_update_it = mask_expand_update_it, - .mask_expand_use_normals = RNA_boolean_get(op->ptr, "use_normals"), - .mask_expand_invert_mask = RNA_boolean_get(op->ptr, "invert"), - .mask_expand_keep_prev_mask = RNA_boolean_get(op->ptr, "keep_previous_mask"), - .mask_expand_create_face_set = RNA_boolean_get(op->ptr, "create_face_set"), - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = ss->filter_cache->nodes; + data.mask_expand_update_it = mask_expand_update_it; + data.mask_expand_use_normals = RNA_boolean_get(op->ptr, "use_normals"); + data.mask_expand_invert_mask = RNA_boolean_get(op->ptr, "invert"); + data.mask_expand_keep_prev_mask = RNA_boolean_get(op->ptr, "keep_previous_mask"); + data.mask_expand_create_face_set = RNA_boolean_get(op->ptr, "create_face_set"); + TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->totnode); BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, sculpt_expand_task_cb, &settings); @@ -280,16 +280,16 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent * return OPERATOR_RUNNING_MODAL; } -typedef struct MaskExpandFloodFillData { +struct MaskExpandFloodFillData { float original_normal[3]; float edge_sensitivity; bool use_normals; -} MaskExpandFloodFillData; +}; static bool mask_expand_floodfill_cb( SculptSession *ss, PBVHVertRef from_v, PBVHVertRef to_v, bool is_duplicate, void *userdata) { - MaskExpandFloodFillData *data = userdata; + MaskExpandFloodFillData *data = static_cast(userdata); 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); @@ -337,7 +337,7 @@ static int sculpt_mask_expand_invoke(bContext *C, wmOperator *op, const wmEvent const bool create_face_set = RNA_boolean_get(op->ptr, "create_face_set"); SculptCursorGeometryInfo sgi; - const float mval_fl[2] = {UNPACK2(event->mval)}; + const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])}; MultiresModifierData *mmd = BKE_sculpt_multires_active(CTX_data_scene(C), ob); BKE_sculpt_mask_layers_ensure(depsgraph, CTX_data_main(C), ob, mmd); @@ -347,15 +347,16 @@ static int sculpt_mask_expand_invoke(bContext *C, wmOperator *op, const wmEvent SCULPT_vertex_random_access_ensure(ss); op->customdata = MEM_mallocN(sizeof(float[2]), "initial mouse position"); - copy_v2_v2(op->customdata, mval_fl); + copy_v2_v2(static_cast(op->customdata), mval_fl); SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false); int vertex_count = SCULPT_vertex_count_get(ss); - ss->filter_cache = MEM_callocN(sizeof(FilterCache), "filter cache"); + ss->filter_cache = MEM_cnew(__func__); - BKE_pbvh_search_gather(pbvh, NULL, NULL, &ss->filter_cache->nodes, &ss->filter_cache->totnode); + BKE_pbvh_search_gather( + pbvh, nullptr, nullptr, &ss->filter_cache->nodes, &ss->filter_cache->totnode); SCULPT_undo_push_begin(ob, op); @@ -372,27 +373,24 @@ static int sculpt_mask_expand_invoke(bContext *C, wmOperator *op, const wmEvent } } - ss->filter_cache->mask_update_it = MEM_callocN(sizeof(int) * vertex_count, - "mask update iteration"); + ss->filter_cache->mask_update_it = MEM_cnew_array(vertex_count, __func__); if (use_normals) { - ss->filter_cache->normal_factor = MEM_callocN(sizeof(float) * vertex_count, - "mask update normal factor"); - ss->filter_cache->edge_factor = MEM_callocN(sizeof(float) * vertex_count, - "mask update normal factor"); + ss->filter_cache->normal_factor = MEM_cnew_array(vertex_count, __func__); + ss->filter_cache->edge_factor = MEM_cnew_array(vertex_count, __func__); for (int i = 0; i < vertex_count; i++) { ss->filter_cache->edge_factor[i] = 1.0f; } } if (create_face_set) { - ss->filter_cache->prev_face_set = MEM_callocN(sizeof(float) * ss->totfaces, "prev face mask"); + ss->filter_cache->prev_face_set = MEM_cnew_array(ss->totfaces, __func__); for (int i = 0; i < ss->totfaces; i++) { ss->filter_cache->prev_face_set[i] = ss->face_sets ? ss->face_sets[i] : 0; } ss->filter_cache->new_face_set = SCULPT_face_set_next_available_get(ss); } else { - ss->filter_cache->prev_mask = MEM_callocN(sizeof(float) * vertex_count, "prev mask"); + ss->filter_cache->prev_mask = MEM_cnew_array(vertex_count, __func__); for (int i = 0; i < vertex_count; i++) { PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); @@ -412,10 +410,10 @@ static int sculpt_mask_expand_invoke(bContext *C, wmOperator *op, const wmEvent SCULPT_floodfill_init(ss, &flood); SCULPT_floodfill_add_active(sd, ob, ss, &flood, FLT_MAX); - MaskExpandFloodFillData fdata = { - .use_normals = use_normals, - .edge_sensitivity = RNA_int_get(op->ptr, "edge_sensitivity"), - }; + MaskExpandFloodFillData fdata{}; + fdata.use_normals = use_normals; + fdata.edge_sensitivity = RNA_int_get(op->ptr, "edge_sensitivity"); + SCULPT_active_vertex_normal_get(ss, fdata.original_normal); SCULPT_floodfill_execute(ss, &flood, mask_expand_floodfill_cb, &fdata); SCULPT_floodfill_free(&flood); @@ -438,16 +436,16 @@ static int sculpt_mask_expand_invoke(bContext *C, wmOperator *op, const wmEvent MEM_SAFE_FREE(ss->filter_cache->edge_factor); } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = ss->filter_cache->nodes, - .mask_expand_update_it = 0, - .mask_expand_use_normals = RNA_boolean_get(op->ptr, "use_normals"), - .mask_expand_invert_mask = RNA_boolean_get(op->ptr, "invert"), - .mask_expand_keep_prev_mask = RNA_boolean_get(op->ptr, "keep_previous_mask"), - .mask_expand_create_face_set = RNA_boolean_get(op->ptr, "create_face_set"), - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = ss->filter_cache->nodes; + data.mask_expand_update_it = 0; + data.mask_expand_use_normals = RNA_boolean_get(op->ptr, "use_normals"); + data.mask_expand_invert_mask = RNA_boolean_get(op->ptr, "invert"); + data.mask_expand_keep_prev_mask = RNA_boolean_get(op->ptr, "keep_previous_mask"); + data.mask_expand_create_face_set = RNA_boolean_get(op->ptr, "create_face_set"); + TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->totnode); BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, sculpt_expand_task_cb, &settings); diff --git a/source/blender/editors/sculpt_paint/sculpt_mask_init.c b/source/blender/editors/sculpt_paint/sculpt_mask_init.cc similarity index 90% rename from source/blender/editors/sculpt_paint/sculpt_mask_init.c rename to source/blender/editors/sculpt_paint/sculpt_mask_init.cc index a4f29fd758a..7bba9b14622 100644 --- a/source/blender/editors/sculpt_paint/sculpt_mask_init.c +++ b/source/blender/editors/sculpt_paint/sculpt_mask_init.cc @@ -36,17 +36,17 @@ #include "bmesh.h" -#include -#include +#include +#include /* Mask Init operator. */ /* Initializes mask values for the entire mesh depending on the mode. */ -typedef enum eSculptMaskInitMode { +enum eSculptMaskInitMode { SCULPT_MASK_INIT_RANDOM_PER_VERTEX, SCULPT_MASK_INIT_RANDOM_PER_FACE_SET, SCULPT_MASK_INIT_RANDOM_PER_LOOSE_PART, -} eSculptMaskInitMode; +}; static EnumPropertyItem prop_sculpt_mask_init_mode_types[] = { { @@ -70,14 +70,14 @@ static EnumPropertyItem prop_sculpt_mask_init_mode_types[] = { "Random per Loose Part", "", }, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static void mask_init_task_cb(void *__restrict userdata, const int i, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHNode *node = data->nodes[i]; PBVHVertexIter vd; @@ -119,7 +119,7 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op) PBVH *pbvh = ob->sculpt->pbvh; PBVHNode **nodes; int totnode; - BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); + BKE_pbvh_search_gather(pbvh, nullptr, nullptr, &nodes, &totnode); if (totnode == 0) { return OPERATOR_CANCELLED; @@ -131,12 +131,11 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op) SCULPT_topology_islands_ensure(ob); } - SculptThreadedTaskData data = { - .ob = ob, - .nodes = nodes, - .mask_init_mode = mode, - .mask_init_seed = PIL_check_seconds_timer(), - }; + SculptThreadedTaskData data{}; + data.ob = ob; + data.nodes = nodes; + data.mask_init_mode = mode; + data.mask_init_seed = PIL_check_seconds_timer(); TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); diff --git a/source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c b/source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.cc similarity index 92% rename from source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c rename to source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.cc index ccee7814f83..313c62713fb 100644 --- a/source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c +++ b/source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.cc @@ -24,23 +24,24 @@ #include "bmesh.h" -#include -#include +#include +#include -typedef struct MultiplaneScrapeSampleData { +struct MultiplaneScrapeSampleData { float area_cos[2][3]; float area_nos[2][3]; int area_count[2]; -} MultiplaneScrapeSampleData; +}; static void calc_multiplane_scrape_surface_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; - MultiplaneScrapeSampleData *mssd = tls->userdata_chunk; + MultiplaneScrapeSampleData *mssd = static_cast( + tls->userdata_chunk); float(*mat)[4] = data->mat; PBVHVertexIter vd; @@ -98,12 +99,12 @@ static void calc_multiplane_scrape_surface_task_cb(void *__restrict userdata, } } -static void calc_multiplane_scrape_surface_reduce(const void *__restrict UNUSED(userdata), +static void calc_multiplane_scrape_surface_reduce(const void *__restrict /*userdata*/, void *__restrict chunk_join, void *__restrict chunk) { - MultiplaneScrapeSampleData *join = chunk_join; - MultiplaneScrapeSampleData *mssd = chunk; + MultiplaneScrapeSampleData *join = static_cast(chunk_join); + MultiplaneScrapeSampleData *mssd = static_cast(chunk); add_v3_v3(join->area_cos[0], mssd->area_cos[0]); add_v3_v3(join->area_cos[1], mssd->area_cos[1]); @@ -119,7 +120,7 @@ static void do_multiplane_scrape_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; float(*mat)[4] = data->mat; @@ -275,14 +276,13 @@ void SCULPT_do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, if (brush->flag2 & BRUSH_MULTIPLANE_SCRAPE_DYNAMIC) { /* Sample the individual normal and area center of the two areas at both sides of the cursor. */ - SculptThreadedTaskData sample_data = { - .sd = NULL, - .ob = ob, - .brush = brush, - .nodes = nodes, - .totnode = totnode, - .mat = mat, - }; + SculptThreadedTaskData sample_data{}; + sample_data.sd = nullptr; + sample_data.ob = ob; + sample_data.brush = brush; + sample_data.nodes = nodes; + sample_data.totnode = totnode; + sample_data.mat = mat; MultiplaneScrapeSampleData mssd = {{{0}}}; @@ -302,13 +302,13 @@ void SCULPT_do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, /* Use the area center of both planes to detect if we are sculpting along a concave or convex * edge. */ - mul_v3_v3fl(sampled_plane_co[0], mssd.area_cos[0], 1.0f / (float)mssd.area_count[0]); - mul_v3_v3fl(sampled_plane_co[1], mssd.area_cos[1], 1.0f / (float)mssd.area_count[1]); + mul_v3_v3fl(sampled_plane_co[0], mssd.area_cos[0], 1.0f / float(mssd.area_count[0])); + mul_v3_v3fl(sampled_plane_co[1], mssd.area_cos[1], 1.0f / float(mssd.area_count[1])); mid_v3_v3v3(mid_co, sampled_plane_co[0], sampled_plane_co[1]); /* Calculate the scrape planes angle based on the sampled normals. */ - mul_v3_v3fl(sampled_plane_normals[0], mssd.area_nos[0], 1.0f / (float)mssd.area_count[0]); - mul_v3_v3fl(sampled_plane_normals[1], mssd.area_nos[1], 1.0f / (float)mssd.area_count[1]); + mul_v3_v3fl(sampled_plane_normals[0], mssd.area_nos[0], 1.0f / float(mssd.area_count[0])); + mul_v3_v3fl(sampled_plane_normals[1], mssd.area_nos[1], 1.0f / float(mssd.area_count[1])); normalize_v3(sampled_plane_normals[0]); normalize_v3(sampled_plane_normals[1]); @@ -347,14 +347,13 @@ void SCULPT_do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, } } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .mat = mat, - .multiplane_scrape_angle = ss->cache->multiplane_scrape_angle, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.mat = mat; + data.multiplane_scrape_angle = ss->cache->multiplane_scrape_angle; /* Calculate the final left and right scrape planes. */ float plane_no[3]; diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.c b/source/blender/editors/sculpt_paint/sculpt_ops.cc similarity index 91% rename from source/blender/editors/sculpt_paint/sculpt_ops.c rename to source/blender/editors/sculpt_paint/sculpt_ops.cc index 35fd8ffc663..0f818aacd57 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.c +++ b/source/blender/editors/sculpt_paint/sculpt_ops.cc @@ -67,13 +67,13 @@ #include "bmesh.h" -#include -#include -#include +#include +#include +#include /* Reset the copy of the mesh that is being sculpted on (currently just for the layer brush). */ -static int sculpt_set_persistent_base_exec(bContext *C, wmOperator *UNUSED(op)) +static int sculpt_set_persistent_base_exec(bContext *C, wmOperator * /*op*/) { Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Object *ob = CTX_data_active_object(C); @@ -127,7 +127,7 @@ static void SCULPT_OT_set_persistent_base(wmOperatorType *ot) /************************* SCULPT_OT_optimize *************************/ -static int sculpt_optimize_exec(bContext *C, wmOperator *UNUSED(op)) +static int sculpt_optimize_exec(bContext *C, wmOperator * /*op*/) { Object *ob = CTX_data_active_object(C); @@ -180,7 +180,7 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *op) } switch (BKE_pbvh_type(pbvh)) { - case PBVH_BMESH: + case PBVH_BMESH: { /* Dyntopo Symmetrize. */ /* To simplify undo for symmetrize, all BMesh elements are logged @@ -188,7 +188,7 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *op) * are logged as added (as opposed to attempting to store just the * parts that symmetrize modifies). */ SCULPT_undo_push_begin(ob, op); - SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_SYMMETRIZE); + SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_DYNTOPO_SYMMETRIZE); BM_log_before_all_removed(ss->bm, ss->bm_log); BM_mesh_toolflags_set(ss->bm, true); @@ -212,17 +212,19 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *op) SCULPT_undo_push_end(ob); break; - case PBVH_FACES: + } + case PBVH_FACES: { /* Mesh Symmetrize. */ ED_sculpt_undo_geometry_begin(ob, op); - Mesh *mesh = ob->data; + Mesh *mesh = static_cast(ob->data); BKE_mesh_mirror_apply_mirror_on_axis(bmain, mesh, sd->symmetrize_direction, dist); ED_sculpt_undo_geometry_end(ob); - BKE_mesh_batch_cache_dirty_tag(ob->data, BKE_MESH_BATCH_DIRTY_ALL); + BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL); break; + } case PBVH_GRIDS: return OPERATOR_CANCELLED; } @@ -266,10 +268,10 @@ static void sculpt_init_session(Main *bmain, Depsgraph *depsgraph, Scene *scene, BKE_sculpt_toolsettings_data_ensure(scene); /* Create sculpt mode session data. */ - if (ob->sculpt != NULL) { + if (ob->sculpt != nullptr) { BKE_sculptsession_free(ob); } - ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); + ob->sculpt = MEM_cnew(__func__); ob->sculpt->mode_type = OB_MODE_SCULPT; /* Trigger evaluation of modifier stack to ensure @@ -359,11 +361,11 @@ void ED_object_sculptmode_enter_ex(Main *bmain, if (me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) { MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob); - const char *message_unsupported = NULL; + const char *message_unsupported = nullptr; if (me->totloop != me->totpoly * 3) { message_unsupported = TIP_("non-triangle face"); } - else if (mmd != NULL) { + else if (mmd != nullptr) { message_unsupported = TIP_("multi-res modifier"); } else { @@ -388,17 +390,17 @@ void ED_object_sculptmode_enter_ex(Main *bmain, } } - if ((message_unsupported == NULL) || force_dyntopo) { + if ((message_unsupported == nullptr) || force_dyntopo) { /* Needed because we may be entering this mode before the undo system loads. */ - wmWindowManager *wm = bmain->wm.first; - bool has_undo = wm->undo_stack != NULL; + wmWindowManager *wm = static_cast(bmain->wm.first); + bool has_undo = wm->undo_stack != nullptr; /* Undo push is needed to prevent memory leak. */ if (has_undo) { SCULPT_undo_push_begin_ex(ob, "Dynamic topology enable"); } SCULPT_dynamic_topology_enable_ex(bmain, depsgraph, scene, ob); if (has_undo) { - SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN); + SCULPT_undo_push_node(ob, nullptr, SCULPT_UNDO_DYNTOPO_BEGIN); SCULPT_undo_push_end(ob); } } @@ -415,7 +417,7 @@ void ED_object_sculptmode_enter_ex(Main *bmain, DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); } -void ED_object_sculptmode_enter(struct bContext *C, Depsgraph *depsgraph, ReportList *reports) +void ED_object_sculptmode_enter(bContext *C, Depsgraph *depsgraph, ReportList *reports) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); @@ -480,7 +482,7 @@ void ED_object_sculptmode_exit(bContext *C, Depsgraph *depsgraph) static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) { - struct wmMsgBus *mbus = CTX_wm_message_bus(C); + wmMsgBus *mbus = CTX_wm_message_bus(C); Main *bmain = CTX_data_main(C); Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C); Scene *scene = CTX_data_scene(C); @@ -492,7 +494,7 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) const bool is_mode_set = (ob->mode & mode_flag) != 0; if (!is_mode_set) { - if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + if (!ED_object_mode_compat_set(C, ob, eObjectMode(mode_flag), op->reports)) { return OPERATOR_CANCELLED; } } @@ -508,7 +510,7 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) BKE_paint_toolslots_brush_validate(bmain, &ts->sculpt->paint); if (ob->mode & mode_flag) { - Mesh *me = ob->data; + Mesh *me = static_cast(ob->data); /* Dyntopo adds its own undo step. */ if ((me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) == 0) { /* Without this the memfile undo step is used, @@ -580,8 +582,8 @@ void SCULPT_geometry_preview_lines_update(bContext *C, SculptSession *ss, float /* Assuming an average of 6 edges per vertex in a triangulated mesh. */ const int max_preview_verts = SCULPT_vertex_count_get(ss) * 3 * 2; - if (ss->preview_vert_list == NULL) { - ss->preview_vert_list = MEM_callocN(max_preview_verts * sizeof(PBVHVertRef), "preview lines"); + if (ss->preview_vert_list == nullptr) { + ss->preview_vert_list = MEM_cnew_array(max_preview_verts, __func__); } GSQueue *non_visited_verts = BLI_gsqueue_new(sizeof(PBVHVertRef)); @@ -621,7 +623,7 @@ void SCULPT_geometry_preview_lines_update(bContext *C, SculptSession *ss, float ss->preview_vert_count = totpoints; } -static int sculpt_sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e)) +static int sculpt_sample_color_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Scene *scene = CTX_data_scene(C); @@ -718,17 +720,18 @@ static float sculpt_mask_by_color_final_mask_get(const float current_mask, return new_mask; } -typedef struct MaskByColorContiguousFloodFillData { +struct MaskByColorContiguousFloodFillData { float threshold; bool invert; float *new_mask; float initial_color[3]; -} MaskByColorContiguousFloodFillData; +}; -static void do_mask_by_color_contiguous_update_nodes_cb( - void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) +static void do_mask_by_color_contiguous_update_nodes_cb(void *__restrict userdata, + const int n, + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_MASK); @@ -759,7 +762,8 @@ static bool sculpt_mask_by_color_contiguous_floodfill_cb( 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); - MaskByColorContiguousFloodFillData *data = userdata; + MaskByColorContiguousFloodFillData *data = static_cast( + userdata); float current_color[4]; SCULPT_vertex_color_get(ss, to_v, current_color); @@ -786,7 +790,7 @@ static void sculpt_mask_by_color_contiguous(Object *object, SculptSession *ss = object->sculpt; const int totvert = SCULPT_vertex_count_get(ss); - float *new_mask = MEM_calloc_arrayN(totvert, sizeof(float), "new mask"); + float *new_mask = MEM_cnew_array(totvert, __func__); if (invert) { for (int i = 0; i < totvert; i++) { @@ -813,17 +817,16 @@ static void sculpt_mask_by_color_contiguous(Object *object, int totnode; PBVHNode **nodes; - BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); + BKE_pbvh_search_gather(ss->pbvh, nullptr, nullptr, &nodes, &totnode); - SculptThreadedTaskData data = { - .ob = object, - .nodes = nodes, - .mask_by_color_floodfill = new_mask, - .mask_by_color_vertex = vertex, - .mask_by_color_threshold = threshold, - .mask_by_color_invert = invert, - .mask_by_color_preserve_mask = preserve_mask, - }; + SculptThreadedTaskData data{}; + data.ob = object; + data.nodes = nodes; + data.mask_by_color_floodfill = new_mask; + data.mask_by_color_vertex = vertex; + data.mask_by_color_threshold = threshold; + data.mask_by_color_invert = invert; + data.mask_by_color_preserve_mask = preserve_mask; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -837,9 +840,9 @@ static void sculpt_mask_by_color_contiguous(Object *object, static void do_mask_by_color_task_cb(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_MASK); @@ -882,16 +885,15 @@ static void sculpt_mask_by_color_full_mesh(Object *object, int totnode; PBVHNode **nodes; - BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); + BKE_pbvh_search_gather(ss->pbvh, nullptr, nullptr, &nodes, &totnode); - SculptThreadedTaskData data = { - .ob = object, - .nodes = nodes, - .mask_by_color_vertex = vertex, - .mask_by_color_threshold = threshold, - .mask_by_color_invert = invert, - .mask_by_color_preserve_mask = preserve_mask, - }; + SculptThreadedTaskData data{}; + data.ob = object; + data.nodes = nodes; + data.mask_by_color_vertex = vertex; + data.mask_by_color_threshold = threshold; + data.mask_by_color_invert = invert; + data.mask_by_color_preserve_mask = preserve_mask; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -924,7 +926,7 @@ static int sculpt_mask_by_color_invoke(bContext *C, wmOperator *op, const wmEven /* Tools that are not brushes do not have the brush gizmo to update the vertex as the mouse move, * so it needs to be updated here. */ SculptCursorGeometryInfo sgi; - const float mval_fl[2] = {UNPACK2(event->mval)}; + const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])}; SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false); SCULPT_undo_push_begin(ob, op); @@ -990,34 +992,34 @@ static void SCULPT_OT_mask_by_color(wmOperatorType *ot) 1.0f); } -typedef enum { +enum CavityBakeMixMode { AUTOMASK_BAKE_MIX, AUTOMASK_BAKE_MULTIPLY, AUTOMASK_BAKE_DIVIDE, AUTOMASK_BAKE_ADD, AUTOMASK_BAKE_SUBTRACT, -} CavityBakeMixMode; +}; -typedef enum { +enum CavityBakeSettingsSource { AUTOMASK_SETTINGS_OPERATOR, AUTOMASK_SETTINGS_SCENE, AUTOMASK_SETTINGS_BRUSH -} CavityBakeSettingsSource; +}; -typedef struct AutomaskBakeTaskData { +struct AutomaskBakeTaskData { SculptSession *ss; AutomaskingCache *automasking; PBVHNode **nodes; CavityBakeMixMode mode; float factor; Object *ob; -} AutomaskBakeTaskData; +}; static void sculpt_bake_cavity_exec_task_cb(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - AutomaskBakeTaskData *tdata = userdata; + AutomaskBakeTaskData *tdata = static_cast(userdata); SculptSession *ss = tdata->ss; PBVHNode *node = tdata->nodes[n]; PBVHVertexIter vd; @@ -1072,7 +1074,7 @@ static int sculpt_bake_cavity_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; Sculpt *sd = CTX_data_tool_settings(C)->sculpt; - Brush *brush = BKE_paint_brush(&sd->paint); + const Brush *brush = BKE_paint_brush(&sd->paint); MultiresModifierData *mmd = BKE_sculpt_multires_active(CTX_data_scene(C), ob); BKE_sculpt_mask_layers_ensure(depsgraph, CTX_data_main(C), ob, mmd); @@ -1082,13 +1084,13 @@ static int sculpt_bake_cavity_exec(bContext *C, wmOperator *op) SCULPT_undo_push_begin(ob, op); - CavityBakeMixMode mode = RNA_enum_get(op->ptr, "mix_mode"); + CavityBakeMixMode mode = CavityBakeMixMode(RNA_enum_get(op->ptr, "mix_mode")); float factor = RNA_float_get(op->ptr, "mix_factor"); PBVHNode **nodes; int totnode; - BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); + BKE_pbvh_search_gather(ss->pbvh, nullptr, nullptr, &nodes, &totnode); AutomaskBakeTaskData tdata; @@ -1096,9 +1098,9 @@ static int sculpt_bake_cavity_exec(bContext *C, wmOperator *op) */ Sculpt sd2 = *sd; - CavityBakeSettingsSource source = (CavityBakeSettingsSource)RNA_enum_get(op->ptr, - "settings_source"); - switch (source) { + CavityBakeSettingsSource src = (CavityBakeSettingsSource)RNA_enum_get(op->ptr, + "settings_source"); + switch (src) { case AUTOMASK_SETTINGS_OPERATOR: if (RNA_boolean_get(op->ptr, "invert")) { sd2.automasking_flags = BRUSH_AUTOMASKING_CAVITY_INVERTED; @@ -1146,7 +1148,7 @@ static int sculpt_bake_cavity_exec(bContext *C, wmOperator *op) } /* Create copy of brush with cleared automasking settings. */ - Brush brush2 = *brush; + Brush brush2 = blender::dna::shallow_copy(*brush); brush2.automasking_flags = 0; brush2.automasking_boundary_edges_propagation_steps = 1; brush2.automasking_cavity_curve = sd2.automasking_cavity_curve; @@ -1180,7 +1182,7 @@ static void cavity_bake_ui(bContext *C, wmOperator *op) { uiLayout *layout = op->layout; Scene *scene = CTX_data_scene(C); - Sculpt *sd = scene->toolsettings ? scene->toolsettings->sculpt : NULL; + Sculpt *sd = scene->toolsettings ? scene->toolsettings->sculpt : nullptr; uiLayoutSetPropSep(layout, true); uiLayoutSetPropDecorate(layout, false); @@ -1193,13 +1195,13 @@ static void cavity_bake_ui(bContext *C, wmOperator *op) switch (source) { case AUTOMASK_SETTINGS_OPERATOR: { - uiItemR(layout, op->ptr, "mix_mode", 0, NULL, ICON_NONE); - uiItemR(layout, op->ptr, "mix_factor", 0, NULL, ICON_NONE); - uiItemR(layout, op->ptr, "settings_source", 0, NULL, ICON_NONE); - uiItemR(layout, op->ptr, "factor", 0, NULL, ICON_NONE); - uiItemR(layout, op->ptr, "blur_steps", 0, NULL, ICON_NONE); - uiItemR(layout, op->ptr, "invert", 0, NULL, ICON_NONE); - uiItemR(layout, op->ptr, "use_curve", 0, NULL, ICON_NONE); + uiItemR(layout, op->ptr, "mix_mode", 0, nullptr, ICON_NONE); + uiItemR(layout, op->ptr, "mix_factor", 0, nullptr, ICON_NONE); + uiItemR(layout, op->ptr, "settings_source", 0, nullptr, ICON_NONE); + uiItemR(layout, op->ptr, "factor", 0, nullptr, ICON_NONE); + uiItemR(layout, op->ptr, "blur_steps", 0, nullptr, ICON_NONE); + uiItemR(layout, op->ptr, "invert", 0, nullptr, ICON_NONE); + uiItemR(layout, op->ptr, "use_curve", 0, nullptr, ICON_NONE); if (sd && RNA_boolean_get(op->ptr, "use_curve")) { PointerRNA sculpt_ptr; @@ -1212,9 +1214,9 @@ static void cavity_bake_ui(bContext *C, wmOperator *op) } case AUTOMASK_SETTINGS_BRUSH: case AUTOMASK_SETTINGS_SCENE: - uiItemR(layout, op->ptr, "mix_mode", 0, NULL, ICON_NONE); - uiItemR(layout, op->ptr, "mix_factor", 0, NULL, ICON_NONE); - uiItemR(layout, op->ptr, "settings_source", 0, NULL, ICON_NONE); + uiItemR(layout, op->ptr, "mix_mode", 0, nullptr, ICON_NONE); + uiItemR(layout, op->ptr, "mix_factor", 0, nullptr, ICON_NONE); + uiItemR(layout, op->ptr, "settings_source", 0, nullptr, ICON_NONE); break; } @@ -1234,7 +1236,7 @@ static void SCULPT_OT_mask_from_cavity(wmOperatorType *ot) {AUTOMASK_BAKE_DIVIDE, "DIVIDE", ICON_NONE, "Divide", ""}, {AUTOMASK_BAKE_ADD, "ADD", ICON_NONE, "Add", ""}, {AUTOMASK_BAKE_SUBTRACT, "SUBTRACT", ICON_NONE, "Subtract", ""}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; /* api callbacks */ @@ -1254,7 +1256,7 @@ static void SCULPT_OT_mask_from_cavity(wmOperatorType *ot) "Use settings from operator properties"}, {AUTOMASK_SETTINGS_BRUSH, "BRUSH", ICON_NONE, "Brush", "Use settings from brush"}, {AUTOMASK_SETTINGS_SCENE, "SCENE", ICON_NONE, "Scene", "Use settings from scene"}, - {0, NULL, 0, NULL, NULL}}; + {0, nullptr, 0, nullptr, nullptr}}; RNA_def_enum(ot->srna, "settings_source", @@ -1304,7 +1306,7 @@ static int sculpt_reveal_all_exec(bContext *C, wmOperator *op) int totnode; bool with_bmesh = BKE_pbvh_type(ss->pbvh) == PBVH_BMESH; - BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); + BKE_pbvh_search_gather(ss->pbvh, nullptr, nullptr, &nodes, &totnode); if (!totnode) { return OPERATOR_CANCELLED; @@ -1330,7 +1332,7 @@ static int sculpt_reveal_all_exec(bContext *C, wmOperator *op) * reduced memory usage without manually clearing it later, and allows sculpt operations to * avoid checking element's hide status. */ CustomData_free_layer_named(&mesh->pdata, ".hide_poly", mesh->totpoly); - ss->hide_poly = NULL; + ss->hide_poly = nullptr; } else { SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_HIDDEN); diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_color.c b/source/blender/editors/sculpt_paint/sculpt_paint_color.cc similarity index 91% rename from source/blender/editors/sculpt_paint/sculpt_paint_color.c rename to source/blender/editors/sculpt_paint/sculpt_paint_color.cc index 3a6f7319bdf..9924ff65a34 100644 --- a/source/blender/editors/sculpt_paint/sculpt_paint_color.c +++ b/source/blender/editors/sculpt_paint/sculpt_paint_color.cc @@ -29,14 +29,14 @@ #include "bmesh.h" -#include -#include +#include +#include static void do_color_smooth_task_cb_exec(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = ss->cache->bstrength; @@ -85,7 +85,7 @@ static void do_paint_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = fabsf(ss->cache->bstrength); @@ -168,7 +168,7 @@ static void do_paint_brush_task_cb_ex(void *__restrict userdata, float noise = 1.0f; const float density = ss->cache->paint_brush.density; if (density < 1.0f) { - const float hash_noise = (float)BLI_hash_int_01(ss->cache->density_seed * 1000 * vd.index); + const float hash_noise = float(BLI_hash_int_01(ss->cache->density_seed * 1000 * vd.index)); if (hash_noise > density) { noise = density * hash_noise; fade = fade * noise; @@ -196,25 +196,25 @@ static void do_paint_brush_task_cb_ex(void *__restrict userdata, float col[4]; SCULPT_vertex_color_get(ss, vd.vertex, col); - IMB_blend_color_float(col, orig_data.col, buffer_color, brush->blend); + IMB_blend_color_float(col, orig_data.col, buffer_color, IMB_BlendMode(brush->blend)); CLAMP4(col, 0.0f, 1.0f); SCULPT_vertex_color_set(ss, vd.vertex, col); } BKE_pbvh_vertex_iter_end; } -typedef struct SampleWetPaintTLSData { +struct SampleWetPaintTLSData { int tot_samples; float color[4]; -} SampleWetPaintTLSData; +}; static void do_sample_wet_paint_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; - SampleWetPaintTLSData *swptd = tls->userdata_chunk; + SampleWetPaintTLSData *swptd = static_cast(tls->userdata_chunk); PBVHVertexIter vd; SculptBrushTest test; @@ -238,12 +238,12 @@ static void do_sample_wet_paint_task_cb(void *__restrict userdata, BKE_pbvh_vertex_iter_end; } -static void sample_wet_paint_reduce(const void *__restrict UNUSED(userdata), +static void sample_wet_paint_reduce(const void *__restrict /*userdata*/, void *__restrict chunk_join, void *__restrict chunk) { - SampleWetPaintTLSData *join = chunk_join; - SampleWetPaintTLSData *swptd = chunk; + SampleWetPaintTLSData *join = static_cast(chunk_join); + SampleWetPaintTLSData *swptd = static_cast(chunk); join->tot_samples += swptd->tot_samples; add_v4_v4(join->color, swptd->color); @@ -271,7 +271,7 @@ void SCULPT_do_paint_brush(PaintModeSettings *paint_mode_settings, if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache)) { if (SCULPT_stroke_is_first_brush_step(ss->cache)) { - ss->cache->density_seed = (float)BLI_hash_int_01(ss->cache->location[0] * 1000); + ss->cache->density_seed = float(BLI_hash_int_01(ss->cache->location[0] * 1000)); } return; } @@ -309,13 +309,12 @@ void SCULPT_do_paint_brush(PaintModeSettings *paint_mode_settings, /* Smooth colors mode. */ if (ss->cache->alt_smooth) { - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .mat = mat, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.mat = mat; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -328,12 +327,11 @@ void SCULPT_do_paint_brush(PaintModeSettings *paint_mode_settings, /* Wet paint color sampling. */ float wet_color[4] = {0.0f}; if (ss->cache->paint_brush.wet_mix > 0.0f) { - SculptThreadedTaskData task_data = { - .sd = sd, - .ob = ob, - .nodes = nodes, - .brush = brush, - }; + SculptThreadedTaskData task_data{}; + task_data.sd = sd; + task_data.ob = ob; + task_data.nodes = nodes; + task_data.brush = brush; SampleWetPaintTLSData swptd; swptd.tot_samples = 0; @@ -364,14 +362,13 @@ void SCULPT_do_paint_brush(PaintModeSettings *paint_mode_settings, } /* Threaded loop over nodes. */ - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .wet_mix_sampled_color = wet_color, - .mat = mat, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.wet_mix_sampled_color = wet_color; + data.mat = mat; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -382,7 +379,7 @@ static void do_smear_brush_task_cb_exec(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = ss->cache->bstrength; @@ -533,9 +530,9 @@ static void do_smear_brush_task_cb_exec(void *__restrict userdata, static void do_smear_store_prev_colors_task_cb_exec(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHVertexIter vd; @@ -557,7 +554,7 @@ void SCULPT_do_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode const int totvert = SCULPT_vertex_count_get(ss); if (!ss->cache->prev_colors) { - ss->cache->prev_colors = MEM_callocN(sizeof(float[4]) * totvert, "prev colors"); + ss->cache->prev_colors = MEM_cnew_array(totvert, __func__); for (int i = 0; i < totvert; i++) { PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); @@ -567,12 +564,11 @@ void SCULPT_do_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode BKE_curvemapping_init(brush->curve); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); diff --git a/source/blender/editors/sculpt_paint/sculpt_pose.c b/source/blender/editors/sculpt_paint/sculpt_pose.cc similarity index 90% rename from source/blender/editors/sculpt_paint/sculpt_pose.c rename to source/blender/editors/sculpt_paint/sculpt_pose.cc index 389a548fb2d..fb9162457c8 100644 --- a/source/blender/editors/sculpt_paint/sculpt_pose.c +++ b/source/blender/editors/sculpt_paint/sculpt_pose.cc @@ -26,8 +26,8 @@ #include "bmesh.h" -#include -#include +#include +#include static void pose_solve_ik_chain(SculptPoseIKChain *ik_chain, const float initial_target[3], @@ -136,9 +136,9 @@ static void pose_solve_scale_chain(SculptPoseIKChain *ik_chain, const float scal static void do_pose_brush_task_cb_ex(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; SculptPoseIKChain *ik_chain = ss->cache->pose_ik_chain; SculptPoseIKChainSegment *segments = ik_chain->segments; @@ -169,9 +169,9 @@ static void do_pose_brush_task_cb_ex(void *__restrict userdata, /* Get the transform matrix for the vertex symmetry area to calculate a displacement in the * vertex. */ - mul_m4_v3(segments[ik].pivot_mat_inv[(int)symm_area], new_co); - mul_m4_v3(segments[ik].trans_mat[(int)symm_area], new_co); - mul_m4_v3(segments[ik].pivot_mat[(int)symm_area], new_co); + mul_m4_v3(segments[ik].pivot_mat_inv[int(symm_area)], new_co); + mul_m4_v3(segments[ik].trans_mat[int(symm_area)], new_co); + mul_m4_v3(segments[ik].pivot_mat[int(symm_area)], new_co); /* Apply the segment weight of the vertex to the displacement. */ sub_v3_v3v3(disp, new_co, orig_data.co); @@ -200,17 +200,17 @@ static void do_pose_brush_task_cb_ex(void *__restrict userdata, BKE_pbvh_vertex_iter_end; } -typedef struct PoseGrowFactorTLSData { +struct PoseGrowFactorTLSData { float pos_avg[3]; int pos_count; -} PoseGrowFactorTLSData; +}; static void pose_brush_grow_factor_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; - PoseGrowFactorTLSData *gftd = tls->userdata_chunk; + SculptThreadedTaskData *data = static_cast(userdata); + PoseGrowFactorTLSData *gftd = static_cast(tls->userdata_chunk); SculptSession *ss = data->ob->sculpt; const char symm = SCULPT_mesh_symmetry_xyz_get(data->ob); PBVHVertexIter vd; @@ -238,12 +238,12 @@ static void pose_brush_grow_factor_task_cb_ex(void *__restrict userdata, BKE_pbvh_vertex_iter_end; } -static void pose_brush_grow_factor_reduce(const void *__restrict UNUSED(userdata), +static void pose_brush_grow_factor_reduce(const void *__restrict /*userdata*/, void *__restrict chunk_join, void *__restrict chunk) { - PoseGrowFactorTLSData *join = chunk_join; - PoseGrowFactorTLSData *gftd = chunk; + PoseGrowFactorTLSData *join = static_cast(chunk_join); + PoseGrowFactorTLSData *gftd = static_cast(chunk); add_v3_v3(join->pos_avg, gftd->pos_avg); join->pos_count += gftd->pos_count; } @@ -263,14 +263,13 @@ static void sculpt_pose_grow_pose_factor(Sculpt *sd, PBVH *pbvh = ob->sculpt->pbvh; int totnode; - BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = nodes, - .totnode = totnode, - .pose_factor = pose_factor, - }; + BKE_pbvh_search_gather(pbvh, nullptr, nullptr, &nodes, &totnode); + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = nodes; + data.totnode = totnode; + data.pose_factor = pose_factor; data.pose_initial_co = pose_target; TaskParallelSettings settings; @@ -284,7 +283,8 @@ static void sculpt_pose_grow_pose_factor(Sculpt *sd, bool grow_next_iteration = true; float prev_len = FLT_MAX; - data.prev_mask = MEM_mallocN(SCULPT_vertex_count_get(ss) * sizeof(float), "prev mask"); + data.prev_mask = static_cast( + MEM_malloc_arrayN(SCULPT_vertex_count_get(ss), sizeof(float), __func__)); while (grow_next_iteration) { zero_v3(gftd.pos_avg); gftd.pos_count = 0; @@ -292,7 +292,7 @@ static void sculpt_pose_grow_pose_factor(Sculpt *sd, BLI_task_parallel_range(0, totnode, &data, pose_brush_grow_factor_task_cb_ex, &settings); if (gftd.pos_count != 0) { - mul_v3_fl(gftd.pos_avg, 1.0f / (float)gftd.pos_count); + mul_v3_fl(gftd.pos_avg, 1.0f / float(gftd.pos_count)); if (pose_origin) { /* Test with pose origin. Used when growing the factors to compensate the Origin Offset. */ /* Stop when the factor's avg_pos starts moving away from the origin instead of getting @@ -344,7 +344,7 @@ static bool sculpt_pose_brush_is_vertex_inside_brush_radius(const float vertex[3 for (char i = 0; i <= symm; ++i) { if (SCULPT_is_symmetry_iteration_valid(i, symm)) { float location[3]; - flip_v3_v3(location, br_co, (char)i); + flip_v3_v3(location, br_co, ePaintSymmetryFlags(i)); if (len_v3v3(location, vertex) < radius) { return true; } @@ -353,7 +353,7 @@ static bool sculpt_pose_brush_is_vertex_inside_brush_radius(const float vertex[3 return false; } -typedef struct PoseFloodFillData { +struct PoseFloodFillData { float pose_initial_co[3]; float radius; int symm; @@ -393,17 +393,14 @@ typedef struct PoseFloodFillData { int masked_face_set_it; int masked_face_set; int target_face_set; -} PoseFloodFillData; +}; -static bool pose_topology_floodfill_cb(SculptSession *ss, - PBVHVertRef UNUSED(from_v), - PBVHVertRef to_v, - bool is_duplicate, - void *userdata) +static bool pose_topology_floodfill_cb( + SculptSession *ss, PBVHVertRef /*from_v*/, PBVHVertRef to_v, bool is_duplicate, void *userdata) { int to_v_i = BKE_pbvh_vertex_to_index(ss->pbvh, to_v); - PoseFloodFillData *data = userdata; + PoseFloodFillData *data = static_cast(userdata); const float *co = SCULPT_vertex_co_get(ss, to_v); if (data->pose_factor) { @@ -429,13 +426,10 @@ static bool pose_topology_floodfill_cb(SculptSession *ss, return false; } -static bool pose_face_sets_floodfill_cb(SculptSession *ss, - PBVHVertRef UNUSED(from_v), - PBVHVertRef to_v, - bool is_duplicate, - void *userdata) +static bool pose_face_sets_floodfill_cb( + SculptSession *ss, PBVHVertRef /*from_v*/, PBVHVertRef to_v, bool is_duplicate, void *userdata) { - PoseFloodFillData *data = userdata; + PoseFloodFillData *data = static_cast(userdata); const int index = BKE_pbvh_vertex_to_index(ss->pbvh, to_v); const PBVHVertRef vertex = to_v; @@ -547,12 +541,12 @@ void SCULPT_pose_calc_pose_data(Sculpt *sd, SCULPT_floodfill_init(ss, &flood); SCULPT_floodfill_add_active(sd, ob, ss, &flood, (r_pose_factor) ? radius : 0.0f); - PoseFloodFillData fdata = { - .radius = radius, - .symm = SCULPT_mesh_symmetry_xyz_get(ob), - .pose_factor = r_pose_factor, - .tot_co = 0, - }; + PoseFloodFillData fdata{}; + fdata.radius = radius; + fdata.symm = SCULPT_mesh_symmetry_xyz_get(ob); + fdata.pose_factor = r_pose_factor; + fdata.tot_co = 0; + zero_v3(fdata.pose_origin); copy_v3_v3(fdata.pose_initial_co, initial_location); copy_v3_v3(fdata.fallback_floodfill_origin, initial_location); @@ -560,7 +554,7 @@ void SCULPT_pose_calc_pose_data(Sculpt *sd, SCULPT_floodfill_free(&flood); if (fdata.tot_co > 0) { - mul_v3_fl(fdata.pose_origin, 1.0f / (float)fdata.tot_co); + mul_v3_fl(fdata.pose_origin, 1.0f / float(fdata.tot_co)); } else { copy_v3_v3(fdata.pose_origin, fdata.fallback_floodfill_origin); @@ -577,15 +571,15 @@ void SCULPT_pose_calc_pose_data(Sculpt *sd, */ if (pose_offset != 0.0f && r_pose_factor) { sculpt_pose_grow_pose_factor( - sd, ob, ss, fdata.pose_origin, fdata.pose_origin, 0, NULL, r_pose_factor); + sd, ob, ss, fdata.pose_origin, fdata.pose_origin, 0, nullptr, r_pose_factor); } } static void pose_brush_init_task_cb_ex(void *__restrict userdata, const int n, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { @@ -608,12 +602,11 @@ static void pose_brush_init_task_cb_ex(void *__restrict userdata, /* Init the IK chain with empty weights. */ static SculptPoseIKChain *pose_ik_chain_new(const int totsegments, const int totverts) { - SculptPoseIKChain *ik_chain = MEM_callocN(sizeof(SculptPoseIKChain), "Pose IK Chain"); + SculptPoseIKChain *ik_chain = MEM_cnew(__func__); ik_chain->tot_segments = totsegments; - ik_chain->segments = MEM_callocN(totsegments * sizeof(SculptPoseIKChainSegment), - "Pose IK Chain Segments"); + ik_chain->segments = MEM_cnew_array(totsegments, __func__); for (int i = 0; i < totsegments; i++) { - ik_chain->segments[i].weights = MEM_callocN(totverts * sizeof(float), "Pose IK weights"); + ik_chain->segments[i].weights = MEM_cnew_array(totverts, __func__); } return ik_chain; } @@ -674,11 +667,10 @@ static SculptPoseIKChain *pose_ik_chain_init_topology(Sculpt *sd, * added to the IK chain. */ /* This stores the whole pose factors values as they grow through the mesh. */ - float *pose_factor_grow = MEM_callocN(totvert * sizeof(float), "Pose Factor Grow"); + float *pose_factor_grow = MEM_cnew_array(totvert, __func__); /* This stores the previous status of the factors when growing a new iteration. */ - float *pose_factor_grow_prev = MEM_callocN(totvert * sizeof(float), - "Pose Factor Grow Prev Iteration"); + float *pose_factor_grow_prev = MEM_cnew_array(totvert, __func__); pose_factor_grow[nearest_vertex_index] = 1.0f; @@ -712,7 +704,7 @@ static SculptPoseIKChain *pose_ik_chain_init_topology(Sculpt *sd, sculpt_pose_grow_pose_factor(sd, ob, ss, - NULL, + nullptr, next_chain_segment_target, chain_segment_len, ik_chain->segments[i].orig, @@ -763,19 +755,19 @@ static SculptPoseIKChain *pose_ik_chain_init_face_sets( BLI_gset_add(visited_face_sets, POINTER_FROM_INT(current_face_set)); - PoseFloodFillData fdata = { - .radius = radius, - .symm = SCULPT_mesh_symmetry_xyz_get(ob), - .pose_factor = ik_chain->segments[s].weights, - .tot_co = 0, - .fallback_count = 0, - .current_face_set = current_face_set, - .prev_face_set = prev_face_set, - .visited_face_sets = visited_face_sets, - .is_weighted = is_weighted, - .next_face_set_found = false, - .is_first_iteration = s == 0, - }; + PoseFloodFillData fdata{}; + fdata.radius = radius; + fdata.symm = SCULPT_mesh_symmetry_xyz_get(ob); + fdata.pose_factor = ik_chain->segments[s].weights; + fdata.tot_co = 0; + fdata.fallback_count = 0; + fdata.current_face_set = current_face_set; + fdata.prev_face_set = prev_face_set; + fdata.visited_face_sets = visited_face_sets; + fdata.is_weighted = is_weighted; + fdata.next_face_set_found = false; + fdata.is_first_iteration = s == 0; + zero_v3(fdata.pose_origin); zero_v3(fdata.fallback_origin); copy_v3_v3(fdata.pose_initial_co, SCULPT_vertex_co_get(ss, current_vertex)); @@ -783,11 +775,11 @@ static SculptPoseIKChain *pose_ik_chain_init_face_sets( SCULPT_floodfill_free(&flood); if (fdata.tot_co > 0) { - mul_v3_fl(fdata.pose_origin, 1.0f / (float)fdata.tot_co); + mul_v3_fl(fdata.pose_origin, 1.0f / float(fdata.tot_co)); copy_v3_v3(ik_chain->segments[s].orig, fdata.pose_origin); } else if (fdata.fallback_count > 0) { - mul_v3_fl(fdata.fallback_origin, 1.0f / (float)fdata.fallback_count); + mul_v3_fl(fdata.fallback_origin, 1.0f / float(fdata.fallback_count)); copy_v3_v3(ik_chain->segments[s].orig, fdata.fallback_origin); } else { @@ -799,7 +791,7 @@ static SculptPoseIKChain *pose_ik_chain_init_face_sets( current_vertex = fdata.next_vertex; } - BLI_gset_free(visited_face_sets, NULL); + BLI_gset_free(visited_face_sets, nullptr); pose_ik_chain_origin_heads_init(ik_chain, SCULPT_active_vertex_co_get(ss)); @@ -811,7 +803,7 @@ static SculptPoseIKChain *pose_ik_chain_init_face_sets( static bool pose_face_sets_fk_find_masked_floodfill_cb( SculptSession *ss, PBVHVertRef from_v, PBVHVertRef to_v, bool is_duplicate, void *userdata) { - PoseFloodFillData *data = userdata; + PoseFloodFillData *data = static_cast(userdata); 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); @@ -846,12 +838,12 @@ static bool pose_face_sets_fk_find_masked_floodfill_cb( } static bool pose_face_sets_fk_set_weights_floodfill_cb(SculptSession *ss, - PBVHVertRef UNUSED(from_v), + PBVHVertRef /*from_v*/, PBVHVertRef to_v, - bool UNUSED(is_duplicate), + bool /*is_duplicate*/, void *userdata) { - PoseFloodFillData *data = userdata; + PoseFloodFillData *data = static_cast(userdata); int to_v_i = BKE_pbvh_vertex_to_index(ss->pbvh, to_v); @@ -875,7 +867,7 @@ static SculptPoseIKChain *pose_ik_chain_init_face_sets_fk( SCULPT_floodfill_init(ss, &flood); SCULPT_floodfill_add_initial(&flood, active_vertex); PoseFloodFillData fdata; - fdata.floodfill_it = MEM_calloc_arrayN(totvert, sizeof(int), "floodfill iteration"); + fdata.floodfill_it = static_cast(MEM_calloc_arrayN(totvert, sizeof(int), __func__)); fdata.floodfill_it[active_vertex_index] = 1; fdata.initial_face_set = active_face_set; fdata.masked_face_set = SCULPT_FACE_SET_NONE; @@ -884,7 +876,7 @@ static SculptPoseIKChain *pose_ik_chain_init_face_sets_fk( fdata.visited_face_sets = BLI_gset_int_new_ex("visited_face_sets", 3); SCULPT_floodfill_execute(ss, &flood, pose_face_sets_fk_find_masked_floodfill_cb, &fdata); SCULPT_floodfill_free(&flood); - BLI_gset_free(fdata.visited_face_sets, NULL); + BLI_gset_free(fdata.visited_face_sets, nullptr); int origin_count = 0; float origin_acc[3] = {0.0f}; @@ -950,7 +942,7 @@ SculptPoseIKChain *SCULPT_pose_ik_chain_init(Sculpt *sd, const float initial_location[3], const float radius) { - SculptPoseIKChain *ik_chain = NULL; + SculptPoseIKChain *ik_chain = nullptr; const bool use_fake_neighbors = !(br->flag2 & BRUSH_USE_CONNECTED_ONLY); @@ -984,14 +976,13 @@ void SCULPT_pose_brush_init(Sculpt *sd, Object *ob, SculptSession *ss, Brush *br PBVH *pbvh = ob->sculpt->pbvh; int totnode; - BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); + BKE_pbvh_search_gather(pbvh, nullptr, nullptr, &nodes, &totnode); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = br, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = br; + data.nodes = nodes; /* Init the IK chain that is going to be used to deform the vertices. */ ss->cache->pose_ik_chain = SCULPT_pose_ik_chain_init( @@ -1094,7 +1085,7 @@ static void sculpt_pose_do_scale_translate_deform(SculptSession *ss, Brush *brus } } -static void sculpt_pose_do_squash_stretch_deform(SculptSession *ss, Brush *UNUSED(brush)) +static void sculpt_pose_do_squash_stretch_deform(SculptSession *ss, Brush * /*brush*/) { float ik_target[3]; SculptPoseIKChain *ik_chain = ss->cache->pose_ik_chain; @@ -1169,7 +1160,7 @@ void SCULPT_do_pose_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) float symm_orig[3]; float symm_initial_orig[3]; - ePaintSymmetryAreas symm_area = symm_it; + ePaintSymmetryAreas symm_area = ePaintSymmetryAreas(symm_it); copy_qt_qt(symm_rot, ik_chain->segments[i].rot); copy_v3_v3(symm_orig, ik_chain->segments[i].orig); @@ -1218,12 +1209,11 @@ void SCULPT_do_pose_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) } } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); diff --git a/source/blender/editors/sculpt_paint/sculpt_smooth.c b/source/blender/editors/sculpt_paint/sculpt_smooth.cc similarity index 94% rename from source/blender/editors/sculpt_paint/sculpt_smooth.c rename to source/blender/editors/sculpt_paint/sculpt_smooth.cc index 5af8381f6da..4dbc0633934 100644 --- a/source/blender/editors/sculpt_paint/sculpt_smooth.c +++ b/source/blender/editors/sculpt_paint/sculpt_smooth.cc @@ -21,8 +21,8 @@ #include "bmesh.h" -#include -#include +#include +#include void SCULPT_neighbor_coords_average_interior(SculptSession *ss, float result[3], @@ -180,7 +180,7 @@ static void do_enhance_details_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; const Brush *brush = data->brush; @@ -241,8 +241,8 @@ static void SCULPT_enhance_details_brush(Sculpt *sd, if (SCULPT_stroke_is_first_brush_step(ss->cache)) { const int totvert = SCULPT_vertex_count_get(ss); - ss->cache->detail_directions = MEM_malloc_arrayN( - totvert, sizeof(float[3]), "details directions"); + ss->cache->detail_directions = static_cast( + MEM_malloc_arrayN(totvert, sizeof(float[3]), "details directions")); for (int i = 0; i < totvert; i++) { PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i); @@ -253,12 +253,11 @@ static void SCULPT_enhance_details_brush(Sculpt *sd, } } - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -269,7 +268,7 @@ static void do_smooth_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; const Brush *brush = data->brush; @@ -345,7 +344,7 @@ void SCULPT_smooth(Sculpt *sd, CLAMP(bstrength, 0.0f, 1.0f); - count = (int)(bstrength * max_iterations); + count = int(bstrength * max_iterations); last = max_iterations * (bstrength - count * fract); if (type == PBVH_FACES && !ss->pmap) { @@ -359,14 +358,13 @@ void SCULPT_smooth(Sculpt *sd, for (iteration = 0; iteration <= count; iteration++) { const float strength = (iteration != count) ? 1.0f : last; - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - .smooth_mask = smooth_mask, - .strength = strength, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; + data.smooth_mask = smooth_mask; + data.strength = strength; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); @@ -447,7 +445,7 @@ void SCULPT_surface_smooth_displace_step(SculptSession *ss, static void SCULPT_do_surface_smooth_brush_laplacian_task_cb_ex( void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = ss->cache->bstrength; @@ -499,7 +497,7 @@ static void SCULPT_do_surface_smooth_brush_laplacian_task_cb_ex( static void SCULPT_do_surface_smooth_brush_displace_task_cb_ex( void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = ss->cache->bstrength; @@ -543,12 +541,11 @@ void SCULPT_do_surface_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, in Brush *brush = BKE_paint_brush(&sd->paint); /* Threaded loop over nodes. */ - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .brush = brush, - .nodes = nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.brush = brush; + data.nodes = nodes; TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); diff --git a/source/blender/editors/sculpt_paint/sculpt_transform.c b/source/blender/editors/sculpt_paint/sculpt_transform.cc similarity index 92% rename from source/blender/editors/sculpt_paint/sculpt_transform.c rename to source/blender/editors/sculpt_paint/sculpt_transform.cc index b8ee3404159..9cc03e0380b 100644 --- a/source/blender/editors/sculpt_paint/sculpt_transform.c +++ b/source/blender/editors/sculpt_paint/sculpt_transform.cc @@ -34,13 +34,10 @@ #include "bmesh.h" -#include -#include +#include +#include -void ED_sculpt_init_transform(struct bContext *C, - Object *ob, - const int mval[2], - const char *undo_name) +void ED_sculpt_init_transform(bContext *C, Object *ob, const int mval[2], const char *undo_name) { Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = ob->sculpt; @@ -72,7 +69,7 @@ void ED_sculpt_init_transform(struct bContext *C, } static void sculpt_transform_matrices_init(SculptSession *ss, - const char symm, + const ePaintSymmetryFlags symm, const SculptTransformDisplacementMode t_mode, float r_transform_mats[8][4][4]) { @@ -96,7 +93,7 @@ static void sculpt_transform_matrices_init(SculptSession *ss, } for (int i = 0; i < PAINT_SYMM_AREAS; i++) { - ePaintSymmetryAreas v_symm = i; + ePaintSymmetryAreas v_symm = ePaintSymmetryAreas(i); copy_v3_v3(final_pivot_pos, ss->pivot_pos); @@ -137,10 +134,10 @@ static void sculpt_transform_matrices_init(SculptSession *ss, static void sculpt_transform_task_cb(void *__restrict userdata, const int i, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHNode *node = data->nodes[i]; @@ -168,7 +165,7 @@ static void sculpt_transform_task_cb(void *__restrict userdata, } copy_v3_v3(transformed_co, start_co); - mul_m4_v3(data->transform_mats[(int)symm_area], transformed_co); + mul_m4_v3(data->transform_mats[int(symm_area)], transformed_co); sub_v3_v3v3(disp, transformed_co, start_co); mul_v3_fl(disp, 1.0f - fade); add_v3_v3v3(vd.co, start_co, disp); @@ -185,13 +182,12 @@ static void sculpt_transform_task_cb(void *__restrict userdata, static void sculpt_transform_all_vertices(Sculpt *sd, Object *ob) { SculptSession *ss = ob->sculpt; - const char symm = SCULPT_mesh_symmetry_xyz_get(ob); + const ePaintSymmetryFlags symm = SCULPT_mesh_symmetry_xyz_get(ob); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = ss->filter_cache->nodes, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = ss->filter_cache->nodes; sculpt_transform_matrices_init( ss, symm, ss->filter_cache->transform_displacement_mode, data.transform_mats); @@ -206,10 +202,10 @@ static void sculpt_transform_all_vertices(Sculpt *sd, Object *ob) static void sculpt_elastic_transform_task_cb(void *__restrict userdata, const int i, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - SculptThreadedTaskData *data = userdata; + SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; PBVHNode *node = data->nodes[i]; @@ -262,14 +258,13 @@ static void sculpt_transform_radius_elastic(Sculpt *sd, Object *ob, const float BLI_assert(ss->filter_cache->transform_displacement_mode == SCULPT_TRANSFORM_DISPLACEMENT_INCREMENTAL); - const char symm = SCULPT_mesh_symmetry_xyz_get(ob); + const ePaintSymmetryFlags symm = SCULPT_mesh_symmetry_xyz_get(ob); - SculptThreadedTaskData data = { - .sd = sd, - .ob = ob, - .nodes = ss->filter_cache->nodes, - .elastic_transform_radius = transform_radius, - }; + SculptThreadedTaskData data{}; + data.sd = sd; + data.ob = ob; + data.nodes = ss->filter_cache->nodes; + data.elastic_transform_radius = transform_radius; sculpt_transform_matrices_init( ss, symm, ss->filter_cache->transform_displacement_mode, data.transform_mats); @@ -279,7 +274,7 @@ static void sculpt_transform_radius_elastic(Sculpt *sd, Object *ob, const float /* Elastic transform needs to apply all transform matrices to all vertices and then combine the * displacement proxies as all vertices are modified by all symmetry passes. */ - for (ePaintSymmetryFlags symmpass = 0; symmpass <= symm; symmpass++) { + for (ePaintSymmetryFlags symmpass = PAINT_SYMM_NONE; symmpass <= symm; symmpass++) { if (SCULPT_is_symmetry_iteration_valid(symmpass, symm)) { flip_v3_v3(data.elastic_transform_pivot, ss->pivot_pos, symmpass); flip_v3_v3(data.elastic_transform_pivot_init, ss->init_pivot_pos, symmpass); @@ -293,7 +288,7 @@ static void sculpt_transform_radius_elastic(Sculpt *sd, Object *ob, const float SCULPT_combine_transform_proxies(sd, ob); } -void ED_sculpt_update_modal_transform(struct bContext *C, Object *ob) +void ED_sculpt_update_modal_transform(bContext *C, Object *ob) { Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = ob->sculpt; @@ -340,7 +335,7 @@ void ED_sculpt_update_modal_transform(struct bContext *C, Object *ob) SCULPT_flush_update_step(C, SCULPT_UPDATE_COORDS); } -void ED_sculpt_end_transform(struct bContext *C, Object *ob) +void ED_sculpt_end_transform(bContext *C, Object *ob) { SculptSession *ss = ob->sculpt; if (ss->filter_cache) { @@ -349,13 +344,13 @@ void ED_sculpt_end_transform(struct bContext *C, Object *ob) SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COORDS); } -typedef enum eSculptPivotPositionModes { +enum eSculptPivotPositionModes { SCULPT_PIVOT_POSITION_ORIGIN = 0, SCULPT_PIVOT_POSITION_UNMASKED = 1, SCULPT_PIVOT_POSITION_MASK_BORDER = 2, SCULPT_PIVOT_POSITION_ACTIVE_VERTEX = 3, SCULPT_PIVOT_POSITION_CURSOR_SURFACE = 4, -} eSculptPivotPositionModes; +}; static EnumPropertyItem prop_sculpt_pivot_position_types[] = { {SCULPT_PIVOT_POSITION_ORIGIN, @@ -383,7 +378,7 @@ static EnumPropertyItem prop_sculpt_pivot_position_types[] = { 0, "Surface", "Sets the pivot position to the surface under the cursor"}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; static int sculpt_set_pivot_position_exec(bContext *C, wmOperator *op) @@ -420,7 +415,7 @@ static int sculpt_set_pivot_position_exec(bContext *C, wmOperator *op) else { PBVHNode **nodes; int totnode; - BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); + BKE_pbvh_search_gather(ss->pbvh, nullptr, nullptr, &nodes, &totnode); float avg[3]; int total = 0; diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt index f5985a4729b..87da287d6a3 100644 --- a/source/blender/editors/transform/CMakeLists.txt +++ b/source/blender/editors/transform/CMakeLists.txt @@ -47,14 +47,14 @@ set(SRC transform_convert_object_texspace.c transform_convert_paintcurve.c transform_convert_particle.c - transform_convert_sculpt.c + transform_convert_sculpt.cc transform_convert_sequencer.c transform_convert_sequencer_image.c transform_convert_tracking.c transform_draw_cursors.c transform_generics.c transform_gizmo_2d.c - transform_gizmo_3d.c + transform_gizmo_3d.cc transform_gizmo_extrude_3d.c transform_input.c transform_mode.c diff --git a/source/blender/editors/transform/transform_convert.h b/source/blender/editors/transform/transform_convert.h index 126f29f4fb4..a9eee34e8b6 100644 --- a/source/blender/editors/transform/transform_convert.h +++ b/source/blender/editors/transform/transform_convert.h @@ -260,7 +260,7 @@ extern TransConvertTypeInfo TransConvertType_PaintCurve; extern TransConvertTypeInfo TransConvertType_Particle; -/* transform_convert_sculpt.c */ +/* transform_convert_sculpt.cc */ extern TransConvertTypeInfo TransConvertType_Sculpt; diff --git a/source/blender/editors/transform/transform_convert_sculpt.c b/source/blender/editors/transform/transform_convert_sculpt.cc similarity index 93% rename from source/blender/editors/transform/transform_convert_sculpt.c rename to source/blender/editors/transform/transform_convert_sculpt.cc index cdd46e08c5c..7872bc03196 100644 --- a/source/blender/editors/transform/transform_convert_sculpt.c +++ b/source/blender/editors/transform/transform_convert_sculpt.cc @@ -43,8 +43,8 @@ static void createTransSculpt(bContext *C, TransInfo *t) TransDataContainer *tc = t->data_container; tc->data_len = 1; tc->is_active = 1; - td = tc->data = MEM_callocN(sizeof(TransData), "TransSculpt"); - td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransSculpt"); + td = tc->data = MEM_cnew(__func__); + td->ext = tc->data_ext = MEM_cnew(__func__); } td->flag = TD_SELECTED; @@ -63,9 +63,9 @@ static void createTransSculpt(bContext *C, TransInfo *t) copy_m3_m4(obmat_inv, ob->object_to_world); invert_m3(obmat_inv); - td->ext->rot = NULL; - td->ext->rotAxis = NULL; - td->ext->rotAngle = NULL; + td->ext->rot = nullptr; + td->ext->rotAxis = nullptr; + td->ext->rotAngle = nullptr; td->ext->quat = ss->pivot_rot; copy_m4_m4(td->ext->obmat, ob->object_to_world); copy_m3_m3(td->ext->l_smtx, obmat_inv); diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.cc similarity index 90% rename from source/blender/editors/transform/transform_gizmo_3d.c rename to source/blender/editors/transform/transform_gizmo_3d.cc index e1afea1e05d..dd4d9ef6a12 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.cc @@ -8,10 +8,10 @@ * Used for 3D View */ -#include -#include -#include -#include +#include +#include +#include +#include #include "DNA_armature_types.h" #include "DNA_curve_types.h" @@ -70,8 +70,8 @@ #include "GPU_state.h" -static wmGizmoGroupType *g_GGT_xform_gizmo = NULL; -static wmGizmoGroupType *g_GGT_xform_gizmo_context = NULL; +static wmGizmoGroupType *g_GGT_xform_gizmo = nullptr; +static wmGizmoGroupType *g_GGT_xform_gizmo_context = nullptr; static void gizmogroup_refresh_from_matrix(wmGizmoGroup *gzgroup, const float twmat[4][4], @@ -148,7 +148,7 @@ enum { MAN_AXES_SCALE, }; -typedef struct GizmoGroup { +struct GizmoGroup { bool all_hidden; int twtype; @@ -165,8 +165,8 @@ typedef struct GizmoGroup { /* Only for Rotate operator. */ float rotation; - struct wmGizmo *gizmos[MAN_AXIS_LAST]; -} GizmoGroup; + wmGizmo *gizmos[MAN_AXIS_LAST]; +}; /* -------------------------------------------------------------------- */ /** \name Utilities @@ -187,7 +187,7 @@ typedef struct GizmoGroup { static wmGizmo *gizmo_get_axis_from_index(const GizmoGroup *ggd, const short axis_idx) { - BLI_assert(IN_RANGE_INCL(axis_idx, (float)MAN_AXIS_TRANS_X, (float)MAN_AXIS_LAST)); + BLI_assert(IN_RANGE_INCL(axis_idx, float(MAN_AXIS_TRANS_X), float(MAN_AXIS_LAST))); return ggd->gizmos[axis_idx]; } @@ -434,7 +434,7 @@ static void gizmo_get_axis_constraint(const int axis_idx, bool r_axis[3]) /* **************** Preparation Stuff **************** */ -static void reset_tw_center(struct TransformBounds *tbounds) +static void reset_tw_center(TransformBounds *tbounds) { INIT_MINMAX(tbounds->min, tbounds->max); zero_v3(tbounds->center); @@ -446,7 +446,7 @@ static void reset_tw_center(struct TransformBounds *tbounds) } /* transform widget center calc helper for below */ -static void calc_tw_center(struct TransformBounds *tbounds, const float co[3]) +static void calc_tw_center(TransformBounds *tbounds, const float co[3]) { minmax_v3v3_v3(tbounds->min, tbounds->max, co); add_v3_v3(tbounds->center, co); @@ -458,7 +458,7 @@ static void calc_tw_center(struct TransformBounds *tbounds, const float co[3]) } } -static void calc_tw_center_with_matrix(struct TransformBounds *tbounds, +static void calc_tw_center_with_matrix(TransformBounds *tbounds, const float co[3], const bool use_matrix, const float matrix[4][4]) @@ -620,8 +620,8 @@ bool gimbal_axis_object(Object *ob, float gmat[3][3]) } int ED_transform_calc_gizmo_stats(const bContext *C, - const struct TransformCalcParams *params, - struct TransformBounds *tbounds) + const TransformCalcParams *params, + TransformBounds *tbounds) { ScrArea *area = CTX_wm_area(C); ARegion *region = CTX_wm_region(C); @@ -630,8 +630,8 @@ int ED_transform_calc_gizmo_stats(const bContext *C, * Is it fine to possibly evaluate dependency graph here? */ Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); ViewLayer *view_layer = CTX_data_view_layer(C); - View3D *v3d = area->spacedata.first; - RegionView3D *rv3d = region->regiondata; + View3D *v3d = static_cast(area->spacedata.first); + RegionView3D *rv3d = static_cast(region->regiondata); Base *base; bGPdata *gpd = CTX_data_gpencil_data(C); const bool is_gp_edit = GPENCIL_ANY_MODE(gpd); @@ -648,7 +648,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, Object *obedit = OBEDIT_FROM_OBACT(ob); if (ob && ob->mode & OB_MODE_WEIGHT_PAINT) { Object *obpose = BKE_object_pose_armature_get(ob); - if (obpose != NULL) { + if (obpose != nullptr) { ob = obpose; } } @@ -662,7 +662,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, zero_v3(rv3d->tw_axis_min); zero_v3(rv3d->tw_axis_max); - rv3d->twdrawflag = 0xFFFF; + rv3d->twdrawflag = short(0xFFFF); /* global, local or normal orientation? * if we could check 'totsel' now, this should be skipped with no selection. */ @@ -695,7 +695,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { /* only editable and visible layers are considered */ - if (BKE_gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) { + if (BKE_gpencil_layer_is_editable(gpl) && (gpl->actframe != nullptr)) { /* calculate difference matrix */ BKE_gpencil_layer_transform_matrix_get(depsgraph, ob, gpl, diff_mat); @@ -707,7 +707,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, } if (is_curve_edit) { - if (gps->editcurve == NULL) { + if (gps->editcurve == nullptr) { continue; } @@ -748,7 +748,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, /* selection center */ if (totsel) { - mul_v3_fl(tbounds->center, 1.0f / (float)totsel); /* centroid! */ + mul_v3_fl(tbounds->center, 1.0f / float(totsel)); /* centroid! */ } } else if (obedit) { @@ -800,7 +800,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, } /* end editmesh */ else if (obedit->type == OB_ARMATURE) { FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) { - bArmature *arm = ob_iter->data; + bArmature *arm = static_cast(ob_iter->data); float mat_local[4][4]; if (use_mat_local) { @@ -814,7 +814,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, } if ((ebo->flag & BONE_ROOTSEL) && /* don't include same point multiple times */ - ((ebo->flag & BONE_CONNECTED) && (ebo->parent != NULL) && + ((ebo->flag & BONE_CONNECTED) && (ebo->parent != nullptr) && (ebo->parent->flag & BONE_TIPSEL) && EBONE_VISIBLE(arm, ebo->parent)) == 0) { calc_tw_center_with_matrix(tbounds, ebo->head, use_mat_local, mat_local); totsel++; @@ -829,8 +829,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, } else if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) { FOREACH_EDIT_OBJECT_BEGIN (ob_iter, use_mat_local) { - Curve *cu = ob_iter->data; - Nurb *nu; + Curve *cu = static_cast(ob_iter->data); BezTriple *bezt; BPoint *bp; ListBase *nurbs = BKE_curve_editNurbs_get(cu); @@ -840,7 +839,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, mul_m4_m4m4(mat_local, obedit->world_to_object, ob_iter->object_to_world); } - nu = nurbs->first; + Nurb *nu = static_cast(nurbs->first); while (nu) { if (nu->type == CU_BEZIER) { bezt = nu->bezt; @@ -936,7 +935,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, /* selection center */ if (totsel) { - mul_v3_fl(tbounds->center, 1.0f / (float)totsel); /* centroid! */ + mul_v3_fl(tbounds->center, 1.0f / float(totsel)); /* centroid! */ mul_m4_v3(obedit->object_to_world, tbounds->center); mul_m4_v3(obedit->object_to_world, tbounds->min); mul_m4_v3(obedit->object_to_world, tbounds->max); @@ -974,7 +973,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, MEM_freeN(objects); if (totsel) { - mul_v3_fl(tbounds->center, 1.0f / (float)totsel); /* centroid! */ + mul_v3_fl(tbounds->center, 1.0f / float(totsel)); /* centroid! */ mul_m4_v3(ob->object_to_world, tbounds->center); mul_m4_v3(ob->object_to_world, tbounds->min); mul_m4_v3(ob->object_to_world, tbounds->max); @@ -1012,7 +1011,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, /* selection center */ if (totsel) { - mul_v3_fl(tbounds->center, 1.0f / (float)totsel); /* centroid! */ + mul_v3_fl(tbounds->center, 1.0f / float(totsel)); /* centroid! */ } } } @@ -1021,26 +1020,27 @@ int ED_transform_calc_gizmo_stats(const bContext *C, /* we need the one selected object, if its not active */ BKE_view_layer_synced_ensure(scene, view_layer); base = BKE_view_layer_active_base_get(view_layer); - ob = base ? base->object : NULL; + ob = base ? base->object : nullptr; if (base && ((base->flag & BASE_SELECTED) == 0)) { - ob = NULL; + ob = nullptr; } - for (base = BKE_view_layer_object_bases_get(view_layer)->first; base; base = base->next) { + for (base = static_cast(BKE_view_layer_object_bases_get(view_layer)->first); base; + base = base->next) { if (!BASE_SELECTED_EDITABLE(v3d, base)) { continue; } - if (ob == NULL) { + if (ob == nullptr) { ob = base->object; } /* Get the boundbox out of the evaluated object. */ - const BoundBox *bb = NULL; + const BoundBox *bb = nullptr; if (params->use_only_center == false) { bb = BKE_object_boundbox_get(base->object); } - if (params->use_only_center || (bb == NULL)) { + if (params->use_only_center || (bb == nullptr)) { calc_tw_center(tbounds, base->object->object_to_world[3]); } else { @@ -1065,7 +1065,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, /* selection center */ if (totsel) { - mul_v3_fl(tbounds->center, 1.0f / (float)totsel); /* centroid! */ + mul_v3_fl(tbounds->center, 1.0f / float(totsel)); /* centroid! */ } } @@ -1093,7 +1093,7 @@ static void gizmo_get_idot(const RegionView3D *rv3d, float r_idot[3]) static void gizmo_prepare_mat(const bContext *C, RegionView3D *rv3d, - const struct TransformBounds *tbounds) + const TransformBounds *tbounds) { Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); @@ -1106,7 +1106,7 @@ static void gizmo_prepare_mat(const bContext *C, if (scene->toolsettings->transform_pivot_point == V3D_AROUND_ACTIVE) { BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); - if (ob != NULL) { + if (ob != nullptr) { /* Grease Pencil uses object origin. */ bGPdata *gpd = CTX_data_gpencil_data(C); if (gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE)) { @@ -1172,23 +1172,22 @@ static void gizmo_line_range(const int twtype, const short axis_type, float *r_s } static void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup, - struct wmMsgBus *mbus, + wmMsgBus *mbus, Scene *scene, bScreen *screen, ScrArea *area, ARegion *region, - const void *type_fn) + void (*type_fn)(wmGizmoGroupType *)) { /* Subscribe to view properties */ - wmMsgSubscribeValue msg_sub_value_gz_tag_refresh = { - .owner = region, - .user_data = gzgroup->parent_gzmap, - .notify = WM_gizmo_do_msg_notify_tag_refresh, - }; + wmMsgSubscribeValue msg_sub_value_gz_tag_refresh{}; + msg_sub_value_gz_tag_refresh.owner = region; + msg_sub_value_gz_tag_refresh.user_data = gzgroup->parent_gzmap; + msg_sub_value_gz_tag_refresh.notify = WM_gizmo_do_msg_notify_tag_refresh; int orient_flag = 0; if (type_fn == VIEW3D_GGT_xform_gizmo) { - GizmoGroup *ggd = gzgroup->customdata; + GizmoGroup *ggd = static_cast(gzgroup->customdata); orient_flag = ggd->twtype_init; } else if (type_fn == VIEW3D_GGT_xform_cage) { @@ -1220,7 +1219,7 @@ static void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup, /* We could be more specific here, for now subscribe to any cursor change. */ PointerRNA cursor_ptr; RNA_pointer_create(&scene->id, &RNA_View3DCursor, &scene->cursor, &cursor_ptr); - WM_msg_subscribe_rna(mbus, &cursor_ptr, NULL, &msg_sub_value_gz_tag_refresh, __func__); + WM_msg_subscribe_rna(mbus, &cursor_ptr, nullptr, &msg_sub_value_gz_tag_refresh, __func__); } { @@ -1263,7 +1262,7 @@ static void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup, RNA_pointer_create(&screen->id, &RNA_SpaceView3D, area->spacedata.first, &view3d_ptr); if (type_fn == VIEW3D_GGT_xform_gizmo) { - GizmoGroup *ggd = gzgroup->customdata; + GizmoGroup *ggd = static_cast(gzgroup->customdata); if (ggd->use_twtype_refresh) { const PropertyRNA *props[] = { &rna_SpaceView3D_show_gizmo_object_translate, @@ -1327,13 +1326,13 @@ static void gizmo_3d_dial_matrixbasis_calc(const ARegion *region, /** Offset of the two-axis planes, depends on the gizmos scale. Define to avoid repeating. */ #define MAN_AXIS_SCALE_PLANE_OFFSET 7.0f -static void rotation_get_fn(const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, void *value) +static void rotation_get_fn(const wmGizmo * /*gz*/, wmGizmoProperty *gz_prop, void *value) { const GizmoGroup *ggd = (const GizmoGroup *)gz_prop->custom_func.user_data; *(float *)value = ggd->rotation; } -static void rotation_set_fn(const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, const void *value) +static void rotation_set_fn(const wmGizmo * /*gz*/, wmGizmoProperty *gz_prop, const void *value) { GizmoGroup *ggd = (GizmoGroup *)gz_prop->custom_func.user_data; ggd->rotation = *(const float *)value; @@ -1504,31 +1503,31 @@ static void gizmo_3d_setup_draw_modal(wmGizmo *axis, const int axis_idx) static GizmoGroup *gizmogroup_init(wmGizmoGroup *gzgroup) { - GizmoGroup *ggd; - - ggd = MEM_callocN(sizeof(GizmoGroup), "gizmo_data"); + GizmoGroup *ggd = MEM_cnew(__func__); const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true); const wmGizmoType *gzt_dial = WM_gizmotype_find("GIZMO_GT_dial_3d", true); const wmGizmoType *gzt_prim = WM_gizmotype_find("GIZMO_GT_primitive_3d", true); - wmGizmoPropertyFnParams params = { - .value_get_fn = rotation_get_fn, .value_set_fn = rotation_set_fn, .user_data = ggd}; + wmGizmoPropertyFnParams params{}; + params.value_get_fn = rotation_get_fn; + params.value_set_fn = rotation_set_fn; + params.user_data = ggd; #define GIZMO_NEW_ARROW(v) \ { \ - ggd->gizmos[v] = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL); \ + ggd->gizmos[v] = WM_gizmo_new_ptr(gzt_arrow, gzgroup, nullptr); \ } \ ((void)0) #define GIZMO_NEW_DIAL(v) \ { \ - ggd->gizmos[v] = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL); \ + ggd->gizmos[v] = WM_gizmo_new_ptr(gzt_dial, gzgroup, nullptr); \ WM_gizmo_target_property_def_func(ggd->gizmos[v], "offset", ¶ms); \ } \ ((void)0) #define GIZMO_NEW_PRIM(v) \ { \ - ggd->gizmos[v] = WM_gizmo_new_ptr(gzt_prim, gzgroup, NULL); \ + ggd->gizmos[v] = WM_gizmo_new_ptr(gzt_prim, gzgroup, nullptr); \ } \ ((void)0) @@ -1576,7 +1575,7 @@ static GizmoGroup *gizmogroup_init(wmGizmoGroup *gzgroup) static int gizmo_modal(bContext *C, wmGizmo *widget, const wmEvent *event, - eWM_GizmoFlagTweak UNUSED(tweak_flag)) + eWM_GizmoFlagTweak /*tweak_flag*/) { /* Avoid unnecessary updates, partially address: T55458. */ if (ELEM(event->type, TIMER, INBETWEEN_MOUSEMOVE)) { @@ -1584,7 +1583,7 @@ static int gizmo_modal(bContext *C, } ARegion *region = CTX_wm_region(C); - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); wmGizmoGroup *gzgroup = widget->parent_gzgroup; /* Recalculating the orientation has two problems. @@ -1596,55 +1595,56 @@ static int gizmo_modal(bContext *C, * when scaling. */ if (false) { - struct TransformBounds tbounds; + TransformBounds tbounds; - if (ED_transform_calc_gizmo_stats(C, - &(struct TransformCalcParams){ - .use_only_center = true, - }, - &tbounds)) { + TransformCalcParams calc_params{}; + calc_params.use_only_center = true; + if (ED_transform_calc_gizmo_stats(C, &calc_params, &tbounds)) { gizmo_prepare_mat(C, rv3d, &tbounds); - for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { + for (wmGizmo *gz = static_cast(gzgroup->gizmos.first); gz; gz = gz->next) { WM_gizmo_set_matrix_location(gz, rv3d->twmat[3]); } } } else { wmWindow *win = CTX_wm_window(C); - wmOperator *op = NULL; + wmOperator *op = nullptr; for (int i = 0; i < widget->op_data_len; i++) { wmGizmoOpElem *gzop = WM_gizmo_operator_get(widget, i); op = WM_operator_find_modal_by_type(win, gzop->type); - if (op != NULL) { + if (op != nullptr) { break; } } - if (op != NULL) { - GizmoGroup *ggd = gzgroup->customdata; + if (op != nullptr) { + GizmoGroup *ggd = static_cast(gzgroup->customdata); const int axis_idx = BLI_array_findindex(ggd->gizmos, ARRAY_SIZE(ggd->gizmos), &widget); const short axis_type = gizmo_get_axis_type(axis_idx); float twmat[4][4]; float scale_buf[3]; - float *scale = NULL; + float *scale = nullptr; bool update = false; copy_m4_m4(twmat, rv3d->twmat); if (axis_type == MAN_AXES_SCALE) { scale = scale_buf; - transform_final_value_get(op->customdata, scale, 3); + transform_final_value_get(static_cast(op->customdata), scale, 3); update = true; } else if (axis_type == MAN_AXES_ROTATE) { - transform_final_value_get(op->customdata, &ggd->rotation, 1); + transform_final_value_get( + static_cast(op->customdata), &ggd->rotation, 1); if (widget != ggd->gizmos[MAN_AXIS_ROT_C]) { ggd->rotation *= -1; } RNA_float_set( - widget->ptr, "incremental_angle", transform_snap_increment_get(op->customdata)); + widget->ptr, + "incremental_angle", + transform_snap_increment_get(static_cast(op->customdata))); } - else if (transform_apply_matrix(op->customdata, twmat)) { + else if (transform_apply_matrix(static_cast(op->customdata), twmat)) { update = true; } @@ -1662,13 +1662,13 @@ static void gizmogroup_init_properties_from_twtype(wmGizmoGroup *gzgroup) { struct { wmOperatorType *translate, *rotate, *trackball, *resize; - } ot_store = {NULL}; - GizmoGroup *ggd = gzgroup->customdata; + } ot_store = {nullptr}; + GizmoGroup *ggd = static_cast(gzgroup->customdata); MAN_ITER_AXES_BEGIN (axis, axis_idx) { const short axis_type = gizmo_get_axis_type(axis_idx); bool constraint_axis[3] = {1, 0, 0}; - PointerRNA *ptr = NULL; + PointerRNA *ptr = nullptr; gizmo_get_axis_constraint(axis_idx, constraint_axis); @@ -1679,33 +1679,33 @@ static void gizmogroup_init_properties_from_twtype(wmGizmoGroup *gzgroup) switch (axis_type) { case MAN_AXES_TRANSLATE: - if (ot_store.translate == NULL) { + if (ot_store.translate == nullptr) { ot_store.translate = WM_operatortype_find("TRANSFORM_OT_translate", true); } - ptr = WM_gizmo_operator_set(axis, 0, ot_store.translate, NULL); + ptr = WM_gizmo_operator_set(axis, 0, ot_store.translate, nullptr); break; case MAN_AXES_ROTATE: { wmOperatorType *ot_rotate; if (axis_idx == MAN_AXIS_ROT_T) { - if (ot_store.trackball == NULL) { + if (ot_store.trackball == nullptr) { ot_store.trackball = WM_operatortype_find("TRANSFORM_OT_trackball", true); } ot_rotate = ot_store.trackball; } else { - if (ot_store.rotate == NULL) { + if (ot_store.rotate == nullptr) { ot_store.rotate = WM_operatortype_find("TRANSFORM_OT_rotate", true); } ot_rotate = ot_store.rotate; } - ptr = WM_gizmo_operator_set(axis, 0, ot_rotate, NULL); + ptr = WM_gizmo_operator_set(axis, 0, ot_rotate, nullptr); break; } case MAN_AXES_SCALE: { - if (ot_store.resize == NULL) { + if (ot_store.resize == nullptr) { ot_store.resize = WM_operatortype_find("TRANSFORM_OT_resize", true); } - ptr = WM_gizmo_operator_set(axis, 0, ot_store.resize, NULL); + ptr = WM_gizmo_operator_set(axis, 0, ot_store.resize, nullptr); break; } } @@ -1776,7 +1776,7 @@ static void gizmo_refresh_from_matrix(wmGizmo *axis, const float scale[3]) { const short axis_type = gizmo_get_axis_type(axis_idx); - const int aidx_norm = gizmo_orientation_axis(axis_idx, NULL); + const int aidx_norm = gizmo_orientation_axis(axis_idx, nullptr); WM_gizmo_set_matrix_location(axis, twmat[3]); switch (axis_idx) { @@ -1841,7 +1841,7 @@ static void gizmogroup_refresh_from_matrix(wmGizmoGroup *gzgroup, const float scale[3], const bool ignore_hidden) { - GizmoGroup *ggd = gzgroup->customdata; + GizmoGroup *ggd = static_cast(gzgroup->customdata); MAN_ITER_AXES_BEGIN (axis, axis_idx) { if (ignore_hidden && axis->flag & WM_GIZMO_HIDDEN) { @@ -1863,12 +1863,12 @@ static void WIDGETGROUP_gizmo_refresh(const bContext *C, wmGizmoGroup *gzgroup) } } - GizmoGroup *ggd = gzgroup->customdata; + GizmoGroup *ggd = static_cast(gzgroup->customdata); Scene *scene = CTX_data_scene(C); ScrArea *area = CTX_wm_area(C); - View3D *v3d = area->spacedata.first; - RegionView3D *rv3d = region->regiondata; - struct TransformBounds tbounds; + View3D *v3d = static_cast(area->spacedata.first); + RegionView3D *rv3d = static_cast(region->regiondata); + TransformBounds tbounds; if (ggd->use_twtype_refresh) { ggd->twtype = v3d->gizmo_show_object & ggd->twtype_init; @@ -1881,23 +1881,21 @@ static void WIDGETGROUP_gizmo_refresh(const bContext *C, wmGizmoGroup *gzgroup) const int orient_index = BKE_scene_orientation_get_index_from_flag(scene, ggd->twtype_init); /* skip, we don't draw anything anyway */ - if ((ggd->all_hidden = (ED_transform_calc_gizmo_stats(C, - &(struct TransformCalcParams){ - .use_only_center = true, - .orientation_index = orient_index + 1, - }, - &tbounds) == 0))) { + TransformCalcParams calc_params{}; + calc_params.use_only_center = true; + calc_params.orientation_index = orient_index + 1; + if ((ggd->all_hidden = (ED_transform_calc_gizmo_stats(C, &calc_params, &tbounds) == 0))) { return; } gizmo_prepare_mat(C, rv3d, &tbounds); - gizmogroup_refresh_from_matrix(gzgroup, rv3d->twmat, NULL, false); + gizmogroup_refresh_from_matrix(gzgroup, rv3d->twmat, nullptr, false); } static void WIDGETGROUP_gizmo_message_subscribe(const bContext *C, wmGizmoGroup *gzgroup, - struct wmMsgBus *mbus) + wmMsgBus *mbus) { Scene *scene = CTX_data_scene(C); bScreen *screen = CTX_wm_screen(C); @@ -1917,11 +1915,11 @@ static void gizmogroup_hide_all(GizmoGroup *ggd) static void WIDGETGROUP_gizmo_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) { - GizmoGroup *ggd = gzgroup->customdata; + GizmoGroup *ggd = static_cast(gzgroup->customdata); // ScrArea *area = CTX_wm_area(C); ARegion *region = CTX_wm_region(C); - // View3D *v3d = area->spacedata.first; - RegionView3D *rv3d = region->regiondata; + // View3D *v3d =static_cast< View3D *> (area->spacedata.first); + RegionView3D *rv3d = static_cast(region->regiondata); float viewinv_m3[3][3]; copy_m3_m4(viewinv_m3, rv3d->viewinv); float idot[3]; @@ -2003,10 +2001,10 @@ static void gizmo_3d_draw_invoke(wmGizmoGroup *gzgroup, const int axis_idx_active, const float mval[2]) { - GizmoGroup *ggd = gzgroup->customdata; - const RegionView3D *rv3d = region->regiondata; + GizmoGroup *ggd = static_cast(gzgroup->customdata); + const RegionView3D *rv3d = static_cast(region->regiondata); - struct wmGizmo *axis_active = ggd->gizmos[axis_idx_active]; + wmGizmo *axis_active = ggd->gizmos[axis_idx_active]; const short axis_active_type = gizmo_get_axis_type(axis_idx_active); if (axis_active_type == MAN_AXES_ROTATE) { @@ -2046,7 +2044,7 @@ static void gizmo_3d_draw_invoke(wmGizmoGroup *gzgroup, if (axis->flag & WM_GIZMO_HIDDEN) { continue; } - gizmo_refresh_from_matrix(axis, axis_idx, ggd->twtype, rv3d->twmat, NULL); + gizmo_refresh_from_matrix(axis, axis_idx, ggd->twtype, rv3d->twmat, nullptr); if (ELEM(axis_idx, MAN_AXIS_TRANS_C, MAN_AXIS_SCALE_C, MAN_AXIS_ROT_C, MAN_AXIS_ROT_T)) { WM_gizmo_set_matrix_rotation_from_z_axis(axis, rv3d->viewinv[2]); @@ -2072,10 +2070,11 @@ static void WIDGETGROUP_gizmo_invoke_prepare(const bContext *C, wmGizmo *gz, const wmEvent *event) { - GizmoGroup *ggd = gzgroup->customdata; + GizmoGroup *ggd = static_cast(gzgroup->customdata); const int axis_idx = BLI_array_findindex(ggd->gizmos, ARRAY_SIZE(ggd->gizmos), &gz); - gizmo_3d_draw_invoke(gzgroup, CTX_wm_region(C), axis_idx, (float[2]){UNPACK2(event->mval)}); + const float mval[2] = {float(event->mval[0]), float(event->mval[1])}; + gizmo_3d_draw_invoke(gzgroup, CTX_wm_region(C), axis_idx, mval); /* Support gizmo specific orientation. */ if (gz != ggd->gizmos[MAN_AXIS_ROT_T]) { @@ -2147,11 +2146,10 @@ static bool WIDGETGROUP_gizmo_poll_generic(View3D *v3d) return true; } -static bool WIDGETGROUP_gizmo_poll_context(const struct bContext *C, - struct wmGizmoGroupType *UNUSED(gzgt)) +static bool WIDGETGROUP_gizmo_poll_context(const bContext *C, wmGizmoGroupType * /*gzgt*/) { ScrArea *area = CTX_wm_area(C); - View3D *v3d = area->spacedata.first; + View3D *v3d = static_cast(area->spacedata.first); if (!WIDGETGROUP_gizmo_poll_generic(v3d)) { return false; } @@ -2172,14 +2170,14 @@ static bool WIDGETGROUP_gizmo_poll_context(const struct bContext *C, return true; } -static bool WIDGETGROUP_gizmo_poll_tool(const struct bContext *C, struct wmGizmoGroupType *gzgt) +static bool WIDGETGROUP_gizmo_poll_tool(const bContext *C, wmGizmoGroupType *gzgt) { if (!ED_gizmo_poll_or_unlink_delayed_from_tool(C, gzgt)) { return false; } ScrArea *area = CTX_wm_area(C); - View3D *v3d = area->spacedata.first; + View3D *v3d = static_cast(area->spacedata.first); if (!WIDGETGROUP_gizmo_poll_generic(v3d)) { return false; } @@ -2218,7 +2216,7 @@ void VIEW3D_GGT_xform_gizmo(wmGizmoGroupType *gzgt) {V3D_GIZMO_SHOW_OBJECT_ROTATE, "ROTATE", 0, "Rotate", ""}, {V3D_GIZMO_SHOW_OBJECT_SCALE, "SCALE", 0, "Scale", ""}, {0, "NONE", 0, "None", ""}, - {0, NULL, 0, NULL, NULL}, + {0, nullptr, 0, nullptr, nullptr}, }; RNA_def_enum(gzgt->srna, "drag_action", @@ -2278,12 +2276,12 @@ static bool WIDGETGROUP_xform_cage_poll(const bContext *C, wmGizmoGroupType *gzg return true; } -static void WIDGETGROUP_xform_cage_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) +static void WIDGETGROUP_xform_cage_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - struct XFormCageWidgetGroup *xgzgroup = MEM_mallocN(sizeof(struct XFormCageWidgetGroup), - __func__); + XFormCageWidgetGroup *xgzgroup = static_cast( + MEM_mallocN(sizeof(XFormCageWidgetGroup), __func__)); const wmGizmoType *gzt_cage = WM_gizmotype_find("GIZMO_GT_cage_3d", true); - xgzgroup->gizmo = WM_gizmo_new_ptr(gzt_cage, gzgroup, NULL); + xgzgroup->gizmo = WM_gizmo_new_ptr(gzt_cage, gzgroup, nullptr); wmGizmo *gz = xgzgroup->gizmo; RNA_enum_set( @@ -2299,16 +2297,16 @@ static void WIDGETGROUP_xform_cage_setup(const bContext *UNUSED(C), wmGizmoGroup PointerRNA *ptr; /* assign operator */ - PropertyRNA *prop_release_confirm = NULL; - PropertyRNA *prop_constraint_axis = NULL; + PropertyRNA *prop_release_confirm = nullptr; + PropertyRNA *prop_constraint_axis = nullptr; int i = ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z; for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { const bool constraint[3] = {x != 1, y != 1, z != 1}; - ptr = WM_gizmo_operator_set(gz, i, ot_resize, NULL); - if (prop_release_confirm == NULL) { + ptr = WM_gizmo_operator_set(gz, i, ot_resize, nullptr); + if (prop_release_confirm == nullptr) { prop_release_confirm = RNA_struct_find_property(ptr, "release_confirm"); prop_constraint_axis = RNA_struct_find_property(ptr, "constraint_axis"); } @@ -2324,22 +2322,20 @@ static void WIDGETGROUP_xform_cage_setup(const bContext *UNUSED(C), wmGizmoGroup static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmGizmoGroup *gzgroup) { ARegion *region = CTX_wm_region(C); - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); Scene *scene = CTX_data_scene(C); - struct XFormCageWidgetGroup *xgzgroup = gzgroup->customdata; + XFormCageWidgetGroup *xgzgroup = static_cast(gzgroup->customdata); wmGizmo *gz = xgzgroup->gizmo; - struct TransformBounds tbounds; + TransformBounds tbounds; const int orient_index = BKE_scene_orientation_get_index_from_flag(scene, SCE_ORIENT_SCALE); - if ((ED_transform_calc_gizmo_stats(C, - &(struct TransformCalcParams){ - .use_local_axis = true, - .orientation_index = orient_index + 1, - }, - &tbounds) == 0) || + TransformCalcParams calc_params{}; + calc_params.use_local_axis = true; + calc_params.orientation_index = orient_index + 1; + if ((ED_transform_calc_gizmo_stats(C, &calc_params, &tbounds) == 0) || equals_v3v3(rv3d->tw_axis_min, rv3d->tw_axis_max)) { WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); } @@ -2368,18 +2364,18 @@ static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmGizmoGroup *gzgr float matrix_offset_global[4][4]; mul_m4_m4m4(matrix_offset_global, gz->matrix_space, gz->matrix_offset); - PropertyRNA *prop_center_override = NULL; + PropertyRNA *prop_center_override = nullptr; float center[3]; float center_global[3]; int i = ED_GIZMO_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z; for (int x = 0; x < 3; x++) { - center[0] = (float)(1 - x) * dims[0]; + center[0] = float(1 - x) * dims[0]; for (int y = 0; y < 3; y++) { - center[1] = (float)(1 - y) * dims[1]; + center[1] = float(1 - y) * dims[1]; for (int z = 0; z < 3; z++) { - center[2] = (float)(1 - z) * dims[2]; - struct wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, i); - if (prop_center_override == NULL) { + center[2] = float(1 - z) * dims[2]; + wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, i); + if (prop_center_override == nullptr) { prop_center_override = RNA_struct_find_property(&gzop->ptr, "center_override"); } mul_v3_m4v3(center_global, matrix_offset_global, center); @@ -2396,7 +2392,7 @@ static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmGizmoGroup *gzgr static void WIDGETGROUP_xform_cage_message_subscribe(const bContext *C, wmGizmoGroup *gzgroup, - struct wmMsgBus *mbus) + wmMsgBus *mbus) { Scene *scene = CTX_data_scene(C); bScreen *screen = CTX_wm_screen(C); @@ -2407,7 +2403,7 @@ static void WIDGETGROUP_xform_cage_message_subscribe(const bContext *C, static void WIDGETGROUP_xform_cage_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) { - struct XFormCageWidgetGroup *xgzgroup = gzgroup->customdata; + XFormCageWidgetGroup *xgzgroup = static_cast(gzgroup->customdata); RegionView3D *rv3d = CTX_wm_region_view3d(C); { @@ -2477,10 +2473,10 @@ static bool WIDGETGROUP_xform_shear_poll(const bContext *C, wmGizmoGroupType *gz return true; } -static void WIDGETGROUP_xform_shear_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) +static void WIDGETGROUP_xform_shear_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - struct XFormShearWidgetGroup *xgzgroup = MEM_mallocN(sizeof(struct XFormShearWidgetGroup), - __func__); + XFormShearWidgetGroup *xgzgroup = static_cast( + MEM_mallocN(sizeof(XFormShearWidgetGroup), __func__)); const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true); wmOperatorType *ot_shear = WM_operatortype_find("TRANSFORM_OT_shear", true); @@ -2491,26 +2487,26 @@ static void WIDGETGROUP_xform_shear_setup(const bContext *UNUSED(C), wmGizmoGrou for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - wmGizmo *gz = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL); + wmGizmo *gz = WM_gizmo_new_ptr(gzt_arrow, gzgroup, nullptr); RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_BOX); const int i_ortho_a = (i + j + 1) % 3; const int i_ortho_b = (i + (1 - j) + 1) % 3; interp_v3_v3v3(gz->color, axis_color[i_ortho_a], axis_color[i_ortho_b], 0.75f); gz->color[3] = 0.5f; - PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot_shear, NULL); + PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot_shear, nullptr); RNA_boolean_set(ptr, "release_confirm", 1); xgzgroup->gizmo[i][j] = gz; } } for (int i = 0; i < 4; i++) { - wmGizmo *gz = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL); + wmGizmo *gz = WM_gizmo_new_ptr(gzt_arrow, gzgroup, nullptr); RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_BOX); RNA_enum_set(gz->ptr, "draw_options", 0); /* No stem. */ copy_v3_fl(gz->color, 1.0f); gz->color[3] = 0.5f; WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_OFFSET_SCALE, true); - PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot_shear, NULL); + PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot_shear, nullptr); RNA_boolean_set(ptr, "release_confirm", 1); xgzgroup->gizmo_view[i] = gz; @@ -2529,10 +2525,10 @@ static void WIDGETGROUP_xform_shear_refresh(const bContext *C, wmGizmoGroup *gzg { Scene *scene = CTX_data_scene(C); ARegion *region = CTX_wm_region(C); - RegionView3D *rv3d = region->regiondata; + RegionView3D *rv3d = static_cast(region->regiondata); - struct XFormShearWidgetGroup *xgzgroup = gzgroup->customdata; - struct TransformBounds tbounds; + XFormShearWidgetGroup *xgzgroup = static_cast(gzgroup->customdata); + TransformBounds tbounds; /* Needed to test view orientation changes. */ copy_m3_m4(xgzgroup->prev.viewinv_m3, rv3d->viewinv); @@ -2541,12 +2537,10 @@ static void WIDGETGROUP_xform_shear_refresh(const bContext *C, wmGizmoGroup *gzg scene, SCE_ORIENT_ROTATE); const int orient_index = BKE_scene_orientation_slot_get_index(orient_slot); - if (ED_transform_calc_gizmo_stats(C, - &(struct TransformCalcParams){ - .use_local_axis = false, - .orientation_index = orient_index + 1, - }, - &tbounds) == 0) { + TransformCalcParams calc_params{}; + calc_params.use_local_axis = false; + calc_params.orientation_index = orient_index + 1; + if (ED_transform_calc_gizmo_stats(C, &calc_params, &tbounds) == 0) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { wmGizmo *gz = xgzgroup->gizmo[i][j]; @@ -2593,7 +2587,7 @@ static void WIDGETGROUP_xform_shear_refresh(const bContext *C, wmGizmoGroup *gzg static void WIDGETGROUP_xform_shear_message_subscribe(const bContext *C, wmGizmoGroup *gzgroup, - struct wmMsgBus *mbus) + wmMsgBus *mbus) { Scene *scene = CTX_data_scene(C); bScreen *screen = CTX_wm_screen(C); @@ -2605,7 +2599,7 @@ static void WIDGETGROUP_xform_shear_message_subscribe(const bContext *C, static void WIDGETGROUP_xform_shear_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) { - struct XFormShearWidgetGroup *xgzgroup = gzgroup->customdata; + XFormShearWidgetGroup *xgzgroup = static_cast(gzgroup->customdata); RegionView3D *rv3d = CTX_wm_region_view3d(C); { Scene *scene = CTX_data_scene(C); @@ -2708,14 +2702,14 @@ static wmGizmoGroup *gizmogroup_xform_find(TransInfo *t) } } - return NULL; + return nullptr; } void transform_gizmo_3d_model_from_constraint_and_mode_init(TransInfo *t) { wmGizmo *gizmo_modal_current = t->region && t->region->gizmo_map ? WM_gizmomap_get_modal(t->region->gizmo_map) : - NULL; + nullptr; if (!gizmo_modal_current || !ELEM(gizmo_modal_current->parent_gzgroup->type, g_GGT_xform_gizmo, g_GGT_xform_gizmo_context)) { @@ -2730,7 +2724,7 @@ void transform_gizmo_3d_model_from_constraint_and_mode_set(TransInfo *t) } wmGizmoGroup *gzgroup_xform = gizmogroup_xform_find(t); - if (gzgroup_xform == NULL) { + if (gzgroup_xform == nullptr) { return; } @@ -2781,12 +2775,12 @@ void transform_gizmo_3d_model_from_constraint_and_mode_set(TransInfo *t) wmGizmo *gizmo_modal_current = WM_gizmomap_get_modal(t->region->gizmo_map); if (axis_idx != -1) { - RegionView3D *rv3d = t->region->regiondata; + RegionView3D *rv3d = static_cast(t->region->regiondata); bool update_orientation = !(equals_v3v3(rv3d->twmat[0], t->spacemtx[0]) && equals_v3v3(rv3d->twmat[1], t->spacemtx[1]) && equals_v3v3(rv3d->twmat[2], t->spacemtx[2])); - GizmoGroup *ggd = gzgroup_xform->customdata; + GizmoGroup *ggd = static_cast(gzgroup_xform->customdata); wmGizmo *gizmo_expected = ggd->gizmos[axis_idx]; if (update_orientation || gizmo_modal_current != gizmo_expected) { if (update_orientation) { @@ -2794,14 +2788,14 @@ void transform_gizmo_3d_model_from_constraint_and_mode_set(TransInfo *t) copy_v3_v3(rv3d->twmat[3], t->center_global); } - wmEvent event = {NULL}; + wmEvent event = {nullptr}; /* Set the initial mouse value. Used for rotation gizmos. */ copy_v2_v2_int(event.mval, t->mouse.imval); /* We need to update the position of the gizmo before invoking otherwise * #wmGizmo::scale_final could be calculated wrong. */ - gizmo_refresh_from_matrix(gizmo_expected, axis_idx, ggd->twtype, rv3d->twmat, NULL); + gizmo_refresh_from_matrix(gizmo_expected, axis_idx, ggd->twtype, rv3d->twmat, nullptr); BLI_assert_msg(!gizmo_modal_current || gizmo_modal_current->highlight_part == 0, "Avoid changing the highlight part"); @@ -2811,7 +2805,7 @@ void transform_gizmo_3d_model_from_constraint_and_mode_set(TransInfo *t) } } else if (gizmo_modal_current) { - WM_gizmo_modal_set_while_modal(t->region->gizmo_map, t->context, NULL, NULL); + WM_gizmo_modal_set_while_modal(t->region->gizmo_map, t->context, nullptr, nullptr); } } @@ -2822,11 +2816,11 @@ void transform_gizmo_3d_model_from_constraint_and_mode_restore(TransInfo *t) } wmGizmoGroup *gzgroup_xform = gizmogroup_xform_find(t); - if (gzgroup_xform == NULL) { + if (gzgroup_xform == nullptr) { return; } - GizmoGroup *ggd = gzgroup_xform->customdata; + GizmoGroup *ggd = static_cast(gzgroup_xform->customdata); /* #wmGizmoGroup::draw_prepare will handle the rest. */ MAN_ITER_AXES_BEGIN (axis, axis_idx) { diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index a415122579e..fd72a58fe14 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -10,6 +10,7 @@ #include "DNA_ID.h" #include "DNA_brush_enums.h" #include "DNA_curve_types.h" +#include "DNA_defs.h" #include "DNA_texture_types.h" /* for MTex */ #ifdef __cplusplus @@ -165,6 +166,8 @@ typedef struct BrushCurvesSculptSettings { } BrushCurvesSculptSettings; typedef struct Brush { + DNA_DEFINE_CXX_METHODS(Brush) + ID id; struct BrushClone clone; diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index a17d70a10a0..92a2b8620d7 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -2429,6 +2429,7 @@ typedef enum ePaintFlags { * (for now just a duplicate of sculpt symmetry flags). */ typedef enum ePaintSymmetryFlags { + PAINT_SYMM_NONE = 0, PAINT_SYMM_X = (1 << 0), PAINT_SYMM_Y = (1 << 1), PAINT_SYMM_Z = (1 << 2), @@ -2438,6 +2439,13 @@ typedef enum ePaintSymmetryFlags { PAINT_TILE_Z = (1 << 6), } ePaintSymmetryFlags; ENUM_OPERATORS(ePaintSymmetryFlags, PAINT_TILE_Z); +#ifdef __cplusplus +inline ePaintSymmetryFlags operator++(ePaintSymmetryFlags &flags, int) +{ + flags = ePaintSymmetryFlags(char(flags) + 1); + return flags; +} +#endif #define PAINT_SYMM_AXIS_ALL (PAINT_SYMM_X | PAINT_SYMM_Y | PAINT_SYMM_Z) -- 2.30.2 From d1ffb49cb966bf3e47ca1ae6b5717738291d83a5 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 7 Feb 2023 16:01:39 -0500 Subject: [PATCH 07/17] Fix #104297: Cycling geometry nodes viewer ignores sockets Sockets after the geometry socket were ignored when cycling through the node's output sockets. If there are multiple geometry sockets, the behavior could still be refined probably, but this should at least make basic non-geometry socket cycling work. --- source/blender/editors/space_node/node_relationships.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index 30a4b950e60..b2c12fe2ea4 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -538,6 +538,11 @@ static bNodeSocket *determine_socket_to_view(bNode &node_to_view) /* This socket is linked to a deactivated viewer, the viewer should be activated. */ return socket; } + if (socket->type == SOCK_GEOMETRY && (target_node.flag & NODE_DO_OUTPUT)) { + /* Skip geometry sockets connected to viewer nodes when deciding whether to cycle through + * outputs. */ + continue; + } last_linked_socket_index = socket->index(); } } -- 2.30.2 From 753aa473a2b8636ee111f3a2f5bc1754fe6fc5b8 Mon Sep 17 00:00:00 2001 From: Lukas Stockner Date: Wed, 8 Feb 2023 00:21:57 +0100 Subject: [PATCH 08/17] Cleanup: format --- release/lts/lts_issue.py | 1 + .../keyconfig/keymap_data/blender_default.py | 2 ++ .../scripts/startup/bl_ui/space_userpref.py | 19 ++++++++++++------- source/blender/editors/include/ED_curves.h | 1 - .../editors/space_view3d/view3d_select.cc | 3 ++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/release/lts/lts_issue.py b/release/lts/lts_issue.py index f84cfb29b15..aa21b36423b 100644 --- a/release/lts/lts_issue.py +++ b/release/lts/lts_issue.py @@ -3,6 +3,7 @@ import requests + class ReleaseLogLine: """ Class containing the information of a single line of the release log diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py index 68fb337f9a4..637580364dc 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -6344,6 +6344,8 @@ def km_node_link_modal_map(_params): return keymap # Fallback for gizmos that don't have custom a custom key-map. + + def km_generic_gizmo(_params): keymap = ( "Generic Gizmo", diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index 421e600c58f..4dbf34d555e 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -2319,13 +2319,18 @@ class USERPREF_PT_experimental_new_features(ExperimentalPanel, Panel): bl_label = "New Features" def draw(self, context): - self._draw_items( - context, ( - ({"property": "use_sculpt_tools_tilt"}, ("blender/blender/issues/82877", "#82877")), - ({"property": "use_extended_asset_browser"}, ("blender/blender/projects/10", "Pipeline, Assets & IO Project Page")), - ({"property": "use_override_templates"}, ("blender/blender/issues/73318", "Milestone 4")), - ), - ) + self._draw_items(context, + (({"property": "use_sculpt_tools_tilt"}, + ("blender/blender/issues/82877", + "#82877")), + ({"property": "use_extended_asset_browser"}, + ("blender/blender/projects/10", + "Pipeline, Assets & IO Project Page")), + ({"property": "use_override_templates"}, + ("blender/blender/issues/73318", + "Milestone 4")), + ), + ) class USERPREF_PT_experimental_prototypes(ExperimentalPanel, Panel): diff --git a/source/blender/editors/include/ED_curves.h b/source/blender/editors/include/ED_curves.h index a63e35313b1..21aeb5f533d 100644 --- a/source/blender/editors/include/ED_curves.h +++ b/source/blender/editors/include/ED_curves.h @@ -146,7 +146,6 @@ bool select_pick(const ViewContext &vc, const SelectPick_Params ¶ms, const int2 mval); - /** \} */ } // namespace blender::ed::curves diff --git a/source/blender/editors/space_view3d/view3d_select.cc b/source/blender/editors/space_view3d/view3d_select.cc index b8c744f1c56..3344eb3aff1 100644 --- a/source/blender/editors/space_view3d/view3d_select.cc +++ b/source/blender/editors/space_view3d/view3d_select.cc @@ -3550,7 +3550,8 @@ static bool do_mesh_box_select(ViewContext *vc, } if (ts->selectmode & SCE_SELECT_EDGE) { /* Does both use_zbuf and non-use_zbuf versions (need screen cos for both) */ - struct BoxSelectUserData_ForMeshEdge cb_data {}; + struct BoxSelectUserData_ForMeshEdge cb_data { + }; cb_data.data = &data; cb_data.esel = use_zbuf ? esel : nullptr; cb_data.backbuf_offset = use_zbuf ? DRW_select_buffer_context_offset_for_object_elem( -- 2.30.2 From a577663ed917e5ffe865f4c58c78a05ab767c4b0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 8 Feb 2023 16:23:08 +1100 Subject: [PATCH 09/17] Fix #103913: Triangulate sometimes creates degenerate triangles The ear clipping method used by polyfill_2d only excluded concave ears which meant ears exactly co-linear edges created zero area triangles even when convex ears are available. While polyfill_2d prioritizes performance over *pretty* results, there is no need to pick degenerate triangles with other candidates are available. As noted in code-comments, callers that require higher quality tessellation should use BLI_polyfill_beautify. --- source/blender/blenlib/intern/polyfill_2d.c | 48 +++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/source/blender/blenlib/intern/polyfill_2d.c b/source/blender/blenlib/intern/polyfill_2d.c index 2b59de5b569..85421c9bdc7 100644 --- a/source/blender/blenlib/intern/polyfill_2d.c +++ b/source/blender/blenlib/intern/polyfill_2d.c @@ -155,7 +155,7 @@ static PolyIndex *pf_ear_tip_find(PolyFill *pf #endif ); -static bool pf_ear_tip_check(PolyFill *pf, PolyIndex *pi_ear_tip); +static bool pf_ear_tip_check(PolyFill *pf, PolyIndex *pi_ear_tip, const eSign sign_accept); static void pf_ear_tip_cut(PolyFill *pf, PolyIndex *pi_ear_tip); BLI_INLINE eSign signum_enum(float a) @@ -590,22 +590,44 @@ static PolyIndex *pf_ear_tip_find(PolyFill *pf uint i; + /* Use two passes when looking for an ear. + * + * - The first pass only picks *good* (concave) choices. + * For polygons which aren't degenerate this works well + * since it avoids creating any zero area faces. + * + * - The second pass is only met if no concave choices are possible, + * so the cost of a second pass is only incurred for degenerate polygons. + * In this case accept zero area faces as better alternatives aren't available. + * + * See: #103913 for reference. + * + * NOTE: these passes draw a distinction between zero area faces and concave + * which is susceptible minor differences in float precision + * (since #TANGENTIAL compares with 0.0f). + * + * While it's possible to compute an error threshold and run a pass that picks + * ears which are more likely not to appear as zero area from a users perspective, + * this API prioritizes performance (for real-time updates). + * Higher quality tessellation can always be achieved using #BLI_polyfill_beautify. + */ + for (eSign sign_accept = CONVEX; sign_accept >= TANGENTIAL; sign_accept--) { #ifdef USE_CLIP_EVEN - pi_ear = pi_ear_init; + pi_ear = pi_ear_init; #else - pi_ear = pf->indices; + pi_ear = pf->indices; #endif - - i = coords_num; - while (i--) { - if (pf_ear_tip_check(pf, pi_ear)) { - return pi_ear; - } + i = coords_num; + while (i--) { + if (pf_ear_tip_check(pf, pi_ear, sign_accept)) { + return pi_ear; + } #ifdef USE_CLIP_SWEEP - pi_ear = reverse ? pi_ear->prev : pi_ear->next; + pi_ear = reverse ? pi_ear->prev : pi_ear->next; #else - pi_ear = pi_ear->next; + pi_ear = pi_ear->next; #endif + } } /* Desperate mode: if no vertex is an ear tip, @@ -638,7 +660,7 @@ static PolyIndex *pf_ear_tip_find(PolyFill *pf return pi_ear; } -static bool pf_ear_tip_check(PolyFill *pf, PolyIndex *pi_ear_tip) +static bool pf_ear_tip_check(PolyFill *pf, PolyIndex *pi_ear_tip, const eSign sign_accept) { #ifndef USE_KDTREE /* localize */ @@ -674,7 +696,7 @@ static bool pf_ear_tip_check(PolyFill *pf, PolyIndex *pi_ear_tip) } #endif - if (UNLIKELY(pi_ear_tip->sign == CONCAVE)) { + if (UNLIKELY(pi_ear_tip->sign != sign_accept)) { return false; } -- 2.30.2 From 3df680e362bafe0e8a7f44fe87657b006f522acf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 8 Feb 2023 17:03:21 +1100 Subject: [PATCH 10/17] Cleanup: use enum literals, order likely case first in polyfill_2d --- source/blender/blenlib/intern/polyfill_2d.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source/blender/blenlib/intern/polyfill_2d.c b/source/blender/blenlib/intern/polyfill_2d.c index 85421c9bdc7..4f4166d8de8 100644 --- a/source/blender/blenlib/intern/polyfill_2d.c +++ b/source/blender/blenlib/intern/polyfill_2d.c @@ -160,14 +160,13 @@ static void pf_ear_tip_cut(PolyFill *pf, PolyIndex *pi_ear_tip); BLI_INLINE eSign signum_enum(float a) { - if (UNLIKELY(a == 0.0f)) { - return 0; - } if (a > 0.0f) { - return 1; + return CONVEX; } - - return -1; + if (UNLIKELY(a == 0.0f)) { + return TANGENTIAL; + } + return CONCAVE; } /** -- 2.30.2 From b6d83c0aaa2ccb4f6b3d49e3619b2c9500e72c79 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Wed, 25 Jan 2023 11:34:58 +0200 Subject: [PATCH 11/17] Subdivision Surface: fix a serious performance hit when mixing CPU & GPU. Subdivision surface efficiency relies on caching pre-computed topology data for evaluation between frames. However, while eed45d2a239a introduced a second GPU subdiv evaluator type, it still only kept one slot for caching this runtime data per mesh. The result is that if the mesh is also needed on CPU, for instance due to a modifier on a different object (e.g. shrinkwrap), the two evaluators are used at the same time and fight over the single slot. This causes the topology data to be discarded and recomputed twice per frame. Since avoiding duplicate evaluation is a complex task, this fix simply adds a second separate cache slot for the GPU data, so that the cost is simply running subdivision twice, not recomputing topology twice. To help diagnostics, I also add a message to show when GPU evaluation is actually used to the modifier panel. Two frame counters are used to suppress flicker in the UI panel. Differential Revision: https://developer.blender.org/D17117 Pull Request #104441 --- .../blender/blenkernel/BKE_subdiv_modifier.h | 9 ++++- .../blender/blenkernel/intern/mesh_wrapper.cc | 2 +- .../blenkernel/intern/subdiv_modifier.cc | 21 ++++++---- .../blender/modifiers/intern/MOD_subsurf.cc | 39 ++++++++++++++++--- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/source/blender/blenkernel/BKE_subdiv_modifier.h b/source/blender/blenkernel/BKE_subdiv_modifier.h index d65df26da77..dd01c4ffd07 100644 --- a/source/blender/blenkernel/BKE_subdiv_modifier.h +++ b/source/blender/blenkernel/BKE_subdiv_modifier.h @@ -32,8 +32,13 @@ typedef struct SubsurfRuntimeData { SubdivSettings settings; /* Cached subdivision surface descriptor, with topology and settings. */ - struct Subdiv *subdiv; - bool set_by_draw_code; + struct Subdiv *subdiv_cpu; + struct Subdiv *subdiv_gpu; + + /* Recent usage markers for UI diagnostics. To avoid UI flicker due to races + * between evaluation and UI redraw, they are set to 2 when an evaluator is used, + * and count down every frame. */ + char used_cpu, used_gpu; /* Cached mesh wrapper data, to be used for GPU subdiv or lazy evaluation on CPU. */ bool has_gpu_subdiv; diff --git a/source/blender/blenkernel/intern/mesh_wrapper.cc b/source/blender/blenkernel/intern/mesh_wrapper.cc index 9c8c36cacb8..3b036274477 100644 --- a/source/blender/blenkernel/intern/mesh_wrapper.cc +++ b/source/blender/blenkernel/intern/mesh_wrapper.cc @@ -350,7 +350,7 @@ static Mesh *mesh_wrapper_ensure_subdivision(Mesh *me) BKE_mesh_calc_normals_split(subdiv_mesh); } - if (subdiv != runtime_data->subdiv) { + if (subdiv != runtime_data->subdiv_cpu && subdiv != runtime_data->subdiv_gpu) { BKE_subdiv_free(subdiv); } diff --git a/source/blender/blenkernel/intern/subdiv_modifier.cc b/source/blender/blenkernel/intern/subdiv_modifier.cc index 3221e43d4e6..60d55af215c 100644 --- a/source/blender/blenkernel/intern/subdiv_modifier.cc +++ b/source/blender/blenkernel/intern/subdiv_modifier.cc @@ -49,6 +49,8 @@ bool BKE_subsurf_modifier_runtime_init(SubsurfModifierData *smd, const bool use_ * was already allocated. */ if (runtime_data) { runtime_data->settings = settings; + + runtime_data->used_cpu = runtime_data->used_gpu = 0; } return false; @@ -162,15 +164,18 @@ Subdiv *BKE_subsurf_modifier_subdiv_descriptor_ensure(SubsurfRuntimeData *runtim const Mesh *mesh, const bool for_draw_code) { - if (runtime_data->subdiv && runtime_data->set_by_draw_code != for_draw_code) { - BKE_subdiv_free(runtime_data->subdiv); - runtime_data->subdiv = nullptr; + if (for_draw_code) { + runtime_data->used_gpu = 2; /* countdown in frames */ + + return runtime_data->subdiv_gpu = BKE_subdiv_update_from_mesh( + runtime_data->subdiv_gpu, &runtime_data->settings, mesh); + } + else { + runtime_data->used_cpu = 2; + + return runtime_data->subdiv_cpu = BKE_subdiv_update_from_mesh( + runtime_data->subdiv_cpu, &runtime_data->settings, mesh); } - Subdiv *subdiv = BKE_subdiv_update_from_mesh( - runtime_data->subdiv, &runtime_data->settings, mesh); - runtime_data->subdiv = subdiv; - runtime_data->set_by_draw_code = for_draw_code; - return subdiv; } int BKE_subsurf_modifier_eval_required_mode(bool is_final_render, bool is_edit_mode) diff --git a/source/blender/modifiers/intern/MOD_subsurf.cc b/source/blender/modifiers/intern/MOD_subsurf.cc index 75377f00bb3..67e8b868f5d 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.cc +++ b/source/blender/modifiers/intern/MOD_subsurf.cc @@ -100,8 +100,11 @@ static void freeRuntimeData(void *runtime_data_v) return; } SubsurfRuntimeData *runtime_data = (SubsurfRuntimeData *)runtime_data_v; - if (runtime_data->subdiv != nullptr) { - BKE_subdiv_free(runtime_data->subdiv); + if (runtime_data->subdiv_cpu != nullptr) { + BKE_subdiv_free(runtime_data->subdiv_cpu); + } + if (runtime_data->subdiv_gpu != nullptr) { + BKE_subdiv_free(runtime_data->subdiv_gpu); } MEM_freeN(runtime_data); } @@ -227,6 +230,15 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * SubsurfRuntimeData *runtime_data = (SubsurfRuntimeData *)smd->modifier.runtime; + /* Decrement the recent usage counters. */ + if (runtime_data->used_cpu) { + runtime_data->used_cpu--; + } + + if (runtime_data->used_gpu) { + runtime_data->used_gpu--; + } + /* Delay evaluation to the draw code if possible, provided we do not have to apply the modifier. */ if ((ctx->flag & MOD_APPLY_TO_BASE_MESH) == 0) { @@ -273,7 +285,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * CustomData_set_layer_flag(&result->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); } // BKE_subdiv_stats_print(&subdiv->stats); - if (subdiv != runtime_data->subdiv) { + if (subdiv != runtime_data->subdiv_cpu && subdiv != runtime_data->subdiv_gpu) { BKE_subdiv_free(subdiv); } return result; @@ -305,7 +317,7 @@ static void deformMatrices(ModifierData *md, return; } BKE_subdiv_deform_coarse_vertices(subdiv, mesh, vertex_cos, verts_num); - if (subdiv != runtime_data->subdiv) { + if (subdiv != runtime_data->subdiv_cpu && subdiv != runtime_data->subdiv_gpu) { BKE_subdiv_free(subdiv); } } @@ -409,12 +421,29 @@ static void panel_draw(const bContext *C, Panel *panel) uiItemR(layout, ptr, "show_only_control_edges", 0, nullptr, ICON_NONE); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); SubsurfModifierData *smd = static_cast(ptr->data); - const Object *ob = static_cast(ob_ptr.data); + Object *ob = static_cast(ob_ptr.data); const Mesh *mesh = static_cast(ob->data); if (BKE_subsurf_modifier_force_disable_gpu_evaluation_for_mesh(smd, mesh)) { uiItemL(layout, "Autosmooth or custom normals detected, disabling GPU subdivision", ICON_INFO); } + else if (Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob)) { + if (ModifierData *md_eval = BKE_modifiers_findby_name(ob_eval, smd->modifier.name)) { + if (md_eval->type == eModifierType_Subsurf) { + SubsurfRuntimeData *runtime_data = (SubsurfRuntimeData *)md_eval->runtime; + + if (runtime_data && runtime_data->used_gpu) { + if (runtime_data->used_cpu) { + uiItemL(layout, "Using both CPU and GPU subdivision", ICON_INFO); + } + else { + uiItemL(layout, "Using GPU subdivision", ICON_INFO); + } + } + } + } + } modifier_panel_end(layout, ptr); } -- 2.30.2 From c92cae64fb59419a019aa92c32fb128f982d3573 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 8 Feb 2023 11:01:01 +0100 Subject: [PATCH 12/17] Fix references to the main branch in the .gitmodules --- .gitmodules | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index a8f3a3f80ab..9fd3a9a2c46 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,20 +1,20 @@ [submodule "release/scripts/addons"] path = release/scripts/addons url = ../blender-addons.git - branch = master + branch = main ignore = all [submodule "release/scripts/addons_contrib"] path = release/scripts/addons_contrib url = ../blender-addons-contrib.git - branch = master + branch = main ignore = all [submodule "release/datafiles/locale"] path = release/datafiles/locale url = ../blender-translations.git - branch = master + branch = main ignore = all [submodule "source/tools"] path = source/tools url = ../blender-dev-tools.git - branch = master + branch = main ignore = all -- 2.30.2 From a212d28ddf9a1388f9f7f004769d22293eda9fb4 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 8 Feb 2023 11:28:53 +0100 Subject: [PATCH 13/17] Un-ignore modules in .gitmodules configuration The meaning of the ignore option for submodules did change since our initial Git setup was done: back then it was affecting both diff and stage families of Git command. Unfortunately, the actual behavior did violate what documentation was stating (the documentation was stating that the option only affects diff family of commands). This got fixed in Git some time after our initial setup and it was the behavior of the commands changed, not the documentation. This lead to a situation when we can no longer see that submodules are modified and staged, and it is very easy to stage the submodules. For the clarity: diff and status are both "status" family, show and diff are "diff" family. Hence this change: since there is no built-in zero-configuration way of forbidding Git from staging submodules lets make it visible and clear what the state of submodules is. We still need to inform people to not stage submodules, for which we can offer some configuration tips and scripts but doing so is outside of the scope of this change at it requires some additional research. Current goal is simple: make it visible and clear what is going to be committed to Git. This is a response to an increased frequency of incidents when the submodules are getting modified and committed without authors even noticing this (which is also a bit annoying to recover from). Differential Revision: https://developer.blender.org/D13001 --- .gitmodules | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index 9fd3a9a2c46..adb6e8b77ad 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,19 +2,15 @@ path = release/scripts/addons url = ../blender-addons.git branch = main - ignore = all [submodule "release/scripts/addons_contrib"] path = release/scripts/addons_contrib url = ../blender-addons-contrib.git branch = main - ignore = all [submodule "release/datafiles/locale"] path = release/datafiles/locale url = ../blender-translations.git branch = main - ignore = all [submodule "source/tools"] path = source/tools url = ../blender-dev-tools.git branch = main - ignore = all -- 2.30.2 From 4390013458085a149c6e030779144425a2c7ecca Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 8 Feb 2023 14:05:50 +0100 Subject: [PATCH 14/17] Make update: Ignore submodules The previous change in the .gitmodules made it so the `make update` rejects to do its thing because it now sees changes in the submodules and rejected to update, thinking there are unstaged changes. Ignore the submodule changes, bringing the old behavior closer to what it was. --- build_files/utils/make_update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_files/utils/make_update.py b/build_files/utils/make_update.py index d367efca675..72909eb6fec 100755 --- a/build_files/utils/make_update.py +++ b/build_files/utils/make_update.py @@ -170,7 +170,7 @@ def git_update_skip(args: argparse.Namespace, check_remote_exists: bool = True) return "rebase or merge in progress, complete it first" # Abort if uncommitted changes. - changes = check_output([args.git_command, 'status', '--porcelain', '--untracked-files=no']) + changes = check_output([args.git_command, 'status', '--porcelain', '--untracked-files=no', '--ignore-submodules']) if len(changes) != 0: return "you have unstaged changes" -- 2.30.2 From 4037b34486de55a54de9175894a635fa0f68ef9e Mon Sep 17 00:00:00 2001 From: illua1 Date: Wed, 8 Feb 2023 18:21:27 +0300 Subject: [PATCH 15/17] checkout wrong changes --- source/tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/tools b/source/tools index 979bfe2504e..6a627cf37f0 160000 --- a/source/tools +++ b/source/tools @@ -1 +1 @@ -Subproject commit 979bfe2504eb2f446639ab5768aac9b80b1f4864 +Subproject commit 6a627cf37f040f27175c430fb6c1a89cb4278297 -- 2.30.2 From 33282263303e8998cec5a56adee9b155406e87dd Mon Sep 17 00:00:00 2001 From: illua1 Date: Wed, 8 Feb 2023 19:13:52 +0300 Subject: [PATCH 16/17] try 4 --- release/datafiles/locale | 2 +- release/scripts/addons | 2 +- release/scripts/addons_contrib | 2 +- .../nodes/node_geo_accumulate_field.cc | 157 ++++++++---------- source/tools | 2 +- 5 files changed, 72 insertions(+), 93 deletions(-) diff --git a/release/datafiles/locale b/release/datafiles/locale index 547a54b294f..4331c8e76c2 160000 --- a/release/datafiles/locale +++ b/release/datafiles/locale @@ -1 +1 @@ -Subproject commit 547a54b294f32ee11bce73273c6f183d8b235f92 +Subproject commit 4331c8e76c2f42b9fd903716c333d6cdeaa5cebd diff --git a/release/scripts/addons b/release/scripts/addons index 78b0fc30b6b..b3f0ffc587d 160000 --- a/release/scripts/addons +++ b/release/scripts/addons @@ -1 +1 @@ -Subproject commit 78b0fc30b6b6e610ef897fc7d26e812da348f2ff +Subproject commit b3f0ffc587d197b37eac9a1566d1d24b7bee7d9a diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib index 65ff08e325d..14ab9273409 160000 --- a/release/scripts/addons_contrib +++ b/release/scripts/addons_contrib @@ -1 +1 @@ -Subproject commit 65ff08e325d54a58b47fb3219ec7dbf417f20f18 +Subproject commit 14ab9273409ea0231d08ba6e86fdc73d4e459e99 diff --git a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc index 5ce67779384..f7a8496868e 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc @@ -2,10 +2,6 @@ #include "BKE_attribute_math.hh" -#include "BLI_array.hh" -#include "BLI_generic_virtual_array.hh" -#include "BLI_virtual_array.hh" - #include "NOD_socket_search_link.hh" #include "node_geometry_util.hh" @@ -196,19 +192,19 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } } -class AccumulateFieldInput final : public bke::GeometryFieldInput { +template class AccumulateFieldInput final : public bke::GeometryFieldInput { private: - GField input_; + Field input_; Field group_index_; eAttrDomain source_domain_; AccumulationMode accumulation_mode_; public: AccumulateFieldInput(const eAttrDomain source_domain, - GField input, + Field input, Field group_index, AccumulationMode accumulation_mode) - : bke::GeometryFieldInput(input.cpp_type(), "Accumulation"), + : bke::GeometryFieldInput(CPPType::get(), "Accumulation"), input_(input), group_index_(group_index), source_domain_(source_domain), @@ -220,7 +216,7 @@ class AccumulateFieldInput final : public bke::GeometryFieldInput { const IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int64_t domain_size = attributes.domain_size(source_domain_); + const int domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -231,55 +227,46 @@ class AccumulateFieldInput final : public bke::GeometryFieldInput { evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const GVArray g_values = evaluator.get_evaluated(0); + const VArray values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - GVArray g_output; + Array accumulations_out(domain_size); - attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { - using T = decltype(dummy); - if constexpr (is_same_any_v) { - Array outputs(domain_size); - const VArray values = g_values.typed(); - - if (group_indices.is_single()) { - T accumulation = T(); - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; - outputs[i] = accumulation; - } - } - else { - for (const int i : values.index_range()) { - outputs[i] = accumulation; - accumulation = values[i] + accumulation; - } - } + if (group_indices.is_single()) { + T accumulation = T(); + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; + accumulations_out[i] = accumulation; } - else { - Map accumulations; - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - accumulation_value += values[i]; - outputs[i] = accumulation_value; - } - } - else { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - outputs[i] = accumulation_value; - accumulation_value += values[i]; - } - } - } - - g_output = VArray::ForContainer(std::move(outputs)); } - }); + else { + for (const int i : values.index_range()) { + accumulations_out[i] = accumulation; + accumulation = values[i] + accumulation; + } + } + } + else { + Map accumulations; + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + accumulation_value += values[i]; + accumulations_out[i] = accumulation_value; + } + } + else { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + accumulations_out[i] = accumulation_value; + accumulation_value += values[i]; + } + } + } - return attributes.adapt_domain(std::move(g_output), source_domain_, context.domain()); + return attributes.adapt_domain( + VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); } uint64_t hash() const override @@ -306,15 +293,15 @@ class AccumulateFieldInput final : public bke::GeometryFieldInput { } }; -class TotalFieldInput final : public bke::GeometryFieldInput { +template class TotalFieldInput final : public bke::GeometryFieldInput { private: - GField input_; + Field input_; Field group_index_; eAttrDomain source_domain_; public: - TotalFieldInput(const eAttrDomain source_domain, GField input, Field group_index) - : bke::GeometryFieldInput(input.cpp_type(), "Total Value"), + TotalFieldInput(const eAttrDomain source_domain, Field input, Field group_index) + : bke::GeometryFieldInput(CPPType::get(), "Total Value"), input_(input), group_index_(group_index), source_domain_(source_domain) @@ -325,7 +312,7 @@ class TotalFieldInput final : public bke::GeometryFieldInput { IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int64_t domain_size = attributes.domain_size(source_domain_); + const int domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -336,38 +323,29 @@ class TotalFieldInput final : public bke::GeometryFieldInput { evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const GVArray g_values = evaluator.get_evaluated(0); + const VArray values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - GVArray g_outputs; - - attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { - using T = decltype(dummy); - if constexpr (is_same_any_v) { - const VArray values = g_values.typed(); - if (group_indices.is_single()) { - T accumulation = {}; - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; - } - g_outputs = VArray::ForSingle(accumulation, domain_size); - } - else { - Map accumulations; - for (const int i : values.index_range()) { - T &value = accumulations.lookup_or_add_default(group_indices[i]); - value = value + values[i]; - } - Array outputs(domain_size); - for (const int i : values.index_range()) { - outputs[i] = accumulations.lookup(group_indices[i]); - } - g_outputs = VArray::ForContainer(std::move(outputs)); - } + if (group_indices.is_single()) { + T accumulation = T(); + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; } - }); + return VArray::ForSingle(accumulation, domain_size); + } - return attributes.adapt_domain(std::move(g_outputs), source_domain_, context.domain()); + Array accumulations_out(domain_size); + Map accumulations; + for (const int i : values.index_range()) { + T &value = accumulations.lookup_or_add_default(group_indices[i]); + value = value + values[i]; + } + for (const int i : values.index_range()) { + accumulations_out[i] = accumulations.lookup(group_indices[i]); + } + + return attributes.adapt_domain( + VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); } uint64_t hash() const override @@ -413,24 +391,25 @@ static void node_geo_exec(GeoNodeExecParams params) Field group_index_field = params.extract_input>("Group Index"); attribute_math::convert_to_static_type(data_type, [&](auto dummy) { using T = decltype(dummy); - if constexpr (is_same_any_v) { + if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v) { const std::string suffix = " " + identifier_suffix(); Field input_field = params.extract_input>("Value" + suffix); if (params.output_is_required("Leading" + suffix)) { params.set_output( "Leading" + suffix, - Field{std::make_shared( + Field{std::make_shared>( source_domain, input_field, group_index_field, AccumulationMode::Leading)}); } if (params.output_is_required("Trailing" + suffix)) { params.set_output( "Trailing" + suffix, - Field{std::make_shared( + Field{std::make_shared>( source_domain, input_field, group_index_field, AccumulationMode::Trailing)}); } if (params.output_is_required("Total" + suffix)) { params.set_output("Total" + suffix, - Field{std::make_shared( + Field{std::make_shared>( source_domain, input_field, group_index_field)}); } } diff --git a/source/tools b/source/tools index 6a627cf37f0..e133fc08cd3 160000 --- a/source/tools +++ b/source/tools @@ -1 +1 @@ -Subproject commit 6a627cf37f040f27175c430fb6c1a89cb4278297 +Subproject commit e133fc08cd3254bb3d3bd1345028c8486700bca4 -- 2.30.2 From e2e5ca83da70fd6fc69368c96ec773da048c2d61 Mon Sep 17 00:00:00 2001 From: illua1 Date: Wed, 8 Feb 2023 19:49:19 +0300 Subject: [PATCH 17/17] fix! --- .../nodes/node_geo_accumulate_field.cc | 161 ++++++++++-------- 1 file changed, 91 insertions(+), 70 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc index f7a8496868e..5ce67779384 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc @@ -2,6 +2,10 @@ #include "BKE_attribute_math.hh" +#include "BLI_array.hh" +#include "BLI_generic_virtual_array.hh" +#include "BLI_virtual_array.hh" + #include "NOD_socket_search_link.hh" #include "node_geometry_util.hh" @@ -192,19 +196,19 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) } } -template class AccumulateFieldInput final : public bke::GeometryFieldInput { +class AccumulateFieldInput final : public bke::GeometryFieldInput { private: - Field input_; + GField input_; Field group_index_; eAttrDomain source_domain_; AccumulationMode accumulation_mode_; public: AccumulateFieldInput(const eAttrDomain source_domain, - Field input, + GField input, Field group_index, AccumulationMode accumulation_mode) - : bke::GeometryFieldInput(CPPType::get(), "Accumulation"), + : bke::GeometryFieldInput(input.cpp_type(), "Accumulation"), input_(input), group_index_(group_index), source_domain_(source_domain), @@ -216,7 +220,7 @@ template class AccumulateFieldInput final : public bke::GeometryFiel const IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int domain_size = attributes.domain_size(source_domain_); + const int64_t domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -227,46 +231,55 @@ template class AccumulateFieldInput final : public bke::GeometryFiel evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const VArray values = evaluator.get_evaluated(0); + const GVArray g_values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - Array accumulations_out(domain_size); + GVArray g_output; - if (group_indices.is_single()) { - T accumulation = T(); - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; - accumulations_out[i] = accumulation; - } - } - else { - for (const int i : values.index_range()) { - accumulations_out[i] = accumulation; - accumulation = values[i] + accumulation; - } - } - } - else { - Map accumulations; - if (accumulation_mode_ == AccumulationMode::Leading) { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - accumulation_value += values[i]; - accumulations_out[i] = accumulation_value; - } - } - else { - for (const int i : values.index_range()) { - T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); - accumulations_out[i] = accumulation_value; - accumulation_value += values[i]; - } - } - } + attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { + using T = decltype(dummy); + if constexpr (is_same_any_v) { + Array outputs(domain_size); + const VArray values = g_values.typed(); - return attributes.adapt_domain( - VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); + if (group_indices.is_single()) { + T accumulation = T(); + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; + outputs[i] = accumulation; + } + } + else { + for (const int i : values.index_range()) { + outputs[i] = accumulation; + accumulation = values[i] + accumulation; + } + } + } + else { + Map accumulations; + if (accumulation_mode_ == AccumulationMode::Leading) { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + accumulation_value += values[i]; + outputs[i] = accumulation_value; + } + } + else { + for (const int i : values.index_range()) { + T &accumulation_value = accumulations.lookup_or_add_default(group_indices[i]); + outputs[i] = accumulation_value; + accumulation_value += values[i]; + } + } + } + + g_output = VArray::ForContainer(std::move(outputs)); + } + }); + + return attributes.adapt_domain(std::move(g_output), source_domain_, context.domain()); } uint64_t hash() const override @@ -293,15 +306,15 @@ template class AccumulateFieldInput final : public bke::GeometryFiel } }; -template class TotalFieldInput final : public bke::GeometryFieldInput { +class TotalFieldInput final : public bke::GeometryFieldInput { private: - Field input_; + GField input_; Field group_index_; eAttrDomain source_domain_; public: - TotalFieldInput(const eAttrDomain source_domain, Field input, Field group_index) - : bke::GeometryFieldInput(CPPType::get(), "Total Value"), + TotalFieldInput(const eAttrDomain source_domain, GField input, Field group_index) + : bke::GeometryFieldInput(input.cpp_type(), "Total Value"), input_(input), group_index_(group_index), source_domain_(source_domain) @@ -312,7 +325,7 @@ template class TotalFieldInput final : public bke::GeometryFieldInpu IndexMask /*mask*/) const final { const AttributeAccessor attributes = *context.attributes(); - const int domain_size = attributes.domain_size(source_domain_); + const int64_t domain_size = attributes.domain_size(source_domain_); if (domain_size == 0) { return {}; } @@ -323,29 +336,38 @@ template class TotalFieldInput final : public bke::GeometryFieldInpu evaluator.add(input_); evaluator.add(group_index_); evaluator.evaluate(); - const VArray values = evaluator.get_evaluated(0); + const GVArray g_values = evaluator.get_evaluated(0); const VArray group_indices = evaluator.get_evaluated(1); - if (group_indices.is_single()) { - T accumulation = T(); - for (const int i : values.index_range()) { - accumulation = values[i] + accumulation; + GVArray g_outputs; + + attribute_math::convert_to_static_type(g_values.type(), [&](auto dummy) { + using T = decltype(dummy); + if constexpr (is_same_any_v) { + const VArray values = g_values.typed(); + if (group_indices.is_single()) { + T accumulation = {}; + for (const int i : values.index_range()) { + accumulation = values[i] + accumulation; + } + g_outputs = VArray::ForSingle(accumulation, domain_size); + } + else { + Map accumulations; + for (const int i : values.index_range()) { + T &value = accumulations.lookup_or_add_default(group_indices[i]); + value = value + values[i]; + } + Array outputs(domain_size); + for (const int i : values.index_range()) { + outputs[i] = accumulations.lookup(group_indices[i]); + } + g_outputs = VArray::ForContainer(std::move(outputs)); + } } - return VArray::ForSingle(accumulation, domain_size); - } + }); - Array accumulations_out(domain_size); - Map accumulations; - for (const int i : values.index_range()) { - T &value = accumulations.lookup_or_add_default(group_indices[i]); - value = value + values[i]; - } - for (const int i : values.index_range()) { - accumulations_out[i] = accumulations.lookup(group_indices[i]); - } - - return attributes.adapt_domain( - VArray::ForContainer(std::move(accumulations_out)), source_domain_, context.domain()); + return attributes.adapt_domain(std::move(g_outputs), source_domain_, context.domain()); } uint64_t hash() const override @@ -391,25 +413,24 @@ static void node_geo_exec(GeoNodeExecParams params) Field group_index_field = params.extract_input>("Group Index"); attribute_math::convert_to_static_type(data_type, [&](auto dummy) { using T = decltype(dummy); - if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v) { + if constexpr (is_same_any_v) { const std::string suffix = " " + identifier_suffix(); Field input_field = params.extract_input>("Value" + suffix); if (params.output_is_required("Leading" + suffix)) { params.set_output( "Leading" + suffix, - Field{std::make_shared>( + Field{std::make_shared( source_domain, input_field, group_index_field, AccumulationMode::Leading)}); } if (params.output_is_required("Trailing" + suffix)) { params.set_output( "Trailing" + suffix, - Field{std::make_shared>( + Field{std::make_shared( source_domain, input_field, group_index_field, AccumulationMode::Trailing)}); } if (params.output_is_required("Total" + suffix)) { params.set_output("Total" + suffix, - Field{std::make_shared>( + Field{std::make_shared( source_domain, input_field, group_index_field)}); } } -- 2.30.2