[Bf-blender-cvs] [27bef3ee02c] blender-v3.1-release: Fix T96303: C++ OBJ exporter needs presets and skip modifiers.

Aras Pranckevicius noreply at git.blender.org
Mon Mar 21 14:06:51 CET 2022


Commit: 27bef3ee02ce776d4e2d00dab349444c4d394841
Author: Aras Pranckevicius
Date:   Sun Mar 13 12:04:52 2022 -0400
Branches: blender-v3.1-release
https://developer.blender.org/rB27bef3ee02ce776d4e2d00dab349444c4d394841

Fix T96303: C++ OBJ exporter needs presets and skip modifiers.

This patch, D14303, from Aras Pranckevicius adds presets to the OBJ exporter,
and also adds a checkbox (default on) to apply modifiers before export.

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

M	source/blender/editors/io/io_obj.c
M	source/blender/io/wavefront_obj/IO_wavefront_obj.h
M	source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
M	source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh

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

diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index 2bc2a832d20..3262397bf63 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -110,6 +110,7 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
   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.apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers");
   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");
@@ -161,6 +162,7 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
   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, "apply_modifiers", 0, IFACE_("Apply Modifiers"), ICON_NONE);
   uiItemR(sub, imfptr, "export_eval_mode", 0, IFACE_("Properties"), ICON_NONE);
 
   /* Options for what to write. */
@@ -253,6 +255,8 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
   ot->ui = wm_obj_export_draw;
   ot->check = wm_obj_export_check;
 
+  ot->flag |= OPTYPE_PRESET;
+
   WM_operator_properties_filesel(ot,
                                  FILE_TYPE_FOLDER | FILE_TYPE_OBJECT_IO,
                                  FILE_BLENDER,
@@ -303,6 +307,11 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
                 0.01,
                 1000.0f);
   /* File Writer options. */
+  RNA_def_boolean(ot->srna,
+                  "apply_modifiers",
+                  true,
+                  "Apply Modifiers",
+                  "Apply modifiers to exported meshes");
   RNA_def_enum(ot->srna,
                "export_eval_mode",
                io_obj_export_evaluation_mode,
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
index 684eb3eda41..66953d63fac 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -69,6 +69,7 @@ struct OBJExportParams {
 
   /* File Write Options. */
   bool export_selected_objects;
+  bool apply_modifiers;
   eEvaluationMode export_eval_mode;
   bool export_uv;
   bool export_normals;
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
index 14e50d726c0..66f10009875 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
@@ -47,7 +47,9 @@ OBJMesh::OBJMesh(Depsgraph *depsgraph, const OBJExportParams &export_params, Obj
   /* We need to copy the object because it may be in temporary space. */
   Object *obj_eval = DEG_get_evaluated_object(depsgraph, mesh_object);
   export_object_eval_ = *obj_eval;
-  export_mesh_eval_ = BKE_object_get_evaluated_mesh(&export_object_eval_);
+  export_mesh_eval_ = export_params.apply_modifiers ?
+                          BKE_object_get_evaluated_mesh(&export_object_eval_) :
+                          BKE_object_get_pre_modified_mesh(&export_object_eval_);
   mesh_eval_needs_free_ = false;
 
   if (!export_mesh_eval_) {
diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
index c101081ca54..073e0daca0f 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
@@ -86,6 +86,7 @@ struct OBJExportParamsDefault {
     params.up_axis = OBJ_AXIS_Y_UP;
     params.scaling_factor = 1.f;
 
+    params.apply_modifiers = true;
     params.export_eval_mode = DAG_EVAL_VIEWPORT;
     params.export_selected_objects = false;
     params.export_uv = true;



More information about the Bf-blender-cvs mailing list