[Bf-blender-cvs] [448dc2da2bd] soc-2020-io-performance: Add exporter specific code.

Ankit Meel noreply at git.blender.org
Wed Sep 16 13:05:50 CEST 2020


Commit: 448dc2da2bdfa30057acc2f7582b1e1067d98e08
Author: Ankit Meel
Date:   Sun Aug 30 20:40:34 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB448dc2da2bdfa30057acc2f7582b1e1067d98e08

Add exporter specific code.

Files like `io_obj.c` which contain both importer and exporter code
are also here.

Differential Revision: https://developer.blender.org/D8754

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

M	release/scripts/startup/bl_ui/space_topbar.py
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.h
A	source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
A	source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh
A	source/blender/io/wavefront_obj/intern/obj_export_mesh.cc
A	source/blender/io/wavefront_obj/intern/obj_export_mesh.hh
A	source/blender/io/wavefront_obj/intern/obj_export_mtl.cc
A	source/blender/io/wavefront_obj/intern/obj_export_mtl.hh
A	source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
A	source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
A	source/blender/io/wavefront_obj/intern/obj_exporter.cc
A	source/blender/io/wavefront_obj/intern/obj_exporter.hh
A	source/blender/io/wavefront_obj/intern/wavefront_obj.cc
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 6fc29119cdc..40c6b024452 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -436,6 +436,7 @@ class TOPBAR_MT_file_import(Menu):
     bl_owner_use_filter = False
 
     def draw(self, _context):
+        self.layout.operator("wm.obj_import", text="Wavefront OBJ (.obj) - New")
         if bpy.app.build_options.collada:
             self.layout.operator("wm.collada_import",
                                  text="Collada (Default) (.dae)")
@@ -449,6 +450,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/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index e7effd05d34..31a77a0adf6 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
   ../../depsgraph
   ../../io/alembic
   ../../io/collada
+  ../../io/wavefront_obj
   ../../io/usd
   ../../makesdna
   ../../makesrna
@@ -39,12 +40,14 @@ set(SRC
   io_alembic.c
   io_cache.c
   io_collada.c
+  io_obj.c
   io_ops.c
   io_usd.c
 
   io_alembic.h
   io_cache.h
   io_collada.h
+  io_obj.h
   io_ops.h
   io_usd.h
 )
@@ -52,6 +55,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..e6f38dd4533
--- /dev/null
+++ b/source/blender/editors/io/io_obj.c
@@ -0,0 +1,480 @@
+/*
+ * 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 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 (Default)", "Negative Y-axis"},
+    {OBJ_AXIS_NEGATIVE_Z_FORWARD, "NEGATIVE_Z_FORWARD", 0, "-Z", "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", "Positive Y-axis"},
+    {OBJ_AXIS_Z_UP, "Z_UP", 0, "Z (Default)", "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 properties",
+     "Modifiers need to be applied for render properties to take effect"},
+    {DAG_EVAL_VIEWPORT,
+     "DAG_EVAL_VIEWPORT",
+     0,
+     "Viewport properties (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 *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;
+
+  UNUSED_VARS(event);
+}
+
+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.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)
+{
+  uiLayout *box;
+  uiLayout *row;
+  const bool export_animation = RNA_boolean_get(imfptr, "export_animation");
+  const bool export_smooth_groups = RNA_boolean_get(imfptr, "export_smooth_groups");
+
+  box = uiLayoutBox(layout);
+  row = uiLayoutRow(box, false);
+  /* Animation options. */
+  uiItemL(row, IFACE_("Animation"), ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_animation", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "start_frame", 0, NULL, ICON_NONE);
+  uiLayoutSetEnabled(row, export_animation);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "end_frame", 0, NULL, ICON_NONE);
+  uiLayoutSetEnabled(row, export_animation);
+
+  /* Geometry Transform options. */
+  box = uiLayoutBox(layout);
+  row = uiLayoutRow(box, false);
+  uiItemL(row, IFACE_("Geometry Transform"), ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "forward_axis", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, 1);
+  uiItemR(row, imfptr, "up_axis", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "scaling_factor", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_eval_mode", 0, NULL, ICON_NONE);
+
+  /* File write options. */
+  box = uiLayoutBox(layout);
+  row = uiLayoutRow(box, false);
+  uiItemL(row, IFACE_("File Write Options"), ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_selected_objects", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_uv", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_normals", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_materials", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_triangulated_mesh", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_curves_as_nurbs", 0, NULL, ICON_NONE);
+
+  box = uiLayoutBox(layout);
+  row = uiLayoutRow(box, false);
+  uiItemL(row, IFACE_("Grouping Options"), ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_object_groups", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_material_groups", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_vertex_groups", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_smooth_groups", 0, NULL, ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "smooth_group_bitflags", 0, NULL, ICON_NONE);
+  uiLayoutSetEnabled(row, export_smooth_groups);
+}
+
+static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op)
+{
+  PointerRNA ptr;
+  RNA_pointer_create(NULL, op->type->srn

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list