Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnkit Meel <ankitjmeel@gmail.com>2022-04-04 13:36:10 +0300
committerAras Pranckevicius <aras@nesnausk.org>2022-04-04 13:36:10 +0300
commite6a9b223844346a34ce195652449fec3229a2ec1 (patch)
tree38b9621299a83515670af0189b8cddc51813f838 /source/blender/editors/io/io_obj.c
parentee3f71d747e3ffd5091335437d52b3ec518d7b67 (diff)
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
Diffstat (limited to 'source/blender/editors/io/io_obj.c')
-rw-r--r--source/blender/editors/io/io_obj.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index df15191916a..97f1e08fdff 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -359,3 +359,87 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
RNA_def_boolean(
ot->srna, "smooth_group_bitflags", false, "Generate Bitflags for Smooth Groups", "");
}
+
+static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ WM_event_add_fileselect(C, op);
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int wm_obj_import_exec(bContext *C, wmOperator *op)
+{
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ BKE_report(op->reports, RPT_ERROR, "No filename given");
+ return OPERATOR_CANCELLED;
+ }
+
+ struct OBJImportParams import_params;
+ RNA_string_get(op->ptr, "filepath", import_params.filepath);
+ import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size");
+ import_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis");
+ import_params.up_axis = RNA_enum_get(op->ptr, "up_axis");
+
+ OBJ_import(C, &import_params);
+
+ return OPERATOR_FINISHED;
+}
+
+static void ui_obj_import_settings(uiLayout *layout, PointerRNA *imfptr)
+{
+ uiLayoutSetPropSep(layout, true);
+ uiLayoutSetPropDecorate(layout, false);
+ uiLayout *box = uiLayoutBox(layout);
+
+ uiItemL(box, IFACE_("Transform"), ICON_OBJECT_DATA);
+ uiLayout *col = uiLayoutColumn(box, false);
+ uiLayout *sub = uiLayoutColumn(col, false);
+ uiItemR(sub, imfptr, "clamp_size", 0, NULL, ICON_NONE);
+ sub = uiLayoutColumn(col, false);
+ uiItemR(sub, imfptr, "forward_axis", 0, IFACE_("Axis Forward"), ICON_NONE);
+ uiItemR(sub, imfptr, "up_axis", 0, IFACE_("Up"), ICON_NONE);
+}
+
+static void wm_obj_import_draw(bContext *C, wmOperator *op)
+{
+ PointerRNA ptr;
+ wmWindowManager *wm = CTX_wm_manager(C);
+ RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
+ ui_obj_import_settings(op->layout, &ptr);
+}
+
+void WM_OT_obj_import(struct wmOperatorType *ot)
+{
+ ot->name = "Import Wavefront OBJ";
+ ot->description = "Load a Wavefront OBJ scene";
+ ot->idname = "WM_OT_obj_import";
+
+ ot->invoke = wm_obj_import_invoke;
+ ot->exec = wm_obj_import_exec;
+ ot->poll = WM_operator_winactive;
+ ot->ui = wm_obj_import_draw;
+
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_FOLDER | FILE_TYPE_OBJECT_IO,
+ FILE_BLENDER,
+ FILE_OPENFILE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_ALPHA);
+ RNA_def_float(
+ ot->srna,
+ "clamp_size",
+ 0.0f,
+ 0.0f,
+ 1000.0f,
+ "Clamp Bounding Box",
+ "Resize the objects to keep bounding box under this value. Value 0 diables clamping",
+ 0.0f,
+ 1000.0f);
+ RNA_def_enum(ot->srna,
+ "forward_axis",
+ io_obj_transform_axis_forward,
+ OBJ_AXIS_NEGATIVE_Z_FORWARD,
+ "Forward Axis",
+ "");
+ RNA_def_enum(ot->srna, "up_axis", io_obj_transform_axis_up, OBJ_AXIS_Y_UP, "Up Axis", "");
+}