[Bf-blender-cvs] [ddbc43afe06] soc-2020-io-performance: Clean up: comments, minor refactor.
Ankit Meel
noreply at git.blender.org
Mon Jun 29 22:34:08 CEST 2020
Commit: ddbc43afe060a9b170be9b3b34c06e38652d45e0
Author: Ankit Meel
Date: Tue Jun 30 02:04:03 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBddbc43afe060a9b170be9b3b34c06e38652d45e0
Clean up: comments, minor refactor.
Use `const char *set_name` instead of `void get_name` which was meant
to copy the buffer originally but then was neglected.
Don't expose `_export_mesh_eval` just for ensuring normals, moved it to
another function.
Use conventional destructor function names.
Upper case enums.
===================================================================
M source/blender/io/wavefront_obj/IO_wavefront_obj.h
M source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.hh
===================================================================
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
index bb5f34c0a91..e63d3db341c 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -57,12 +57,12 @@ struct OBJExportParams {
/** The last frame to be exported. */
int end_frame;
- /** Geometry Transform options */
+ /** Geometry Transform options. */
int forward_axis;
int up_axis;
float scaling_factor;
- /** File Write Options */
+ /** File Write Options. */
bool export_selected_objects;
bool export_uv;
bool export_normals;
@@ -70,7 +70,7 @@ struct OBJExportParams {
bool export_triangulated_mesh;
bool export_curves_as_nurbs;
- /** Grouping options */
+ /** Grouping options. */
bool export_object_groups;
bool export_material_groups;
};
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
index 9478c0b4521..94121677aeb 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
@@ -93,7 +93,7 @@ static void export_frame(bContext *C, const OBJExportParams *export_params, cons
if (export_params->export_materials) {
/* Write MTL filename to the OBJ file. Also create an empty MTL file of the same name as the
- * OBJ*/
+ * OBJ. */
frame_writer.write_mtllib(filepath);
}
for (uint ob_iter = 0; ob_iter < exportable_meshes.size(); ob_iter++) {
@@ -122,7 +122,7 @@ static void export_frame(bContext *C, const OBJExportParams *export_params, cons
}
frame_writer.update_index_offsets(mesh_to_export);
- mesh_to_export.destruct();
+ mesh_to_export.~OBJMesh();
}
/* Export nurbs in parm form, not as vertices and edges. */
for (uint ob_iter = 0; ob_iter < exportable_nurbs.size(); ob_iter++) {
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc
index 2f77ac483e2..b4c6212f106 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.cc
@@ -125,14 +125,31 @@ void OBJMesh::store_world_axes_transform()
copy_v4_v4(_world_and_axes_transform[3], _export_object_eval->obmat[3]);
}
-void OBJMesh::set_object_name(const char **r_object_name)
+const char *OBJMesh::get_object_name()
{
- *r_object_name = _export_object_eval->id.name + 2;
+ return _export_object_eval->id.name + 2;
}
-void OBJMesh::set_object_data_name(const char **r_object_data_name)
+const char *OBJMesh::get_object_data_name()
{
- *r_object_data_name = _export_mesh_eval->id.name + 2;
+ return _export_mesh_eval->id.name + 2;
+}
+
+const char *OBJMesh::get_object_material_name(short mat_nr)
+{
+ Material *mat = BKE_object_material_get(_export_object_eval, mat_nr);
+ return mat->id.name + 2;
+}
+
+void OBJMesh::ensure_normals()
+{
+ BKE_mesh_ensure_normals(_export_mesh_eval);
+}
+
+/** Return mat_nr-th material of the object. */
+Material *OBJMesh::get_export_object_material(short mat_nr)
+{
+ return BKE_object_material_get(_export_object_eval, mat_nr);
}
/**
@@ -232,15 +249,6 @@ void OBJMesh::calc_poly_normal(float r_poly_normal[3], uint poly_index)
normalize_v3(r_poly_normal);
}
-/**
- * Set argument pointer to the name of an object's mat_nr-th index material.
- */
-void OBJMesh::set_object_material_name(const char **r_mat_name, short mat_nr)
-{
- Material *mat = BKE_object_material_get(_export_object_eval, mat_nr);
- *r_mat_name = mat->id.name + 2;
-}
-
/**
* Calculate face normal indices of all polygons.
*/
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh
index 34ba48d759c..55ce8f0cf80 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mesh.hh
@@ -51,7 +51,7 @@ class OBJMesh {
}
/** Free new meshes we allocate for triangulated meshes, and curves converted to meshes. */
- void destruct()
+ ~OBJMesh()
{
if (_me_eval_needs_free) {
BKE_id_free(NULL, _export_mesh_eval);
@@ -84,54 +84,45 @@ class OBJMesh {
return _export_mesh_eval->totcol;
}
- Mesh *export_mesh_eval()
- {
- return _export_mesh_eval;
- }
-
const MPoly &get_ith_poly(uint i)
{
return _export_mesh_eval->mpoly[i];
}
+ void ensure_normals();
/** Return mat_nr-th material of the object. */
- Material *get_export_object_material(short mat_nr)
- {
- return BKE_object_material_get(_export_object_eval, mat_nr);
- }
+ Material *get_export_object_material(short mat_nr);
- /**
- * Set argument pointer to an object's name, as it appears in outliner.
- */
- void set_object_name(const char **object_name);
- void set_object_data_name(const char **r_object_data_name);
- void set_object_material_name(const char **r_mat_name, short mat_nr);
+ /* Names as they appear in the outliner. */
+ const char *get_object_name();
+ const char *get_object_data_name();
+ const char *get_object_material_name(short mat_nr);
/**
* Calculate coordinates of the vertex at given index.
*/
- void calc_vertex_coords(float coords[3], uint vert_index);
+ void calc_vertex_coords(float r_coords[3], uint vert_index);
/**
* Calculate vertex indices of all vertices of a polygon.
*/
- void calc_poly_vertex_indices(Vector<uint> &poly_vertex_indices, uint poly_index);
+ void calc_poly_vertex_indices(Vector<uint> &r_poly_vertex_indices, uint poly_index);
/**
* Store UV vertex coordinates as well as their indices.
*/
- void store_uv_coords_and_indices(Vector<std::array<float, 2>> &uv_coords,
- Vector<Vector<uint>> &uv_indices);
+ void store_uv_coords_and_indices(Vector<std::array<float, 2>> &r_uv_coords,
+ Vector<Vector<uint>> &r_uv_indices);
/**
* Calculate face normal of the polygon at given index.
*/
- void calc_poly_normal(float poly_normal[3], uint poly_index);
+ void calc_poly_normal(float r_poly_normal[3], uint poly_index);
/**
* Calculate face normal indices of all polygons.
*/
- void calc_poly_normal_indices(Vector<uint> &normal_indices, uint poly_indices);
+ void calc_poly_normal_indices(Vector<uint> &r_normal_indices, uint poly_indices);
/**
* Only for curve converted to meshes: calculate vertex indices of one edge.
*/
- void calc_edge_vert_indices(uint vert_indices[2], uint edge_index);
+ void calc_edge_vert_indices(uint r_vert_indices[2], uint edge_index);
private:
bContext *_C;
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc
index 0e2152cb3ec..997b7a1bc83 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.cc
@@ -309,13 +309,11 @@ void MTLWriter::append_materials(OBJMesh &mesh_to_export)
}
const char *object_name;
- mesh_to_export.set_object_name(&object_name);
+ object_name = mesh_to_export.get_object_name();
for (int curr_mat = 0; curr_mat < mesh_to_export.tot_col(); curr_mat++) {
_export_mtl = mesh_to_export.get_export_object_material(curr_mat + 1);
write_curr_material(object_name);
}
-
- fclose(_mtl_outfile);
}
} // namespace obj
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.hh
index 742dd062fd4..c1f66ec8291 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_mtl.hh
@@ -42,6 +42,11 @@ class MTLWriter {
BLI_strncpy(_mtl_filepath, obj_filepath, PATH_MAX);
BLI_path_extension_replace(_mtl_filepath, PATH_MAX, ".mtl");
}
+
+ ~MTLWriter(){
+ fclose(_mtl_outfile);
+ }
+
/** Append an object's materials to the .mtl file. */
void append_materials(OBJMesh &mesh_to_export);
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.cc
index 7188de1f139..bc2f3228367 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.cc
@@ -43,9 +43,9 @@ void OBJNurbs::init_nurbs_curve(Object *export_object)
_export_curve = (Curve *)_export_object_eval->data;
}
-void OBJNurbs::get_curve_name(const char **r_object_name)
+const char *OBJNurbs::get_curve_name()
{
- *r_object_name = _export_object_eval->id.name + 2;
+ return _export_object_eval->id.name + 2;
}
/** Get coordinates of a vertex at given point index. */
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.hh
index 9da9c31681c..c1b5336d4b2 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter_nurbs.hh
@@ -39,12 +39,14 @@ class OBJNurbs {
{
init_nurbs_curve(export_object);
}
- void get_curve_name(const char **r_object_name);
+
+ const char *get_curve_name();
/** Getter for export curve. Used to obtain a curve's nurbs in OBJWriter class. */
const Curve *export_curve()
{
return _export_curve;
}
+
/** Get coordinates of a vertex at given point index. */
void calc_point_coords(float r_coords[3], uint point_index, Nurb *nurb);
/** Get nurbs' degree and number of "curv" points of a nurb. */
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_file_handler.cc
index 6afb4cf4ac3..723dc1dec13 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list