[Bf-blender-cvs] [1d75ece6add] soc-2020-io-performance: Add forward and up axes transform in preferences.
Ankit Meel
noreply at git.blender.org
Wed Jun 17 11:32:30 CEST 2020
Commit: 1d75ece6add7ad7f2661396ae36d62d36eabe710
Author: Ankit Meel
Date: Wed Jun 17 14:58:21 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB1d75ece6add7ad7f2661396ae36d62d36eabe710
Add forward and up axes transform in preferences.
===================================================================
M source/blender/editors/io/io_obj.c
M source/blender/io/wavefront_obj/IO_wavefront_obj.h
M source/blender/io/wavefront_obj/intern/wavefront_obj.hh
M source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
===================================================================
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index 1056858b876..74ef10405c7 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -49,6 +49,24 @@
#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}};
+
static int wm_obj_export_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
@@ -85,6 +103,9 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
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");
+
OBJ_export(C, &export_params);
return OPERATOR_FINISHED;
@@ -98,6 +119,7 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
box = uiLayoutBox(layout);
row = uiLayoutRow(box, false);
+ /* Animation options. */
uiItemL(row, IFACE_("Animation"), ICON_NONE);
row = uiLayoutRow(box, false);
@@ -110,6 +132,16 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "end_frame", 0, NULL, ICON_NONE);
uiLayoutSetEnabled(row, export_animation);
+
+ /* Transform options. */
+ box = uiLayoutBox(layout);
+ row = uiLayoutRow(box, false);
+ uiItemL(row, IFACE_("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);
}
static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op)
@@ -144,6 +176,12 @@ static bool wm_obj_export_check(bContext *C, wmOperator *op)
RNA_int_set(op->ptr, "end_frame", RNA_int_get(op->ptr, "start_frame"));
ret = true;
}
+
+ /* Both forward and up axes cannot be the same (or same except opposite sign). */
+ if ((RNA_enum_get(op->ptr, "forward_axis")) % 3 == (RNA_enum_get(op->ptr, "up_axis")) % 3) {
+ /* TODO (ankitm) Show a warning here. */
+ RNA_enum_set(op->ptr, "up_axis", RNA_enum_get(op->ptr, "up_axis") % 3 + 1);
+ }
return ret;
}
@@ -172,7 +210,7 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
false,
"Export Animation",
"Write selected range of frames to individual files. If unchecked, exports the "
- "current viewport frame ");
+ "current viewport frame");
RNA_def_int(ot->srna,
"start_frame",
INT_MAX,
@@ -191,6 +229,13 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
"The last frame to be exported",
0,
250);
+ RNA_def_enum(ot->srna,
+ "forward_axis",
+ io_obj_transform_axis_forward,
+ OBJ_AXIS_NEGATIVE_Y_FORWARD,
+ "Forward",
+ "");
+ RNA_def_enum(ot->srna, "up_axis", io_obj_transform_axis_up, OBJ_AXIS_Z_UP, "Up", "");
}
static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
index ca6bbcff2b9..4b8fa72b5bf 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -28,15 +28,38 @@
extern "C" {
#endif
+typedef enum {
+ OBJ_AXIS_X_UP = 0,
+ OBJ_AXIS_Y_UP = 1,
+ OBJ_AXIS_Z_UP = 2,
+ OBJ_AXIS_NEGATIVE_X_UP = 3,
+ OBJ_AXIS_NEGATIVE_Y_UP = 4,
+ OBJ_AXIS_NEGATIVE_Z_UP = 5,
+} eTransformAxisUp;
+
+typedef enum {
+ OBJ_AXIS_X_FORWARD = 0,
+ OBJ_AXIS_Y_FORWARD = 1,
+ OBJ_AXIS_Z_FORWARD = 2,
+ OBJ_AXIS_NEGATIVE_X_FORWARD = 3,
+ OBJ_AXIS_NEGATIVE_Y_FORWARD = 4,
+ OBJ_AXIS_NEGATIVE_Z_FORWARD = 5,
+} eTransformAxisForward;
+
struct OBJExportParams {
/** Full path to the destination OBJ file to export. */
char filepath[FILENAME_MAX];
+
/** Whether mutiple frames are to be exported or not. */
bool export_animation;
/** The first frame to be exported. */
int start_frame;
/** The last frame to be exported. */
int end_frame;
+
+ /** Geometry Transform options */
+ int forward_axis;
+ int up_axis;
};
struct OBJImportParams {
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj.hh
index 0d98c1e741a..6e6811b5959 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj.hh
@@ -36,6 +36,11 @@
namespace io {
namespace obj {
+/* -Y */
+#define DEFAULT_AXIS_FORWARD 4
+/* Z */
+#define DEFAULT_AXIS_UP 2
+
/**
* Polygon stores the data of one face of the mesh.
* f v1/vt1/vn1 v2/vt2/vn2 .. (n)
@@ -77,6 +82,9 @@ typedef struct OBJ_object_to_export {
std::vector<std::array<float, 2>> uv_coords;
/** Number of UV vertices of a mesh in texture map. */
uint tot_uv_vertices;
+
+ int forward_axis;
+ int up_axis;
} OBJ_object_to_export;
} // namespace obj
} // namespace io
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
index b76f40f3cbf..01d5ba754f8 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
@@ -59,14 +59,22 @@ static void get_transformed_mesh_vertices(Mesh *me_eval,
OBJ_object_to_export &object_to_export)
{
uint num_verts = object_to_export.tot_vertices = me_eval->totvert;
- float transformed_co[3];
object_to_export.mvert = (MVert *)MEM_callocN(num_verts * sizeof(MVert),
"OBJ object vertex coordinates & normals");
-
+ float axes_transform[3][3];
+ unit_m3(axes_transform);
+ mat3_from_axis_conversion(DEFAULT_AXIS_FORWARD,
+ DEFAULT_AXIS_UP,
+ object_to_export.forward_axis,
+ object_to_export.up_axis,
+ axes_transform);
+
+ float world_transform[4][4];
+ copy_m4_m4(world_transform, ob_eval->obmat);
+ mul_m4_m3m4(world_transform, axes_transform, world_transform);
for (uint i = 0; i < num_verts; i++) {
- copy_v3_v3(transformed_co, me_eval->mvert[i].co);
- mul_m4_v3(ob_eval->obmat, transformed_co);
- copy_v3_v3(object_to_export.mvert[i].co, transformed_co);
+ copy_v3_v3(object_to_export.mvert[i].co, me_eval->mvert[i].co);
+ mul_m4_v3(world_transform, object_to_export.mvert[i].co);
}
}
@@ -219,6 +227,9 @@ static void export_frame(bContext *C, const OBJExportParams *export_params, cons
object_to_export.C = C;
object_to_export.depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ object_to_export.forward_axis = export_params->forward_axis;
+ object_to_export.up_axis = export_params->up_axis;
+
get_geometry_per_object(export_params, object_to_export);
}
More information about the Bf-blender-cvs
mailing list