IO: Add file handlers to c++ import operators #116873

Merged
Jesse Yurkovich merged 18 commits from guishe/blender:io-fh into main 2024-01-27 23:38:55 +01:00
18 changed files with 290 additions and 40 deletions

View File

@ -37,6 +37,7 @@ set(SRC
io_ply_ops.cc
io_stl_ops.cc
io_usd.cc
io_utils.cc
io_alembic.hh
io_cache.hh
@ -48,6 +49,7 @@ set(SRC
io_ply_ops.hh
io_stl_ops.hh
io_usd.hh
io_utils.hh
)
set(LIB

View File

@ -26,6 +26,7 @@
# include "DNA_space_types.h"
# include "BKE_context.hh"
# include "BKE_file_handler.hh"
# include "BKE_main.hh"
# include "BKE_report.h"
@ -52,6 +53,7 @@
# include "DEG_depsgraph.hh"
# include "io_alembic.hh"
# include "io_utils.hh"
# include "ABC_alembic.h"
@ -595,7 +597,7 @@ static int wm_alembic_import_invoke(bContext *C, wmOperator *op, const wmEvent *
if (!RNA_struct_property_is_set(op->ptr, "as_background_job")) {
RNA_boolean_set(op->ptr, "as_background_job", true);
}
return WM_operator_filesel(C, op, event);
return blender::ed::io::filesel_drop_import_invoke(C, op, event);
}
static int wm_alembic_import_exec(bContext *C, wmOperator *op)
@ -651,7 +653,7 @@ void WM_OT_alembic_import(wmOperatorType *ot)
ot->name = "Import Alembic";
ot->description = "Load an Alembic archive";
ot->idname = "WM_OT_alembic_import";
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET;
ot->flag = OPTYPE_UNDO | OPTYPE_PRESET;
ot->invoke = wm_alembic_import_invoke;
ot->exec = wm_alembic_import_exec;
@ -716,4 +718,17 @@ void WM_OT_alembic_import(wmOperatorType *ot)
"to run as a background job");
}
namespace blender::ed::io {
void alembic_file_handler_add()
{
auto fh = std::make_unique<blender::bke::FileHandlerType>();
STRNCPY(fh->idname, "IO_FH_alembic");
STRNCPY(fh->import_operator, "WM_OT_alembic_import");
guishe marked this conversation as resolved Outdated

I think this can just be auto fh = std::make_unique ... and use fh-> to access the fields. The usage of unique_ptr in blender typically doesn't make a distinction between the ptr and the actual data, especially in cases like this where there would be no confusion, so this just seems like extra ceremony.

I think this can just be `auto fh = std::make_unique ...` and use `fh->` to access the fields. The usage of unique_ptr in blender typically doesn't make a distinction between the `ptr` and the actual data, especially in cases like this where there would be no confusion, so this just seems like extra ceremony.
STRNCPY(fh->label, "Alembic");
STRNCPY(fh->file_extensions_str, ".abc");
fh->poll_drop = poll_file_object_drop;
bke::file_handler_add(std::move(fh));
}
} // namespace blender::ed::io
#endif

View File

@ -12,3 +12,7 @@ struct wmOperatorType;
void WM_OT_alembic_export(wmOperatorType *ot);
void WM_OT_alembic_import(wmOperatorType *ot);
namespace blender::ed::io {
void alembic_file_handler_add();
}

View File

@ -11,9 +11,11 @@
# include "BLT_translation.h"
# include "BLI_blenlib.h"
# include "BLI_string.h"
# include "BLI_utildefines.h"
# include "BKE_context.hh"
# include "BKE_file_handler.hh"
# include "BKE_main.hh"
# include "BKE_object.hh"
# include "BKE_report.h"
@ -22,6 +24,7 @@
# include "ED_fileselect.hh"
# include "ED_object.hh"
# include "ED_outliner.hh"
# include "RNA_access.hh"
# include "RNA_define.hh"
@ -35,6 +38,7 @@
# include "collada.h"
# include "io_collada.hh"
# include "io_utils.hh"
static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
@ -750,6 +754,11 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op)
if (collada_import(C, &import_settings)) {
DEG_id_tag_update(&CTX_data_scene(C)->id, ID_RECALC_BASE_FLAGS);
Scene *scene = CTX_data_scene(C);
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
ED_outliner_select_sync_from_object_tag(C);
return OPERATOR_FINISHED;
}
@ -757,7 +766,7 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
static void uiCollada_importSettings(uiLayout *layout, PointerRNA *imfptr)
static void wm_collada_import_settings(uiLayout *layout, PointerRNA *imfptr)
{
uiLayout *box, *col;
@ -787,7 +796,7 @@ static void uiCollada_importSettings(uiLayout *layout, PointerRNA *imfptr)
static void wm_collada_import_draw(bContext * /*C*/, wmOperator *op)
{
uiCollada_importSettings(op->layout, op->ptr);
wm_collada_import_settings(op->layout, op->ptr);
}
void WM_OT_collada_import(wmOperatorType *ot)
@ -795,9 +804,9 @@ void WM_OT_collada_import(wmOperatorType *ot)
ot->name = "Import COLLADA";
ot->description = "Load a Collada file";
ot->idname = "WM_OT_collada_import";
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET;
ot->flag = OPTYPE_UNDO | OPTYPE_PRESET;
ot->invoke = WM_operator_filesel;
ot->invoke = blender::ed::io::filesel_drop_import_invoke;
ot->exec = wm_collada_import_exec;
ot->poll = WM_operator_winactive;
@ -862,4 +871,18 @@ void WM_OT_collada_import(wmOperatorType *ot)
"Keep Bind Info",
"Store Bindpose information in custom bone properties for later use during Collada export");
}
namespace blender::ed::io {
void collada_file_handler_add()
{
auto fh = std::make_unique<blender::bke::FileHandlerType>();
STRNCPY(fh->idname, "IO_FH_collada");
STRNCPY(fh->import_operator, "WM_OT_collada_import");
STRNCPY(fh->label, "Collada");
STRNCPY(fh->file_extensions_str, ".dae");
fh->poll_drop = poll_file_object_drop;
bke::file_handler_add(std::move(fh));
}
} // namespace blender::ed::io
#endif

View File

@ -12,3 +12,7 @@ struct wmOperatorType;
void WM_OT_collada_export(wmOperatorType *ot);
void WM_OT_collada_import(wmOperatorType *ot);
namespace blender::ed::io {
void collada_file_handler_add();
}

View File

@ -24,3 +24,7 @@ void WM_OT_gpencil_export_pdf(wmOperatorType *ot);
ARegion *get_invoke_region(bContext *C);
View3D *get_invoke_view3d(bContext *C);
namespace blender::ed::io {
void gpencil_file_handler_add();
}

View File

@ -9,6 +9,7 @@
#ifdef WITH_IO_GPENCIL
# include "BLI_path_util.h"
# include "BLI_string.h"
# include "MEM_guardedalloc.h"
@ -16,6 +17,7 @@
# include "DNA_space_types.h"
# include "BKE_context.hh"
# include "BKE_file_handler.hh"
# include "BKE_gpencil_legacy.h"
# include "BKE_report.h"
@ -36,6 +38,7 @@
# include "ED_gpencil_legacy.hh"
# include "io_gpencil.hh"
# include "io_utils.hh"
# include "gpencil_io.h"
@ -55,13 +58,6 @@ static bool wm_gpencil_import_svg_common_check(bContext * /*C*/, wmOperator *op)
return false;
}
static int wm_gpencil_import_svg_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
WM_event_add_fileselect(C, op);
return OPERATOR_RUNNING_MODAL;
}
static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
@ -136,7 +132,8 @@ static void ui_gpencil_import_svg_settings(uiLayout *layout, PointerRNA *imfptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiLayout *col = uiLayoutColumn(layout, false);
uiLayout *box = uiLayoutBox(layout);
uiLayout *col = uiLayoutColumn(box, false);
uiItemR(col, imfptr, "resolution", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, imfptr, "scale", UI_ITEM_NONE, nullptr, ICON_NONE);
}
@ -161,7 +158,7 @@ void WM_OT_gpencil_import_svg(wmOperatorType *ot)
ot->description = "Import SVG into grease pencil";
ot->idname = "WM_OT_gpencil_import_svg";
ot->invoke = wm_gpencil_import_svg_invoke;
ot->invoke = blender::ed::io::filesel_drop_import_invoke;
ot->exec = wm_gpencil_import_svg_exec;
ot->poll = wm_gpencil_import_svg_poll;
ot->ui = wm_gpencil_import_svg_draw;
@ -197,4 +194,17 @@ void WM_OT_gpencil_import_svg(wmOperatorType *ot)
100.0f);
}
namespace blender::ed::io {
void gpencil_file_handler_add()
{
auto fh = std::make_unique<blender::bke::FileHandlerType>();
STRNCPY(fh->idname, "IO_FH_gpencil_svg");
STRNCPY(fh->import_operator, "WM_OT_gpencil_import_svg");
STRNCPY(fh->label, "SVG as Grease Pencil");
STRNCPY(fh->file_extensions_str, ".svg");
fh->poll_drop = poll_file_object_drop;
bke::file_handler_add(std::move(fh));
}
} // namespace blender::ed::io
#endif /* WITH_IO_GPENCIL */

View File

@ -11,6 +11,7 @@
# include "DNA_space_types.h"
# include "BKE_context.hh"
# include "BKE_file_handler.hh"
# include "BKE_main.hh"
# include "BKE_report.h"
@ -41,6 +42,7 @@
# include "IO_wavefront_obj.hh"
# include "io_obj.hh"
# include "io_utils.hh"
static const EnumPropertyItem io_obj_export_evaluation_mode[] = {
{DAG_EVAL_RENDER, "DAG_EVAL_RENDER", 0, "Render", "Export objects as they appear in render"},
@ -385,12 +387,6 @@ void WM_OT_obj_export(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN);
}
static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
WM_event_add_fileselect(C, op);
return OPERATOR_RUNNING_MODAL;
}
static int wm_obj_import_exec(bContext *C, wmOperator *op)
{
OBJImportParams import_params{};
@ -485,9 +481,9 @@ void WM_OT_obj_import(wmOperatorType *ot)
ot->name = "Import Wavefront OBJ";
ot->description = "Load a Wavefront OBJ scene";
ot->idname = "WM_OT_obj_import";
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET;
ot->flag = OPTYPE_UNDO | OPTYPE_PRESET;
ot->invoke = wm_obj_import_invoke;
ot->invoke = blender::ed::io::filesel_drop_import_invoke;
ot->exec = wm_obj_import_exec;
ot->poll = WM_operator_winactive;
ot->ui = wm_obj_import_draw;
@ -559,4 +555,17 @@ void WM_OT_obj_import(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN);
}
namespace blender::ed::io {
void obj_file_handler_add()
{
auto fh = std::make_unique<blender::bke::FileHandlerType>();
STRNCPY(fh->idname, "IO_FH_obj");
STRNCPY(fh->import_operator, "WM_OT_obj_import");
STRNCPY(fh->label, "Wavefront OBJ");
STRNCPY(fh->file_extensions_str, ".obj");
fh->poll_drop = poll_file_object_drop;
bke::file_handler_add(std::move(fh));
}
} // namespace blender::ed::io
#endif /* WITH_IO_WAVEFRONT_OBJ */

View File

@ -12,3 +12,7 @@ struct wmOperatorType;
void WM_OT_obj_export(wmOperatorType *ot);
void WM_OT_obj_import(wmOperatorType *ot);
namespace blender::ed::io {
void obj_file_handler_add();
}

View File

@ -31,22 +31,27 @@
void ED_operatortypes_io()
{
using namespace blender;
#ifdef WITH_COLLADA
/* Collada operators: */
WM_operatortype_append(WM_OT_collada_export);
WM_operatortype_append(WM_OT_collada_import);
ed::io::collada_file_handler_add();
#endif
#ifdef WITH_ALEMBIC
WM_operatortype_append(WM_OT_alembic_import);
WM_operatortype_append(WM_OT_alembic_export);
ed::io::alembic_file_handler_add();
#endif
#ifdef WITH_USD
WM_operatortype_append(WM_OT_usd_import);
WM_operatortype_append(WM_OT_usd_export);
ed::io::usd_file_handler_add();
#endif
#ifdef WITH_IO_GPENCIL
WM_operatortype_append(WM_OT_gpencil_import_svg);
ed::io::gpencil_file_handler_add();
# ifdef WITH_PUGIXML
WM_operatortype_append(WM_OT_gpencil_export_svg);
# endif
@ -64,16 +69,19 @@ void ED_operatortypes_io()
#ifdef WITH_IO_WAVEFRONT_OBJ
WM_operatortype_append(WM_OT_obj_export);
WM_operatortype_append(WM_OT_obj_import);
ed::io::obj_file_handler_add();
#endif
#ifdef WITH_IO_PLY
WM_operatortype_append(WM_OT_ply_export);
WM_operatortype_append(WM_OT_ply_import);
ed::io::ply_file_handler_add();
#endif
#ifdef WITH_IO_STL
WM_operatortype_append(WM_OT_stl_import);
WM_operatortype_append(WM_OT_stl_export);
ed::io::stl_file_handler_add();
#endif
WM_operatortype_append(WM_OT_drop_import_file);
ED_dropbox_drop_import_file();

View File

@ -9,9 +9,12 @@
#ifdef WITH_IO_PLY
# include "BKE_context.hh"
# include "BKE_file_handler.hh"
# include "BKE_main.hh"
# include "BKE_report.h"
# include "BLI_string.h"
# include "WM_api.hh"
# include "WM_types.hh"
@ -37,6 +40,7 @@
# include "IO_ply.hh"
# include "io_ply_ops.hh"
# include "io_utils.hh"
static const EnumPropertyItem ply_vertex_colors_mode[] = {
{PLY_VERTEX_COLOR_NONE, "NONE", 0, "None", "Do not import/export color attributes"},
@ -236,11 +240,6 @@ void WM_OT_ply_export(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN);
}
static int wm_ply_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
return WM_operator_filesel(C, op, event);
}
static int wm_ply_import_exec(bContext *C, wmOperator *op)
{
PLYImportParams params{};
@ -286,6 +285,26 @@ static int wm_ply_import_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static void ui_ply_import_settings(uiLayout *layout, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiLayout *box = uiLayoutBox(layout);
uiLayout *col = uiLayoutColumn(box, false);
uiItemR(col, ptr, "global_scale", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "use_scene_unit", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "forward_axis", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "up_axis", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "merge_verts", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "import_colors", UI_ITEM_NONE, nullptr, ICON_NONE);
}
static void wm_ply_import_draw(bContext * /*C*/, wmOperator *op)
{
ui_ply_import_settings(op->layout, op->ptr);
}
void WM_OT_ply_import(wmOperatorType *ot)
{
PropertyRNA *prop;
@ -294,10 +313,11 @@ void WM_OT_ply_import(wmOperatorType *ot)
ot->description = "Import an PLY file as an object";
ot->idname = "WM_OT_ply_import";
ot->invoke = wm_ply_import_invoke;
ot->invoke = blender::ed::io::filesel_drop_import_invoke;
ot->exec = wm_ply_import_exec;
ot->ui = wm_ply_import_draw;
ot->poll = WM_operator_winactive;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET;
ot->flag = OPTYPE_UNDO | OPTYPE_PRESET;
WM_operator_properties_filesel(ot,
FILE_TYPE_FOLDER,
@ -333,4 +353,17 @@ void WM_OT_ply_import(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN);
}
namespace blender::ed::io {
void ply_file_handler_add()
{
auto fh = std::make_unique<blender::bke::FileHandlerType>();
STRNCPY(fh->idname, "IO_FH_ply");
STRNCPY(fh->import_operator, "WM_OT_ply_import");
STRNCPY(fh->label, "Stanford PLY");
STRNCPY(fh->file_extensions_str, ".ply");
fh->poll_drop = poll_file_object_drop;
bke::file_handler_add(std::move(fh));
}
} // namespace blender::ed::io
#endif /* WITH_IO_PLY */

View File

@ -12,3 +12,7 @@ struct wmOperatorType;
void WM_OT_ply_export(wmOperatorType *ot);
void WM_OT_ply_import(wmOperatorType *ot);
namespace blender::ed::io {
void ply_file_handler_add();
}

View File

@ -9,8 +9,11 @@
#ifdef WITH_IO_STL
# include "BKE_context.hh"
# include "BKE_file_handler.hh"
# include "BKE_report.h"
# include "BLI_string.h"
# include "WM_api.hh"
# include "WM_types.hh"
@ -29,6 +32,7 @@
# include "IO_stl.hh"
# include "io_stl_ops.hh"
# include "io_utils.hh"
static int wm_stl_export_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
@ -175,11 +179,6 @@ void WM_OT_stl_export(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN);
}
static int wm_stl_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
return WM_operator_filesel(C, op, event);
}
static int wm_stl_import_exec(bContext *C, wmOperator *op)
{
STLImportParams params{};
@ -237,6 +236,26 @@ static bool wm_stl_import_check(bContext * /*C*/, wmOperator *op)
return false;
}
static void ui_stl_import_settings(uiLayout *layout, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiLayout *box = uiLayoutBox(layout);
uiLayout *col = uiLayoutColumn(box, false);
uiItemR(col, ptr, "global_scale", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "use_scene_unit", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "use_facet_normal", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "forward_axis", UI_ITEM_NONE, IFACE_("Forward Axis"), ICON_NONE);
uiItemR(col, ptr, "up_axis", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "use_mesh_validate", UI_ITEM_NONE, nullptr, ICON_NONE);
}
static void wm_stl_import_draw(bContext * /*C*/, wmOperator *op)
{
ui_stl_import_settings(op->layout, op->ptr);
}
void WM_OT_stl_import(wmOperatorType *ot)
{
PropertyRNA *prop;
@ -245,11 +264,12 @@ void WM_OT_stl_import(wmOperatorType *ot)
ot->description = "Import an STL file as an object";
ot->idname = "WM_OT_stl_import";
ot->invoke = wm_stl_import_invoke;
ot->invoke = blender::ed::io::filesel_drop_import_invoke;
ot->exec = wm_stl_import_exec;
ot->poll = WM_operator_winactive;
ot->check = wm_stl_import_check;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET;
ot->ui = wm_stl_import_draw;
ot->flag = OPTYPE_UNDO | OPTYPE_PRESET;
WM_operator_properties_filesel(ot,
FILE_TYPE_FOLDER,
@ -284,4 +304,17 @@ void WM_OT_stl_import(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN);
}
namespace blender::ed::io {
void stl_file_handler_add()
{
auto fh = std::make_unique<blender::bke::FileHandlerType>();
STRNCPY(fh->idname, "IO_FH_stl");
STRNCPY(fh->import_operator, "WM_OT_stl_import");
STRNCPY(fh->label, "STL");
guishe marked this conversation as resolved Outdated

slt -> stl here and in the label below.

`slt` -> `stl` here and in the `label` below.
STRNCPY(fh->file_extensions_str, ".stl");
fh->poll_drop = poll_file_object_drop;
bke::file_handler_add(std::move(fh));
}
} // namespace blender::ed::io
#endif /* WITH_IO_STL */

View File

@ -12,3 +12,7 @@ struct wmOperatorType;
void WM_OT_stl_export(wmOperatorType *ot);
void WM_OT_stl_import(wmOperatorType *ot);
namespace blender::ed::io {
void stl_file_handler_add();
}

View File

@ -13,6 +13,7 @@
# include <cstring>
# include "BKE_context.hh"
# include "BKE_file_handler.hh"
# include "BKE_main.hh"
# include "BKE_report.h"
@ -42,6 +43,7 @@
# include "DEG_depsgraph.hh"
# include "io_usd.hh"
# include "io_utils.hh"
# include "usd.h"
# include <cstdio>
@ -457,7 +459,7 @@ static int wm_usd_import_invoke(bContext *C, wmOperator *op, const wmEvent *even
options->as_background_job = true;
op->customdata = options;
return WM_operator_filesel(C, op, event);
return blender::ed::io::filesel_drop_import_invoke(C, op, event);
}
static int wm_usd_import_exec(bContext *C, wmOperator *op)
@ -603,7 +605,6 @@ static void wm_usd_import_draw(bContext * /*C*/, wmOperator *op)
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiLayout *box = uiLayoutBox(layout);
uiLayout *col = uiLayoutColumnWithHeading(box, true, IFACE_("Data Types"));
uiItemR(col, ptr, "import_cameras", UI_ITEM_NONE, nullptr, ICON_NONE);
@ -672,7 +673,7 @@ void WM_OT_usd_import(wmOperatorType *ot)
ot->poll = WM_operator_winactive;
ot->ui = wm_usd_import_draw;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET;
ot->flag = OPTYPE_UNDO | OPTYPE_PRESET;
WM_operator_properties_filesel(ot,
FILE_TYPE_FOLDER | FILE_TYPE_USD,
@ -827,4 +828,17 @@ void WM_OT_usd_import(wmOperatorType *ot)
"Behavior when the name of an imported texture file conflicts with an existing file");
}
namespace blender::ed::io {
void usd_file_handler_add()
{
auto fh = std::make_unique<blender::bke::FileHandlerType>();
STRNCPY(fh->idname, "IO_FH_usd");
STRNCPY(fh->import_operator, "WM_OT_usd_import");
STRNCPY(fh->label, "Universal Scene Description");
STRNCPY(fh->file_extensions_str, ".usd;.usda;.usdc;.usdz");
fh->poll_drop = poll_file_object_drop;
bke::file_handler_add(std::move(fh));
guishe marked this conversation as resolved Outdated

As much as possible, try to use labels that match what's shown in the current File->Import menu. So this should at least be "Universal Scene Description" (see also the PLY and gpencil changes). Ideally the strings wouldn't be duplicated at all but haven't thought about how to do that easily right now.

As much as possible, try to use labels that match what's shown in the current `File`->`Import` menu. So this should at least be "Universal Scene Description" (see also the PLY and gpencil changes). Ideally the strings wouldn't be duplicated at all but haven't thought about how to do that easily right now.

Should include .ext?
Also I'm not sure if is Wavefront OBJ or just Wavefront for obj

Should include .ext? Also I'm not sure if is `Wavefront OBJ` or just `Wavefront` for obj

Also I'm not sure if is Wavefront OBJ or just Wavefront for obj

I think it's the other way around, if you have to drop a word, drop the "wavefront" but leave OBJ by all means. Almost no one knows what "wavefront" means or what it stands for these days.

> Also I'm not sure if is `Wavefront OBJ` or just `Wavefront` for obj I think it's the other way around, if you have to drop a word, drop the "wavefront" but leave OBJ by all means. Almost no one knows what "wavefront" means or what it stands for these days.
}
} // namespace blender::ed::io
#endif /* WITH_USD */

View File

@ -12,3 +12,6 @@ struct wmOperatorType;
void WM_OT_usd_export(wmOperatorType *ot);
void WM_OT_usd_import(wmOperatorType *ot);
namespace blender::ed::io {
void usd_file_handler_add();
}

View File

@ -0,0 +1,50 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
guishe marked this conversation as resolved Outdated

Looks like this file is missing copyright info

Looks like this file is missing copyright info
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_context.hh"
#include "DNA_space_types.h"
#include "ED_fileselect.hh"
#include "RNA_access.hh"
#include "WM_api.hh"
#include "io_utils.hh"
namespace blender::ed::io {
int filesel_drop_import_invoke(bContext *C, wmOperator *op, const wmEvent * /* event */)
{
PropertyRNA *filepath_prop = RNA_struct_find_property(op->ptr, "filepath");
PropertyRNA *directory_prop = RNA_struct_find_property(op->ptr, "directory");
if ((filepath_prop && RNA_property_is_set(op->ptr, filepath_prop)) ||
(directory_prop && RNA_property_is_set(op->ptr, directory_prop)))
{
return WM_operator_props_dialog_popup(C, op, 350);
}
WM_event_add_fileselect(C, op);
return OPERATOR_RUNNING_MODAL;
}
bool poll_file_object_drop(const bContext *C, blender::bke::FileHandlerType * /*fh*/)
{
View3D *v3d = CTX_wm_view3d(C);
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
ARegion *region = CTX_wm_region(C);
if (!region || region->regiontype != RGN_TYPE_WINDOW) {
return false;
}
if (v3d) {
return true;
}
if (space_outliner && space_outliner->outlinevis == SO_VIEW_LAYER) {
return true;
}
guishe marked this conversation as resolved Outdated

I wonder if the OP_IS_INVOKE flag can be used here to make this test here
Because creating the operator in #116646
for drawing probably won't set this flag
People may want add export collection panel to the npanel

I wonder if the `OP_IS_INVOKE` flag can be used here to make this test here Because creating the operator in https://projects.blender.org/blender/blender/pulls/116646 for drawing probably won't set this flag People may want add export collection panel to the npanel
return false;
}
guishe marked this conversation as resolved Outdated

Comments within a function generally don't get the doxygen styling-- the first line will be on the same line as /*

Comments within a function generally don't get the doxygen styling-- the first line will be on the same line as `/*`
} // namespace blender::ed::io

View File

@ -0,0 +1,26 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
guishe marked this conversation as resolved Outdated

Copyright here too

Copyright here too
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "WM_types.hh"
struct wmOperator;
struct wmOperatorType;
struct wmDrag;
struct wmDropBox;
namespace blender::bke {
struct FileHanlderType;
} // namespace blender::bke
namespace blender::ed::io {
/**
* Shows a import dialog if the operator was invoked with filepath properties set, otherwise
* invokes the fileselect window.
*/
int filesel_drop_import_invoke(bContext *C, wmOperator *op, const wmEvent *event);
bool poll_file_object_drop(const bContext *C, blender::bke::FileHandlerType *fh);
} // namespace blender::ed::io