Blender V5.0
rna_cachefile.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "DNA_scene_types.h"
11
12#include "BLT_translation.hh"
13
14#include "RNA_define.hh"
15#include "RNA_enum_types.hh"
16
17#include "rna_internal.hh"
18
20 {CACHEFILE_VELOCITY_UNIT_SECOND, "SECOND", 0, "Second", ""},
21 {CACHEFILE_VELOCITY_UNIT_FRAME, "FRAME", 0, "Frame", ""},
22 {0, nullptr, 0, nullptr, nullptr},
23};
24
25#ifdef RNA_RUNTIME
26
27# include "BLI_math_base.h"
28
29# include "BKE_cachefile.hh"
30# include "BKE_context.hh"
31# include "BKE_report.hh"
32
33# include "DEG_depsgraph.hh"
34# include "DEG_depsgraph_build.hh"
35
36# include "WM_api.hh"
37# include "WM_types.hh"
38
39# ifdef WITH_ALEMBIC
40# include "ABC_alembic.h"
41# endif
42
43static void rna_CacheFile_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
44{
45 CacheFile *cache_file = (CacheFile *)ptr->data;
46
49}
50
51static void rna_CacheFileLayer_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
52{
53 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
54
57}
58
59static void rna_CacheFile_object_paths_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
60{
61 CacheFile *cache_file = (CacheFile *)ptr->data;
62 rna_iterator_listbase_begin(iter, ptr, &cache_file->object_paths, nullptr);
63}
64
65static PointerRNA rna_CacheFile_active_layer_get(PointerRNA *ptr)
66{
67 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
69 *ptr, &RNA_CacheFileLayer, BKE_cachefile_get_active_layer(cache_file));
70}
71
72static void rna_CacheFile_active_layer_set(PointerRNA *ptr, PointerRNA value, ReportList *reports)
73{
74 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
75 int index = BLI_findindex(&cache_file->layers, value.data);
76 if (index == -1) {
77 BKE_reportf(reports,
79 "Layer '%s' not found in object '%s'",
80 ((CacheFileLayer *)value.data)->filepath,
81 cache_file->id.name + 2);
82 return;
83 }
84
85 cache_file->active_layer = index + 1;
86}
87
88static int rna_CacheFile_active_layer_index_get(PointerRNA *ptr)
89{
90 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
91 return cache_file->active_layer - 1;
92}
93
94static void rna_CacheFile_active_layer_index_set(PointerRNA *ptr, int value)
95{
96 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
97 cache_file->active_layer = value + 1;
98}
99
100static void rna_CacheFile_active_layer_index_range(
101 PointerRNA *ptr, int *min, int *max, int * /*softmin*/, int * /*softmax*/)
102{
103 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
104
105 *min = 0;
106 *max = max_ii(0, BLI_listbase_count(&cache_file->layers) - 1);
107}
108
109static void rna_CacheFileLayer_hidden_flag_set(PointerRNA *ptr, const bool value)
110{
111 CacheFileLayer *layer = (CacheFileLayer *)ptr->data;
112
113 if (value) {
114 layer->flag |= CACHEFILE_LAYER_HIDDEN;
115 }
116 else {
117 layer->flag &= ~CACHEFILE_LAYER_HIDDEN;
118 }
119}
120
121static CacheFileLayer *rna_CacheFile_layer_new(CacheFile *cache_file,
122 bContext *C,
123 ReportList *reports,
124 const char *filepath)
125{
126 CacheFileLayer *layer = BKE_cachefile_add_layer(cache_file, filepath);
127 if (layer == nullptr) {
129 reports, RPT_ERROR, "Cannot add a layer to CacheFile '%s'", cache_file->id.name + 2);
130 return nullptr;
131 }
132
134 BKE_cachefile_reload(depsgraph, cache_file);
136 return layer;
137}
138
139static void rna_CacheFile_layer_remove(CacheFile *cache_file, bContext *C, PointerRNA *layer_ptr)
140{
141 CacheFileLayer *layer = static_cast<CacheFileLayer *>(layer_ptr->data);
142 BKE_cachefile_remove_layer(cache_file, layer);
144 BKE_cachefile_reload(depsgraph, cache_file);
146}
147
148#else
149
150/* cachefile.object_paths */
152{
153 StructRNA *srna = RNA_def_struct(brna, "CacheObjectPath", nullptr);
154 RNA_def_struct_sdna(srna, "CacheObjectPath");
155 RNA_def_struct_ui_text(srna, "Object Path", "Path of an object inside of an Alembic archive");
156 RNA_def_struct_ui_icon(srna, ICON_NONE);
157
159
160 PropertyRNA *prop = RNA_def_property(srna, "path", PROP_STRING, PROP_NONE);
161 RNA_def_property_ui_text(prop, "Path", "Object path");
164
166}
167
168/* cachefile.object_paths */
170{
171 RNA_def_property_srna(cprop, "CacheObjectPaths");
172 StructRNA *srna = RNA_def_struct(brna, "CacheObjectPaths", nullptr);
173 RNA_def_struct_sdna(srna, "CacheFile");
174 RNA_def_struct_ui_text(srna, "Object Paths", "Collection of object paths");
175}
176
178{
179 StructRNA *srna = RNA_def_struct(brna, "CacheFileLayer", nullptr);
180 RNA_def_struct_sdna(srna, "CacheFileLayer");
182 srna,
183 "Cache Layer",
184 "Layer of the cache, used to load or override data from the first the first layer");
185
186 PropertyRNA *prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
187 RNA_def_property_ui_text(prop, "File Path", "Path to the archive");
189 RNA_def_property_update(prop, 0, "rna_CacheFileLayer_update");
190
191 prop = RNA_def_property(srna, "hide_layer", PROP_BOOLEAN, PROP_NONE);
193 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CacheFileLayer_hidden_flag_set");
194 RNA_def_property_ui_icon(prop, ICON_HIDE_OFF, -1);
195 RNA_def_property_ui_text(prop, "Hide Layer", "Do not load data from this layer");
196 RNA_def_property_update(prop, 0, "rna_CacheFileLayer_update");
197}
198
200{
201 RNA_def_property_srna(cprop, "CacheFileLayers");
202 StructRNA *srna = RNA_def_struct(brna, "CacheFileLayers", nullptr);
203 RNA_def_struct_sdna(srna, "CacheFile");
204 RNA_def_struct_ui_text(srna, "Cache Layers", "Collection of cache layers");
205
206 PropertyRNA *prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
207 RNA_def_property_struct_type(prop, "CacheFileLayer");
209 prop, "rna_CacheFile_active_layer_get", "rna_CacheFile_active_layer_set", nullptr, nullptr);
211 RNA_def_property_ui_text(prop, "Active Layer", "Active layer of the CacheFile");
212
213 /* Add a layer. */
214 FunctionRNA *func = RNA_def_function(srna, "new", "rna_CacheFile_layer_new");
216 RNA_def_function_ui_description(func, "Add a new layer");
218 func, "filepath", "File Path", 0, "", "File path to the archive used as a layer");
220 /* Return type. */
221 parm = RNA_def_pointer(func, "layer", "CacheFileLayer", "", "Newly created layer");
222 RNA_def_function_return(func, parm);
223
224 /* Remove a layer. */
225 func = RNA_def_function(srna, "remove", "rna_CacheFile_layer_remove");
227 RNA_def_function_ui_description(func, "Remove an existing layer from the cache file");
228 parm = RNA_def_pointer(func, "layer", "CacheFileLayer", "", "Layer to remove");
231}
232
234{
235 StructRNA *srna = RNA_def_struct(brna, "CacheFile", "ID");
236 RNA_def_struct_sdna(srna, "CacheFile");
237 RNA_def_struct_ui_text(srna, "CacheFile", "");
238 RNA_def_struct_ui_icon(srna, ICON_FILE);
239
241
242 PropertyRNA *prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
243 RNA_def_property_ui_text(prop, "File Path", "Path to external displacements file");
245 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
246
247 prop = RNA_def_property(srna, "is_sequence", PROP_BOOLEAN, PROP_NONE);
249 prop, "Sequence", "Whether the cache is separated in a series of files");
250 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
251
252 /* ----------------- For Scene time ------------------- */
253
254 prop = RNA_def_property(srna, "override_frame", PROP_BOOLEAN, PROP_NONE);
256 "Override Frame",
257 "Whether to use a custom frame for looking up data in the cache file,"
258 " instead of using the current scene frame");
259 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
260
261 prop = RNA_def_property(srna, "frame", PROP_FLOAT, PROP_NONE);
262 RNA_def_property_float_sdna(prop, nullptr, "frame");
265 "Frame",
266 "The time to use for looking up the data in the cache file,"
267 " or to determine which file to use in a file sequence");
268 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
269
270 prop = RNA_def_property(srna, "frame_offset", PROP_FLOAT, PROP_NONE);
271 RNA_def_property_float_sdna(prop, nullptr, "frame_offset");
274 "Frame Offset",
275 "Subtracted from the current frame to use for "
276 "looking up the data in the cache file, or to "
277 "determine which file to use in a file sequence");
278 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
279
280 /* ----------------- Axis Conversion ----------------- */
281
282 prop = RNA_def_property(srna, "forward_axis", PROP_ENUM, PROP_NONE);
283 RNA_def_property_enum_sdna(prop, nullptr, "forward_axis");
285 RNA_def_property_ui_text(prop, "Forward", "");
286 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
287
288 prop = RNA_def_property(srna, "up_axis", PROP_ENUM, PROP_NONE);
289 RNA_def_property_enum_sdna(prop, nullptr, "up_axis");
291 RNA_def_property_ui_text(prop, "Up", "");
292 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
293
294 prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
295 RNA_def_property_float_sdna(prop, nullptr, "scale");
296 RNA_def_property_range(prop, 0.0001f, 1000.0f);
298 prop,
299 "Scale",
300 "Value by which to enlarge or shrink the object with respect to the world's origin"
301 " (only applicable through a Transform Cache constraint)");
302 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
303
304 /* object paths */
305 prop = RNA_def_property(srna, "object_paths", PROP_COLLECTION, PROP_NONE);
306 RNA_def_property_collection_sdna(prop, nullptr, "object_paths", nullptr);
308 "rna_CacheFile_object_paths_begin",
309 "rna_iterator_listbase_next",
310 "rna_iterator_listbase_end",
311 "rna_iterator_listbase_get",
312 nullptr,
313 nullptr,
314 nullptr,
315 nullptr);
316 RNA_def_property_struct_type(prop, "CacheObjectPath");
317 RNA_def_property_srna(prop, "CacheObjectPaths");
319 prop, "Object Paths", "Paths of the objects inside the Alembic archive");
320
321 /* ----------------- Alembic Velocity Attribute ----------------- */
322
323 prop = RNA_def_property(srna, "velocity_name", PROP_STRING, PROP_NONE);
325 "Velocity Attribute",
326 "Name of the Alembic attribute used for generating motion blur data");
327 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
329
330 prop = RNA_def_property(srna, "velocity_unit", PROP_ENUM, PROP_NONE);
331 RNA_def_property_enum_sdna(prop, nullptr, "velocity_unit");
334 prop,
335 "Velocity Unit",
336 "Define how the velocity vectors are interpreted with regard to time, 'frame' means "
337 "the delta time is 1 frame, 'second' means the delta time is 1 / FPS");
339 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
341
342 /* ----------------- Alembic Layers ----------------- */
343
344 prop = RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
345 RNA_def_property_collection_sdna(prop, nullptr, "layers", nullptr);
346 RNA_def_property_struct_type(prop, "CacheFileLayer");
348 RNA_def_property_ui_text(prop, "Cache Layers", "Layers of the cache");
349 rna_def_cachefile_layers(brna, prop);
350
351 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
353 RNA_def_property_int_sdna(prop, nullptr, "active_layer");
355 "rna_CacheFile_active_layer_index_get",
356 "rna_CacheFile_active_layer_index_set",
357 "rna_CacheFile_active_layer_index_range");
358
360
362
364}
365
372
373#endif
void BKE_cachefile_remove_layer(CacheFile *cache_file, CacheFileLayer *layer)
Definition cachefile.cc:444
CacheFileLayer * BKE_cachefile_get_active_layer(CacheFile *cache_file)
Definition cachefile.cc:438
CacheFileLayer * BKE_cachefile_add_layer(CacheFile *cache_file, const char filepath[1024])
Definition cachefile.cc:418
void BKE_cachefile_reload(Depsgraph *depsgraph, CacheFile *cache_file)
Definition cachefile.cc:318
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
@ RPT_ERROR
Definition BKE_report.hh:39
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:524
MINLINE int max_ii(int a, int b)
#define BLT_I18NCONTEXT_UNIT
#define BLT_I18NCONTEXT_EDITOR_FILEBROWSER
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ CACHEFILE_VELOCITY_UNIT_SECOND
@ CACHEFILE_VELOCITY_UNIT_FRAME
@ CACHEFILE_LAYER_HIDDEN
#define MAXFRAME
ParameterFlag
Definition RNA_types.hh:544
@ PARM_RNAPTR
Definition RNA_types.hh:547
@ PARM_REQUIRED
Definition RNA_types.hh:545
@ FUNC_USE_REPORTS
Definition RNA_types.hh:914
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:913
@ PROP_FLOAT
Definition RNA_types.hh:164
@ PROP_BOOLEAN
Definition RNA_types.hh:162
@ PROP_ENUM
Definition RNA_types.hh:166
@ PROP_INT
Definition RNA_types.hh:163
@ PROP_STRING
Definition RNA_types.hh:165
@ PROP_POINTER
Definition RNA_types.hh:167
@ PROP_COLLECTION
Definition RNA_types.hh:168
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:503
PropertyFlag
Definition RNA_types.hh:300
@ PROP_THICK_WRAP
Definition RNA_types.hh:423
@ PROP_ANIMATABLE
Definition RNA_types.hh:319
@ PROP_PATH_SUPPORTS_BLEND_RELATIVE
Definition RNA_types.hh:456
@ PROP_EDITABLE
Definition RNA_types.hh:306
@ PROP_NEVER_NULL
Definition RNA_types.hh:377
@ PROP_NONE
Definition RNA_types.hh:233
@ PROP_UNSIGNED
Definition RNA_types.hh:249
@ PROP_FILEPATH
Definition RNA_types.hh:236
#define C
Definition RandGen.cpp:29
#define ND_DRAW
Definition WM_types.hh:461
#define NC_OBJECT
Definition WM_types.hh:379
BPy_StructRNA * depsgraph
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, ListBase *lb, IteratorSkipFunc skip)
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
void rna_def_animdata_common(StructRNA *srna)
const EnumPropertyItem rna_enum_velocity_unit_items[]
void RNA_def_cachefile(BlenderRNA *brna)
static void rna_def_cachefile_layer(BlenderRNA *brna)
static void rna_def_cachefile(BlenderRNA *brna)
static void rna_def_alembic_object_path(BlenderRNA *brna)
static void rna_def_cachefile_layers(BlenderRNA *brna, PropertyRNA *cprop)
static void rna_def_cachefile_object_paths(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_define_lib_overridable(const bool make_overridable)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_function_flag(FunctionRNA *func, int flag)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_override_clear_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
const EnumPropertyItem rna_enum_object_axis_items[]
#define min(a, b)
Definition sort.cc:36
char name[258]
Definition DNA_ID.h:432
void * data
Definition RNA_types.hh:53
max
Definition text_draw.cc:251
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4238