[Bf-blender-cvs] [4e44cfa3d99] master: Add a new C++ version of an exporter for the Wavefront .obj format.

Howard Trickey noreply at git.blender.org
Mon Jan 3 20:52:28 CET 2022


Commit: 4e44cfa3d9969f0f3e175b53f116f377278a3245
Author: Howard Trickey
Date:   Mon Jan 3 14:49:31 2022 -0500
Branches: master
https://developer.blender.org/rB4e44cfa3d9969f0f3e175b53f116f377278a3245

Add a new C++ version of an exporter for the Wavefront .obj format.

This was originally written by Ankit Meel as a GSoC 2020 project.
Howard Trickey added some tests and made some corrections/modifications.
See D13046 for more details.

This commit inserts a new menu item into the export menu called
"Wavefront OBJ (.obj) - New".
For now the old Python exporter remains in the menu, along with
the Python importer, but we plan to remove it soon (leaving the
old addon bundled with Blender but not enabled by default).

===================================================================

M	release/scripts/startup/bl_ui/space_topbar.py
M	source/blender/blenloader/CMakeLists.txt
M	source/blender/blenloader/tests/blendfile_loading_base_test.cc
M	source/blender/editors/io/CMakeLists.txt
A	source/blender/editors/io/io_obj.c
A	source/blender/editors/io/io_obj.h
M	source/blender/editors/io/io_ops.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/io/CMakeLists.txt
A	source/blender/io/wavefront_obj/CMakeLists.txt
A	source/blender/io/wavefront_obj/IO_wavefront_obj.cc
A	source/blender/io/wavefront_obj/IO_wavefront_obj.h
A	source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
A	source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh
A	source/blender/io/wavefront_obj/exporter/obj_export_io.hh
A	source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
A	source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh
A	source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc
A	source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh
A	source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc
A	source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh
A	source/blender/io/wavefront_obj/exporter/obj_exporter.cc
A	source/blender/io/wavefront_obj/exporter/obj_exporter.hh
A	source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
A	source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
M	source/blender/windowmanager/intern/wm_operator_props.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 3137ac43549..99abc60db6f 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -481,6 +481,7 @@ class TOPBAR_MT_file_export(Menu):
     bl_owner_use_filter = False
 
     def draw(self, _context):
+        self.layout.operator("wm.obj_export", text="Wavefront OBJ (.obj) - New")
         if bpy.app.build_options.collada:
             self.layout.operator("wm.collada_export",
                                  text="Collada (Default) (.dae)")
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index 05f74bfa834..245514d4977 100644
--- a/source/blender/blenloader/CMakeLists.txt
+++ b/source/blender/blenloader/CMakeLists.txt
@@ -26,6 +26,7 @@ set(INC
   ../blentranslation
   ../depsgraph
   ../draw
+  ../editors/include
   ../imbuf
   ../makesdna
   ../makesrna
diff --git a/source/blender/blenloader/tests/blendfile_loading_base_test.cc b/source/blender/blenloader/tests/blendfile_loading_base_test.cc
index 32d288f35e1..7a8afbcb227 100644
--- a/source/blender/blenloader/tests/blendfile_loading_base_test.cc
+++ b/source/blender/blenloader/tests/blendfile_loading_base_test.cc
@@ -27,9 +27,11 @@
 #include "BKE_idtype.h"
 #include "BKE_image.h"
 #include "BKE_main.h"
+#include "BKE_mball_tessellate.h"
 #include "BKE_modifier.h"
 #include "BKE_node.h"
 #include "BKE_scene.h"
+#include "BKE_vfont.h"
 
 #include "BLI_path_util.h"
 #include "BLI_threads.h"
@@ -44,6 +46,8 @@
 
 #include "IMB_imbuf.h"
 
+#include "ED_datafiles.h"
+
 #include "RNA_define.h"
 
 #include "WM_api.h"
@@ -73,6 +77,7 @@ void BlendfileLoadingBaseTest::SetUpTestCase()
   RNA_init();
   BKE_node_system_init();
   BKE_callback_global_init();
+  BKE_vfont_builtin_register(datatoc_bfont_pfb, datatoc_bfont_pfb_size);
 
   G.background = true;
   G.factory_startup = true;
@@ -111,6 +116,7 @@ void BlendfileLoadingBaseTest::TearDownTestCase()
 
 void BlendfileLoadingBaseTest::TearDown()
 {
+  BKE_mball_cubeTable_free();
   depsgraph_free();
   blendfile_free();
 
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index 44b5f85050f..f4da114159f 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -25,6 +25,20 @@ set(INC
   ../../io/alembic
   ../../io/collada
   ../../io/gpencil
+  ../../io/wavefront_obj
+  ../../io/usd
+  ../../makesdna
+  ../../makesrna
+  ../../windowmanager
+  ../../../../intern/guardedalloc
+)
+
+set(INC_SYS
+
+)
+
+set(SRC
+  io_alembic.c
   ../../io/usd
   ../../makesdna
   ../../makesrna
@@ -43,6 +57,7 @@ set(SRC
   io_gpencil_export.c
   io_gpencil_import.c
   io_gpencil_utils.c
+  io_obj.c
   io_ops.c
   io_usd.c
 
@@ -57,6 +72,7 @@ set(SRC
 set(LIB
   bf_blenkernel
   bf_blenlib
+  bf_wavefront_obj
 )
 
 if(WITH_OPENCOLLADA)
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
new file mode 100644
index 00000000000..1e1e3c2ff42
--- /dev/null
+++ b/source/blender/editors/io/io_obj.c
@@ -0,0 +1,369 @@
+/*
+ * 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.
+ */
+
+/** \file
+ * \ingroup editor/io
+ */
+
+#include "DNA_space_types.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 "BLT_translation.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "DEG_depsgraph.h"
+
+#include "IO_wavefront_obj.h"
+#include "io_obj.h"
+
+const EnumPropertyItem io_obj_transform_axis_forward[] = {
+    {OBJ_AXIS_X_FORWARD, "X_FORWARD", 0, "X", "Positive X axis"},
+    {OBJ_AXIS_Y_FORWARD, "Y_FORWARD", 0, "Y", "Positive Y axis"},
+    {OBJ_AXIS_Z_FORWARD, "Z_FORWARD", 0, "Z", "Positive Z axis"},
+    {OBJ_AXIS_NEGATIVE_X_FORWARD, "NEGATIVE_X_FORWARD", 0, "-X", "Negative X axis"},
+    {OBJ_AXIS_NEGATIVE_Y_FORWARD, "NEGATIVE_Y_FORWARD", 0, "-Y", "Negative Y axis"},
+    {OBJ_AXIS_NEGATIVE_Z_FORWARD, "NEGATIVE_Z_FORWARD", 0, "-Z (Default)", "Negative Z axis"},
+    {0, NULL, 0, NULL, NULL}};
+
+const EnumPropertyItem io_obj_transform_axis_up[] = {
+    {OBJ_AXIS_X_UP, "X_UP", 0, "X", "Positive X axis"},
+    {OBJ_AXIS_Y_UP, "Y_UP", 0, "Y (Default)", "Positive Y axis"},
+    {OBJ_AXIS_Z_UP, "Z_UP", 0, "Z", "Positive Z axis"},
+    {OBJ_AXIS_NEGATIVE_X_UP, "NEGATIVE_X_UP", 0, "-X", "Negative X axis"},
+    {OBJ_AXIS_NEGATIVE_Y_UP, "NEGATIVE_Y_UP", 0, "-Y", "Negative Y axis"},
+    {OBJ_AXIS_NEGATIVE_Z_UP, "NEGATIVE_Z_UP", 0, "-Z", "Negative Z axis"},
+    {0, NULL, 0, NULL, NULL}};
+
+const EnumPropertyItem io_obj_export_evaluation_mode[] = {
+    {DAG_EVAL_RENDER, "DAG_EVAL_RENDER", 0, "Render", "Export objects as they appear in render"},
+    {DAG_EVAL_VIEWPORT,
+     "DAG_EVAL_VIEWPORT",
+     0,
+     "Viewport (Default)",
+     "Export objects as they appear in the viewport"},
+    {0, NULL, 0, NULL, NULL}};
+
+static int wm_obj_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+  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;
+}
+
+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 export_params;
+  RNA_string_get(op->ptr, "filepath", export_params.filepath);
+  export_params.blen_filepath = CTX_data_main(C)->filepath;
+  export_params.export_animation = RNA_boolean_get(op->ptr, "export_animation");
+  export_params.start_frame = RNA_int_get(op->ptr, "start_frame");
+  export_params.end_frame = RNA_int_get(op->ptr, "end_frame");
+
+  export_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis");
+  export_params.up_axis = RNA_enum_get(op->ptr, "up_axis");
+  export_params.scaling_factor = RNA_float_get(op->ptr, "scaling_factor");
+  export_params.export_eval_mode = RNA_enum_get(op->ptr, "export_eval_mode");
+
+  export_params.export_selected_objects = RNA_boolean_get(op->ptr, "export_selected_objects");
+  export_params.export_uv = RNA_boolean_get(op->ptr, "export_uv");
+  export_params.export_normals = RNA_boolean_get(op->ptr, "export_normals");
+  export_params.export_materials = RNA_boolean_get(op->ptr, "export_materials");
+  export_params.export_triangulated_mesh = RNA_boolean_get(op->ptr, "export_triangulated_mesh");
+  export_params.export_curves_as_nurbs = RNA_boolean_get(op->ptr, "export_curves_as_nurbs");
+
+  export_params.export_object_groups = RNA_boolean_get(op->ptr, "export_object_groups");
+  export_params.export_material_groups = RNA_boolean_get(op->ptr, "export_material_groups");
+  export_params.export_vertex_groups = RNA_boolean_get(op->ptr, "export_vertex_groups");
+  export_params.export_smooth_groups = RNA_boolean_get(op->ptr, "export_smooth_groups");
+  export_params.smooth_groups_bitflags = RNA_boolean_get(op->ptr, "smooth_group_bitflags");
+
+  OBJ_export(C, &export_params);
+
+  return OPERATOR_FINISHED;
+}
+
+static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
+{
+
+  const bool export_animation = RNA_boolean_get(imfptr, "export_animation");
+  const bool export_smooth_groups = RNA_boolean_get(imfptr, "export_smooth_groups");
+
+  uiLayoutSetPropSep(layout, true);
+  uiLayoutSetPropDecorate(layout, false);
+
+  /* Animation options. */
+  uiLayout *box = uiLayoutBox(layout);
+  uiItemL(box, IFACE_("Animation"), ICON_ANIM);
+  uiLayout *col = uiLayoutColumn(box, false);
+  uiLayout *sub = uiLayoutColumn(col, false);
+  uiItemR(sub, imfptr, "export_animation", 0, NULL, ICON_NONE);
+  sub = uiLayoutColumn(sub, true);
+  uiItemR(sub, imfptr, "start_frame", 0, IFACE_("Frame Start"), ICON_NONE);
+  uiItemR(sub, imfptr, "end_frame", 0, IFACE_("End"), ICON_NONE);
+  uiLayoutSetEnabled(sub, export_animation);
+
+  /* Object Transform options. */
+  box = uiLayoutBox(layout);
+  uiItemL(box, IFACE_("Object Properties"), ICON_OBJECT_DATA);
+  col = uiLayoutColumn(box, false);
+  sub = uiLayoutColumn(col, false);
+  uiItemR(sub, imfptr, "forward_axis", 0, IFACE_("Axis Forward"), ICON_NONE);
+  uiItemR(sub, imfptr, "up_axis", 0, IFACE_("Up"), ICON_NONE);
+  sub = uiLayoutColumn(col, false);
+  uiItemR(sub, imfptr, "scaling_factor", 0, NULL, ICON_NONE);
+  sub = uiLayoutColumnWithHeading(col, false, IFACE_("Objects"));
+  uiItemR(sub, imfptr, "export_selected_objects", 0, IFACE_("Selected Only"), ICON_NONE);
+  uiItemR(sub, imfptr, "export_eval_mode", 0, IFACE_("Properties"), ICON_NONE);
+
+  /* Options for what to write. */
+  box = uiLayoutBox(layout);
+  uiItemL(box, IFACE_("Geometry Export"), ICON_EXPORT);
+  col = uiLayoutColumn(box, false);
+  sub = uiLayoutColumnWithHeading(col, false, IFACE_("Export"));
+  uiItemR(sub, imfptr, "export_uv", 0, IFACE_("UV Coordin

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list