Blender V4.3
object_volume.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstring>
10
11#include "BLI_listbase.h"
12#include "BLI_math_base.h"
13#include "BLI_path_utils.hh"
14#include "BLI_string.h"
15
16#include "DNA_object_types.h"
17#include "DNA_volume_types.h"
18
19#include "RNA_access.hh"
20#include "RNA_define.hh"
21
22#include "BKE_context.hh"
23#include "BKE_lib_id.hh"
24#include "BKE_main.hh"
25#include "BKE_report.hh"
26#include "BKE_volume.hh"
27
28#include "WM_api.hh"
29#include "WM_types.hh"
30
31#include "ED_image.hh"
32#include "ED_object.hh"
33#include "ED_screen.hh"
34
35#include "object_intern.hh"
36
37namespace blender::ed::object {
38
39/* Volume Add */
40
41static Object *object_volume_add(bContext *C, wmOperator *op, const char *name)
42{
43 ushort local_view_bits;
44 float loc[3], rot[3];
45
46 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
47
48 return add_type(C, OB_VOLUME, name, loc, rot, false, local_view_bits);
49}
50
52{
53 return (object_volume_add(C, op, nullptr) != nullptr) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
54}
55
57{
58 /* identifiers */
59 ot->name = "Add Volume";
60 ot->description = "Add a volume object to the scene";
61 ot->idname = "OBJECT_OT_volume_add";
62
63 /* api callbacks */
66
67 /* flags */
69
70 add_generic_props(ot, false);
71}
72
73/* Volume Import */
74
76{
77 Main *bmain = CTX_data_main(C);
78 const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path");
79 bool imported = false;
80
82 LISTBASE_FOREACH (ImageFrameRange *, range, &ranges) {
83 char filepath[FILE_MAX];
84 BLI_path_split_file_part(range->filepath, filepath, sizeof(filepath));
86
87 Object *object = object_volume_add(C, op, filepath);
88 Volume *volume = (Volume *)object->data;
89
90 STRNCPY(volume->filepath, range->filepath);
91 if (is_relative_path) {
92 BLI_path_rel(volume->filepath, BKE_main_blendfile_path(bmain));
93 }
94
95 if (!BKE_volume_load(volume, bmain)) {
98 "Volume \"%s\" failed to load: %s",
99 filepath,
101 BKE_id_delete(bmain, &object->id);
102 BKE_id_delete(bmain, &volume->id);
103 continue;
104 }
105 if (BKE_volume_is_points_only(volume)) {
108 "Volume \"%s\" contains points, only voxel grids are supported",
109 filepath);
110 BKE_id_delete(bmain, &object->id);
111 BKE_id_delete(bmain, &volume->id);
112 continue;
113 }
114
115 /* Set sequence parameters after trying to load the first frame, for file validation we want
116 * to use a consistent frame rather than whatever corresponds to the current scene frame. */
117 volume->is_sequence = (range->length > 1);
118 volume->frame_duration = (volume->is_sequence) ? range->length : 0;
119 volume->frame_start = 1;
120 volume->frame_offset = (volume->is_sequence) ? range->offset - 1 : 0;
121
122 if (BKE_volume_is_y_up(volume)) {
123 object->rot[0] += M_PI_2;
124 }
125
126 BKE_volume_unload(volume);
127
128 imported = true;
129 }
130 BLI_freelistN(&ranges);
131
132 return (imported) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
133}
134
135static int volume_import_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
136{
137 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
138 return volume_import_exec(C, op);
139 }
140
141 RNA_string_set(op->ptr, "filepath", U.textudir);
143
145}
146
148{
149 /* identifiers */
150 ot->name = "Import OpenVDB Volume";
151 ot->description = "Import OpenVDB volume file";
152 ot->idname = "OBJECT_OT_volume_import";
153
154 /* api callbacks */
157
158 /* flags */
160
161 /* properties */
170
172 ot->srna,
173 "use_sequence_detection",
174 true,
175 "Detect Sequences",
176 "Automatically detect animated sequences in selected volume files (based on file names)");
177
178 add_generic_props(ot, false);
179}
180
181} // namespace blender::ed::object
Main * CTX_data_main(const bContext *C)
void BKE_id_delete(Main *bmain, void *idv) ATTR_NONNULL()
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:832
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Volume data-block.
bool BKE_volume_is_y_up(const Volume *volume)
bool BKE_volume_load(const Volume *volume, const Main *bmain)
bool BKE_volume_is_points_only(const Volume *volume)
void BKE_volume_unload(Volume *volume)
const char * BKE_volume_grids_error_msg(const Volume *volume)
#define LISTBASE_FOREACH(type, var, list)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:496
#define M_PI_2
bool bool BLI_path_extension_strip(char *path) ATTR_NONNULL(1)
#define FILE_MAX
void void void BLI_path_split_file_part(const char *filepath, char *file, size_t file_maxncpy) ATTR_NONNULL(1
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
#define STRNCPY(dst, src)
Definition BLI_string.h:593
unsigned short ushort
Object is a sort of wrapper for general info.
@ OB_VOLUME
@ FILE_SORT_DEFAULT
@ FILE_SPECIAL
@ FILE_TYPE_VOLUME
@ FILE_TYPE_FOLDER
@ FILE_DEFAULTDISPLAY
@ OPERATOR_RUNNING_MODAL
ListBase ED_image_filesel_detect_sequences(blender::StringRefNull root_path, wmOperator *op, bool detect_udim)
bool ED_operator_objectmode(bContext *C)
@ WM_FILESEL_FILES
Definition WM_api.hh:937
@ WM_FILESEL_DIRECTORY
Definition WM_api.hh:934
@ WM_FILESEL_RELPATH
Definition WM_api.hh:933
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:936
@ FILE_OPENFILE
Definition WM_api.hh:945
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
unsigned int U
Definition btGjkEpa3.h:78
#define rot(x, k)
Object * add_type(bContext *C, int type, const char *name, const float loc[3], const float rot[3], bool enter_editmode, unsigned short local_view_bits) ATTR_NONNULL(1) ATTR_RETURNS_NONNULL
static int volume_import_invoke(bContext *C, wmOperator *op, const wmEvent *)
static Object * object_volume_add(bContext *C, wmOperator *op, const char *name)
static int object_volume_add_exec(bContext *C, wmOperator *op)
void OBJECT_OT_volume_add(wmOperatorType *ot)
void OBJECT_OT_volume_import(wmOperatorType *ot)
static int volume_import_exec(bContext *C, wmOperator *op)
void add_generic_props(wmOperatorType *ot, bool do_editmode)
void add_generic_get_opts(bContext *C, wmOperator *op, char view_align_axis, float r_loc[3], float r_rot[3], float r_scale[3], bool *r_enter_editmode, unsigned short *r_local_view_bits, bool *r_is_view_aligned)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1022
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
StructRNA * srna
Definition WM_types.hh:1080
struct ReportList * reports
struct PointerRNA * ptr
void WM_event_add_fileselect(bContext *C, wmOperator *op)
wmOperatorType * ot
Definition wm_files.cc:4125
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)