Mesh: Replace auto smooth with node group #108014
|
@ -387,34 +387,19 @@ blender::Span<blender::float3> Mesh::face_normals() const
|
||||||
blender::Span<blender::float3> Mesh::corner_normals() const
|
blender::Span<blender::float3> Mesh::corner_normals() const
|
||||||
{
|
{
|
||||||
using namespace blender;
|
using namespace blender;
|
||||||
using namespace blender::bke;
|
this->runtime->corner_normals_cache.ensure([&](Vector<float3> &r_data) {
|
||||||
if (!this->runtime->corner_normals_dirty) {
|
|
||||||
BLI_assert(this->runtime->corner_normals.size() == this->totloop);
|
|
||||||
return this->runtime->corner_normals;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Span<float3> vert_normals = this->vert_normals();
|
|
||||||
const Span<float3> face_normals = this->face_normals();
|
|
||||||
std::lock_guard lock{this->runtime->normals_mutex};
|
|
||||||
if (!this->runtime->corner_normals_dirty) {
|
|
||||||
BLI_assert(this->runtime->corner_normals.size() == this->totloop);
|
|
||||||
return this->runtime->corner_normals;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Isolate task because a mutex is locked and computing normals is multi-threaded. */
|
|
||||||
threading::isolate_task([&]() {
|
|
||||||
const OffsetIndices faces = this->faces();
|
const OffsetIndices faces = this->faces();
|
||||||
this->runtime->corner_normals.reinitialize(this->totloop);
|
r_data.reinitialize(faces.total_size());
|
||||||
MutableSpan<float3> corner_normals = this->runtime->corner_normals;
|
|
||||||
switch (this->normal_domain_all_info()) {
|
switch (this->normal_domain_all_info()) {
|
||||||
case ATTR_DOMAIN_POINT: {
|
case ATTR_DOMAIN_POINT: {
|
||||||
array_utils::gather(vert_normals, this->corner_verts(), corner_normals);
|
array_utils::gather(this->vert_normals(), this->corner_verts(), r_data.as_mutable_span());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ATTR_DOMAIN_FACE: {
|
case ATTR_DOMAIN_FACE: {
|
||||||
threading::parallel_for(face_normals.index_range(), 1024, [&](const IndexRange range) {
|
const Span<float3> face_normals = this->face_normals();
|
||||||
|
threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
|
||||||
for (const int i : range) {
|
for (const int i : range) {
|
||||||
corner_normals.slice(faces[i]).fill(face_normals[i]);
|
r_data.as_mutable_span().slice(faces[i]).fill(face_normals[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -432,23 +417,20 @@ blender::Span<blender::float3> Mesh::corner_normals() const
|
||||||
this->corner_verts(),
|
this->corner_verts(),
|
||||||
this->corner_edges(),
|
this->corner_edges(),
|
||||||
{},
|
{},
|
||||||
vert_normals,
|
this->vert_normals(),
|
||||||
face_normals,
|
this->face_normals(),
|
||||||
sharp_edges,
|
sharp_edges,
|
||||||
sharp_faces,
|
sharp_faces,
|
||||||
custom_normals,
|
custom_normals,
|
||||||
nullptr,
|
nullptr,
|
||||||
this->runtime->corner_normals);
|
r_data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BLI_assert_unreachable();
|
BLI_assert_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->runtime->corner_normals_dirty = false;
|
|
||||||
});
|
});
|
||||||
|
return this->runtime->corner_normals_cache.data();
|
||||||
return this->runtime->corner_normals;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr,
|
void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr,
|
||||||
|
|
Loading…
Reference in New Issue