From c81c8a10961ec12c6d2c775e76038236c92f338d Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Mon, 4 Apr 2022 13:36:10 +0300 Subject: 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 --- source/blender/editors/io/io_obj.c | 84 ++++++++++++++++++++++++++++++++++++++ source/blender/editors/io/io_obj.h | 1 + source/blender/editors/io/io_ops.c | 1 + 3 files changed, 86 insertions(+) (limited to 'source/blender/editors/io') 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", ""); +} diff --git a/source/blender/editors/io/io_obj.h b/source/blender/editors/io/io_obj.h index cb9cdc8e74d..30857b33f21 100644 --- a/source/blender/editors/io/io_obj.h +++ b/source/blender/editors/io/io_obj.h @@ -9,3 +9,4 @@ struct wmOperatorType; void WM_OT_obj_export(struct wmOperatorType *ot); +void WM_OT_obj_import(struct wmOperatorType *ot); diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c index ccd19608ddd..094f89d1540 100644 --- a/source/blender/editors/io/io_ops.c +++ b/source/blender/editors/io/io_ops.c @@ -59,4 +59,5 @@ void ED_operatortypes_io(void) WM_operatortype_append(CACHEFILE_OT_layer_move); WM_operatortype_append(WM_OT_obj_export); + WM_operatortype_append(WM_OT_obj_import); } -- cgit v1.2.3