forked from blender/blender
main sync #3
@ -196,16 +196,4 @@ inline blender::MutableSpan<MDeformVert> Mesh::deform_verts_for_write()
|
|||||||
return {BKE_mesh_deform_verts_for_write(this), this->totvert};
|
return {BKE_mesh_deform_verts_for_write(this), this->totvert};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline blender::Span<blender::float3> Mesh::poly_normals() const
|
|
||||||
{
|
|
||||||
return {reinterpret_cast<const blender::float3 *>(BKE_mesh_poly_normals_ensure(this)),
|
|
||||||
this->totpoly};
|
|
||||||
}
|
|
||||||
|
|
||||||
inline blender::Span<blender::float3> Mesh::vert_normals() const
|
|
||||||
{
|
|
||||||
return {reinterpret_cast<const blender::float3 *>(BKE_mesh_vert_normals_ensure(this)),
|
|
||||||
this->totvert};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
@ -327,71 +327,73 @@ void normals_calc_poly_vert(const Span<float3> positions,
|
|||||||
/** \name Mesh Normal Calculation
|
/** \name Mesh Normal Calculation
|
||||||
* \{ */
|
* \{ */
|
||||||
|
|
||||||
const float (*BKE_mesh_vert_normals_ensure(const Mesh *mesh))[3]
|
blender::Span<blender::float3> Mesh::vert_normals() const
|
||||||
{
|
{
|
||||||
if (!mesh->runtime->vert_normals_dirty) {
|
if (!this->runtime->vert_normals_dirty) {
|
||||||
BLI_assert(mesh->runtime->vert_normals.size() == mesh->totvert);
|
BLI_assert(this->runtime->vert_normals.size() == this->totvert);
|
||||||
return reinterpret_cast<const float(*)[3]>(mesh->runtime->vert_normals.data());
|
return this->runtime->vert_normals;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mesh->totvert == 0) {
|
std::lock_guard lock{this->runtime->normals_mutex};
|
||||||
return nullptr;
|
if (!this->runtime->vert_normals_dirty) {
|
||||||
}
|
BLI_assert(this->runtime->vert_normals.size() == this->totvert);
|
||||||
|
return this->runtime->vert_normals;
|
||||||
std::lock_guard lock{mesh->runtime->normals_mutex};
|
|
||||||
if (!mesh->runtime->vert_normals_dirty) {
|
|
||||||
BLI_assert(mesh->runtime->vert_normals.size() == mesh->totvert);
|
|
||||||
return reinterpret_cast<const float(*)[3]>(mesh->runtime->vert_normals.data());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Isolate task because a mutex is locked and computing normals is multi-threaded. */
|
/* Isolate task because a mutex is locked and computing normals is multi-threaded. */
|
||||||
blender::threading::isolate_task([&]() {
|
blender::threading::isolate_task([&]() {
|
||||||
const Span<float3> positions = mesh->vert_positions();
|
const Span<float3> positions = this->vert_positions();
|
||||||
const Span<MPoly> polys = mesh->polys();
|
const Span<MPoly> polys = this->polys();
|
||||||
const Span<MLoop> loops = mesh->loops();
|
const Span<MLoop> loops = this->loops();
|
||||||
|
|
||||||
mesh->runtime->vert_normals.reinitialize(positions.size());
|
this->runtime->vert_normals.reinitialize(positions.size());
|
||||||
mesh->runtime->poly_normals.reinitialize(polys.size());
|
this->runtime->poly_normals.reinitialize(polys.size());
|
||||||
blender::bke::mesh::normals_calc_poly_vert(
|
blender::bke::mesh::normals_calc_poly_vert(
|
||||||
positions, polys, loops, mesh->runtime->poly_normals, mesh->runtime->vert_normals);
|
positions, polys, loops, this->runtime->poly_normals, this->runtime->vert_normals);
|
||||||
|
|
||||||
mesh->runtime->vert_normals_dirty = false;
|
this->runtime->vert_normals_dirty = false;
|
||||||
mesh->runtime->poly_normals_dirty = false;
|
this->runtime->poly_normals_dirty = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
return reinterpret_cast<const float(*)[3]>(mesh->runtime->vert_normals.data());
|
return this->runtime->vert_normals;
|
||||||
|
}
|
||||||
|
|
||||||
|
blender::Span<blender::float3> Mesh::poly_normals() const
|
||||||
|
{
|
||||||
|
if (!this->runtime->poly_normals_dirty) {
|
||||||
|
BLI_assert(this->runtime->poly_normals.size() == this->totpoly);
|
||||||
|
return this->runtime->poly_normals;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::lock_guard lock{this->runtime->normals_mutex};
|
||||||
|
if (!this->runtime->poly_normals_dirty) {
|
||||||
|
BLI_assert(this->runtime->poly_normals.size() == this->totpoly);
|
||||||
|
return this->runtime->poly_normals;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Isolate task because a mutex is locked and computing normals is multi-threaded. */
|
||||||
|
blender::threading::isolate_task([&]() {
|
||||||
|
const Span<float3> positions = this->vert_positions();
|
||||||
|
const Span<MPoly> polys = this->polys();
|
||||||
|
const Span<MLoop> loops = this->loops();
|
||||||
|
|
||||||
|
this->runtime->poly_normals.reinitialize(polys.size());
|
||||||
|
blender::bke::mesh::normals_calc_polys(positions, polys, loops, this->runtime->poly_normals);
|
||||||
|
|
||||||
|
this->runtime->poly_normals_dirty = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
return this->runtime->poly_normals;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float (*BKE_mesh_vert_normals_ensure(const Mesh *mesh))[3]
|
||||||
|
{
|
||||||
|
return reinterpret_cast<const float(*)[3]>(mesh->vert_normals().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
const float (*BKE_mesh_poly_normals_ensure(const Mesh *mesh))[3]
|
const float (*BKE_mesh_poly_normals_ensure(const Mesh *mesh))[3]
|
||||||
{
|
{
|
||||||
if (!mesh->runtime->poly_normals_dirty) {
|
return reinterpret_cast<const float(*)[3]>(mesh->vert_normals().data());
|
||||||
BLI_assert(mesh->runtime->poly_normals.size() == mesh->totpoly);
|
|
||||||
return reinterpret_cast<const float(*)[3]>(mesh->runtime->poly_normals.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mesh->totpoly == 0) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::lock_guard lock{mesh->runtime->normals_mutex};
|
|
||||||
if (!mesh->runtime->poly_normals_dirty) {
|
|
||||||
BLI_assert(mesh->runtime->poly_normals.size() == mesh->totpoly);
|
|
||||||
return reinterpret_cast<const float(*)[3]>(mesh->runtime->poly_normals.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Isolate task because a mutex is locked and computing normals is multi-threaded. */
|
|
||||||
blender::threading::isolate_task([&]() {
|
|
||||||
const Span<float3> positions = mesh->vert_positions();
|
|
||||||
const Span<MPoly> polys = mesh->polys();
|
|
||||||
const Span<MLoop> loops = mesh->loops();
|
|
||||||
|
|
||||||
mesh->runtime->poly_normals.reinitialize(polys.size());
|
|
||||||
blender::bke::mesh::normals_calc_polys(positions, polys, loops, mesh->runtime->poly_normals);
|
|
||||||
|
|
||||||
mesh->runtime->poly_normals_dirty = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
return reinterpret_cast<const float(*)[3]>(mesh->runtime->poly_normals.data());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BKE_mesh_ensure_normals_for_display(Mesh *mesh)
|
void BKE_mesh_ensure_normals_for_display(Mesh *mesh)
|
||||||
|
Loading…
Reference in New Issue
Block a user