GPencil: Allow import several SVG at time
For SVG is very convenient to be able to import several SVG in one operation. Each SVG is imported as a new Grease Pencil object. Also, now the SVG file name is used as Object name. Important: As all SVG imported are converted to Grease Pencil object in the same location of the 3D cursor, the SVG imported are not moved and the result may require a manual fix of location. The same is applied for depth order, the files are imported in alphabetic order according to the File list. Reviewed By: mendio, pepeland Differential Revision: https://developer.blender.org/D14865
This commit is contained in:
parent
f263334529
commit
670ced9758
Notes:
blender-bot
2023-02-14 07:25:46 +01:00
Referenced by issue #100749, Blender LTS: Maintenance Task 3.3
|
@ -9,6 +9,8 @@
|
|||
|
||||
# include "BLI_path_util.h"
|
||||
|
||||
# include "MEM_guardedalloc.h"
|
||||
|
||||
# include "DNA_gpencil_types.h"
|
||||
# include "DNA_space_types.h"
|
||||
|
||||
|
@ -63,7 +65,8 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
|
||||
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
|
||||
if (!RNA_struct_property_is_set(op->ptr, "filepath") ||
|
||||
!(RNA_struct_find_property(op->ptr, "directory"))) {
|
||||
BKE_report(op->reports, RPT_ERROR, "No filename given");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
@ -75,9 +78,6 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
|
|||
}
|
||||
View3D *v3d = get_invoke_view3d(C);
|
||||
|
||||
char filename[FILE_MAX];
|
||||
RNA_string_get(op->ptr, "filepath", filename);
|
||||
|
||||
/* Set flags. */
|
||||
int flag = 0;
|
||||
|
||||
|
@ -101,13 +101,31 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
|
|||
.resolution = resolution,
|
||||
};
|
||||
|
||||
/* Do Import. */
|
||||
WM_cursor_wait(1);
|
||||
const bool done = gpencil_io_import(filename, ¶ms);
|
||||
WM_cursor_wait(0);
|
||||
/* Loop all selected files to import them. All SVG imported shared the same import
|
||||
* parameters, but they are created in separated grease pencil objects. */
|
||||
PropertyRNA *prop;
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
|
||||
char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
|
||||
|
||||
if (!done) {
|
||||
BKE_report(op->reports, RPT_WARNING, "Unable to import SVG");
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
|
||||
char file_path[FILE_MAX];
|
||||
RNA_PROP_BEGIN (op->ptr, itemptr, prop) {
|
||||
char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
|
||||
BLI_join_dirfile(file_path, sizeof(file_path), directory, filename);
|
||||
MEM_freeN(filename);
|
||||
|
||||
/* Do Import. */
|
||||
WM_cursor_wait(1);
|
||||
RNA_string_get(&itemptr, "name", params.filename);
|
||||
const bool done = gpencil_io_import(file_path, ¶ms);
|
||||
WM_cursor_wait(0);
|
||||
if (!done) {
|
||||
BKE_reportf(op->reports, RPT_WARNING, "Unable to import '%s'", file_path);
|
||||
}
|
||||
}
|
||||
RNA_PROP_END;
|
||||
}
|
||||
MEM_freeN(directory);
|
||||
}
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
|
@ -149,10 +167,11 @@ void WM_OT_gpencil_import_svg(wmOperatorType *ot)
|
|||
ot->check = wm_gpencil_import_svg_common_check;
|
||||
|
||||
WM_operator_properties_filesel(ot,
|
||||
FILE_TYPE_OBJECT_IO,
|
||||
FILE_TYPE_FOLDER | FILE_TYPE_OBJECT_IO,
|
||||
FILE_BLENDER,
|
||||
FILE_OPENFILE,
|
||||
WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS,
|
||||
WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS |
|
||||
WM_FILESEL_DIRECTORY | WM_FILESEL_FILES,
|
||||
FILE_DEFAULTDISPLAY,
|
||||
FILE_SORT_DEFAULT);
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ typedef struct GpencilIOParams {
|
|||
/** Stroke sampling factor. */
|
||||
float stroke_sample;
|
||||
int32_t resolution;
|
||||
/** Filename to be used in new objects. */
|
||||
char filename[128];
|
||||
} GpencilIOParams;
|
||||
|
||||
/* GpencilIOParams->flag. */
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "BKE_material.h"
|
||||
|
||||
#include "ED_gpencil.h"
|
||||
#include "ED_object.h"
|
||||
|
||||
#include "gpencil_io_import_base.hh"
|
||||
|
||||
|
@ -27,10 +28,22 @@ GpencilImporter::GpencilImporter(const GpencilIOParams *iparams) : GpencilIO(ipa
|
|||
|
||||
Object *GpencilImporter::create_object()
|
||||
{
|
||||
const float *cur = scene_->cursor.location;
|
||||
const float *cur_loc = scene_->cursor.location;
|
||||
const float rot[3] = {0.0f};
|
||||
ushort local_view_bits = (params_.v3d && params_.v3d->localvd) ? params_.v3d->local_view_uuid :
|
||||
(ushort)0;
|
||||
Object *ob_gpencil = ED_gpencil_add_object(params_.C, cur, local_view_bits);
|
||||
|
||||
Object *ob_gpencil = ED_object_add_type(params_.C,
|
||||
OB_GPENCIL,
|
||||
(params_.filename != nullptr) ? params_.filename :
|
||||
nullptr,
|
||||
cur_loc,
|
||||
rot,
|
||||
false,
|
||||
local_view_bits);
|
||||
|
||||
/* Set object defaults. */
|
||||
ED_gpencil_add_defaults(params_.C, ob_gpencil);
|
||||
|
||||
return ob_gpencil;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue