[Bf-blender-cvs] [7582bbd5740] soc-2020-io-performance: Break code into mesh, objects, and reader files.
Ankit Meel
noreply at git.blender.org
Mon Jul 13 11:43:55 CEST 2020
Commit: 7582bbd57405251cca5447f03c4453e3a6665db9
Author: Ankit Meel
Date: Mon Jul 13 15:13:48 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB7582bbd57405251cca5447f03c4453e3a6665db9
Break code into mesh, objects, and reader files.
===================================================================
M source/blender/io/wavefront_obj/CMakeLists.txt
A source/blender/io/wavefront_obj/intern/wavefront_obj_file_reader.cc
A source/blender/io/wavefront_obj/intern/wavefront_obj_file_reader.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc
M source/blender/io/wavefront_obj/intern/wavefront_obj_importer.hh
A source/blender/io/wavefront_obj/intern/wavefront_obj_importer_mesh.cc
A source/blender/io/wavefront_obj/intern/wavefront_obj_importer_mesh.hh
A source/blender/io/wavefront_obj/intern/wavefront_obj_importer_objects.cc
A source/blender/io/wavefront_obj/intern/wavefront_obj_importer_objects.hh
===================================================================
diff --git a/source/blender/io/wavefront_obj/CMakeLists.txt b/source/blender/io/wavefront_obj/CMakeLists.txt
index 2e7b044e81c..13abcf5d62a 100644
--- a/source/blender/io/wavefront_obj/CMakeLists.txt
+++ b/source/blender/io/wavefront_obj/CMakeLists.txt
@@ -46,7 +46,10 @@ set(SRC
intern/wavefront_obj_exporter_mtl.cc
intern/wavefront_obj_exporter_nurbs.cc
intern/wavefront_obj_file_handler.cc
+ intern/wavefront_obj_file_reader.cc
intern/wavefront_obj_importer.cc
+ intern/wavefront_obj_importer_mesh.cc
+ intern/wavefront_obj_importer_objects.cc
IO_wavefront_obj.h
intern/wavefront_obj.hh
@@ -55,7 +58,10 @@ set(SRC
intern/wavefront_obj_exporter_mtl.hh
intern/wavefront_obj_exporter_nurbs.hh
intern/wavefront_obj_file_handler.hh
+ intern/wavefront_obj_file_reader.hh
intern/wavefront_obj_importer.hh
+ intern/wavefront_obj_importer_mesh.hh
+ intern/wavefront_obj_importer_objects.hh
)
set(LIB
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_file_reader.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_file_reader.cc
new file mode 100644
index 00000000000..63775a9be1a
--- /dev/null
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_file_reader.cc
@@ -0,0 +1,101 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup obj
+ */
+
+#include <fstream>
+#include <iostream>
+
+#include "BKE_context.h"
+
+#include "BLI_vector.hh"
+#include "BLI_string_ref.hh"
+
+#include "wavefront_obj_file_reader.hh"
+#include "wavefront_obj_file_handler.hh"
+
+namespace blender::io::obj {
+
+OBJImporter::OBJImporter(const OBJImportParams &import_params) : import_params_(import_params)
+{
+ infile_.open(import_params_.filepath);
+}
+
+void OBJImporter::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_objects)
+{
+ std::string line;
+ std::unique_ptr<OBJRawObject> *curr_ob;
+ while (std::getline(infile_, line)) {
+ std::stringstream s_line(line);
+ std::string line_key;
+ s_line >> line_key;
+
+ if (line_key == "o") {
+ /* Update index offsets if an object has been processed already. */
+ if (list_of_objects.size() > 0) {
+ index_offsets[VERTEX_OFF] += (*curr_ob)->vertices.size();
+ index_offsets[UV_VERTEX_OFF] += (*curr_ob)->texture_vertices.size();
+ }
+ list_of_objects.append(std::make_unique<OBJRawObject>(s_line.str()));
+ curr_ob = &list_of_objects.last();
+ }
+ /* TODO ankitm Check that an object exists. */
+ else if (line_key == "v") {
+ MVert curr_vert;
+ s_line >> curr_vert.co[0] >> curr_vert.co[1] >> curr_vert.co[2];
+ (*curr_ob)->vertices.append(curr_vert);
+ }
+ else if (line_key == "vn") {
+ (*curr_ob)->tot_normals++;
+ }
+ else if (line_key == "vt") {
+ MLoopUV curr_tex_vert;
+ s_line >> curr_tex_vert.uv[0] >> curr_tex_vert.uv[1];
+ (*curr_ob)->texture_vertices.append(curr_tex_vert);
+ }
+ else if (line_key == "f") {
+ Vector<OBJFaceCorner> curr_face;
+ while (s_line) {
+ OBJFaceCorner corner;
+ if (!(s_line >> corner.vert_index)) {
+ break;
+ }
+ /* Base 1 in OBJ to base 0 in C++. */
+ corner.vert_index--;
+ /* Adjust for index offset of previous objects. */
+ corner.vert_index -= index_offsets[VERTEX_OFF];
+
+ // TODO texture coords handling. It's mostly string manipulation. Normal indices will be
+ // ignored and calculated depending on the smooth flag.
+ // s_line >> corner.tex_vert_index;
+ curr_face.append(corner);
+ }
+ (*curr_ob)->face_elements.append(curr_face);
+ (*curr_ob)->tot_loop += curr_face.size();
+ }
+ else if (line_key == "usemtl") {
+ (*curr_ob)->material_name.append(s_line.str());
+ }
+ else if (line_key == "#") {
+ }
+ }
+}
+}
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_file_reader.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_file_reader.hh
new file mode 100644
index 00000000000..7c0f5fbb668
--- /dev/null
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_file_reader.hh
@@ -0,0 +1,48 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup obj
+ */
+
+#ifndef __WAVEFRONT_OBJ_FILE_READER_HH__
+#define __WAVEFRONT_OBJ_FILE_READER_HH__
+
+#include "IO_wavefront_obj.h"
+#include "wavefront_obj_importer_objects.hh"
+
+namespace blender::io::obj{
+class OBJImporter {
+private:
+ const OBJImportParams &import_params_;
+ std::ifstream infile_;
+ uint index_offsets[2] = {0, 0};
+
+public:
+ OBJImporter(const OBJImportParams &import_params);
+
+ void parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_objects);
+ void print_obj_data(Vector<std::unique_ptr<OBJRawObject>> &list_of_objects);
+ void make_objects(Main *bmain,
+ Scene *scene,
+ Vector<std::unique_ptr<OBJRawObject>> &list_of_objects);
+};
+
+}
+#endif
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc
index b2cc0d3c722..5c80028978f 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc
@@ -24,91 +24,21 @@
#include <cstdio>
#include <fstream>
#include <iostream>
-#include <optional>
-#include <string>
-
-#include "BKE_collection.h"
-#include "BKE_customdata.h"
-#include "BKE_object.h"
#include "BLI_array.hh"
-#include "BLI_path_util.h"
+#include "BLI_float2.hh"
+#include "BLI_float3.hh"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "bmesh.h"
-#include "DEG_depsgraph.h"
-#include "DEG_depsgraph_query.h"
-
-#include "wavefront_obj_file_handler.hh"
+#include "wavefront_obj_file_reader.hh"
#include "wavefront_obj_importer.hh"
+#include "wavefront_obj_importer_mesh.hh"
+#include "wavefront_obj_importer_objects.hh"
namespace blender::io::obj {
-OBJImporter::OBJImporter(const OBJImportParams &import_params) : import_params_(import_params)
-{
- infile_.open(import_params_.filepath);
-}
-
-void OBJImporter::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of_objects)
-{
- std::string line;
- std::unique_ptr<OBJRawObject> *curr_ob;
- while (std::getline(infile_, line)) {
- std::stringstream s_line(line);
- std::string line_key;
- s_line >> line_key;
-
- if (line_key == "o") {
- /* Update index offsets if an object has been processed already. */
- if (list_of_objects.size() > 0) {
- index_offsets[VERTEX_OFF] += (*curr_ob)->vertices.size();
- index_offsets[UV_VERTEX_OFF] += (*curr_ob)->texture_vertices.size();
- }
- list_of_objects.append(std::make_unique<OBJRawObject>(s_line.str()));
- curr_ob = &list_of_objects.last();
- }
- /* TODO ankitm Check that an object exists. */
- else if (line_key == "v") {
- MVert curr_vert;
- s_line >> curr_vert.co[0] >> curr_vert.co[1] >> curr_vert.co[2];
- (*curr_ob)->vertices.append(curr_vert);
- }
- else if (line_key == "vn") {
- (*curr_ob)->tot_normals++;
- }
- else if (line_key == "vt") {
- MLoopUV curr_tex_vert;
- s_line >> curr_tex_vert.uv[0] >> curr_tex_vert.uv[1];
- (*curr_ob)->texture_vertices.append(curr_tex_vert);
- }
- else if (line_key == "f") {
- Vector<OBJFaceCorner> curr_face;
- while (s_line) {
- OBJFaceCorner corner;
- if (!(s_line >> corner.vert_index)) {
- break;
- }
- /* Base 1 in OBJ to base 0 in C++. */
- corner.vert_index--;
- /* Adjust for index offset of previous objects. */
- corner.vert_index -= index_offsets[VERTEX_OFF];
-
- // TODO texture coords handling. It's mostly string manipulation. Normal indices will be
- // ignored and calculated depending on the smooth flag.
- // s_line >> corner.tex_vert_index;
- curr_face.append(corner);
- }
- (*curr_ob)->face_elements.append(curr_face);
- (*curr_ob)->tot_loop += curr_face.size();
- }
- else if (line_key == "usemtl") {
- (*curr_ob)->material_name.append(s_line.str());
- }
- else if (line_key == "#") {
- }
- }
-}
void OBJImporter::print_obj_data(Vector<std::unique_ptr<OBJRawObject>> &list_of_objects)
{
@@ -134,83 +64,6 @@ void OBJImporter::print_obj_data(Vector<std::unique_ptr<OBJRawObject>> &list_of_
}
}
-OBJBmeshFromRaw::OBJBmeshFromRaw(const OBJRawObject &curr_object)
-{
- auto creator_mesh = [&]() {
- return BKE_mesh_new_nomain(0, 0, 0, curr_object.tot_loop, curr_object.face_elements.size());
- };
- auto
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list