Cleanup: Variable name style in STL importer
Designate private variable names as described by the style guide, and also add `num` at the end of variable names rather than at the beginning, as discussed in T85728.
This commit is contained in:
parent
4475c38c5c
commit
28f4fc664f
|
@ -21,30 +21,30 @@
|
|||
|
||||
namespace blender::io::stl {
|
||||
|
||||
STLMeshHelper::STLMeshHelper(int num_tris, bool use_custom_normals)
|
||||
: m_use_custom_normals(use_custom_normals)
|
||||
STLMeshHelper::STLMeshHelper(int tris_num, bool use_custom_normals)
|
||||
: use_custom_normals_(use_custom_normals)
|
||||
{
|
||||
m_num_degenerate_tris = 0;
|
||||
m_num_duplicate_tris = 0;
|
||||
m_tris.reserve(num_tris);
|
||||
degenerate_tris_num_ = 0;
|
||||
duplicate_tris_num_ = 0;
|
||||
tris_.reserve(tris_num);
|
||||
/* Upper bound (all vertices are unique). */
|
||||
m_verts.reserve(num_tris * 3);
|
||||
verts_.reserve(tris_num * 3);
|
||||
if (use_custom_normals) {
|
||||
m_loop_normals.reserve(num_tris * 3);
|
||||
loop_normals_.reserve(tris_num * 3);
|
||||
}
|
||||
}
|
||||
|
||||
bool STLMeshHelper::add_triangle(const float3 &a, const float3 &b, const float3 &c)
|
||||
{
|
||||
int v1_id = m_verts.index_of_or_add(a);
|
||||
int v2_id = m_verts.index_of_or_add(b);
|
||||
int v3_id = m_verts.index_of_or_add(c);
|
||||
int v1_id = verts_.index_of_or_add(a);
|
||||
int v2_id = verts_.index_of_or_add(b);
|
||||
int v3_id = verts_.index_of_or_add(c);
|
||||
if ((v1_id == v2_id) || (v1_id == v3_id) || (v2_id == v3_id)) {
|
||||
m_num_degenerate_tris++;
|
||||
degenerate_tris_num_++;
|
||||
return false;
|
||||
}
|
||||
if (!m_tris.add({v1_id, v2_id, v3_id})) {
|
||||
m_num_duplicate_tris++;
|
||||
if (!tris_.add({v1_id, v2_id, v3_id})) {
|
||||
duplicate_tris_num_++;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -56,18 +56,18 @@ void STLMeshHelper::add_triangle(const float3 &a,
|
|||
const float3 &custom_normal)
|
||||
{
|
||||
if (add_triangle(a, b, c)) {
|
||||
m_loop_normals.append_n_times(custom_normal, 3);
|
||||
loop_normals_.append_n_times(custom_normal, 3);
|
||||
}
|
||||
}
|
||||
|
||||
Mesh *STLMeshHelper::to_mesh(Main *bmain, char *mesh_name)
|
||||
{
|
||||
if (m_num_degenerate_tris > 0) {
|
||||
std::cout << "STL Importer: " << m_num_degenerate_tris << "degenerate triangles were removed"
|
||||
if (degenerate_tris_num_ > 0) {
|
||||
std::cout << "STL Importer: " << degenerate_tris_num_ << "degenerate triangles were removed"
|
||||
<< std::endl;
|
||||
}
|
||||
if (m_num_duplicate_tris > 0) {
|
||||
std::cout << "STL Importer: " << m_num_duplicate_tris << "duplicate triangles were removed"
|
||||
if (duplicate_tris_num_ > 0) {
|
||||
std::cout << "STL Importer: " << duplicate_tris_num_ << "duplicate triangles were removed"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
@ -75,36 +75,36 @@ Mesh *STLMeshHelper::to_mesh(Main *bmain, char *mesh_name)
|
|||
/* User count is already 1 here, but will be set later in #BKE_mesh_assign_object. */
|
||||
id_us_min(&mesh->id);
|
||||
|
||||
mesh->totvert = m_verts.size();
|
||||
mesh->totvert = verts_.size();
|
||||
mesh->mvert = static_cast<MVert *>(
|
||||
CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CALLOC, nullptr, mesh->totvert));
|
||||
for (int i = 0; i < mesh->totvert; i++) {
|
||||
copy_v3_v3(mesh->mvert[i].co, m_verts[i]);
|
||||
copy_v3_v3(mesh->mvert[i].co, verts_[i]);
|
||||
}
|
||||
|
||||
mesh->totpoly = m_tris.size();
|
||||
mesh->totloop = m_tris.size() * 3;
|
||||
mesh->totpoly = tris_.size();
|
||||
mesh->totloop = tris_.size() * 3;
|
||||
mesh->mpoly = static_cast<MPoly *>(
|
||||
CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_CALLOC, nullptr, mesh->totpoly));
|
||||
mesh->mloop = static_cast<MLoop *>(
|
||||
CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_CALLOC, nullptr, mesh->totloop));
|
||||
|
||||
threading::parallel_for(m_tris.index_range(), 2048, [&](IndexRange tris_range) {
|
||||
threading::parallel_for(tris_.index_range(), 2048, [&](IndexRange tris_range) {
|
||||
for (const int i : tris_range) {
|
||||
mesh->mpoly[i].loopstart = 3 * i;
|
||||
mesh->mpoly[i].totloop = 3;
|
||||
|
||||
mesh->mloop[3 * i].v = m_tris[i].v1;
|
||||
mesh->mloop[3 * i + 1].v = m_tris[i].v2;
|
||||
mesh->mloop[3 * i + 2].v = m_tris[i].v3;
|
||||
mesh->mloop[3 * i].v = tris_[i].v1;
|
||||
mesh->mloop[3 * i + 1].v = tris_[i].v2;
|
||||
mesh->mloop[3 * i + 2].v = tris_[i].v3;
|
||||
}
|
||||
});
|
||||
|
||||
/* NOTE: edges must be calculated first before setting custom normals. */
|
||||
BKE_mesh_calc_edges(mesh, false, false);
|
||||
|
||||
if (m_use_custom_normals && m_loop_normals.size() == mesh->totloop) {
|
||||
BKE_mesh_set_custom_normals(mesh, reinterpret_cast<float(*)[3]>(m_loop_normals.data()));
|
||||
if (use_custom_normals_ && loop_normals_.size() == mesh->totloop) {
|
||||
BKE_mesh_set_custom_normals(mesh, reinterpret_cast<float(*)[3]>(loop_normals_.data()));
|
||||
mesh->flag |= ME_AUTOSMOOTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,15 +47,15 @@ class Triangle {
|
|||
|
||||
class STLMeshHelper {
|
||||
private:
|
||||
VectorSet<float3> m_verts;
|
||||
VectorSet<Triangle> m_tris;
|
||||
Vector<float3> m_loop_normals;
|
||||
int m_num_degenerate_tris;
|
||||
int m_num_duplicate_tris;
|
||||
const bool m_use_custom_normals;
|
||||
VectorSet<float3> verts_;
|
||||
VectorSet<Triangle> tris_;
|
||||
Vector<float3> loop_normals_;
|
||||
int degenerate_tris_num_;
|
||||
int duplicate_tris_num_;
|
||||
const bool use_custom_normals_;
|
||||
|
||||
public:
|
||||
STLMeshHelper(int num_tris, bool use_custom_normals);
|
||||
STLMeshHelper(int tris_num, bool use_custom_normals);
|
||||
|
||||
/* Creates a new triangle from specified vertex locations,
|
||||
* duplicate vertices and triangles are merged.
|
||||
|
|
Loading…
Reference in New Issue