[Bf-blender-cvs] [d6604558823] soc-2020-io-performance: Cleanup: Remove Raw* terminology, use geom_type.
Ankit Meel
noreply at git.blender.org
Thu Aug 6 12:38:44 CEST 2020
Commit: d66045588235af86cbf6e218a3d2fcc917788ffd
Author: Ankit Meel
Date: Thu Aug 6 16:08:26 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBd66045588235af86cbf6e218a3d2fcc917788ffd
Cleanup: Remove Raw* terminology, use geom_type.
After discussion with the mentors [1], the terminology to use
Raw has been removed & `Geometry` is the new name for
"raw objects". eGeometryType has also been added to remove
confusion with OB_MESH etc.
`std::unique_ptr<T > *a` has been replaced with `T *a`.
Naming changes:
`curr_ob` -> `current_geometry` in the parser &
`geometry` in the `Mesh` & `Curve` creators.
`mesh_from_raw_` -> `blender_mesh_`. Similar for curve.
[1]: https://docs.google.com/document/d/17Uzl47OljjoKgaMbukiLHUVGQP220lPTmPS-atb65mw/
===================================================================
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc
===================================================================
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
index 1d667e22db1..995a64e8d19 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
@@ -143,25 +143,24 @@ BLI_INLINE void copy_string_to_int(Span<string> src,
}
/**
- * Based on the properties of the given raw object, return whether a new raw object
+ * Based on the properties of the given Geometry instance, return whether a new Geometry instance
* should be created. Caller should get some hint that the encountered object is a curve before
* calling this function.
*
* This relies on the fact that the object type is updated to include CU_NURBS only _after_
* this function returns true.
*/
-static bool create_raw_curve(std::unique_ptr<OBJRawObject> *raw_object)
+static bool create_geometry_curve(Geometry *geometry)
{
- if (raw_object) {
- /* After the creation of a raw object, at least one element has been found in the OBJ file
- * that indicates that this is a mesh, not a curve. */
- if ((*raw_object)->tot_face_elems() || (*raw_object)->tot_uv_verts() ||
- (*raw_object)->tot_normals()) {
+ if (geometry) {
+ /* After the creation of a Geometry instance, at least one element has been found in the OBJ
+ * file that indicates that it is a mesh, not a curve. */
+ if (geometry->tot_face_elems() || geometry->tot_uv_verts() || geometry->tot_normals()) {
return true;
}
/* If not, then the given object could be a curve with all fields complete.
- * So create a new object if its type contains CU_NURBS. */
- return (*raw_object)->object_type() & OB_CURVE;
+ * So create a new Geometry only if its type doesn't contain GEOM_CURVE. */
+ return geometry->geom_type() & GEOM_CURVE;
}
return true;
}
@@ -178,24 +177,24 @@ OBJParser::OBJParser(const OBJImportParams &import_params) : import_params_(impo
* Always update these offsets whenever a new object is created.
* See the documentation of index offsets member array too.
*/
-void OBJParser::update_index_offsets(std::unique_ptr<OBJRawObject> *curr_ob)
+void OBJParser::update_index_offsets(Geometry *geometry)
{
- if (curr_ob) {
- if ((*curr_ob)->object_type_ & OB_MESH) {
- index_offsets_[VERTEX_OFF] += (*curr_ob)->vertex_indices_.size();
- index_offsets_[UV_VERTEX_OFF] += (*curr_ob)->uv_vertex_indices_.size();
+ if (geometry) {
+ if (geometry->geom_type_ & GEOM_MESH) {
+ index_offsets_[VERTEX_OFF] += geometry->vertex_indices_.size();
+ index_offsets_[UV_VERTEX_OFF] += geometry->uv_vertex_indices_.size();
}
- else if ((*curr_ob)->object_type_ & OB_CURVE) {
- index_offsets_[VERTEX_OFF] += (*curr_ob)->nurbs_element_.curv_indices.size();
+ else if (geometry->geom_type_ & GEOM_CURVE) {
+ index_offsets_[VERTEX_OFF] += geometry->nurbs_element_.curv_indices.size();
}
}
}
/**
- * Read the OBJ file line by line and create OBJ raw objects. Also store all the vertex
- * and UV vertex coordinates in a struct readable by all objects.
+ * Read the OBJ file line by line and create OBJ Geometry instances. Also store all the vertex
+ * and UV vertex coordinates in a struct accessible by all objects.
*/
-void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_objects,
+void OBJParser::parse_and_store(Vector<std::unique_ptr<Geometry>> &list_of_objects,
GlobalVertices &global_vertices)
{
if (!obj_file_.good()) {
@@ -204,9 +203,9 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
}
string line;
- /* Non owning raw pointer to the unique_ptr to a raw object.
+ /* Non owning raw pointer to a Geometry.
* Needed to update object data in the same while loop. */
- std::unique_ptr<OBJRawObject> *curr_ob = nullptr;
+ Geometry *current_geometry = nullptr;
/* State-setting variables: if set, they remain the same for the remaining
* elements in the object. */
bool shaded_smooth = false;
@@ -224,12 +223,11 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
}
else if (line_key == "o") {
/* Update index offsets to keep track of objects which have claimed their vertices. */
- update_index_offsets(curr_ob);
+ update_index_offsets(current_geometry);
shaded_smooth = false;
object_group = {};
- list_of_objects.append(std::make_unique<OBJRawObject>(rest_line));
- curr_ob = &list_of_objects.last();
- (*curr_ob)->object_type_ = OB_MESH;
+ list_of_objects.append(std::make_unique<Geometry>(GEOM_MESH, rest_line));
+ current_geometry = list_of_objects.last().get();
}
else if (line_key == "v") {
float3 curr_vert{};
@@ -237,13 +235,13 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
split_by_char(rest_line, ' ', str_vert_split);
copy_string_to_float(str_vert_split, FLT_MAX, {curr_vert, 3});
global_vertices.vertices.append(curr_vert);
- if (curr_ob) {
+ if (current_geometry) {
/* Always keep indices zero-based. */
- (*curr_ob)->vertex_indices_.append(global_vertices.vertices.size() - 1);
+ current_geometry->vertex_indices_.append(global_vertices.vertices.size() - 1);
}
}
else if (line_key == "vn") {
- (*curr_ob)->tot_normals_++;
+ current_geometry->tot_normals_++;
}
else if (line_key == "vt") {
float2 curr_uv_vert{};
@@ -251,8 +249,8 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
split_by_char(rest_line, ' ', str_uv_vert_split);
copy_string_to_float(str_uv_vert_split, FLT_MAX, {curr_uv_vert, 2});
global_vertices.uv_vertices.append(curr_uv_vert);
- if (curr_ob) {
- (*curr_ob)->uv_vertex_indices_.append(global_vertices.uv_vertices.size() - 1);
+ if (current_geometry) {
+ current_geometry->uv_vertex_indices_.append(global_vertices.uv_vertices.size() - 1);
}
}
else if (line_key == "l") {
@@ -261,13 +259,13 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
split_by_char(rest_line, ' ', str_edge_split);
copy_string_to_int(str_edge_split[0], -1, edge_v1);
copy_string_to_int(str_edge_split[1], -1, edge_v2);
- /* Remove the indices of vertices "claimed" by other raw objects. Subtract 1 to make the OBJ
- * indices (one-based) C++'s zero-based. In the other case, make relative index positive and
- * absolute, starting with zero. */
+ /* Remove the indices of vertices "claimed" by other Geometry instances. Subtract 1 to make
+ * the OBJ indices (one-based) C++'s zero-based. In the other case, make relative index
+ * positive and absolute, starting with zero. */
edge_v1 -= edge_v1 > 0 ? index_offsets_[VERTEX_OFF] + 1 : -(global_vertices.vertices.size());
edge_v2 -= edge_v2 > 0 ? index_offsets_[VERTEX_OFF] + 1 : -(global_vertices.vertices.size());
BLI_assert(edge_v1 >= 0 && edge_v2 >= 0);
- (*curr_ob)->edges_.append({static_cast<uint>(edge_v1), static_cast<uint>(edge_v2)});
+ current_geometry->edges_.append({static_cast<uint>(edge_v1), static_cast<uint>(edge_v2)});
}
else if (line_key == "g") {
object_group = rest_line;
@@ -304,7 +302,7 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
if (!object_group.empty()) {
curr_face.vertex_group = object_group;
/* Yes it repeats several times, but another if-check will not reduce steps either. */
- (*curr_ob)->use_vertex_groups_ = true;
+ current_geometry->use_vertex_groups_ = true;
}
Vector<string> str_corners_split;
@@ -323,7 +321,7 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
copy_string_to_int(vert_uv_split[0], INT32_MAX, corner.vert_index);
if (vert_uv_split.size() == 2) {
copy_string_to_int(vert_uv_split[1], INT32_MAX, corner.uv_vert_index);
- (*curr_ob)->tot_uv_verts_++;
+ current_geometry->tot_uv_verts_++;
}
}
else if (n_slash == 2) {
@@ -334,7 +332,7 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
copy_string_to_int(vert_uv_normal_split[0], INT32_MAX, corner.vert_index);
if (vert_uv_normal_split.size() == 3) {
copy_string_to_int(vert_uv_normal_split[1], INT32_MAX, corner.uv_vert_index);
- (*curr_ob)->tot_uv_verts_++;
+ current_geometry->tot_uv_verts_++;
}
/* Discard normals. They'll be calculated on the basis of smooth
* shading flag. */
@@ -347,18 +345,16 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_o
curr_face.face_corners.append(corner);
}
- (*curr_ob)->face_elements_.append(curr_face);
- (*curr_ob)->tot_loops_ += curr_face.face_corners.size();
+ current_geometry->face_elements_.append(curr_face);
+ current_geometry->tot_loops_ += curr_face.face_corners.size();
}
else if (line_key == "cstype") {
if (rest_line.find("bspline") != string::npos) {
- if (create_raw_curve(curr_ob)) {
- update_index_offsets(curr_ob);
- list_of_objects.append(std::make_unique<OBJRawObject>("NURBSCurve"));
- curr_ob = &list_of_objects.last();
- (*curr_ob)->nurbs_element_.group_ = object_group;
- /* Make sure that the flags are overridden & set only after a new object is created. */
- (*curr_ob)->object_type_ = OB_CURVE;
+ if (create_geometry_curve(current_geometry)) {
+ update_index_offsets(current_geometry);
+ list_of_objects.append(std::make_unique<Geometry>(GEOM_CURVE, "NURBSCurve"));
+ current_geometry = list_of_objects.last().get();
+ current_geometry->nurbs_element_.group_ = object_group;
}
}
els
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list