[Bf-blender-cvs] [a45112a9ece] soc-2020-io-performance: Add smooth group constants, use "0" instead of "off".
Ankit Meel
noreply at git.blender.org
Wed Sep 16 13:05:54 CEST 2020
Commit: a45112a9ece3de8278471db426a9abe3dab3e282
Author: Ankit Meel
Date: Wed Sep 16 15:00:31 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBa45112a9ece3de8278471db426a9abe3dab3e282
Add smooth group constants, use "0" instead of "off".
===================================================================
M source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
M source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
M source/blender/io/wavefront_obj/intern/obj_export_mesh.hh
===================================================================
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
index 180507863bb..bec8c81ade5 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
@@ -34,6 +34,10 @@
namespace blender::io::obj {
+/* Default values of some parameters. */
+const int SMOOTH_GROUP_DISABLED = 0;
+const int SMOOTH_GROUP_DEFAULT = 1;
+
/**
* Write one line of polygon indices as f v1/vt1/vn1 v2/vt2/vn2 ... .
*/
@@ -204,32 +208,28 @@ void OBJWriter::write_poly_normals(OBJMesh &obj_mesh_data) const
/**
* Write smooth group if the polygon at given index is shaded smooth and export settings specify
- * so. If the polygon is not shaded smooth, write "off".
+ * so. If the polygon is not shaded smooth, write "0".
*/
void OBJWriter::write_smooth_group(const OBJMesh &obj_mesh_data,
const uint poly_index,
int &r_last_face_smooth_group) const
{
- int curr_group = 0;
+ int current_group = SMOOTH_GROUP_DISABLED;
if (!export_params_.export_smooth_groups && obj_mesh_data.is_ith_poly_smooth(poly_index)) {
/* Smooth group calculation is disabled, but face is smooth. */
- curr_group = 1;
+ current_group = SMOOTH_GROUP_DEFAULT;
}
else if (obj_mesh_data.is_ith_poly_smooth(poly_index)) {
/* Smooth group calc enabled and face is smooth and so find the group. */
- curr_group = obj_mesh_data.ith_smooth_group(poly_index);
- }
- if (curr_group == r_last_face_smooth_group) {
- /* Group has already been written including s off. */
- return;
+ current_group = obj_mesh_data.ith_smooth_group(poly_index);
}
- if (curr_group == 0) {
- fprintf(outfile_, "s off\n");
- r_last_face_smooth_group = curr_group;
+
+ if (current_group == r_last_face_smooth_group) {
+ /* Group has already been written, even if it is "s 0". */
return;
}
- fprintf(outfile_, "s %d\n", curr_group);
- r_last_face_smooth_group = curr_group;
+ fprintf(outfile_, "s %d\n", current_group);
+ r_last_face_smooth_group = current_group;
}
/**
@@ -286,8 +286,6 @@ void OBJWriter::write_vertex_group(const OBJMesh &obj_mesh_data,
OBJWriter::func_vert_uv_normal_indices OBJWriter::get_poly_element_writer(
const OBJMesh &obj_mesh_data)
{
- /* -1 has no significant value, it can be any negative number. */
- int last_face_smooth_group = -1;
/* -1 is used to denote face having no vertex group. It can be any _other_ negative
* number. */
short last_face_vertex_group = -2;
@@ -317,6 +315,7 @@ OBJWriter::func_vert_uv_normal_indices OBJWriter::get_poly_element_writer(
*/
void OBJWriter::write_poly_elements(const OBJMesh &obj_mesh_data)
{
+ int last_face_smooth_group = NEGATIVE_INIT;
Vector<uint> vertex_indices;
const int totloop = obj_mesh_data.ith_poly_totloop(i);
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc b/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
index 22bef835171..2aa0609b976 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
@@ -181,8 +181,8 @@ short OBJMesh::tot_materials() const
*/
uint OBJMesh::tot_smooth_groups() const
{
- BLI_assert(tot_smooth_groups_ != -1);
/* Calculate smooth groups first: `OBJMesh::calc_smooth_groups`. */
+ BLI_assert(tot_smooth_groups_ != NEGATIVE_INIT);
return tot_smooth_groups_;
}
@@ -191,8 +191,8 @@ uint OBJMesh::tot_smooth_groups() const
*/
int OBJMesh::ith_smooth_group(const int poly_index) const
{
- BLI_assert(tot_smooth_groups_ != -1);
/* Calculate smooth groups first: `OBJMesh::calc_smooth_groups`. */
+ BLI_assert(tot_smooth_groups_ != -NEGATIVE_INIT);
BLI_assert(poly_smooth_groups_);
return poly_smooth_groups_[poly_index];
}
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_mesh.hh b/source/blender/io/wavefront_obj/intern/obj_export_mesh.hh
index 66d3efa0e6a..7a217d82761 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mesh.hh
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mesh.hh
@@ -39,6 +39,10 @@
#include "IO_wavefront_obj.h"
namespace blender::io::obj {
+/* Denote absence for usually non-negative numbers. */
+const int NOT_FOUND = -1;
+/* Any negative number other than -1 to initialise usually non-negative numbers. */
+const int NEGATIVE_INIT = -10;
struct CustomBMeshDeleter {
void operator()(BMesh *bmesh)
@@ -77,7 +81,7 @@ class OBJMesh : NonMovable, NonCopyable {
/**
* Total smooth groups in an object.
*/
- uint tot_smooth_groups_ = -1;
+ int tot_smooth_groups_ = NEGATIVE_INIT;
/**
* Polygon aligned array of their smooth groups.
*/
More information about the Bf-blender-cvs
mailing list