Mesh: Replace auto smooth with node group #108014
|
@ -317,21 +317,20 @@ eAttrDomain Mesh::normal_domain_all_info() const
|
||||||
const VArray<bool> sharp_faces = *attributes.lookup_or_default<bool>(
|
const VArray<bool> sharp_faces = *attributes.lookup_or_default<bool>(
|
||||||
"sharp_face", ATTR_DOMAIN_FACE, false);
|
"sharp_face", ATTR_DOMAIN_FACE, false);
|
||||||
|
|
||||||
const array_utils::BoolArrayMix face_mix = array_utils::booleans_mix_calc(sharp_faces);
|
const array_utils::BooleanMix face_mix = array_utils::booleans_mix_calc(sharp_faces);
|
||||||
if (face_mix == array_utils::BoolArrayMix::AllTrue) {
|
if (face_mix == array_utils::BooleanMix::AllTrue) {
|
||||||
return ATTR_DOMAIN_FACE;
|
return ATTR_DOMAIN_FACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VArray<bool> sharp_edges = *attributes.lookup_or_default<bool>(
|
const VArray<bool> sharp_edges = *attributes.lookup_or_default<bool>(
|
||||||
"sharp_edge", ATTR_DOMAIN_EDGE, false);
|
"sharp_edge", ATTR_DOMAIN_EDGE, false);
|
||||||
const array_utils::BoolArrayMix edge_mix = array_utils::booleans_mix_calc(sharp_edges);
|
const array_utils::BooleanMix edge_mix = array_utils::booleans_mix_calc(sharp_edges);
|
||||||
if (edge_mix == array_utils::BoolArrayMix::AllTrue) {
|
if (edge_mix == array_utils::BooleanMix::AllTrue) {
|
||||||
return ATTR_DOMAIN_FACE;
|
return ATTR_DOMAIN_FACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edge_mix == array_utils::BoolArrayMix::AllFalse &&
|
if (edge_mix == array_utils::BooleanMix::AllFalse &&
|
||||||
face_mix == array_utils::BoolArrayMix::AllFalse)
|
face_mix == array_utils::BooleanMix::AllFalse) {
|
||||||
{
|
|
||||||
return ATTR_DOMAIN_POINT;
|
return ATTR_DOMAIN_POINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,14 +140,15 @@ inline void gather(const VArray<T> &src,
|
||||||
}
|
}
|
||||||
|
|
||||||
void invert_booleans(MutableSpan<bool> span);
|
void invert_booleans(MutableSpan<bool> span);
|
||||||
enum class BoolArrayMix {
|
|
||||||
|
enum class BooleanMix {
|
||||||
None,
|
None,
|
||||||
AllFalse,
|
AllFalse,
|
||||||
AllTrue,
|
AllTrue,
|
||||||
Mixed,
|
Mixed,
|
||||||
};
|
};
|
||||||
BoolArrayMix booleans_mix_calc(const VArray<bool> &varray, IndexRange range_to_check);
|
BooleanMix booleans_mix_calc(const VArray<bool> &varray, IndexRange range_to_check);
|
||||||
inline BoolArrayMix booleans_mix_calc(const VArray<bool> &varray)
|
inline BooleanMix booleans_mix_calc(const VArray<bool> &varray)
|
||||||
{
|
{
|
||||||
return booleans_mix_calc(varray, varray.index_range());
|
return booleans_mix_calc(varray, varray.index_range());
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,23 +52,23 @@ void invert_booleans(MutableSpan<bool> span)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
BoolArrayMix booleans_mix_calc(const VArray<bool> &varray, const IndexRange range_to_check)
|
BooleanMix booleans_mix_calc(const VArray<bool> &varray, const IndexRange range_to_check)
|
||||||
{
|
{
|
||||||
if (varray.is_empty()) {
|
if (varray.is_empty()) {
|
||||||
return BoolArrayMix::None;
|
return BooleanMix::None;
|
||||||
}
|
}
|
||||||
const CommonVArrayInfo info = varray.common_info();
|
const CommonVArrayInfo info = varray.common_info();
|
||||||
if (info.type == CommonVArrayInfo::Type::Single) {
|
if (info.type == CommonVArrayInfo::Type::Single) {
|
||||||
return *static_cast<const bool *>(info.data) ? BoolArrayMix::AllTrue : BoolArrayMix::AllFalse;
|
return *static_cast<const bool *>(info.data) ? BooleanMix::AllTrue : BooleanMix::AllFalse;
|
||||||
}
|
}
|
||||||
if (info.type == CommonVArrayInfo::Type::Span) {
|
if (info.type == CommonVArrayInfo::Type::Span) {
|
||||||
const Span<bool> span(static_cast<const bool *>(info.data), varray.size());
|
const Span<bool> span(static_cast<const bool *>(info.data), varray.size());
|
||||||
return threading::parallel_reduce(
|
return threading::parallel_reduce(
|
||||||
range_to_check,
|
range_to_check,
|
||||||
4096,
|
4096,
|
||||||
BoolArrayMix::None,
|
BooleanMix::None,
|
||||||
[&](const IndexRange range, const BoolArrayMix init) {
|
[&](const IndexRange range, const BooleanMix init) {
|
||||||
if (init == BoolArrayMix::Mixed) {
|
if (init == BooleanMix::Mixed) {
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,31 +76,31 @@ BoolArrayMix booleans_mix_calc(const VArray<bool> &varray, const IndexRange rang
|
||||||
const bool first = slice.first();
|
const bool first = slice.first();
|
||||||
for (const bool value : slice.drop_front(1)) {
|
for (const bool value : slice.drop_front(1)) {
|
||||||
if (value != first) {
|
if (value != first) {
|
||||||
return BoolArrayMix::Mixed;
|
return BooleanMix::Mixed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return first ? BoolArrayMix::AllTrue : BoolArrayMix::AllFalse;
|
return first ? BooleanMix::AllTrue : BooleanMix::AllFalse;
|
||||||
},
|
},
|
||||||
[&](BoolArrayMix a, BoolArrayMix b) { return (a == b) ? a : BoolArrayMix::Mixed; });
|
[&](BooleanMix a, BooleanMix b) { return (a == b) ? a : BooleanMix::Mixed; });
|
||||||
}
|
}
|
||||||
return threading::parallel_reduce(
|
return threading::parallel_reduce(
|
||||||
range_to_check,
|
range_to_check,
|
||||||
2048,
|
2048,
|
||||||
BoolArrayMix::None,
|
BooleanMix::None,
|
||||||
[&](const IndexRange range, const BoolArrayMix init) {
|
[&](const IndexRange range, const BooleanMix init) {
|
||||||
if (init == BoolArrayMix::Mixed) {
|
if (init == BooleanMix::Mixed) {
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
/* Alternatively, this could use #materialize to retrieve many values at once. */
|
/* Alternatively, this could use #materialize to retrieve many values at once. */
|
||||||
const bool first = varray[range.first()];
|
const bool first = varray[range.first()];
|
||||||
for (const int64_t i : range.drop_front(1)) {
|
for (const int64_t i : range.drop_front(1)) {
|
||||||
if (varray[i] != first) {
|
if (varray[i] != first) {
|
||||||
return BoolArrayMix::Mixed;
|
return BooleanMix::Mixed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return first ? BoolArrayMix::AllTrue : BoolArrayMix::AllFalse;
|
return first ? BooleanMix::AllTrue : BooleanMix::AllFalse;
|
||||||
},
|
},
|
||||||
[&](BoolArrayMix a, BoolArrayMix b) { return (a == b) ? a : BoolArrayMix::Mixed; });
|
[&](BooleanMix a, BooleanMix b) { return (a == b) ? a : BooleanMix::Mixed; });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::array_utils
|
} // namespace blender::array_utils
|
||||||
|
|
Loading…
Reference in New Issue