Files
test/source/blender/editors/object/object_volume.cc
John Kiril Swenson 5a0c0826b7 VSE: Support adding multiple images
Before, trying to add multiple strips would always create an image
sequence. This patch allows images to be added in bulk, just like movie
& sound strips.

A new "Image Sequence Detection" property has been added which works
like the image editor. Toggling it off will always import individual
images and never create image sequences.
If it's on, you can also optionally "Use Placeholders" to fill in gaps,
which exhibits the same behavior as before (placeholders will show as
pink in the preview until you have the files on your system in the right
folders).

You can even add both image sequences and regular images at the same
time. Only caveat is that this doesn't work if the regular images are
interspersed within sequence frames in the file browser view when you
add them. I.e., all frames of a sequence should be listed without any
regular frames in between (but the sequence frame numbers don't have to
be in order). This can usually be ensured on all sort types (like date,
name).

NOTE: This patch also replaces the "end_frame" property on image /
effect strips with "length," to support behavior when multiple strips
are involved. This is a breaking change for the API, but is a fairly
small change and will be included in the release notes.

The "length" property allows one to adjust all image strips' lengths at
once. It does nothing for image sequences, however, since their lengths
are defined by their image count.

Pull Request: https://projects.blender.org/blender/blender/pulls/143974
2025-08-19 00:09:04 +02:00

185 lines
5.1 KiB
C++

/* SPDX-FileCopyrightText: 2008 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edobj
*/
#include <cstring>
#include "BLI_listbase.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "DNA_object_types.h"
#include "DNA_volume_types.h"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "BKE_context.hh"
#include "BKE_lib_id.hh"
#include "BKE_main.hh"
#include "BKE_report.hh"
#include "BKE_volume.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "ED_image.hh"
#include "ED_object.hh"
#include "ED_screen.hh"
#include "object_intern.hh"
namespace blender::ed::object {
/* Volume Add */
static Object *object_volume_add(bContext *C, wmOperator *op, const char *name)
{
ushort local_view_bits;
float loc[3], rot[3];
add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
return add_type(C, OB_VOLUME, name, loc, rot, false, local_view_bits);
}
static wmOperatorStatus object_volume_add_exec(bContext *C, wmOperator *op)
{
return (object_volume_add(C, op, nullptr) != nullptr) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
void OBJECT_OT_volume_add(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Add Volume";
ot->description = "Add a volume object to the scene";
ot->idname = "OBJECT_OT_volume_add";
/* API callbacks. */
ot->exec = object_volume_add_exec;
ot->poll = ED_operator_objectmode;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
add_generic_props(ot, false);
}
/* Volume Import */
static wmOperatorStatus volume_import_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path");
bool imported = false;
ListBase ranges = ED_image_filesel_detect_sequences(BKE_main_blendfile_path(bmain), op, false);
LISTBASE_FOREACH (ImageFrameRange *, range, &ranges) {
char filepath[FILE_MAX];
BLI_path_split_file_part(range->filepath, filepath, sizeof(filepath));
BLI_path_extension_strip(filepath);
Object *object = object_volume_add(C, op, filepath);
Volume *volume = (Volume *)object->data;
STRNCPY(volume->filepath, range->filepath);
if (is_relative_path) {
BLI_path_rel(volume->filepath, BKE_main_blendfile_path(bmain));
}
if (!BKE_volume_load(volume, bmain)) {
BKE_reportf(op->reports,
RPT_WARNING,
"Volume \"%s\" failed to load: %s",
filepath,
BKE_volume_grids_error_msg(volume));
BKE_id_delete(bmain, &object->id);
BKE_id_delete(bmain, &volume->id);
continue;
}
if (BKE_volume_is_points_only(volume)) {
BKE_reportf(op->reports,
RPT_WARNING,
"Volume \"%s\" contains points, only voxel grids are supported",
filepath);
BKE_id_delete(bmain, &object->id);
BKE_id_delete(bmain, &volume->id);
continue;
}
/* Set sequence parameters after trying to load the first frame, for file validation we want
* to use a consistent frame rather than whatever corresponds to the current scene frame. */
volume->is_sequence = (range->length > 1);
volume->frame_duration = (volume->is_sequence) ? range->length : 0;
volume->frame_start = 1;
volume->frame_offset = (volume->is_sequence) ? range->offset - 1 : 0;
if (BKE_volume_is_y_up(volume)) {
object->rot[0] += M_PI_2;
}
BKE_volume_unload(volume);
imported = true;
BLI_freelistN(&range->frames);
}
BLI_freelistN(&ranges);
return (imported) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
static wmOperatorStatus volume_import_invoke(bContext *C,
wmOperator *op,
const wmEvent * /*event*/)
{
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
return volume_import_exec(C, op);
}
RNA_string_set(op->ptr, "filepath", U.textudir);
WM_event_add_fileselect(C, op);
return OPERATOR_RUNNING_MODAL;
}
void OBJECT_OT_volume_import(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Import OpenVDB Volume";
ot->description = "Import OpenVDB volume file";
ot->idname = "OBJECT_OT_volume_import";
/* API callbacks. */
ot->exec = volume_import_exec;
ot->invoke = volume_import_invoke;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
WM_operator_properties_filesel(ot,
FILE_TYPE_FOLDER | FILE_TYPE_VOLUME,
FILE_SPECIAL,
FILE_OPENFILE,
WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILES |
WM_FILESEL_RELPATH,
FILE_DEFAULTDISPLAY,
FILE_SORT_DEFAULT);
RNA_def_boolean(
ot->srna,
"use_sequence_detection",
true,
"Detect Sequences",
"Automatically detect animated sequences in selected volume files (based on file names)");
add_generic_props(ot, false);
}
} // namespace blender::ed::object