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:
Diffstat (limited to 'source/blender/editors/io/io_usd.c')
-rw-r--r--source/blender/editors/io/io_usd.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index a59cdf60243..c776fbf0dd7 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -21,6 +21,7 @@
# include "BLT_translation.h"
+# include "ED_fileselect.h"
# include "ED_object.h"
# include "MEM_guardedalloc.h"
@@ -84,21 +85,7 @@ static int wm_usd_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
options->as_background_job = true;
op->customdata = options;
- if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
- Main *bmain = CTX_data_main(C);
- char filepath[FILE_MAX];
- const char *main_blendfile_path = BKE_main_blendfile_path(bmain);
-
- if (main_blendfile_path[0] == '\0') {
- BLI_strncpy(filepath, "untitled", sizeof(filepath));
- }
- else {
- BLI_strncpy(filepath, main_blendfile_path, sizeof(filepath));
- }
-
- BLI_path_extension_replace(filepath, sizeof(filepath), ".usdc");
- RNA_string_set(op->ptr, "filepath", filepath);
- }
+ ED_fileselect_ensure_default_filepath(C, op, ".usdc");
WM_event_add_fileselect(C, op);
@@ -107,7 +94,7 @@ static int wm_usd_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
static int wm_usd_export_exec(bContext *C, wmOperator *op)
{
- if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
BKE_report(op->reports, RPT_ERROR, "No filename given");
return OPERATOR_CANCELLED;
}
@@ -204,6 +191,19 @@ static void wm_usd_export_draw(bContext *UNUSED(C), wmOperator *op)
uiItemR(box, ptr, "use_instancing", 0, NULL, ICON_NONE);
}
+static void free_operator_customdata(wmOperator *op)
+{
+ if (op->customdata) {
+ MEM_freeN(op->customdata);
+ op->customdata = NULL;
+ }
+}
+
+static void wm_usd_export_cancel(bContext *UNUSED(C), wmOperator *op)
+{
+ free_operator_customdata(op);
+}
+
static bool wm_usd_export_check(bContext *UNUSED(C), wmOperator *op)
{
char filepath[FILE_MAX];
@@ -228,6 +228,7 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
ot->exec = wm_usd_export_exec;
ot->poll = WM_operator_winactive;
ot->ui = wm_usd_export_draw;
+ ot->cancel = wm_usd_export_cancel;
ot->check = wm_usd_export_check;
ot->flag = OPTYPE_REGISTER | OPTYPE_PRESET; /* No UNDO possible. */
@@ -331,7 +332,7 @@ static int wm_usd_import_invoke(bContext *C, wmOperator *op, const wmEvent *even
static int wm_usd_import_exec(bContext *C, wmOperator *op)
{
- if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
BKE_report(op->reports, RPT_ERROR, "No filename given");
return OPERATOR_CANCELLED;
}
@@ -373,7 +374,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
const bool create_collection = RNA_boolean_get(op->ptr, "create_collection");
- char *prim_path_mask = malloc(1024);
+ char prim_path_mask[1024];
RNA_string_get(op->ptr, "prim_path_mask", prim_path_mask);
const bool import_guide = RNA_boolean_get(op->ptr, "import_guide");
@@ -415,7 +416,6 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
.import_materials = import_materials,
.import_meshes = import_meshes,
.import_volumes = import_volumes,
- .prim_path_mask = prim_path_mask,
.import_subdiv = import_subdiv,
.import_instance_proxies = import_instance_proxies,
.create_collection = create_collection,
@@ -429,11 +429,18 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
.light_intensity_scale = light_intensity_scale,
.mtl_name_collision_mode = mtl_name_collision_mode};
+ STRNCPY(params.prim_path_mask, prim_path_mask);
+
const bool ok = USD_import(C, filename, &params, as_background_job);
return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
+static void wm_usd_import_cancel(bContext *UNUSED(C), wmOperator *op)
+{
+ free_operator_customdata(op);
+}
+
static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op)
{
uiLayout *layout = op->layout;
@@ -489,10 +496,11 @@ void WM_OT_usd_import(struct wmOperatorType *ot)
ot->invoke = wm_usd_import_invoke;
ot->exec = wm_usd_import_exec;
+ ot->cancel = wm_usd_import_cancel;
ot->poll = WM_operator_winactive;
ot->ui = wm_usd_import_draw;
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET;
WM_operator_properties_filesel(ot,
FILE_TYPE_FOLDER | FILE_TYPE_USD,
@@ -500,7 +508,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot)
FILE_OPENFILE,
WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS,
FILE_DEFAULTDISPLAY,
- FILE_SORT_ALPHA);
+ FILE_SORT_DEFAULT);
RNA_def_float(
ot->srna,