diff options
author | Iyad Ahmed <iyadahmed430@gmail.com> | 2022-06-06 20:57:38 +0300 |
---|---|---|
committer | Aras Pranckevicius <aras@nesnausk.org> | 2022-06-06 20:57:38 +0300 |
commit | 7c511f1b47d857f37aa36ee6ed8107cb88eb5c39 (patch) | |
tree | d376a5e21bc21f40e0b062f9623887f4018ed61a /source/blender/io/wavefront_obj | |
parent | 14fc89f38f0e3ce00e4fd6fffd72eea5d998af5a (diff) |
STL: Add new C++ based STL importer
A new experimentatl STL importer, written in C++. Roughly 7-9x faster than the
Python based one.
Reviewed By: Aras Pranckevicius, Hans Goudey.
Differential Revision: https://developer.blender.org/D14941
Diffstat (limited to 'source/blender/io/wavefront_obj')
9 files changed, 39 insertions, 61 deletions
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h index bebad06d37f..0a78cdc714d 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h @@ -9,30 +9,13 @@ #include "BKE_context.h" #include "BLI_path_util.h" #include "DEG_depsgraph.h" +#include "IO_orientation.h" #include "IO_path_util_types.h" #ifdef __cplusplus 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; - static const int TOTAL_AXES = 3; struct OBJExportParams { @@ -52,8 +35,8 @@ struct OBJExportParams { int end_frame; /* Geometry Transform options. */ - eTransformAxisForward forward_axis; - eTransformAxisUp up_axis; + eIOAxis forward_axis; + eIOAxis up_axis; float scaling_factor; /* File Write Options. */ @@ -86,8 +69,8 @@ struct OBJImportParams { char filepath[FILE_MAX]; /** Value 0 disables clamping. */ float clamp_size; - eTransformAxisForward forward_axis; - eTransformAxisUp up_axis; + eIOAxis forward_axis; + eIOAxis up_axis; bool validate_meshes; }; 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 092ba24db64..8556d7c275c 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc @@ -117,13 +117,12 @@ std::pair<Mesh *, bool> OBJMesh::triangulate_mesh_eval() return {triangulated, true}; } -void OBJMesh::set_world_axes_transform(const eTransformAxisForward forward, - const eTransformAxisUp up) +void OBJMesh::set_world_axes_transform(const eIOAxis forward, const eIOAxis 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(OBJ_AXIS_Y_FORWARD, OBJ_AXIS_Z_UP, forward, up, axes_transform); + mat3_from_axis_conversion(IO_AXIS_Y, IO_AXIS_Z, forward, up, axes_transform); /* mat3_from_axis_conversion returns a transposed matrix! */ transpose_m3(axes_transform); mul_m4_m3m4(world_and_axes_transform_, axes_transform, export_object_eval_.obmat); 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 f47ca423dbc..91213ec8152 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh @@ -256,6 +256,6 @@ class OBJMesh : NonCopyable { /** * Set the final transform after applying axes settings and an Object's world transform. */ - void set_world_axes_transform(eTransformAxisForward forward, eTransformAxisUp up); + void set_world_axes_transform(eIOAxis forward, eIOAxis 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 c247048ce13..c0c29fcfdf8 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc @@ -25,13 +25,12 @@ OBJCurve::OBJCurve(const Depsgraph *depsgraph, set_world_axes_transform(export_params.forward_axis, export_params.up_axis); } -void OBJCurve::set_world_axes_transform(const eTransformAxisForward forward, - const eTransformAxisUp up) +void OBJCurve::set_world_axes_transform(const eIOAxis forward, const eIOAxis 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(OBJ_AXIS_Y_FORWARD, OBJ_AXIS_Z_UP, forward, up, axes_transform); + mat3_from_axis_conversion(IO_AXIS_Y, IO_AXIS_Z, forward, up, axes_transform); /* mat3_from_axis_conversion returns a transposed matrix! */ transpose_m3(axes_transform); mul_m4_m3m4(world_axes_transform_, axes_transform, export_object_eval_->obmat); 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 fe826725daf..65389d44f59 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh @@ -56,7 +56,7 @@ class OBJCurve : NonCopyable { /** * Set the final transform after applying axes settings and an Object's world transform. */ - void set_world_axes_transform(eTransformAxisForward forward, eTransformAxisUp up); + void set_world_axes_transform(eIOAxis forward, eIOAxis 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 7019e67419e..3c0ef646e13 100644 --- a/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc +++ b/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc @@ -99,11 +99,8 @@ void transform_object(Object *object, const OBJImportParams &import_params) float obmat[4][4]; unit_m4(obmat); /* +Y-forward and +Z-up are the default Blender axis settings. */ - mat3_from_axis_conversion(import_params.forward_axis, - import_params.up_axis, - OBJ_AXIS_Y_FORWARD, - OBJ_AXIS_Z_UP, - axes_transform); + mat3_from_axis_conversion( + import_params.forward_axis, import_params.up_axis, IO_AXIS_Y, IO_AXIS_Z, axes_transform); /* mat3_from_axis_conversion returns a transposed matrix! */ transpose_m3(axes_transform); copy_m4_m3(obmat, axes_transform); diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index 8c49af90a82..b384d934c82 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -315,8 +315,8 @@ TEST_F(obj_exporter_regression_test, all_quads) TEST_F(obj_exporter_regression_test, fgons) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_materials = false; compare_obj_export_to_golden( "io_tests/blend_geometry/fgons.blend", "io_tests/obj/fgons.obj", "", _export.params); @@ -325,8 +325,8 @@ TEST_F(obj_exporter_regression_test, fgons) TEST_F(obj_exporter_regression_test, edges) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_materials = false; compare_obj_export_to_golden( "io_tests/blend_geometry/edges.blend", "io_tests/obj/edges.obj", "", _export.params); @@ -335,8 +335,8 @@ TEST_F(obj_exporter_regression_test, edges) TEST_F(obj_exporter_regression_test, vertices) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_materials = false; compare_obj_export_to_golden( "io_tests/blend_geometry/vertices.blend", "io_tests/obj/vertices.obj", "", _export.params); @@ -355,8 +355,8 @@ TEST_F(obj_exporter_regression_test, non_uniform_scale) TEST_F(obj_exporter_regression_test, nurbs_as_nurbs) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_materials = false; _export.params.export_curves_as_nurbs = true; compare_obj_export_to_golden( @@ -366,8 +366,8 @@ TEST_F(obj_exporter_regression_test, nurbs_as_nurbs) TEST_F(obj_exporter_regression_test, nurbs_curves_as_nurbs) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_materials = false; _export.params.export_curves_as_nurbs = true; compare_obj_export_to_golden("io_tests/blend_geometry/nurbs_curves.blend", @@ -379,8 +379,8 @@ TEST_F(obj_exporter_regression_test, nurbs_curves_as_nurbs) TEST_F(obj_exporter_regression_test, nurbs_as_mesh) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_materials = false; _export.params.export_curves_as_nurbs = false; compare_obj_export_to_golden( @@ -390,8 +390,8 @@ TEST_F(obj_exporter_regression_test, nurbs_as_mesh) TEST_F(obj_exporter_regression_test, cube_all_data_triangulated) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_materials = false; _export.params.export_triangulated_mesh = true; compare_obj_export_to_golden("io_tests/blend_geometry/cube_all_data.blend", @@ -403,8 +403,8 @@ TEST_F(obj_exporter_regression_test, cube_all_data_triangulated) TEST_F(obj_exporter_regression_test, cube_normal_edit) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_materials = false; compare_obj_export_to_golden("io_tests/blend_geometry/cube_normal_edit.blend", "io_tests/obj/cube_normal_edit.obj", @@ -459,8 +459,8 @@ TEST_F(obj_exporter_regression_test, cubes_with_textures_relative) TEST_F(obj_exporter_regression_test, suzanne_all_data) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_materials = false; _export.params.export_smooth_groups = true; compare_obj_export_to_golden("io_tests/blend_geometry/suzanne_all_data.blend", @@ -491,8 +491,8 @@ TEST_F(obj_exporter_regression_test, all_curves_as_nurbs) TEST_F(obj_exporter_regression_test, all_objects) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_smooth_groups = true; compare_obj_export_to_golden("io_tests/blend_scene/all_objects.blend", "io_tests/obj/all_objects.obj", @@ -503,8 +503,8 @@ TEST_F(obj_exporter_regression_test, all_objects) TEST_F(obj_exporter_regression_test, all_objects_mat_groups) { OBJExportParamsDefault _export; - _export.params.forward_axis = OBJ_AXIS_Y_FORWARD; - _export.params.up_axis = OBJ_AXIS_Z_UP; + _export.params.forward_axis = IO_AXIS_Y; + _export.params.up_axis = IO_AXIS_Z; _export.params.export_smooth_groups = true; _export.params.export_material_groups = true; compare_obj_export_to_golden("io_tests/blend_scene/all_objects.blend", 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 ef27a65fb4b..42f7620999d 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh @@ -17,8 +17,8 @@ struct OBJExportParamsDefault { params.start_frame = 0; params.end_frame = 1; - params.forward_axis = OBJ_AXIS_NEGATIVE_Z_FORWARD; - params.up_axis = OBJ_AXIS_Y_UP; + params.forward_axis = IO_AXIS_NEGATIVE_Z; + params.up_axis = IO_AXIS_Y; params.scaling_factor = 1.f; params.apply_modifiers = true; diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index d7f4ce3d773..48990975416 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -55,8 +55,8 @@ class obj_importer_test : public BlendfileLoadingBaseTest { OBJImportParams params; params.clamp_size = 0; - params.forward_axis = OBJ_AXIS_NEGATIVE_Z_FORWARD; - params.up_axis = OBJ_AXIS_Y_UP; + params.forward_axis = IO_AXIS_NEGATIVE_Z; + params.up_axis = IO_AXIS_Y; std::string obj_path = blender::tests::flags_test_asset_dir() + "/io_tests/obj/" + path; strncpy(params.filepath, obj_path.c_str(), FILE_MAX - 1); |