[Bf-blender-cvs] [3c947bd5a6a] soc-2020-io-performance: Working UI for importer too. Got the mesh.
Ankit Meel
noreply at git.blender.org
Tue May 26 22:11:13 CEST 2020
Commit: 3c947bd5a6a2095cbadc327fcd16cfecaadec6a6
Author: Ankit Meel
Date: Wed May 27 01:32:58 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB3c947bd5a6a2095cbadc327fcd16cfecaadec6a6
Working UI for importer too. Got the mesh.
- Added all required dummy files.
- Finished rudimentary UI for Importer too.
- Among the several ways to get the current/ active object, picked
the most common way to get to the vertices. Might have to change
it, when _export all objects_, etc settings appear.
TODO:
- Will finalise a singular data structure.
- Will discuss about `#include`s in `.h` vs `.cpp`.
- Filepath may be moved inside `OBJExportParams`.
- Clear up `io_obj.c`'s includes.
===================================================================
M source/blender/editors/io/io_obj.c
M source/blender/io/obj/CMakeLists.txt
M source/blender/io/obj/obj.cpp
M source/blender/io/obj/obj.h
A source/blender/io/obj/obj_exporter.cpp
A source/blender/io/obj/obj_exporter.h
A source/blender/io/obj/obj_file_handler.cpp
A source/blender/io/obj/obj_file_handler.h
A source/blender/io/obj/obj_importer.cpp
A source/blender/io/obj/obj_importer.h
M source/blender/windowmanager/intern/wm_operator_props.c
===================================================================
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index 1a4c34b904e..59b28d76052 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -21,75 +21,70 @@
* \ingroup editor/io
*/
-# include "DNA_space_types.h"
+#include "DNA_space_types.h"
-# include "BKE_context.h"
-# include "BKE_main.h"
-# include "BKE_report.h"
+#include "BKE_context.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
-# include "BLI_path_util.h"
-# include "BLI_string.h"
-# include "BLI_utildefines.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
-# include "BLT_translation.h"
+#include "BLT_translation.h"
-# include "MEM_guardedalloc.h"
+#include "MEM_guardedalloc.h"
-# include "RNA_access.h"
-# include "RNA_define.h"
+#include "RNA_access.h"
+#include "RNA_define.h"
-# include "UI_interface.h"
-# include "UI_resources.h"
+#include "UI_interface.h"
+#include "UI_resources.h"
-# include "WM_api.h"
-# include "WM_types.h"
+#include "WM_api.h"
+#include "WM_types.h"
-# include "DEG_depsgraph.h"
+#include "DEG_depsgraph.h"
-# include "io_obj.h"
-# include "obj.h"
+#include "io_obj.h"
+#include "obj.h"
+
+static int wm_obj_export_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
-static int wm_obj_export_invoke(bContext *C, wmOperator *op, const wmEvent *event){
- if (!RNA_struct_property_is_set(op->ptr, "print_name")) {
- printf("\n Name not set \n");
- }
-
- if (!RNA_struct_property_is_set(op->ptr, "print_the_float")) {
- printf("float not set");
- }
-
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
Main *bmain = CTX_data_main(C);
char filepath[FILE_MAX];
-
+
if (BKE_main_blendfile_path(bmain)[0] == '\0') {
BLI_strncpy(filepath, "untitled", sizeof(filepath));
}
else {
BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
}
-
+
BLI_path_extension_replace(filepath, sizeof(filepath), ".obj");
RNA_string_set(op->ptr, "filepath", filepath);
}
-
+
WM_event_add_fileselect(C, op);
return OPERATOR_RUNNING_MODAL;
-
+
UNUSED_VARS(event);
}
-static int wm_obj_export_exec(bContext *C, wmOperator *op){
+static int wm_obj_export_exec(bContext *C, wmOperator *op)
+{
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
BKE_report(op->reports, RPT_ERROR, "No filename given");
return OPERATOR_CANCELLED;
}
struct OBJExportParams a;
- char filename[FILE_MAX];
- RNA_string_get(op->ptr, "filepath", filename);
+ char filepath[FILE_MAX];
+ 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, &a);
+
+ bool ok = OBJ_export(C, filepath, &a);
return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@@ -97,59 +92,81 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
{
uiLayout *box;
uiLayout *row;
-
+
box = uiLayoutBox(layout);
row = uiLayoutRow(box, false);
uiItemL(row, IFACE_("Some Options"), ICON_NONE);
-
+
row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "print_name", 0, NULL, ICON_NONE);
-
+
row = uiLayoutRow(box, false);
- uiItemR(row, imfptr, "print_the_float", 0, NULL, ICON_NONE);
+ uiItemR(row, imfptr, "print_the_float", 0, NULL, ICON_NONE);
}
-static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op ){
+static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op)
+{
PointerRNA ptr;
RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
ui_obj_export_settings(op->layout, &ptr);
}
-
-void WM_OT_obj_export(struct wmOperatorType *ot){
+void WM_OT_obj_export(struct wmOperatorType *ot)
+{
ot->name = "Export Wavefront OBJ";
ot->description = "Save the scene to a Wavefront OBJ file";
ot->idname = "WM_OT_obj_export";
-
+
ot->invoke = wm_obj_export_invoke;
ot->exec = wm_obj_export_exec;
ot->poll = WM_operator_winactive;
ot->ui = wm_obj_export_draw;
-
+
WM_operator_properties_filesel(ot,
FILE_TYPE_FOLDER | FILE_TYPE_OBJECT_IO,
FILE_BLENDER,
- FILE_SAVE,
+ FILE_OPENFILE,
WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
FILE_DEFAULTDISPLAY,
FILE_SORT_ALPHA);
-
+
RNA_def_boolean(ot->srna, "print_name", 0, "Print Name?", "If enabled, prints name of OP");
- RNA_def_float(ot->srna, "print_the_float", 4.56, 0.0f, 10.0f, "Print the Float", "Prints the given Float", 1.0f, 9.0f);
+ RNA_def_float(ot->srna,
+ "print_the_float",
+ 4.56,
+ 0.0f,
+ 10.0f,
+ "Print the Float",
+ "Prints the given Float",
+ 1.0f,
+ 9.0f);
}
-
-static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *event){
- return 1;
+static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ WM_event_add_fileselect(C, op);
+ return OPERATOR_RUNNING_MODAL;
+ UNUSED_VARS(event);
}
-static int wm_obj_import_exec(bContext *C, wmOperator *op){
- return 1;
+static int wm_obj_import_exec(bContext *C, wmOperator *op)
+{
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ BKE_report(op->reports, RPT_ERROR, "No filename given");
+ return OPERATOR_CANCELLED;
+ }
+ char filepath[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filepath);
+ struct OBJImportParams a;
+ a.number = 3.0f;
+ a.print_name = 1;
+ bool ok = OBJ_import(C, filepath, &a);
+
+ return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
-static void wm_obj_import_draw(bContext *UNUSED(C), wmOperator *op){
-
+static void wm_obj_import_draw(bContext *UNUSED(C), wmOperator *UNUSED(op))
+{
}
-
void WM_OT_obj_import(struct wmOperatorType *ot)
{
ot->name = "Import Wavefront OBJ";
@@ -164,10 +181,8 @@ void WM_OT_obj_import(struct wmOperatorType *ot)
WM_operator_properties_filesel(ot,
FILE_TYPE_FOLDER | FILE_TYPE_OBJECT_IO,
FILE_BLENDER,
- FILE_SAVE,
+ FILE_OPENFILE,
WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
FILE_DEFAULTDISPLAY,
FILE_SORT_ALPHA);
-
}
-
diff --git a/source/blender/io/obj/CMakeLists.txt b/source/blender/io/obj/CMakeLists.txt
index b556747549c..dad540c6a6f 100644
--- a/source/blender/io/obj/CMakeLists.txt
+++ b/source/blender/io/obj/CMakeLists.txt
@@ -20,9 +20,19 @@
set(INC
.
-../../blenlib
-../../makesrna
+ ../../blenkernel
+ ../../blenlib
+ ../../blentranslation
+ ../../depsgraph
+ ../../editors/include
+ ../../imbuf
+ ../../makesdna
+ ../../makesrna
+ ../../windowmanager
../../../../intern/guardedalloc
+ ../../ikplugin
+ ../../../../intern/iksolver/extern
+ ../../bmesh
)
set(INC_SYS
@@ -31,8 +41,14 @@ set(INC_SYS
set(SRC
obj.cpp
+ obj_exporter.cpp
+ obj_file_handler.cpp
+ obj_importer.cpp
obj.h
+ obj_exporter.h
+ obj_file_handler.h
+ obj_importer.h
)
set(LIB
diff --git a/source/blender/io/obj/obj.cpp b/source/blender/io/obj/obj.cpp
index c6e1353c91f..f84dd1eba57 100644
--- a/source/blender/io/obj/obj.cpp
+++ b/source/blender/io/obj/obj.cpp
@@ -1,11 +1,42 @@
+/*
+ * 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.h"
+#include "obj_exporter.h"
-bool obj_export(bContext *C, OBJExportParams * a){
+bool OBJ_export(bContext *C, const char *filepath, OBJExportParams *a)
+{
if (a->print_name) {
printf("\n OP");
}
if (a->number) {
- printf("\n%f\n",a->number);
+ printf("\n%f\n", a->number);
}
+ exporter_main(C, filepath);
+ return true;
+}
+
+bool OBJ_import(bContext *C, const char *filepath, OBJImportParams *a)
+{
return true;
}
diff --git a/source/blender/io/obj/obj.h b/source/blender/io/obj/obj.h
index 069070585e4..8c32237bcbc 100644
--- a/source/blender/io/obj/obj.h
+++ b/source/blender/io/obj/obj.h
@@ -20,7 +20,7 @@
#include <stdlib.h>
-
+#include "BKE_context.h"
#include "BLI_linklist.h"
#include "BLI_path_util.h"
#include "RNA_types.h"
@@ -28,25 +28,23 @@
#ifdef __cplusplus
extern "C" {
#endif
-
- struct bContext;
- struct OBJExportParams{
- bool print_name;
- float number;
- };
- struct OBJImportParams{
- bool print_name;
- float number;
- };
+
+struct OBJExportParams {
+ bool print_name;
+ float number;
+};
+struct OBJImportParams {
+ bool print_name;
+ float number;
+};
/*
* both return 1 on success, 0 on error
*/
- bool obj_import(struct bContext *C, struct OBJImportParams *import_settings);
+bool OBJ_import(struct bContext *C, const char *filename, struct OBJImportParams *import_settings);
- bool obj_export(struct bContext *C, struct OBJExportParams *export_settings);
+bool OBJ_export(struct bContext *C, const char *filename, struct OBJExportParams *export_settings);
#ifdef __cplusplus
}
#endif
-
diff --git a/source/blender/io/obj/obj_exporter.cpp b/source/blender/io/obj/obj_exporter.cpp
new file
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list