2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-01-03 14:49:31 -05:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup obj
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-02-17 23:26:52 +01:00
|
|
|
#include <limits.h>
|
|
|
|
|
|
2024-09-26 21:13:39 +10:00
|
|
|
#include "BLI_path_utils.hh"
|
2023-08-31 12:51:57 -04:00
|
|
|
|
2024-07-08 20:20:38 +02:00
|
|
|
#include "BKE_geometry_set.hh"
|
|
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
2022-01-03 14:49:31 -05:00
|
|
|
|
2023-09-01 10:31:17 +10:00
|
|
|
#include "IO_orientation.hh"
|
2023-08-31 12:51:57 -04:00
|
|
|
#include "IO_path_util_types.hh"
|
2022-01-03 14:49:31 -05:00
|
|
|
|
2024-03-10 04:28:00 +01:00
|
|
|
struct bContext;
|
|
|
|
|
struct ReportList;
|
|
|
|
|
|
2022-01-03 14:49:31 -05:00
|
|
|
struct OBJExportParams {
|
2024-05-04 15:06:46 +10:00
|
|
|
/** Full path to the destination `.OBJ` file. */
|
2024-12-26 18:16:57 +02:00
|
|
|
char filepath[FILE_MAX] = "";
|
2022-05-10 11:34:42 +03:00
|
|
|
/** Pretend that destination file folder is this, if non-empty. Used only for tests. */
|
2024-12-26 18:16:57 +02:00
|
|
|
char file_base_for_tests[FILE_MAX] = "";
|
2024-04-08 22:10:39 +02:00
|
|
|
char collection[MAX_IDPROP_NAME] = "";
|
2022-01-03 14:49:31 -05:00
|
|
|
|
|
|
|
|
/** Full path to current blender file (used for comments in output). */
|
2024-12-26 18:16:57 +02:00
|
|
|
const char *blen_filepath = nullptr;
|
2022-01-03 14:49:31 -05:00
|
|
|
|
|
|
|
|
/** Whether multiple frames should be exported. */
|
2024-12-26 18:16:57 +02:00
|
|
|
bool export_animation = false;
|
2022-01-03 14:49:31 -05:00
|
|
|
/** The first frame to be exported. */
|
2024-12-26 18:16:57 +02:00
|
|
|
int start_frame = INT_MIN;
|
2022-01-03 14:49:31 -05:00
|
|
|
/** The last frame to be exported. */
|
2024-12-26 18:16:57 +02:00
|
|
|
int end_frame = INT_MAX;
|
2022-01-03 14:49:31 -05:00
|
|
|
|
|
|
|
|
/* Geometry Transform options. */
|
2024-12-26 18:16:57 +02:00
|
|
|
eIOAxis forward_axis = IO_AXIS_NEGATIVE_Z;
|
|
|
|
|
eIOAxis up_axis = IO_AXIS_Y;
|
|
|
|
|
float global_scale = 1.0f;
|
2022-01-03 14:49:31 -05:00
|
|
|
|
|
|
|
|
/* File Write Options. */
|
2024-12-26 18:16:57 +02:00
|
|
|
bool export_selected_objects = false;
|
|
|
|
|
bool apply_modifiers = true;
|
|
|
|
|
eEvaluationMode export_eval_mode = DAG_EVAL_VIEWPORT;
|
|
|
|
|
bool export_uv = true;
|
|
|
|
|
bool export_normals = true;
|
|
|
|
|
bool export_colors = false;
|
|
|
|
|
bool export_materials = true;
|
|
|
|
|
bool export_triangulated_mesh = false;
|
|
|
|
|
bool export_curves_as_nurbs = false;
|
|
|
|
|
ePathReferenceMode path_mode = PATH_REFERENCE_AUTO;
|
|
|
|
|
bool export_pbr_extensions = false;
|
2022-01-03 14:49:31 -05:00
|
|
|
|
|
|
|
|
/* Grouping options. */
|
2024-12-26 18:16:57 +02:00
|
|
|
bool export_object_groups = false;
|
|
|
|
|
bool export_material_groups = false;
|
|
|
|
|
bool export_vertex_groups = false;
|
2022-09-13 13:28:57 +03:00
|
|
|
/* Calculate smooth groups from sharp edges. */
|
2024-12-26 18:16:57 +02:00
|
|
|
bool export_smooth_groups = false;
|
2022-09-13 13:28:57 +03:00
|
|
|
/* Create bitflags instead of the default "0"/"1" group IDs. */
|
2024-12-26 18:16:57 +02:00
|
|
|
bool smooth_groups_bitflags = false;
|
2024-02-26 20:45:46 +01:00
|
|
|
|
|
|
|
|
ReportList *reports = nullptr;
|
2022-01-03 14:49:31 -05:00
|
|
|
};
|
|
|
|
|
|
OBJ: New C++ based wavefront OBJ importer
This takes state of soc-2020-io-performance branch as it was at
e9bbfd0c8c7 (2021 Oct 31), merges latest master (2022 Apr 4),
adds a bunch of tests, and fixes a bunch of stuff found by said
tests. The fixes are detailed in the differential.
Timings on my machine (Windows, VS2022 release build, AMD Ryzen
5950X 32 threads):
- Rungholt minecraft level (269MB file, 1 mesh): 54.2s -> 14.2s
(memory usage: 7.0GB -> 1.9GB).
- Blender 3.0 splash scene: "I waited for 90 minutes and gave up"
-> 109s. Now, this time is not great, but at least 20% of the
time is spent assigning unique names for the imported objects
(the scene has 24 thousand objects). This is not specific to obj
importer, but rather a general issue across blender overall.
Test suite file updates done in Subversion tests repository.
Reviewed By: @howardt, @sybren
Differential Revision: https://developer.blender.org/D13958
2022-04-04 13:36:10 +03:00
|
|
|
struct OBJImportParams {
|
|
|
|
|
/** Full path to the source OBJ file to import. */
|
2024-12-26 18:16:57 +02:00
|
|
|
char filepath[FILE_MAX] = "";
|
OBJ: New C++ based wavefront OBJ importer
This takes state of soc-2020-io-performance branch as it was at
e9bbfd0c8c7 (2021 Oct 31), merges latest master (2022 Apr 4),
adds a bunch of tests, and fixes a bunch of stuff found by said
tests. The fixes are detailed in the differential.
Timings on my machine (Windows, VS2022 release build, AMD Ryzen
5950X 32 threads):
- Rungholt minecraft level (269MB file, 1 mesh): 54.2s -> 14.2s
(memory usage: 7.0GB -> 1.9GB).
- Blender 3.0 splash scene: "I waited for 90 minutes and gave up"
-> 109s. Now, this time is not great, but at least 20% of the
time is spent assigning unique names for the imported objects
(the scene has 24 thousand objects). This is not specific to obj
importer, but rather a general issue across blender overall.
Test suite file updates done in Subversion tests repository.
Reviewed By: @howardt, @sybren
Differential Revision: https://developer.blender.org/D13958
2022-04-04 13:36:10 +03:00
|
|
|
/** Value 0 disables clamping. */
|
2023-12-04 09:54:52 +01:00
|
|
|
float clamp_size = 0.0f;
|
|
|
|
|
float global_scale = 1.0f;
|
|
|
|
|
eIOAxis forward_axis = IO_AXIS_NEGATIVE_Z;
|
|
|
|
|
eIOAxis up_axis = IO_AXIS_Y;
|
|
|
|
|
char collection_separator = 0;
|
|
|
|
|
bool use_split_objects = true;
|
|
|
|
|
bool use_split_groups = false;
|
|
|
|
|
bool import_vertex_groups = false;
|
2024-05-04 13:30:15 +10:00
|
|
|
bool validate_meshes = true;
|
2024-12-03 13:16:16 +01:00
|
|
|
bool close_spline_loops = true;
|
2023-12-04 09:54:52 +01:00
|
|
|
bool relative_paths = true;
|
|
|
|
|
bool clear_selection = true;
|
2024-02-26 20:45:46 +01:00
|
|
|
|
|
|
|
|
ReportList *reports = nullptr;
|
OBJ: New C++ based wavefront OBJ importer
This takes state of soc-2020-io-performance branch as it was at
e9bbfd0c8c7 (2021 Oct 31), merges latest master (2022 Apr 4),
adds a bunch of tests, and fixes a bunch of stuff found by said
tests. The fixes are detailed in the differential.
Timings on my machine (Windows, VS2022 release build, AMD Ryzen
5950X 32 threads):
- Rungholt minecraft level (269MB file, 1 mesh): 54.2s -> 14.2s
(memory usage: 7.0GB -> 1.9GB).
- Blender 3.0 splash scene: "I waited for 90 minutes and gave up"
-> 109s. Now, this time is not great, but at least 20% of the
time is spent assigning unique names for the imported objects
(the scene has 24 thousand objects). This is not specific to obj
importer, but rather a general issue across blender overall.
Test suite file updates done in Subversion tests repository.
Reviewed By: @howardt, @sybren
Differential Revision: https://developer.blender.org/D13958
2022-04-04 13:36:10 +03:00
|
|
|
};
|
|
|
|
|
|
2024-07-08 20:20:38 +02:00
|
|
|
/**
|
2024-07-13 16:56:57 +10:00
|
|
|
* Reads and returns just the meshes in the obj file
|
2024-07-08 20:20:38 +02:00
|
|
|
*/
|
|
|
|
|
void OBJ_import_geometries(const OBJImportParams *import_params,
|
|
|
|
|
blender::Vector<blender::bke::GeometrySet> &geometries);
|
|
|
|
|
|
2022-04-05 07:44:36 +10:00
|
|
|
/**
|
2022-05-23 20:42:27 +03:00
|
|
|
* Perform the full import process.
|
|
|
|
|
* Import also changes the selection & the active object; callers
|
|
|
|
|
* need to update the UI bits if needed.
|
2022-04-05 07:44:36 +10:00
|
|
|
*/
|
2023-08-31 12:51:57 -04:00
|
|
|
void OBJ_import(bContext *C, const OBJImportParams *import_params);
|
OBJ: New C++ based wavefront OBJ importer
This takes state of soc-2020-io-performance branch as it was at
e9bbfd0c8c7 (2021 Oct 31), merges latest master (2022 Apr 4),
adds a bunch of tests, and fixes a bunch of stuff found by said
tests. The fixes are detailed in the differential.
Timings on my machine (Windows, VS2022 release build, AMD Ryzen
5950X 32 threads):
- Rungholt minecraft level (269MB file, 1 mesh): 54.2s -> 14.2s
(memory usage: 7.0GB -> 1.9GB).
- Blender 3.0 splash scene: "I waited for 90 minutes and gave up"
-> 109s. Now, this time is not great, but at least 20% of the
time is spent assigning unique names for the imported objects
(the scene has 24 thousand objects). This is not specific to obj
importer, but rather a general issue across blender overall.
Test suite file updates done in Subversion tests repository.
Reviewed By: @howardt, @sybren
Differential Revision: https://developer.blender.org/D13958
2022-04-04 13:36:10 +03:00
|
|
|
|
2022-04-05 07:44:36 +10:00
|
|
|
/**
|
2022-05-23 20:42:27 +03:00
|
|
|
* Perform the full export process.
|
2022-04-05 07:44:36 +10:00
|
|
|
*/
|
2023-08-31 12:51:57 -04:00
|
|
|
void OBJ_export(bContext *C, const OBJExportParams *export_params);
|