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
|
|
|
|
|
|
|
|
|
|
#include "BLI_path_util.h"
|
2023-08-31 12:51:57 -04:00
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
struct OBJExportParams {
|
|
|
|
|
/** Full path to the destination .OBJ file. */
|
|
|
|
|
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. */
|
|
|
|
|
char file_base_for_tests[FILE_MAX];
|
2022-01-03 14:49:31 -05:00
|
|
|
|
|
|
|
|
/** Full path to current blender file (used for comments in output). */
|
|
|
|
|
const char *blen_filepath;
|
|
|
|
|
|
|
|
|
|
/** Whether multiple frames should be exported. */
|
|
|
|
|
bool export_animation;
|
|
|
|
|
/** The first frame to be exported. */
|
|
|
|
|
int start_frame;
|
|
|
|
|
/** The last frame to be exported. */
|
|
|
|
|
int end_frame;
|
|
|
|
|
|
|
|
|
|
/* Geometry Transform options. */
|
2023-09-01 10:31:17 +10:00
|
|
|
eIOAxis forward_axis;
|
|
|
|
|
eIOAxis up_axis;
|
2022-10-10 10:10:33 +03:00
|
|
|
float global_scale;
|
2022-01-03 14:49:31 -05:00
|
|
|
|
|
|
|
|
/* File Write Options. */
|
|
|
|
|
bool export_selected_objects;
|
2022-03-13 12:04:52 -04:00
|
|
|
bool apply_modifiers;
|
2022-01-03 14:49:31 -05:00
|
|
|
eEvaluationMode export_eval_mode;
|
|
|
|
|
bool export_uv;
|
|
|
|
|
bool export_normals;
|
2022-06-14 10:19:02 +03:00
|
|
|
bool export_colors;
|
2022-01-03 14:49:31 -05:00
|
|
|
bool export_materials;
|
|
|
|
|
bool export_triangulated_mesh;
|
|
|
|
|
bool export_curves_as_nurbs;
|
2022-05-10 11:34:42 +03:00
|
|
|
ePathReferenceMode path_mode;
|
2022-09-13 13:28:57 +03:00
|
|
|
bool export_pbr_extensions;
|
2022-01-03 14:49:31 -05:00
|
|
|
|
|
|
|
|
/* Grouping options. */
|
|
|
|
|
bool export_object_groups;
|
|
|
|
|
bool export_material_groups;
|
|
|
|
|
bool export_vertex_groups;
|
2022-09-13 13:28:57 +03:00
|
|
|
/* Calculate smooth groups from sharp edges. */
|
2022-01-03 14:49:31 -05:00
|
|
|
bool export_smooth_groups;
|
2022-09-13 13:28:57 +03:00
|
|
|
/* Create bitflags instead of the default "0"/"1" group IDs. */
|
2022-01-03 14:49:31 -05:00
|
|
|
bool smooth_groups_bitflags;
|
|
|
|
|
};
|
|
|
|
|
|
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. */
|
|
|
|
|
char filepath[FILE_MAX];
|
|
|
|
|
/** Value 0 disables clamping. */
|
|
|
|
|
float clamp_size;
|
2022-10-10 10:10:33 +03:00
|
|
|
float global_scale;
|
2023-09-01 10:31:17 +10:00
|
|
|
eIOAxis forward_axis;
|
|
|
|
|
eIOAxis up_axis;
|
2023-01-12 22:47:39 +02:00
|
|
|
bool use_split_objects;
|
|
|
|
|
bool use_split_groups;
|
2022-06-19 17:39:54 +03:00
|
|
|
bool import_vertex_groups;
|
OBJ: further optimize, cleanup and harden the new C++ importer
Continued improvements to the new C++ based OBJ importer.
Performance: about 2x faster.
- Rungholt.obj (several meshes, 263MB file): Windows 12.7s -> 5.9s, Mac 7.7s -> 3.1s.
- Blender 3.0 splash (24k meshes, 2.4GB file): Windows 97.3s -> 53.6s, Mac 137.3s -> 80.0s.
- "Windows" is VS2022, AMD Ryzen 5950X (32 threads), "Mac" is Xcode/clang 13, M1Max (10 threads).
- Slightly reduced memory usage during import as well.
The performance gains are a combination of several things:
- Replacing `std::stof` / `std::stoi` with C++17 `from_chars`.
- Stop reading input file char-by-char using `std::getline`, and instead read in 64kb chunks, and parse from there (taking care of possibly handling lines split mid-way due to chunk boundaries).
- Removing abstractions for splitting a line by some char,
- Avoid tiny memory allocations: instead of storing a vector of polygon corners in each face, store all the corners in one big array, and per-face only store indices "where do corners start, and how many". Likewise, don't store full string names of material/group names for each face; only store indices into overall material/group names arrays.
- Stop always doing mesh validation, which is slow. Do it just like the Alembic importer does: only do validation if found some invalid faces during import, or if requested by the user via an import setting checkbox (which defaults to off).
- Stop doing "collection sync" for each object being added; instead do the collection sync right after creating all the objects.
Cleanup / Robustness:
This reworking of parser (see "removing abstractions" point above) means that all the functions that were in `parser_string_utils` file are gone, and replaced with different set of functions. However they are not OBJ specific, so as pointed out during review of the previous differential, they are now in `source/blender/io/common` library.
Added gtest coverage for said functions as well; something that was only indirectly covered by obj tests previously.
Rework of some bits of parsing made the parser actually better able to deal with invalid syntax. E.g. previously, if a face corner were a `/123` string, it would have incorrectly treated that as a vertex index (since it would get "hey that's one number" after splitting a string by a slash), instead of properly marking it as invalid syntax.
Added gtest coverage for .mtl parsing; something that was not covered by any tests at all previously.
Reviewed By: Howard Trickey
Differential Revision: https://developer.blender.org/D14586
2022-04-17 22:07:43 +03:00
|
|
|
bool validate_meshes;
|
2022-08-01 13:39:08 +03:00
|
|
|
bool relative_paths;
|
2022-08-11 17:05:54 +03:00
|
|
|
bool clear_selection;
|
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 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);
|