[Bf-blender-cvs] [e96dd70fac9] soc-2020-io-performance: Cleanup: use const, edit comments, reorder includes.
Ankit Meel
noreply at git.blender.org
Mon Sep 21 13:35:39 CEST 2020
Commit: e96dd70fac9b3a9a0a55dae79bffb06639df0a3d
Author: Ankit Meel
Date: Mon Sep 21 13:22:59 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBe96dd70fac9b3a9a0a55dae79bffb06639df0a3d
Cleanup: use const, edit comments, reorder includes.
No functional change.
===================================================================
M source/blender/editors/io/io_obj.c
M source/blender/io/wavefront_obj/IO_wavefront_obj.h
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_nurbs.cc
M source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
M source/blender/io/wavefront_obj/intern/obj_exporter.cc
M source/blender/io/wavefront_obj/intern/obj_exporter.hh
===================================================================
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index de1f55053b5..35cde0e3ea5 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -67,8 +67,6 @@ const EnumPropertyItem io_obj_transform_axis_up[] = {
{OBJ_AXIS_NEGATIVE_Z_UP, "NEGATIVE_Z_UP", 0, "-Z", "Negative Z axis"},
{0, NULL, 0, NULL, NULL}};
-const int TOTAL_AXES = 3;
-
const EnumPropertyItem io_obj_export_evaluation_mode[] = {
{DAG_EVAL_RENDER,
"DAG_EVAL_RENDER",
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
index 4a2d9a10d7d..5340389feb1 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -49,23 +49,25 @@ typedef enum {
OBJ_AXIS_NEGATIVE_Z_FORWARD = 5,
} eTransformAxisForward;
+const int TOTAL_AXES = 3;
+
struct OBJExportParams {
/** Full path to the destination OBJ file to export. */
char filepath[FILE_MAX];
- /** Whether mutiple frames are to be exported or not. */
+ /** Whether export multiple frames. */
bool export_animation;
/** The first frame to be exported. */
int start_frame;
/** The last frame to be exported. */
int end_frame;
- /** Geometry Transform options. */
+ /* Geometry Transform options. */
eTransformAxisForward forward_axis;
eTransformAxisUp up_axis;
float scaling_factor;
- /** File Write Options. */
+ /* File Write Options. */
bool export_selected_objects;
eEvaluationMode export_eval_mode;
bool export_uv;
@@ -74,7 +76,7 @@ struct OBJExportParams {
bool export_triangulated_mesh;
bool export_curves_as_nurbs;
- /** Grouping options. */
+ /* Grouping options. */
bool export_object_groups;
bool export_material_groups;
bool export_vertex_groups;
@@ -83,7 +85,7 @@ struct OBJExportParams {
*/
bool export_smooth_groups;
/**
- * If true, generate bitflags for smooth groups' IDs. Generates upto 32 but usually much less.
+ * If true, generate bitflags for smooth groups' IDs.
*/
bool smooth_groups_bitflags;
};
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 03a20a2fda8..6e7f084dd69 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
@@ -25,11 +25,12 @@
#include "BKE_blender_version.h"
-#include "obj_export_file_writer.hh"
#include "obj_export_mesh.hh"
#include "obj_export_mtl.hh"
#include "obj_export_nurbs.hh"
+#include "obj_export_file_writer.hh"
+
namespace blender::io::obj {
/* Default values of some parameters. */
@@ -354,8 +355,8 @@ void OBJWriter::write_edges_indices(const OBJMesh &obj_mesh_data) const
obj_mesh_data.ensure_mesh_edges();
const int tot_edges = obj_mesh_data.tot_edges();
for (uint edge_index = 0; edge_index < tot_edges; edge_index++) {
- std::optional<std::array<int, 2>> vertex_indices = obj_mesh_data.calc_loose_edge_vert_indices(
- edge_index);
+ const std::optional<std::array<int, 2>> vertex_indices =
+ obj_mesh_data.calc_loose_edge_vert_indices(edge_index);
if (!vertex_indices) {
continue;
}
@@ -376,7 +377,7 @@ void OBJWriter::write_nurbs_curve(const OBJCurve &obj_nurbs_data) const
/* Total control points in a nurbs. */
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(
+ const float3 point_coord = obj_nurbs_data.calc_nurbs_point_coords(
i, point_idx, export_params_.scaling_factor);
fprintf(outfile_, "v %f %f %f\n", point_coord[0], point_coord[1], point_coord[2]);
}
@@ -384,7 +385,12 @@ void OBJWriter::write_nurbs_curve(const OBJCurve &obj_nurbs_data) const
const char *nurbs_name = obj_nurbs_data.get_curve_name();
const int nurbs_degree = obj_nurbs_data.get_nurbs_degree(i);
- fprintf(outfile_, "g %s\ncstype bspline\ndeg %d\n", nurbs_name, nurbs_degree);
+ fprintf(outfile_,
+ "g %s\n"
+ "cstype bspline\n"
+ "deg %d\n",
+ nurbs_name,
+ nurbs_degree);
/**
* curv_num indices into the point vertices above, in relative indices.
* 0.0 1.0 -1 -2 -3 -4 for a non-cyclic curve with 4 points.
@@ -478,7 +484,10 @@ const char *MTLWriter::mtl_file_path() const
return mtl_filepath_;
}
-void MTLWriter::write_bsdf_properties(const blender::io::obj::MTLMaterial &mtl_material)
+/**
+ * Write properties sourced from p-BSDF node or `Object.Material`.
+ */
+void MTLWriter::write_bsdf_properties(const MTLMaterial &mtl_material)
{
fprintf(mtl_outfile_,
"Ni %0.6f\n"
@@ -501,9 +510,9 @@ void MTLWriter::write_bsdf_properties(const blender::io::obj::MTLMaterial &mtl_m
void MTLWriter::write_texture_map(const MTLMaterial &mtl_material,
const Map<const std::string, tex_map_XX>::Item &texture_map)
{
- std::string map_bump_strength;
- std::string scale;
std::string translation;
+ std::string scale;
+ std::string map_bump_strength;
/* Optional strings should have their own leading spaces. */
if (texture_map.value.translation != float3{0.0f, 0.0f, 0.0f}) {
translation.append(" -s ").append(float3_to_string(texture_map.value.translation));
@@ -525,6 +534,9 @@ void MTLWriter::write_texture_map(const MTLMaterial &mtl_material,
texture_map.value.image_path.c_str());
}
+/**
+ * Append the `Material`(s) of the given Object to the MTL file.
+ */
void MTLWriter::append_materials(const OBJMesh &mesh_to_export)
{
BLI_assert(this->good());
@@ -543,6 +555,7 @@ void MTLWriter::append_materials(const OBJMesh &mesh_to_export)
#endif
for (const MTLMaterial &mtl_material : mtl_materials) {
fprintf(mtl_outfile_, "\nnewmtl %s\n", mtl_material.name.c_str());
+ /* At least one material property has not been modified since its initialisation. */
BLI_assert(all_items_positive({mtl_material.d, mtl_material.Ns, mtl_material.Ni}) &&
mtl_material.illum > 0);
BLI_assert(all_items_positive(mtl_material.Ka) && all_items_positive(mtl_material.Kd) &&
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 c4b60400aee..f71a1dd59d1 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
@@ -32,8 +32,6 @@
#include "obj_export_mtl.hh"
namespace blender::io::obj {
-class OBJMesh;
-class OBJCurve;
/**
* For an Object, total vertices/ UV vertices/ Normals written by previous objects
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 353066b59cf..26744e4507b 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
@@ -81,6 +81,7 @@ OBJMesh::~OBJMesh()
void OBJMesh::free_mesh_if_needed()
{
+ /* Don't free `Mesh`es in the Scene which we didn't create. */
if (mesh_eval_needs_free_ && export_mesh_eval_) {
BKE_id_free(NULL, export_mesh_eval_);
}
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 a4da543965b..b0d79c0cf15 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mesh.hh
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mesh.hh
@@ -41,9 +41,12 @@
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. */
+/* Any negative number other than `NOT_FOUND` to initialise usually non-negative numbers. */
const int NEGATIVE_INIT = -10;
+/**
+ * std::unique_ptr deleter for BMesh.
+ */
struct CustomBMeshDeleter {
void operator()(BMesh *bmesh)
{
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_mtl.cc b/source/blender/io/wavefront_obj/intern/obj_export_mtl.cc
index 02b68767a80..b0c6a6df7c8 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_mtl.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_mtl.cc
@@ -78,6 +78,7 @@ static void copy_property_from_node(MutableSpan<float> r_property,
break;
}
default: {
+ /* Other socket types are not handled here. */
BLI_assert(0);
break;
}
@@ -118,7 +119,7 @@ static void linked_sockets_to_dest_id(Vector<const nodes::OutputSocketRef *> &r_
* From a list of sockets, get the parent node which is of the given node type.
*/
static const bNode *get_node_of_type(Span<const nodes::OutputSocketRef *> sockets_list,
- int sh_node_type)
+ const int sh_node_type)
{
for (const nodes::SocketRef *sock : sockets_list) {
const bNode *curr_node = sock->bnode();
@@ -132,7 +133,7 @@ static const bNode *get_node_of_type(Span<const nodes::OutputSocketRef *> socket
/**
* From a texture image shader node, get the image's filepath.
* Returned filepath is stripped of inital "//". If packed image is found,
- * Only the leaf file name is given.
+ * only the file "name" is returned.
*/
static const char *get_image_filepath(const bNode *tex_node)
{
@@ -188,7 +189,7 @@ void MaterialWrap::init_bsdf_node(StringRefNull object_name)
*/
void MaterialWrap::store_bsdf_properties(MTLMaterial &r_mtl_mat) const
{
- /* Empirical, and copied from original python exporter. */
+ /* Emperical approximation. Importer should use the inverse of this method. */
float spec_exponent = (1.0f - export_mtl_->roughness) * 30;
spec_exponent *= spec_exponent;
/* If p-BSDF is not present, fallback to `Material *` of the object. */
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
index f91f3bbca6a.
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list