[Bf-blender-cvs] [8b3f87f9f7a] soc-2020-io-performance: Cleanup: rename functions, use const, edit comments.
Ankit Meel
noreply at git.blender.org
Wed Sep 16 13:05:53 CEST 2020
Commit: 8b3f87f9f7a0139f6c6de9d2df0bae08b678a7c8
Author: Ankit Meel
Date: Wed Sep 16 11:58:30 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB8b3f87f9f7a0139f6c6de9d2df0bae08b678a7c8
Cleanup: rename functions, use const, edit comments.
===================================================================
M source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
M source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh
M source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
M source/blender/io/wavefront_obj/intern/obj_export_mesh.hh
M source/blender/io/wavefront_obj/intern/obj_export_mtl.cc
M source/blender/io/wavefront_obj/intern/obj_export_mtl.hh
M source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
M source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
M source/blender/io/wavefront_obj/intern/obj_exporter.cc
===================================================================
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 c3afebd07d0..1cd414316ee 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
@@ -21,6 +21,8 @@
* \ingroup obj
*/
+#include <cstdio>
+
#include "BKE_blender_version.h"
#include "obj_export_file_writer.hh"
@@ -104,6 +106,7 @@ void OBJWriter::write_vert_indices(Span<uint> vert_indices,
/**
* Open the OBJ file and write file header.
+ * \return Whether the destination file is writable.
*/
bool OBJWriter::init_writer(const char *filepath)
{
@@ -182,6 +185,7 @@ void OBJWriter::write_vertex_coords(const OBJMesh &obj_mesh_data) const
void OBJWriter::write_uv_coords(OBJMesh &obj_mesh_data) const
{
Vector<std::array<float, 2>> uv_coords;
+ /* UV indices are calculated and stored in an OBJMesh member here. */
obj_mesh_data.store_uv_coords_and_indices(uv_coords);
for (const std::array<float, 2> &uv_vertex : uv_coords) {
@@ -198,13 +202,12 @@ void OBJWriter::write_poly_normals(OBJMesh &obj_mesh_data) const
Vector<float3> lnormals;
for (uint i = 0; i < obj_mesh_data.tot_polygons(); i++) {
if (obj_mesh_data.is_ith_poly_smooth(i)) {
- obj_mesh_data.calc_loop_normal(i, lnormals);
- for (int j = 0; j < lnormals.size(); j++) {
- fprintf(outfile_, "vn %f %f %f\n", lnormals[j][0], lnormals[j][1], lnormals[j][2]);
+ obj_mesh_data.calc_loop_normals(i, lnormals);
+ for (const float3 &lnormal : lnormals) {
+ fprintf(outfile_, "vn %f %f %f\n", lnormal[0], lnormal[1], lnormal[2]);
}
}
else {
- UNUSED_VARS(lnormals);
float3 poly_normal = obj_mesh_data.calc_poly_normal(i);
fprintf(outfile_, "vn %f %f %f\n", poly_normal[0], poly_normal[1], poly_normal[2]);
}
@@ -249,7 +252,7 @@ void OBJWriter::write_poly_material(const OBJMesh &obj_mesh_data,
const uint poly_index,
short &r_last_face_mat_nr) const
{
- if (!export_params_.export_materials || obj_mesh_data.tot_col() <= 0) {
+ if (!export_params_.export_materials || obj_mesh_data.tot_materials() <= 0) {
return;
}
const short mat_nr = obj_mesh_data.ith_poly_matnr(poly_index);
@@ -363,13 +366,13 @@ void OBJWriter::write_poly_elements(const OBJMesh &obj_mesh_data)
}
/**
- * Write loose edges of a mesh, a curve converted to mesh, or a primitive circle as l v1 v2 .
+ * Write loose edges of a mesh as l v1 v2 .
*/
-void OBJWriter::write_loose_edges(const OBJMesh &obj_mesh_data) const
+void OBJWriter::write_edges_indices(const OBJMesh &obj_mesh_data) const
{
obj_mesh_data.ensure_mesh_edges();
for (uint edge_index = 0; edge_index < obj_mesh_data.tot_edges(); edge_index++) {
- std::optional<std::array<int, 2>> vertex_indices = obj_mesh_data.calc_edge_vert_indices(
+ std::optional<std::array<int, 2>> vertex_indices = obj_mesh_data.calc_loose_edge_vert_indices(
edge_index);
if (!vertex_indices) {
continue;
@@ -389,7 +392,7 @@ void OBJWriter::write_nurbs_curve(const OBJCurve &obj_nurbs_data) const
const int tot_nurbs = obj_nurbs_data.tot_nurbs();
for (int i = 0; i < tot_nurbs; i++) {
/* Total control points in a nurbs. */
- int tot_points = obj_nurbs_data.get_nurbs_points(i);
+ const int tot_points = obj_nurbs_data.get_nurbs_points(i);
for (int point_idx = 0; point_idx < tot_points; point_idx++) {
float3 point_coord = obj_nurbs_data.calc_nurbs_point_coords(
i, point_idx, export_params_.scaling_factor);
@@ -397,9 +400,7 @@ void OBJWriter::write_nurbs_curve(const OBJCurve &obj_nurbs_data) const
}
const char *nurbs_name = obj_nurbs_data.get_curve_name();
- int nurbs_degree = obj_nurbs_data.get_nurbs_degree(i);
- /* Number of vertices in the curve + degree of the curve if it is cyclic. */
- int curv_num = obj_nurbs_data.get_nurbs_num(i);
+ const int nurbs_degree = obj_nurbs_data.get_nurbs_degree(i);
fprintf(outfile_, "g %s\ncstype bspline\ndeg %d\n", nurbs_name, nurbs_degree);
/**
@@ -407,8 +408,11 @@ void OBJWriter::write_nurbs_curve(const OBJCurve &obj_nurbs_data) const
* 0.0 1.0 -1 -2 -3 -4 for a non-cyclic curve with 4 points.
* 0.0 1.0 -1 -2 -3 -4 -1 -2 -3 for a cyclic curve with 4 points.
*/
+ /* Number of vertices in the curve + degree of the curve if it is cyclic. */
+ const int curv_num = obj_nurbs_data.get_nurbs_num(i);
fprintf(outfile_, "curv 0.0 1.0");
for (int i = 0; i < curv_num; i++) {
+ /* + 1 to keep indices one-based, even if they're negative. */
fprintf(outfile_, " %d", -1 * ((i % tot_points) + 1));
}
fprintf(outfile_, "\n");
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh
index 18c366fdc0d..7cfb9e79fe9 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh
+++ b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh
@@ -45,10 +45,13 @@ struct IndexOffsets {
uint normal_offset;
};
+/**
+ * Responsible for writing a .OBJ file.
+ */
class OBJWriter {
private:
/**
- * Destination OBJ file for one frame, and one writer instance.
+ * Destination .OBJ file.
*/
FILE *outfile_;
const OBJExportParams &export_params_;
@@ -92,7 +95,7 @@ class OBJWriter {
const uint poly_index,
short &r_last_face_vertex_group) const;
void write_poly_elements(const OBJMesh &obj_mesh_data);
- void write_loose_edges(const OBJMesh &obj_mesh_data) const;
+ void write_edges_indices(const OBJMesh &obj_mesh_data) const;
void write_nurbs_curve(const OBJCurve &obj_nurbs_data) const;
void update_index_offsets(const OBJMesh &obj_mesh_data);
@@ -116,6 +119,9 @@ class OBJWriter {
const uint tot_loop) const;
};
+/**
+ * Responsible for writing a .MTL file.
+ */
class MTLWriter {
private:
FILE *mtl_outfile_;
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 79b10ce1124..6ab7f165ef8 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
@@ -78,7 +78,7 @@ OBJMesh::OBJMesh(Depsgraph *depsgraph, const OBJExportParams &export_params, Obj
break;
}
}
- store_world_axes_transform(export_params.forward_axis, export_params.up_axis);
+ set_world_axes_transform(export_params.forward_axis, export_params.up_axis);
}
/**
@@ -104,9 +104,10 @@ void OBJMesh::triangulate_mesh_eval()
mesh_eval_needs_free_ = false;
return;
}
- struct BMeshCreateParams bm_create_params = {false};
- /* If calc_face_normal is false, it triggers BLI_assert(BM_face_is_normal_valid(f)). */
- struct BMeshFromMeshParams bm_convert_params = {true, 0, 0, 0};
+ const struct BMeshCreateParams bm_create_params = {false};
+ /* If `BMeshFromMeshParams.calc_face_normal` is false, it triggers
+ * BLI_assert(BM_face_is_normal_valid(f)). */
+ const struct BMeshFromMeshParams bm_convert_params = {true, 0, 0, 0};
/* Lower threshold where triangulation of a face starts, i.e. a quadrilateral will be
* triangulated here. */
const int triangulate_min_verts = 4;
@@ -129,8 +130,8 @@ void OBJMesh::triangulate_mesh_eval()
* Store the product of export axes settings and an object's world transform matrix in
* world_and_axes_transform[4][4].
*/
-void OBJMesh::store_world_axes_transform(const eTransformAxisForward forward,
- const eTransformAxisUp up)
+void OBJMesh::set_world_axes_transform(const eTransformAxisForward forward,
+ const eTransformAxisUp up)
{
float axes_transform[3][3];
unit_m3(axes_transform);
@@ -175,7 +176,7 @@ uint OBJMesh::tot_edges() const
/**
* Total materials in the object to export.
*/
-short OBJMesh::tot_col() const
+short OBJMesh::tot_materials() const
{
return export_mesh_eval_->totcol;
}
@@ -185,8 +186,8 @@ short OBJMesh::tot_col() const
*/
uint OBJMesh::tot_smooth_groups() const
{
- /* Calculate smooth groups first. */
BLI_assert(tot_smooth_groups_ != -1);
+ /* Calculate smooth groups first: `OBJMesh::calc_smooth_groups`. */
return tot_smooth_groups_;
}
@@ -195,8 +196,8 @@ uint OBJMesh::tot_smooth_groups() const
*/
int OBJMesh::ith_smooth_group(const int poly_index) const
{
- /* Calculate smooth groups first. */
BLI_assert(tot_smooth_groups_ != -1);
+ /* Calculate smooth groups first: `OBJMesh::calc_smooth_groups`. */
BLI_assert(poly_smooth_groups_);
return poly_smooth_groups_[poly_index];
}
@@ -380,11 +381,11 @@ float3 OBJMesh::calc_poly_normal(const uint poly_index) const
}
/**
- * Calculate loop normal of a loop at the given index.
+ * Calculate loop normals of a polygon at the given index.
*
- * Should be used when a polygon is shaded smooth.
+ * Should be used if a polygon is shaded smooth.
*/
-void OBJMesh::calc_loop_normal(const uint poly_index, Vector<float3> &r_loop_normals) const
+void OBJMesh::calc_loop_normals(const uint poly_index, Vector<float3> &r_loop_normals) const
{
r_loop_normals.clear();
const MPoly &mpoly = export_mesh_eval_->mpoly[poly_index];
@@ -471,9 +472,10 @@ const char *OBJMesh::get_poly_deform_group_name(const uint poly_index,
}
/**
- * Only for curve converted to meshes and primitive circle: calculate vertex indices of one edge.
+ * Calculate vertex indices of an edge's corners if it is a loose edge.
*/
-std::optional<std::array<int, 2>> OBJMesh::calc_edge_vert_indices(const uint edge_index) const
+std::optional<std::array<int, 2>> OBJMesh::calc_loose_edge_vert_indices(
+ const uint edge_index) const
{
const MEdge &edge = export_mesh_eval_->medge[edge_index];
if (edge.flag & ME_LOOSEEDGE) {
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 20f3cbdab11
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list