[Bf-blender-cvs] [92be92befea] soc-2020-io-performance: Fix UV crashes and redundant loops in v1//vn1 case.
Ankit Meel
noreply at git.blender.org
Thu Jul 16 12:34:23 CEST 2020
Commit: 92be92befeafb3d02ae4d11f883962161df30779
Author: Ankit Meel
Date: Thu Jul 16 16:00:46 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB92be92befeafb3d02ae4d11f883962161df30779
Fix UV crashes and redundant loops in v1//vn1 case.
===================================================================
M source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
===================================================================
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh
index 2070a85b5a6..26deda8213a 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh
@@ -66,9 +66,7 @@ class OBJWriter {
void write_vertex_coords(OBJMesh &obj_mesh_data);
void write_uv_coords(OBJMesh &obj_mesh_data, Vector<Vector<uint>> &uv_indices);
void write_poly_normals(OBJMesh &obj_mesh_data);
- void write_smooth_group(OBJMesh &obj_mesh_data,
- int &r_last_face_smooth_group,
- uint poly_index);
+ void write_smooth_group(OBJMesh &obj_mesh_data, int &r_last_face_smooth_group, uint poly_index);
void write_poly_material(OBJMesh &obj_mesh_data, short &r_last_face_mat_nr, uint poly_index);
void write_vertex_group(OBJMesh &obj_mesh_data,
short &r_last_face_vertex_group,
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 06e43ebbbb7..75d4bab9dcc 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
@@ -150,8 +150,10 @@ void OBJImporter::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of
Vector<std::string> vert_texture;
split_by_char(str_corner, '/', vert_texture);
corner.vert_index = std::stoi(vert_texture[0]);
- corner.tex_vert_index = vert_texture.size() >= 2 ? std::stoi(vert_texture[1]) : -1;
- (*curr_ob)->tot_uv_verts++;
+ if (vert_texture.size() == 2) {
+ corner.tex_vert_index = std::stoi(vert_texture[1]);
+ (*curr_ob)->tot_uv_verts++;
+ }
}
else if (n_slash == 2) {
/* Case: f v1//vn1 v2//vn2 v3//vn3 . */
@@ -159,8 +161,10 @@ void OBJImporter::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of
Vector<std::string> vert_tex_normal;
split_by_char(str_corner, '/', vert_tex_normal);
corner.vert_index = std::stoi(vert_tex_normal[0]);
- corner.tex_vert_index = vert_tex_normal.size() >= 2 ? std::stoi(vert_tex_normal[1]) : -1;
- (*curr_ob)->tot_uv_verts++;
+ if (vert_tex_normal.size() == 3) {
+ corner.tex_vert_index = std::stoi(vert_tex_normal[1]);
+ (*curr_ob)->tot_uv_verts++;
+ }
/* Discard normals. They'll be calculated on the basis of smooth
* shading flag. */
}
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
index 888c1d578f3..f56f4fc5c57 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
@@ -63,29 +63,30 @@ OBJMeshFromRaw::OBJMeshFromRaw(class OBJRawObject &curr_object)
}
}
+ /* TODO ankitm merge the face iteration loops. Kept separate for ease of debugging. */
int uv_vert_index = 0;
- if (curr_object.tot_uv_verts > 0) {
+ if (curr_object.tot_uv_verts > 0 && curr_object.texture_vertices.size() > 0) {
ED_mesh_uv_texture_ensure(mesh_from_bm_.get(), nullptr);
- }
- for (int i = 0; i < tot_face_elems; ++i) {
- const OBJFaceElem curr_face = curr_object.face_elements[i];
- for (int j = 0; j < curr_face.face_corners.size(); ++j) {
- const OBJFaceCorner curr_corner = curr_face.face_corners[j];
- MLoopUV *mluv_dst = (MLoopUV *)CustomData_get_layer(&mesh_from_bm_->ldata, CD_MLOOPUV);
- if (!mluv_dst) {
- fprintf(stderr, "No UV layer found.\n");
- break;
- }
- if (curr_corner.tex_vert_index < 0 ||
- curr_corner.tex_vert_index >= curr_object.tot_uv_verts) {
- continue;
- }
- MLoopUV *mluv_src = &curr_object.texture_vertices[curr_corner.tex_vert_index];
- int &set_uv = mluv_src->flag;
- if (set_uv == false && uv_vert_index <= curr_object.tot_uv_verts) {
- copy_v2_v2(mluv_dst[uv_vert_index].uv, mluv_src->uv);
- uv_vert_index++;
- set_uv = true;
+ for (int i = 0; i < tot_face_elems; ++i) {
+ const OBJFaceElem curr_face = curr_object.face_elements[i];
+ for (int j = 0; j < curr_face.face_corners.size(); ++j) {
+ const OBJFaceCorner curr_corner = curr_face.face_corners[j];
+ MLoopUV *mluv_dst = (MLoopUV *)CustomData_get_layer(&mesh_from_bm_->ldata, CD_MLOOPUV);
+ if (!mluv_dst) {
+ fprintf(stderr, "No UV layer found.\n");
+ break;
+ }
+ if (curr_corner.tex_vert_index < 0 ||
+ curr_corner.tex_vert_index >= curr_object.tot_uv_verts) {
+ continue;
+ }
+ MLoopUV *mluv_src = &curr_object.texture_vertices[curr_corner.tex_vert_index];
+ int &set_uv = mluv_src->flag;
+ if (set_uv == false && uv_vert_index <= curr_object.tot_uv_verts) {
+ copy_v2_v2(mluv_dst[uv_vert_index].uv, mluv_src->uv);
+ uv_vert_index++;
+ set_uv = true;
+ }
}
}
}
More information about the Bf-blender-cvs
mailing list