Blender V4.3
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
10#include "DNA_scene_types.h"
11
12#include "BLT_translation.hh"
13
14#include "RNA_access.hh"
15#include "RNA_define.hh"
16#include "RNA_enum_types.hh"
17
18#include "rna_internal.hh"
19
21 {CACHEFILE_VELOCITY_UNIT_SECOND, "SECOND", 0, "Second", ""},
22 {CACHEFILE_VELOCITY_UNIT_FRAME, "FRAME", 0, "Frame", ""},
23 {0, nullptr, 0, nullptr, nullptr},
24};
25
26#ifdef RNA_RUNTIME
27
28# include "BLI_string.h"
29
30# include "BKE_cachefile.hh"
31
32# include "DEG_depsgraph.hh"
33# include "DEG_depsgraph_build.hh"
34
35# include "WM_api.hh"
36# include "WM_types.hh"
37
38# ifdef WITH_ALEMBIC
39# include "ABC_alembic.h"
40# endif
41
42static void rna_CacheFile_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
43{
44 CacheFile *cache_file = (CacheFile *)ptr->data;
45
48}
49
50static void rna_CacheFileLayer_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
51{
52 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
53
56}
57
58static void rna_CacheFile_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
59{
60 rna_CacheFile_update(bmain, scene, ptr);
62}
63
64static void rna_CacheFile_object_paths_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
65{
66 CacheFile *cache_file = (CacheFile *)ptr->data;
67 rna_iterator_listbase_begin(iter, &cache_file->object_paths, nullptr);
68}
69
70static PointerRNA rna_CacheFile_active_layer_get(PointerRNA *ptr)
71{
72 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
74 ptr, &RNA_CacheFileLayer, BKE_cachefile_get_active_layer(cache_file));
75}
76
77static void rna_CacheFile_active_layer_set(PointerRNA *ptr, PointerRNA value, ReportList *reports)
78{
79 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
80 int index = BLI_findindex(&cache_file->layers, value.data);
81 if (index == -1) {
82 BKE_reportf(reports,
84 "Layer '%s' not found in object '%s'",
85 ((CacheFileLayer *)value.data)->filepath,
86 cache_file->id.name + 2);
87 return;
88 }
89
90 cache_file->active_layer = index + 1;
91}
92
93static int rna_CacheFile_active_layer_index_get(PointerRNA *ptr)
94{
95 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
96 return cache_file->active_layer - 1;
97}
98
99static void rna_CacheFile_active_layer_index_set(PointerRNA *ptr, int value)
100{
101 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
102 cache_file->active_layer = value + 1;
103}
104
105static void rna_CacheFile_active_layer_index_range(
106 PointerRNA *ptr, int *min, int *max, int * /*softmin*/, int * /*softmax*/)
107{
108 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
109
110 *min = 0;
111 *max = max_ii(0, BLI_listbase_count(&cache_file->layers) - 1);
112}
113
114static void rna_CacheFileLayer_hidden_flag_set(PointerRNA *ptr, const bool value)
115{
117
118 if (value) {
119 layer->flag |= CACHEFILE_LAYER_HIDDEN;
120 }
121 else {
122 layer->flag &= ~CACHEFILE_LAYER_HIDDEN;
123 }
124}
125
126static CacheFileLayer *rna_CacheFile_layer_new(CacheFile *cache_file,
127 bContext *C,
128 ReportList *reports,
129 const char *filepath)
130{
131 CacheFileLayer *layer = BKE_cachefile_add_layer(cache_file, filepath);
132 if (layer == nullptr) {
134 reports, RPT_ERROR, "Cannot add a layer to CacheFile '%s'", cache_file->id.name + 2);
135 return nullptr;
136 }
137
139 BKE_cachefile_reload(depsgraph, cache_file);
141 return layer;
142}
143
144static void rna_CacheFile_layer_remove(CacheFile *cache_file, bContext *C, PointerRNA *layer_ptr)
145{
146 CacheFileLayer *layer = static_cast<CacheFileLayer *>(layer_ptr->data);
147 BKE_cachefile_remove_layer(cache_file, layer);
149 BKE_cachefile_reload(depsgraph, cache_file);
151}
152
153#else
154
155/* cachefile.object_paths */
157{
158 StructRNA *srna = RNA_def_struct(brna, "CacheObjectPath", nullptr);
159 RNA_def_struct_sdna(srna, "CacheObjectPath");
160 RNA_def_struct_ui_text(srna, "Object Path", "Path of an object inside of an Alembic archive");
161 RNA_def_struct_ui_icon(srna, ICON_NONE);
162
164
165 PropertyRNA *prop = RNA_def_property(srna, "path", PROP_STRING, PROP_NONE);
166 RNA_def_property_ui_text(prop, "Path", "Object path");
169
171}
172
173/* cachefile.object_paths */
175{
176 RNA_def_property_srna(cprop, "CacheObjectPaths");
177 StructRNA *srna = RNA_def_struct(brna, "CacheObjectPaths", nullptr);
178 RNA_def_struct_sdna(srna, "CacheFile");
179 RNA_def_struct_ui_text(srna, "Object Paths", "Collection of object paths");
180}
181
183{
184 StructRNA *srna = RNA_def_struct(brna, "CacheFileLayer", nullptr);
185 RNA_def_struct_sdna(srna, "CacheFileLayer");
187 srna,
188 "Cache Layer",
189 "Layer of the cache, used to load or override data from the first the first layer");
190
191 PropertyRNA *prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
192 RNA_def_property_ui_text(prop, "File Path", "Path to the archive");
193 RNA_def_property_update(prop, 0, "rna_CacheFileLayer_update");
194
195 prop = RNA_def_property(srna, "hide_layer", PROP_BOOLEAN, PROP_NONE);
197 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CacheFileLayer_hidden_flag_set");
198 RNA_def_property_ui_icon(prop, ICON_HIDE_OFF, -1);
199 RNA_def_property_ui_text(prop, "Hide Layer", "Do not load data from this layer");
200 RNA_def_property_update(prop, 0, "rna_CacheFileLayer_update");
201}
202
204{
205 RNA_def_property_srna(cprop, "CacheFileLayers");
206 StructRNA *srna = RNA_def_struct(brna, "CacheFileLayers", nullptr);
207 RNA_def_struct_sdna(srna, "CacheFile");
208 RNA_def_struct_ui_text(srna, "Cache Layers", "Collection of cache layers");
209
210 PropertyRNA *prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
211 RNA_def_property_struct_type(prop, "CacheFileLayer");
213 prop, "rna_CacheFile_active_layer_get", "rna_CacheFile_active_layer_set", nullptr, nullptr);
215 RNA_def_property_ui_text(prop, "Active Layer", "Active layer of the CacheFile");
216
217 /* Add a layer. */
218 FunctionRNA *func = RNA_def_function(srna, "new", "rna_CacheFile_layer_new");
220 RNA_def_function_ui_description(func, "Add a new layer");
222 func, "filepath", "File Path", 0, "", "File path to the archive used as a layer");
224 /* Return type. */
225 parm = RNA_def_pointer(func, "layer", "CacheFileLayer", "", "Newly created layer");
226 RNA_def_function_return(func, parm);
227
228 /* Remove a layer. */
229 func = RNA_def_function(srna, "remove", "rna_CacheFile_layer_remove");
231 RNA_def_function_ui_description(func, "Remove an existing layer from the cache file");
232 parm = RNA_def_pointer(func, "layer", "CacheFileLayer", "", "Layer to remove");
235}
236
238{
239 StructRNA *srna = RNA_def_struct(brna, "CacheFile", "ID");
240 RNA_def_struct_sdna(srna, "CacheFile");
241 RNA_def_struct_ui_text(srna, "CacheFile", "");
242 RNA_def_struct_ui_icon(srna, ICON_FILE);
243
245
246 PropertyRNA *prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
247 RNA_def_property_ui_text(prop, "File Path", "Path to external displacements file");
248 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
249
250 prop = RNA_def_property(srna, "is_sequence", PROP_BOOLEAN, PROP_NONE);
252 prop, "Sequence", "Whether the cache is separated in a series of files");
253 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
254
255 prop = RNA_def_property(srna, "use_render_procedural", PROP_BOOLEAN, PROP_NONE);
257 prop,
258 "Use Render Engine Procedural",
259 "Display boxes in the viewport as placeholders for the objects, Cycles will use a "
260 "procedural to load the objects during viewport rendering in experimental mode, "
261 "other render engines will also receive a placeholder and should take care of loading the "
262 "Alembic data themselves if possible");
263 RNA_def_property_update(prop, 0, "rna_CacheFile_dependency_update");
264
265 /* ----------------- For Scene time ------------------- */
266
267 prop = RNA_def_property(srna, "override_frame", PROP_BOOLEAN, PROP_NONE);
269 "Override Frame",
270 "Whether to use a custom frame for looking up data in the cache file,"
271 " instead of using the current scene frame");
272 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
273
274 prop = RNA_def_property(srna, "frame", PROP_FLOAT, PROP_NONE);
275 RNA_def_property_float_sdna(prop, nullptr, "frame");
278 "Frame",
279 "The time to use for looking up the data in the cache file,"
280 " or to determine which file to use in a file sequence");
281 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
282
283 prop = RNA_def_property(srna, "frame_offset", PROP_FLOAT, PROP_NONE);
284 RNA_def_property_float_sdna(prop, nullptr, "frame_offset");
287 "Frame Offset",
288 "Subtracted from the current frame to use for "
289 "looking up the data in the cache file, or to "
290 "determine which file to use in a file sequence");
291 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
292
293 /* ----------------- Cache controls ----------------- */
294
295 prop = RNA_def_property(srna, "use_prefetch", PROP_BOOLEAN, PROP_NONE);
297 prop,
298 "Use Prefetch",
299 "When enabled, the Cycles Procedural will preload animation data for faster updates");
300 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
301
302 prop = RNA_def_property(srna, "prefetch_cache_size", PROP_INT, PROP_UNSIGNED);
304 prop,
305 "Prefetch Cache Size",
306 "Memory usage limit in megabytes for the Cycles Procedural cache, if the data does not "
307 "fit within the limit, rendering is aborted");
308 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
309
310 /* ----------------- Axis Conversion ----------------- */
311
312 prop = RNA_def_property(srna, "forward_axis", PROP_ENUM, PROP_NONE);
313 RNA_def_property_enum_sdna(prop, nullptr, "forward_axis");
315 RNA_def_property_ui_text(prop, "Forward", "");
316 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
317
318 prop = RNA_def_property(srna, "up_axis", PROP_ENUM, PROP_NONE);
319 RNA_def_property_enum_sdna(prop, nullptr, "up_axis");
321 RNA_def_property_ui_text(prop, "Up", "");
322 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
323
324 prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
325 RNA_def_property_float_sdna(prop, nullptr, "scale");
326 RNA_def_property_range(prop, 0.0001f, 1000.0f);
328 prop,
329 "Scale",
330 "Value by which to enlarge or shrink the object with respect to the world's origin"
331 " (only applicable through a Transform Cache constraint)");
332 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
333
334 /* object paths */
335 prop = RNA_def_property(srna, "object_paths", PROP_COLLECTION, PROP_NONE);
336 RNA_def_property_collection_sdna(prop, nullptr, "object_paths", nullptr);
338 "rna_CacheFile_object_paths_begin",
339 "rna_iterator_listbase_next",
340 "rna_iterator_listbase_end",
341 "rna_iterator_listbase_get",
342 nullptr,
343 nullptr,
344 nullptr,
345 nullptr);
346 RNA_def_property_struct_type(prop, "CacheObjectPath");
347 RNA_def_property_srna(prop, "CacheObjectPaths");
349 prop, "Object Paths", "Paths of the objects inside the Alembic archive");
350
351 /* ----------------- Alembic Velocity Attribute ----------------- */
352
353 prop = RNA_def_property(srna, "velocity_name", PROP_STRING, PROP_NONE);
355 "Velocity Attribute",
356 "Name of the Alembic attribute used for generating motion blur data");
357 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
359
360 prop = RNA_def_property(srna, "velocity_unit", PROP_ENUM, PROP_NONE);
361 RNA_def_property_enum_sdna(prop, nullptr, "velocity_unit");
364 prop,
365 "Velocity Unit",
366 "Define how the velocity vectors are interpreted with regard to time, 'frame' means "
367 "the delta time is 1 frame, 'second' means the delta time is 1 / FPS");
369 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
371
372 /* ----------------- Alembic Layers ----------------- */
373
374 prop = RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
375 RNA_def_property_collection_sdna(prop, nullptr, "layers", nullptr);
376 RNA_def_property_struct_type(prop, "CacheFileLayer");
378 RNA_def_property_ui_text(prop, "Cache Layers", "Layers of the cache");
379 rna_def_cachefile_layers(brna, prop);
380
381 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
383 RNA_def_property_int_sdna(prop, nullptr, "active_layer");
385 "rna_CacheFile_active_layer_index_get",
386 "rna_CacheFile_active_layer_index_set",
387 "rna_CacheFile_active_layer_index_range");
388
390
392
394}
395
402
403#endif
void BKE_cachefile_remove_layer(CacheFile *cache_file, CacheFileLayer *layer)
Definition cachefile.cc:458
CacheFileLayer * BKE_cachefile_get_active_layer(CacheFile *cache_file)
Definition cachefile.cc:452
CacheFileLayer * BKE_cachefile_add_layer(CacheFile *cache_file, const char filepath[1024])
Definition cachefile.cc:431
void BKE_cachefile_reload(Depsgraph *depsgraph, CacheFile *cache_file)
Definition cachefile.cc:325
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
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)
void DEG_relations_tag_update(Main *bmain)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1085
@ CACHEFILE_VELOCITY_UNIT_SECOND
@ CACHEFILE_VELOCITY_UNIT_FRAME
@ CACHEFILE_LAYER_HIDDEN
#define MAXFRAME
ParameterFlag
Definition RNA_types.hh:396
@ PARM_RNAPTR
Definition RNA_types.hh:399
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ FUNC_USE_REPORTS
Definition RNA_types.hh:680
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:679
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_INT
Definition RNA_types.hh:66
@ PROP_STRING
Definition RNA_types.hh:68
@ PROP_POINTER
Definition RNA_types.hh:70
@ PROP_COLLECTION
Definition RNA_types.hh:71
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:355
PropertyFlag
Definition RNA_types.hh:201
@ PROP_THICK_WRAP
Definition RNA_types.hh:312
@ PROP_ANIMATABLE
Definition RNA_types.hh:220
@ PROP_EDITABLE
Definition RNA_types.hh:207
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_UNSIGNED
Definition RNA_types.hh:152
@ PROP_FILEPATH
Definition RNA_types.hh:139
#define ND_DRAW
Definition WM_types.hh:428
#define NC_OBJECT
Definition WM_types.hh:346
const Depsgraph * depsgraph
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip)
PointerRNA rna_pointer_inherit_refine(const PointerRNA *ptr, 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_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_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
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.c:32
char name[66]
Definition DNA_ID.h:425
ID * owner_id
Definition RNA_types.hh:40
void * data
Definition RNA_types.hh:42
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4126