diff --git a/source/blender/editors/io/io_obj.cc b/source/blender/editors/io/io_obj.cc index 6e76e821b33..8af922eb174 100644 --- a/source/blender/editors/io/io_obj.cc +++ b/source/blender/editors/io/io_obj.cc @@ -82,8 +82,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 = eIOAxis(RNA_enum_get(op->ptr, "forward_axis")); - export_params.up_axis = eIOAxis(RNA_enum_get(op->ptr, "up_axis")); + export_params.forward_axis = blender::math::AxisSigned::from_int( + RNA_enum_get(op->ptr, "forward_axis")); + export_params.up_axis = blender::math::AxisSigned::from_int(RNA_enum_get(op->ptr, "up_axis")); export_params.global_scale = RNA_float_get(op->ptr, "global_scale"); export_params.apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers"); export_params.export_eval_mode = eEvaluationMode(RNA_enum_get(op->ptr, "export_eval_mode")); @@ -286,11 +287,7 @@ void WM_OT_obj_export(wmOperatorType *ot) INT_MIN, INT_MAX); /* Object transform options. */ - prop = RNA_def_enum( - ot->srna, "forward_axis", io_transform_axis, IO_AXIS_NEGATIVE_Z, "Forward Axis", ""); - RNA_def_property_update_runtime(prop, io_ui_forward_axis_update); - prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", ""); - RNA_def_property_update_runtime(prop, io_ui_up_axis_update); + io_ui_axes_register(*ot->srna); RNA_def_float( ot->srna, "global_scale", @@ -398,8 +395,9 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filepath", import_params.filepath); import_params.global_scale = RNA_float_get(op->ptr, "global_scale"); import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size"); - import_params.forward_axis = eIOAxis(RNA_enum_get(op->ptr, "forward_axis")); - import_params.up_axis = eIOAxis(RNA_enum_get(op->ptr, "up_axis")); + import_params.forward_axis = blender::math::AxisSigned::from_int( + RNA_enum_get(op->ptr, "forward_axis")); + import_params.up_axis = blender::math::AxisSigned::from_int(RNA_enum_get(op->ptr, "up_axis")); import_params.use_split_objects = RNA_boolean_get(op->ptr, "use_split_objects"); import_params.use_split_groups = RNA_boolean_get(op->ptr, "use_split_groups"); import_params.import_vertex_groups = RNA_boolean_get(op->ptr, "import_vertex_groups"); @@ -519,11 +517,7 @@ void WM_OT_obj_import(wmOperatorType *ot) "Resize the objects to keep bounding box under this value. Value 0 disables clamping", 0.0f, 1000.0f); - prop = RNA_def_enum( - ot->srna, "forward_axis", io_transform_axis, IO_AXIS_NEGATIVE_Z, "Forward Axis", ""); - RNA_def_property_update_runtime(prop, io_ui_forward_axis_update); - prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", ""); - RNA_def_property_update_runtime(prop, io_ui_up_axis_update); + io_ui_axes_register(*ot->srna); RNA_def_boolean(ot->srna, "use_split_objects", true, diff --git a/source/blender/editors/io/io_ply_ops.cc b/source/blender/editors/io/io_ply_ops.cc index 34a023a69e2..4a4506816aa 100644 --- a/source/blender/editors/io/io_ply_ops.cc +++ b/source/blender/editors/io/io_ply_ops.cc @@ -71,8 +71,9 @@ static int wm_ply_export_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filepath", export_params.filepath); export_params.blen_filepath = CTX_data_main(C)->filepath; - export_params.forward_axis = eIOAxis(RNA_enum_get(op->ptr, "forward_axis")); - export_params.up_axis = eIOAxis(RNA_enum_get(op->ptr, "up_axis")); + export_params.forward_axis = blender::math::AxisSigned::from_int( + RNA_enum_get(op->ptr, "forward_axis")); + export_params.up_axis = blender::math::AxisSigned::from_int(RNA_enum_get(op->ptr, "up_axis")); export_params.global_scale = RNA_float_get(op->ptr, "global_scale"); export_params.apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers"); @@ -177,10 +178,7 @@ void WM_OT_ply_export(wmOperatorType *ot) FILE_SORT_DEFAULT); /* Object transform options. */ - prop = RNA_def_enum(ot->srna, "forward_axis", io_transform_axis, IO_AXIS_Y, "Forward Axis", ""); - RNA_def_property_update_runtime(prop, io_ui_forward_axis_update); - prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Z, "Up Axis", ""); - RNA_def_property_update_runtime(prop, io_ui_up_axis_update); + io_ui_axes_register(*ot->srna); RNA_def_float( ot->srna, "global_scale", @@ -239,8 +237,8 @@ static int wm_ply_import_invoke(bContext *C, wmOperator *op, const wmEvent *even static int wm_ply_import_exec(bContext *C, wmOperator *op) { PLYImportParams params{}; - params.forward_axis = eIOAxis(RNA_enum_get(op->ptr, "forward_axis")); - params.up_axis = eIOAxis(RNA_enum_get(op->ptr, "up_axis")); + params.forward_axis = blender::math::AxisSigned::from_int(RNA_enum_get(op->ptr, "forward_axis")); + params.up_axis = blender::math::AxisSigned::from_int(RNA_enum_get(op->ptr, "up_axis")); params.use_scene_unit = RNA_boolean_get(op->ptr, "use_scene_unit"); params.global_scale = RNA_float_get(op->ptr, "global_scale"); params.merge_verts = RNA_boolean_get(op->ptr, "merge_verts"); @@ -308,10 +306,7 @@ void WM_OT_ply_import(wmOperatorType *ot) false, "Scene Unit", "Apply current scene's unit (as defined by unit scale) to imported data"); - prop = RNA_def_enum(ot->srna, "forward_axis", io_transform_axis, IO_AXIS_Y, "Forward Axis", ""); - RNA_def_property_update_runtime(prop, io_ui_forward_axis_update); - prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Z, "Up Axis", ""); - RNA_def_property_update_runtime(prop, io_ui_up_axis_update); + io_ui_axes_register(*ot->srna); RNA_def_boolean(ot->srna, "merge_verts", false, "Merge Vertices", "Merges vertices by distance"); RNA_def_enum(ot->srna, "import_colors", diff --git a/source/blender/editors/io/io_stl_ops.cc b/source/blender/editors/io/io_stl_ops.cc index 777dfc2631a..083305e14d9 100644 --- a/source/blender/editors/io/io_stl_ops.cc +++ b/source/blender/editors/io/io_stl_ops.cc @@ -21,6 +21,7 @@ # include "RNA_access.hh" # include "RNA_define.hh" +# include "IO_orientation.hh" # include "IO_stl.hh" # include "io_stl_ops.hh" @@ -32,8 +33,8 @@ static int wm_stl_import_invoke(bContext *C, wmOperator *op, const wmEvent *even static int wm_stl_import_exec(bContext *C, wmOperator *op) { STLImportParams params{}; - params.forward_axis = eIOAxis(RNA_enum_get(op->ptr, "forward_axis")); - params.up_axis = eIOAxis(RNA_enum_get(op->ptr, "up_axis")); + params.forward_axis = blender::math::AxisSigned::from_int(RNA_enum_get(op->ptr, "forward_axis")); + params.up_axis = blender::math::AxisSigned::from_int(RNA_enum_get(op->ptr, "up_axis")); params.use_facet_normal = RNA_boolean_get(op->ptr, "use_facet_normal"); params.use_scene_unit = RNA_boolean_get(op->ptr, "use_scene_unit"); params.global_scale = RNA_float_get(op->ptr, "global_scale"); @@ -120,8 +121,7 @@ void WM_OT_stl_import(wmOperatorType *ot) false, "Facet Normals", "Use (import) facet normals (note that this will still give flat shading)"); - RNA_def_enum(ot->srna, "forward_axis", io_transform_axis, IO_AXIS_Y, "Forward Axis", ""); - RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Z, "Up Axis", ""); + io_ui_axes_register(*ot->srna); RNA_def_boolean(ot->srna, "use_mesh_validate", false, diff --git a/source/blender/io/common/IO_orientation.hh b/source/blender/io/common/IO_orientation.hh index 4da659eaea1..ee52f091dac 100644 --- a/source/blender/io/common/IO_orientation.hh +++ b/source/blender/io/common/IO_orientation.hh @@ -4,21 +4,6 @@ #pragma once -struct EnumPropertyItem; -struct Main; -struct PointerRNA; -struct Scene; +struct StructRNA; -enum eIOAxis { - IO_AXIS_X = 0, - IO_AXIS_Y = 1, - IO_AXIS_Z = 2, - IO_AXIS_NEGATIVE_X = 3, - IO_AXIS_NEGATIVE_Y = 4, - IO_AXIS_NEGATIVE_Z = 5, -}; - -extern const EnumPropertyItem io_transform_axis[]; - -void io_ui_forward_axis_update(Main *main, Scene *scene, PointerRNA *ptr); -void io_ui_up_axis_update(Main *main, Scene *scene, PointerRNA *ptr); +void io_ui_axes_register(StructRNA &srna); diff --git a/source/blender/io/common/intern/orientation.cc b/source/blender/io/common/intern/orientation.cc index 629b3789dea..b044c3fa2b8 100644 --- a/source/blender/io/common/intern/orientation.cc +++ b/source/blender/io/common/intern/orientation.cc @@ -5,20 +5,23 @@ #include "BKE_main.h" #include "DNA_scene_types.h" #include "RNA_access.hh" +#include "RNA_define.hh" #include "RNA_types.hh" +#include "BLI_math_basis_types.hh" + #include "IO_orientation.hh" -const EnumPropertyItem io_transform_axis[] = { - {IO_AXIS_X, "X", 0, "X", "Positive X axis"}, - {IO_AXIS_Y, "Y", 0, "Y", "Positive Y axis"}, - {IO_AXIS_Z, "Z", 0, "Z", "Positive Z axis"}, - {IO_AXIS_NEGATIVE_X, "NEGATIVE_X", 0, "-X", "Negative X axis"}, - {IO_AXIS_NEGATIVE_Y, "NEGATIVE_Y", 0, "-Y", "Negative Y axis"}, - {IO_AXIS_NEGATIVE_Z, "NEGATIVE_Z", 0, "-Z", "Negative Z axis"}, +static const EnumPropertyItem io_transform_axis[] = { + {int(blender::math::AxisSigned::X_POS), "X", 0, "X", "Positive X axis"}, + {int(blender::math::AxisSigned::Y_POS), "Y", 0, "Y", "Positive Y axis"}, + {int(blender::math::AxisSigned::Z_POS), "Z", 0, "Z", "Positive Z axis"}, + {int(blender::math::AxisSigned::X_NEG), "NEGATIVE_X", 0, "-X", "Negative X axis"}, + {int(blender::math::AxisSigned::Y_NEG), "NEGATIVE_Y", 0, "-Y", "Negative Y axis"}, + {int(blender::math::AxisSigned::Z_NEG), "NEGATIVE_Z", 0, "-Z", "Negative Z axis"}, {0, nullptr, 0, nullptr, nullptr}}; -void io_ui_forward_axis_update(Main * /*main*/, Scene * /*scene*/, PointerRNA *ptr) +static void io_ui_forward_axis_update(Main * /*main*/, Scene * /*scene*/, PointerRNA *ptr) { /* Both forward and up axes cannot be along the same direction. */ @@ -29,7 +32,7 @@ void io_ui_forward_axis_update(Main * /*main*/, Scene * /*scene*/, PointerRNA *p } } -void io_ui_up_axis_update(Main * /*main*/, Scene * /*scene*/, PointerRNA *ptr) +static void io_ui_up_axis_update(Main * /*main*/, Scene * /*scene*/, PointerRNA *ptr) { int forward = RNA_enum_get(ptr, "forward_axis"); int up = RNA_enum_get(ptr, "up_axis"); @@ -37,3 +40,17 @@ void io_ui_up_axis_update(Main * /*main*/, Scene * /*scene*/, PointerRNA *ptr) RNA_enum_set(ptr, "forward_axis", (forward + 1) % 6); } } + +void io_ui_axes_register(StructRNA &srna) +{ + PropertyRNA *forward = RNA_def_enum(&srna, + "forward_axis", + io_transform_axis, + int(blender::math::AxisSigned::Y_POS), + "Forward Axis", + ""); + RNA_def_property_update_runtime(forward, io_ui_forward_axis_update); + PropertyRNA *up = RNA_def_enum( + &srna, "up_axis", io_transform_axis, int(blender::math::AxisSigned::Z_POS), "Up Axis", ""); + RNA_def_property_update_runtime(up, io_ui_up_axis_update); +} diff --git a/source/blender/io/ply/IO_ply.hh b/source/blender/io/ply/IO_ply.hh index 248e7bf75ec..b08bf58233c 100644 --- a/source/blender/io/ply/IO_ply.hh +++ b/source/blender/io/ply/IO_ply.hh @@ -10,9 +10,10 @@ #include "BKE_context.h" +#include "BLI_math_basis_types.hh" #include "BLI_path_util.h" + #include "DNA_windowmanager_types.h" -#include "IO_orientation.hh" enum ePLYVertexColorMode { PLY_VERTEX_COLOR_NONE = 0, @@ -33,8 +34,8 @@ struct PLYExportParams { bool ascii_format; /* Geometry Transform options. */ - eIOAxis forward_axis; - eIOAxis up_axis; + blender::math::AxisSigned forward_axis; + blender::math::AxisSigned up_axis; float global_scale; /* File Write Options. */ @@ -49,8 +50,8 @@ struct PLYExportParams { struct PLYImportParams { /** Full path to the source PLY file to import. */ char filepath[FILE_MAX]; - eIOAxis forward_axis; - eIOAxis up_axis; + blender::math::AxisSigned forward_axis; + blender::math::AxisSigned up_axis; bool use_scene_unit; float global_scale; ePLYVertexColorMode vertex_colors; diff --git a/source/blender/io/ply/exporter/ply_export_load_plydata.cc b/source/blender/io/ply/exporter/ply_export_load_plydata.cc index 88bd818d32c..826a16b28f7 100644 --- a/source/blender/io/ply/exporter/ply_export_load_plydata.cc +++ b/source/blender/io/ply/exporter/ply_export_load_plydata.cc @@ -17,6 +17,7 @@ #include "BLI_hash.hh" #include "BLI_math_color.hh" #include "BLI_math_matrix.h" +#include "BLI_math_matrix.hh" #include "BLI_math_rotation.h" #include "BLI_math_vector.h" #include "BLI_vector.hh" @@ -45,18 +46,16 @@ static Mesh *do_triangulation(const Mesh *mesh, bool force_triangulation) } static void set_world_axes_transform(Object *object, - const eIOAxis forward, - const eIOAxis up, + const math::AxisSigned forward, + const math::AxisSigned up, float r_world_and_axes_transform[4][4], float r_world_and_axes_normal_transform[3][3]) { - float axes_transform[3][3]; - unit_m3(axes_transform); - /* +Y-forward and +Z-up are the default Blender axis settings. */ - mat3_from_axis_conversion(forward, up, IO_AXIS_Y, IO_AXIS_Z, axes_transform); - mul_m4_m3m4(r_world_and_axes_transform, axes_transform, object->object_to_world); + const math::CartesianBasis basis = math::from_orthonormal_axes(forward, up); + const float3x3 axes_transform = math::from_rotation(basis); + mul_m4_m3m4(r_world_and_axes_transform, axes_transform.ptr(), object->object_to_world); /* mul_m4_m3m4 does not transform last row of obmat, i.e. location data. */ - mul_v3_m3v3(r_world_and_axes_transform[3], axes_transform, object->object_to_world[3]); + mul_v3_m3v3(r_world_and_axes_transform[3], axes_transform.ptr(), object->object_to_world[3]); r_world_and_axes_transform[3][3] = object->object_to_world[3][3]; /* Normals need inverse transpose of the regular matrix to handle non-uniform scale. */ diff --git a/source/blender/io/ply/importer/ply_import.cc b/source/blender/io/ply/importer/ply_import.cc index d0534bba05b..a99231ecbe6 100644 --- a/source/blender/io/ply/importer/ply_import.cc +++ b/source/blender/io/ply/importer/ply_import.cc @@ -17,6 +17,7 @@ #include "DNA_scene_types.h" #include "BLI_math_matrix.h" +#include "BLI_math_matrix.hh" #include "BLI_math_rotation.h" #include "BLI_math_vector.h" #include "BLI_memory_utils.hh" @@ -227,14 +228,14 @@ void importer_main(Main *bmain, global_scale *= scene->unit.scale_length; } float scale_vec[3] = {global_scale, global_scale, global_scale}; - float obmat3x3[3][3]; - unit_m3(obmat3x3); + + const math::CartesianBasis basis = math::from_orthonormal_axes(import_params.forward_axis, + import_params.up_axis); + const float3x3 axes_transform = math::from_rotation(basis); + float obmat4x4[4][4]; unit_m4(obmat4x4); - /* +Y-forward and +Z-up are the Blender's default axis settings. */ - mat3_from_axis_conversion( - IO_AXIS_Y, IO_AXIS_Z, import_params.forward_axis, import_params.up_axis, obmat3x3); - copy_m4_m3(obmat4x4, obmat3x3); + copy_m4_m3(obmat4x4, axes_transform.ptr()); rescale_m4(obmat4x4, scale_vec); BKE_object_apply_mat4(obj, obmat4x4, true, false); diff --git a/source/blender/io/stl/IO_stl.hh b/source/blender/io/stl/IO_stl.hh index ab8d62bd96b..4d2c8edcd29 100644 --- a/source/blender/io/stl/IO_stl.hh +++ b/source/blender/io/stl/IO_stl.hh @@ -9,14 +9,15 @@ #pragma once #include "BKE_context.h" + +#include "BLI_math_basis_types.hh" #include "BLI_path_util.h" -#include "IO_orientation.hh" struct STLImportParams { /** Full path to the source STL file to import. */ char filepath[FILE_MAX]; - eIOAxis forward_axis; - eIOAxis up_axis; + blender::math::AxisSigned forward_axis; + blender::math::AxisSigned up_axis; bool use_facet_normal; bool use_scene_unit; float global_scale; diff --git a/source/blender/io/stl/importer/stl_import.cc b/source/blender/io/stl/importer/stl_import.cc index 16515b756e1..7df2aca0af3 100644 --- a/source/blender/io/stl/importer/stl_import.cc +++ b/source/blender/io/stl/importer/stl_import.cc @@ -18,6 +18,7 @@ #include "BLI_fileops.hh" #include "BLI_math_matrix.h" +#include "BLI_math_matrix.hh" #include "BLI_math_rotation.h" #include "BLI_math_vector.h" #include "BLI_memory_utils.hh" @@ -115,14 +116,14 @@ void importer_main(Main *bmain, global_scale *= scene->unit.scale_length; } float scale_vec[3] = {global_scale, global_scale, global_scale}; - float obmat3x3[3][3]; - unit_m3(obmat3x3); + + const math::CartesianBasis basis = math::from_orthonormal_axes(import_params.forward_axis, + import_params.up_axis); + const float3x3 axes_transform = math::from_rotation(basis); + float obmat4x4[4][4]; unit_m4(obmat4x4); - /* +Y-forward and +Z-up are the Blender's default axis settings. */ - mat3_from_axis_conversion( - IO_AXIS_Y, IO_AXIS_Z, import_params.forward_axis, import_params.up_axis, obmat3x3); - copy_m4_m3(obmat4x4, obmat3x3); + copy_m4_m3(obmat4x4, axes_transform.ptr()); rescale_m4(obmat4x4, scale_vec); BKE_object_apply_mat4(obj, obmat4x4, true, false); diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.hh b/source/blender/io/wavefront_obj/IO_wavefront_obj.hh index 0d28bcd95dc..6ccf1fa3a5e 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.hh +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.hh @@ -8,13 +8,13 @@ #pragma once +#include "BLI_math_basis_types.hh" #include "BLI_path_util.h" #include "BKE_context.h" #include "DEG_depsgraph.h" -#include "IO_orientation.hh" #include "IO_path_util_types.hh" struct OBJExportParams { @@ -34,8 +34,8 @@ struct OBJExportParams { int end_frame; /* Geometry Transform options. */ - eIOAxis forward_axis; - eIOAxis up_axis; + blender::math::AxisSigned forward_axis; + blender::math::AxisSigned up_axis; float global_scale; /* File Write Options. */ @@ -67,8 +67,8 @@ struct OBJImportParams { /** Value 0 disables clamping. */ float clamp_size; float global_scale; - eIOAxis forward_axis; - eIOAxis up_axis; + blender::math::AxisSigned forward_axis; + blender::math::AxisSigned up_axis; bool use_split_objects; bool use_split_groups; bool import_vertex_groups; 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 9ceae9d6bb2..18164679a1b 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc @@ -15,6 +15,7 @@ #include "BKE_mesh_mapping.hh" #include "BKE_object.h" #include "BLI_math_matrix.h" +#include "BLI_math_matrix.hh" #include "BLI_math_rotation.h" #include "BLI_math_vector.h" @@ -134,16 +135,15 @@ void OBJMesh::triangulate_mesh_eval() this->set_mesh(triangulated); } -void OBJMesh::set_world_axes_transform(const eIOAxis forward, const eIOAxis up) +void OBJMesh::set_world_axes_transform(const math::AxisSigned forward, const math::AxisSigned up) { - float axes_transform[3][3]; - unit_m3(axes_transform); - /* +Y-forward and +Z-up are the default Blender axis settings. */ - mat3_from_axis_conversion(forward, up, IO_AXIS_Y, IO_AXIS_Z, axes_transform); - mul_m4_m3m4(world_and_axes_transform_, axes_transform, export_object_eval_.object_to_world); + const math::CartesianBasis basis = math::from_orthonormal_axes(forward, up); + const float3x3 axes_transform = math::from_rotation(basis); + mul_m4_m3m4( + world_and_axes_transform_, axes_transform.ptr(), export_object_eval_.object_to_world); /* mul_m4_m3m4 does not transform last row of obmat, i.e. location data. */ mul_v3_m3v3( - world_and_axes_transform_[3], axes_transform, export_object_eval_.object_to_world[3]); + world_and_axes_transform_[3], axes_transform.ptr(), export_object_eval_.object_to_world[3]); world_and_axes_transform_[3][3] = export_object_eval_.object_to_world[3][3]; /* Normals need inverse transpose of the regular matrix to handle non-uniform scale. */ diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh index a47b2679956..7f772fbb95f 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh @@ -234,6 +234,6 @@ class OBJMesh : NonCopyable { /** * Set the final transform after applying axes settings and an Object's world transform. */ - void set_world_axes_transform(eIOAxis forward, eIOAxis up); + void set_world_axes_transform(math::AxisSigned forward, math::AxisSigned up); }; } // namespace blender::io::obj diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc index c2c908000f1..0de9a6a0f9b 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc @@ -8,6 +8,7 @@ #include "BLI_listbase.h" #include "BLI_math_matrix.h" +#include "BLI_math_matrix.hh" #include "BLI_math_rotation.h" #include "BLI_math_vector.h" #include "BLI_math_vector_types.hh" @@ -29,15 +30,14 @@ OBJCurve::OBJCurve(const Depsgraph *depsgraph, set_world_axes_transform(export_params.forward_axis, export_params.up_axis); } -void OBJCurve::set_world_axes_transform(const eIOAxis forward, const eIOAxis up) +void OBJCurve::set_world_axes_transform(const math::AxisSigned forward, const math::AxisSigned up) { - float axes_transform[3][3]; - unit_m3(axes_transform); - /* +Y-forward and +Z-up are the Blender's default axis settings. */ - mat3_from_axis_conversion(forward, up, IO_AXIS_Y, IO_AXIS_Z, axes_transform); - mul_m4_m3m4(world_axes_transform_, axes_transform, export_object_eval_->object_to_world); + const math::CartesianBasis basis = math::from_orthonormal_axes(forward, up); + const float3x3 axes_transform = math::from_rotation(basis); + mul_m4_m3m4(world_axes_transform_, axes_transform.ptr(), export_object_eval_->object_to_world); /* #mul_m4_m3m4 does not transform last row of #Object.object_to_world, i.e. location data. */ - mul_v3_m3v3(world_axes_transform_[3], axes_transform, export_object_eval_->object_to_world[3]); + mul_v3_m3v3( + world_axes_transform_[3], axes_transform.ptr(), export_object_eval_->object_to_world[3]); world_axes_transform_[3][3] = export_object_eval_->object_to_world[3][3]; } diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh index 7642bd12d34..8c30deda33e 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh @@ -58,7 +58,7 @@ class OBJCurve : NonCopyable { /** * Set the final transform after applying axes settings and an Object's world transform. */ - void set_world_axes_transform(eIOAxis forward, eIOAxis up); + void set_world_axes_transform(math::AxisSigned forward, math::AxisSigned up); }; } // namespace blender::io::obj diff --git a/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc b/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc index 3963dfad3bf..8cd9fc5a9d9 100644 --- a/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc +++ b/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc @@ -12,6 +12,7 @@ #include "BLI_delaunay_2d.h" #include "BLI_math_geom.h" #include "BLI_math_matrix.h" +#include "BLI_math_matrix.hh" #include "BLI_math_rotation.h" #include "BLI_math_vector.h" #include "BLI_set.hh" @@ -99,14 +100,12 @@ Vector> fixup_invalid_polygon(Span vertex_coords, void transform_object(Object *object, const OBJImportParams &import_params) { - float axes_transform[3][3]; - unit_m3(axes_transform); + const math::CartesianBasis basis = math::from_orthonormal_axes(import_params.forward_axis, + import_params.up_axis); + const float3x3 axes_transform = math::from_rotation(basis); float obmat[4][4]; unit_m4(obmat); - /* +Y-forward and +Z-up are the default Blender axis settings. */ - mat3_from_axis_conversion( - IO_AXIS_Y, IO_AXIS_Z, import_params.forward_axis, import_params.up_axis, axes_transform); - copy_m4_m3(obmat, axes_transform); + copy_m4_m3(obmat, axes_transform.ptr()); float scale_vec[3] = { import_params.global_scale, import_params.global_scale, import_params.global_scale};