[Bf-blender-cvs] [485cc4330af] soc-2020-io-performance: Preliminary geometry data exported, without any axes modification.
Ankit Meel
noreply at git.blender.org
Tue Jun 2 09:53:11 CEST 2020
Commit: 485cc4330aff5f38c8af7874a450829cdd975cf7
Author: Ankit Meel
Date: Tue Jun 2 13:19:16 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB485cc4330aff5f38c8af7874a450829cdd975cf7
Preliminary geometry data exported, without any axes modification.
Single object geometry data exporter: vertex, vertex normal, faces.
Completed the todos in rB3c947bd5a6a2.
Todo:
Add object name.
Export multiple objects in the same file.
Verify it on other complex shapes.
Texture coordinates.
===================================================================
M source/blender/editors/io/io_obj.c
M source/blender/editors/io/io_obj.h
M source/blender/io/obj/CMakeLists.txt
R081 source/blender/io/obj/obj.cpp source/blender/io/obj/obj.cc
M source/blender/io/obj/obj.h
A source/blender/io/obj/obj_exporter.cc
D source/blender/io/obj/obj_exporter.cpp
M source/blender/io/obj/obj_exporter.h
A source/blender/io/obj/obj_file_handler.cc
D source/blender/io/obj/obj_file_handler.cpp
M source/blender/io/obj/obj_file_handler.h
R099 source/blender/io/obj/obj_importer.cpp source/blender/io/obj/obj_importer.cc
M source/blender/io/obj/obj_importer.h
===================================================================
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index 59b28d76052..d58cd8c8470 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -83,8 +83,8 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
RNA_string_get(op->ptr, "filepath", filepath);
a.print_name = RNA_boolean_get(op->ptr, "print_name");
a.number = RNA_float_get(op->ptr, "print_the_float");
-
- bool ok = OBJ_export(C, filepath, &a);
+ a.filepath = filepath;
+ bool ok = OBJ_export(C, &a);
return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
diff --git a/source/blender/editors/io/io_obj.h b/source/blender/editors/io/io_obj.h
index 257c90e64c2..58873320754 100644
--- a/source/blender/editors/io/io_obj.h
+++ b/source/blender/editors/io/io_obj.h
@@ -21,7 +21,12 @@
* \ingroup editor/io
*/
+#ifndef __IO_OBJ_H__
+#define __IO_OBJ_H__
+
struct wmOperatorType;
void WM_OT_obj_export(struct wmOperatorType *ot);
void WM_OT_obj_import(struct wmOperatorType *ot);
+
+#endif
diff --git a/source/blender/io/obj/CMakeLists.txt b/source/blender/io/obj/CMakeLists.txt
index dad540c6a6f..547cb87f6cc 100644
--- a/source/blender/io/obj/CMakeLists.txt
+++ b/source/blender/io/obj/CMakeLists.txt
@@ -40,10 +40,10 @@ set(INC_SYS
)
set(SRC
- obj.cpp
- obj_exporter.cpp
- obj_file_handler.cpp
- obj_importer.cpp
+ obj.cc
+ obj_exporter.cc
+ obj_file_handler.cc
+ obj_importer.cc
obj.h
obj_exporter.h
diff --git a/source/blender/io/obj/obj.cpp b/source/blender/io/obj/obj.cc
similarity index 81%
rename from source/blender/io/obj/obj.cpp
rename to source/blender/io/obj/obj.cc
index f84dd1eba57..f4a5fbcbed1 100644
--- a/source/blender/io/obj/obj.cpp
+++ b/source/blender/io/obj/obj.cc
@@ -24,19 +24,19 @@
#include "obj.h"
#include "obj_exporter.h"
-bool OBJ_export(bContext *C, const char *filepath, OBJExportParams *a)
+bool OBJ_export(bContext *C, OBJExportParams *export_params)
{
- if (a->print_name) {
+ if (export_params->print_name) {
printf("\n OP");
}
- if (a->number) {
- printf("\n%f\n", a->number);
+ if (export_params->number) {
+ printf("\n%f\n", export_params->number);
}
- exporter_main(C, filepath);
+ exporter_main(C, export_params);
return true;
}
-bool OBJ_import(bContext *C, const char *filepath, OBJImportParams *a)
+bool OBJ_import(bContext *C, const char *filepath, OBJImportParams *import_params)
{
return true;
}
diff --git a/source/blender/io/obj/obj.h b/source/blender/io/obj/obj.h
index 8c32237bcbc..94a2ff98033 100644
--- a/source/blender/io/obj/obj.h
+++ b/source/blender/io/obj/obj.h
@@ -18,18 +18,36 @@
* \ingroup obj
*/
-#include <stdlib.h>
+#ifndef __OBJ_H__
+#define __OBJ_H__
#include "BKE_context.h"
-#include "BLI_linklist.h"
-#include "BLI_path_util.h"
-#include "RNA_types.h"
#ifdef __cplusplus
+# include <vector>
+struct faces {
+ int total_vertices_per_face;
+ std::vector<int> vertex_references;
+ std::vector<int> vertex_normal_references;
+};
+
+struct OBJ_data_to_export {
+ int tot_vertices;
+ std::vector<struct MVert> vertices;
+ std::vector<std::array<float, 3>> normals;
+ int tot_faces;
+ std::vector<struct faces> faces_list;
+};
extern "C" {
#endif
struct OBJExportParams {
+ const char *filepath;
+
+ bContext *C;
+ Depsgraph *depsgraph;
+ Scene *scene;
+
bool print_name;
float number;
};
@@ -38,13 +56,12 @@ struct OBJImportParams {
float number;
};
-/*
- * both return 1 on success, 0 on error
- */
-bool OBJ_import(struct bContext *C, const char *filename, struct OBJImportParams *import_settings);
+bool OBJ_import(struct bContext *C, const char *filepath, struct OBJImportParams *import_params);
-bool OBJ_export(struct bContext *C, const char *filename, struct OBJExportParams *export_settings);
+bool OBJ_export(struct bContext *C, struct OBJExportParams *export_params);
#ifdef __cplusplus
}
#endif
+
+#endif /* __OBJ_H__ */
diff --git a/source/blender/io/obj/obj_exporter.cc b/source/blender/io/obj/obj_exporter.cc
new file mode 100644
index 00000000000..1e74fc430a5
--- /dev/null
+++ b/source/blender/io/obj/obj_exporter.cc
@@ -0,0 +1,112 @@
+/*
+ * 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) 2008 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup obj
+ */
+
+#include "obj_exporter.h"
+#include "obj_file_handler.h"
+
+#include <array>
+#include <fstream>
+#include <iostream>
+#include <stdio.h>
+#include <vector>
+
+#include "BKE_DerivedMesh.h"
+#include "BKE_context.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_runtime.h"
+#include "BKE_object.h"
+#include "BKE_scene.h"
+
+#include "BLI_linklist.h"
+#include "BLI_math.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+void prepare_vertices(OBJExportParams *export_params, OBJ_data_to_export *data_to_export)
+{
+
+ Depsgraph *depsgraph = export_params->depsgraph;
+ Object *ob = CTX_data_active_object(export_params->C);
+ Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
+ // Scene *scene = export_params->scene;
+ // Mesh *me_eval = mesh_create_eval_final_view(depsgraph, scene, ob_eval, &CD_MASK_BAREMESH);
+ // causing memory leak in lite & assert in full.
+ Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval);
+
+ int num_verts = data_to_export->tot_vertices = me_eval->totvert;
+ MVert empty_mvert;
+ float transformed_co[3];
+
+ for (int i = 0; i < num_verts; i++) {
+ data_to_export->vertices.push_back(empty_mvert);
+ copy_v3_v3(transformed_co, me_eval->mvert[i].co);
+ mul_m4_v3(ob_eval->obmat, transformed_co);
+ for (int j = 0; j < 3; j++) {
+ data_to_export->vertices[i].co[j] = transformed_co[j];
+ me_eval->mvert[i].co[j] = transformed_co[j];
+ }
+ }
+ float transformed_normals[3];
+ const MLoop *ml;
+ const MPoly *mp = me_eval->mpoly;
+ const MVert *mvert = me_eval->mvert;
+ struct faces empty_face;
+
+ data_to_export->tot_faces = me_eval->totpoly;
+ for (int i = 0; i < me_eval->totpoly; i++, mp++) {
+ data_to_export->normals.push_back(std::array<float, 3>());
+ data_to_export->faces_list.push_back(empty_face);
+
+ ml = &me_eval->mloop[mp->loopstart];
+ BKE_mesh_calc_poly_normal(mp, ml, mvert, transformed_normals);
+
+ for (int j = 0; j < 3; j++) {
+ data_to_export->normals[i][j] = transformed_normals[j];
+ }
+
+ data_to_export->faces_list[i].total_vertices_per_face = mp->totloop;
+ for (int j = 0; j < mp->totloop; j++) {
+ data_to_export->faces_list[i].vertex_references.push_back((ml + j)->v + 1);
+ data_to_export->faces_list[i].vertex_normal_references.push_back(i + 1);
+ }
+ }
+}
+
+bool exporter_main(bContext *C, OBJExportParams *export_params)
+{
+
+ const char *filepath = export_params->filepath;
+
+ export_params->C = C;
+ export_params->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ export_params->scene = CTX_data_scene(C);
+ struct OBJ_data_to_export data_to_export;
+
+ prepare_vertices(export_params, &data_to_export);
+ write_prepared_data(filepath, &data_to_export);
+ return true;
+}
diff --git a/source/blender/io/obj/obj_exporter.cpp b/source/blender/io/obj/obj_exporter.cpp
deleted file mode 100644
index 53418085280..00000000000
--- a/source/blender/io/obj/obj_exporter.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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) 2008 Blender Foundation.
- * All rights reserved.
- */
-
-/** \file
- * \ingroup obj
- */
-
-#include <stdio.h>
-
-#include "obj_file_handler.h"
-#include "obj_exporter.h"
-
-#include "BKE_context.h"
-#include "BLI_linklist.h"
-#include "BKE_object.h"
-#include "DEG_depsgraph.h"
-#include "DEG_depsgraph_query.h"
-#include "DNA_layer_types.h"
-#include "DNA_object_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-
-bool exporter_main(bContext *C, const char *filepath){
-
- const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- Object *ob = CTX_data_active_object(C);
- Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
-
- printf("\n%d\n", ob_eval->type & OB_MESH);
- Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval);
- int numVerts = me_eval->totvert;
- for (int i=0; i < numVerts; i++) {
- for (int j=0 ; j<3; j++) {
- printf("%f ", me_eval->mvert[i].co[j]);
- }
- printf("\n");
- }
-
- return true;
-}
diff --git a/source/blender/io/obj/obj_exporter.h b/source/blender/io/obj/obj_exporter.h
index 6e3b6a757b4..5bc6d4c309d 100644
--- a/source/blender/io/obj/obj_exporter.h
+++ b/source/blender/io/obj/obj_exporter.h
@@ -21,7 +21,13 @@
* \ingroup obj
*/
-#include "BKE_context.h"
-#include "DEG_depsgraph.h"
+#ifndef __OBJ_EXPORTER_H__
+#define __OBJ_E
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list