Blender V4.5
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_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
60{
61 rna_CacheFile_update(bmain, scene, ptr);
63}
64
65static void rna_CacheFile_object_paths_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
66{
67 CacheFile *cache_file = (CacheFile *)ptr->data;
68 rna_iterator_listbase_begin(iter, ptr, &cache_file->object_paths, nullptr);
69}
70
71static PointerRNA rna_CacheFile_active_layer_get(PointerRNA *ptr)
72{
73 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
75 *ptr, &RNA_CacheFileLayer, BKE_cachefile_get_active_layer(cache_file));
76}
77
78static void rna_CacheFile_active_layer_set(PointerRNA *ptr, PointerRNA value, ReportList *reports)
79{
80 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
81 int index = BLI_findindex(&cache_file->layers, value.data);
82 if (index == -1) {
85 "Layer '%s' not found in object '%s'",
86 ((CacheFileLayer *)value.data)->filepath,
87 cache_file->id.name + 2);
88 return;
89 }
90
91 cache_file->active_layer = index + 1;
92}
93
94static int rna_CacheFile_active_layer_index_get(PointerRNA *ptr)
95{
96 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
97 return cache_file->active_layer - 1;
98}
99
100static void rna_CacheFile_active_layer_index_set(PointerRNA *ptr, int value)
101{
102 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
103 cache_file->active_layer = value + 1;
104}
105
106static void rna_CacheFile_active_layer_index_range(
107 PointerRNA *ptr, int *min, int *max, int * /*softmin*/, int * /*softmax*/)
108{
109 CacheFile *cache_file = (CacheFile *)ptr->owner_id;
110
111 *min = 0;
112 *max = max_ii(0, BLI_listbase_count(&cache_file->layers) - 1);
113}
114
115static void rna_CacheFileLayer_hidden_flag_set(PointerRNA *ptr, const bool value)
116{
117 CacheFileLayer *layer = (CacheFileLayer *)ptr->data;
118
119 if (value) {
120 layer->flag |= CACHEFILE_LAYER_HIDDEN;
121 }
122 else {
123 layer->flag &= ~CACHEFILE_LAYER_HIDDEN;
124 }
125}
126
127static CacheFileLayer *rna_CacheFile_layer_new(CacheFile *cache_file,
128 bContext *C,
130 const char *filepath)
131{
132 CacheFileLayer *layer = BKE_cachefile_add_layer(cache_file, filepath);
133 if (layer == nullptr) {
135 reports, RPT_ERROR, "Cannot add a layer to CacheFile '%s'", cache_file->id.name + 2);
136 return nullptr;
137 }
138
140 BKE_cachefile_reload(depsgraph, cache_file);
142 return layer;
143}
144
145static void rna_CacheFile_layer_remove(CacheFile *cache_file, bContext *C, PointerRNA *layer_ptr)
146{
147 CacheFileLayer *layer = static_cast<CacheFileLayer *>(layer_ptr->data);
148 BKE_cachefile_remove_layer(cache_file, layer);
150 BKE_cachefile_reload(depsgraph, cache_file);
152}
153
154#else
155
156/* cachefile.object_paths */
158{
159 StructRNA *srna = RNA_def_struct(brna, "CacheObjectPath", nullptr);
160 RNA_def_struct_sdna(srna, "CacheObjectPath");
161 RNA_def_struct_ui_text(srna, "Object Path", "Path of an object inside of an Alembic archive");
162 RNA_def_struct_ui_icon(srna, ICON_NONE);
163
165
166 PropertyRNA *prop = RNA_def_property(srna, "path", PROP_STRING, PROP_NONE);
167 RNA_def_property_ui_text(prop, "Path", "Object path");
170
172}
173
174/* cachefile.object_paths */
176{
177 RNA_def_property_srna(cprop, "CacheObjectPaths");
178 StructRNA *srna = RNA_def_struct(brna, "CacheObjectPaths", nullptr);
179 RNA_def_struct_sdna(srna, "CacheFile");
180 RNA_def_struct_ui_text(srna, "Object Paths", "Collection of object paths");
181}
182
184{
185 StructRNA *srna = RNA_def_struct(brna, "CacheFileLayer", nullptr);
186 RNA_def_struct_sdna(srna, "CacheFileLayer");
188 srna,
189 "Cache Layer",
190 "Layer of the cache, used to load or override data from the first the first layer");
191
192 PropertyRNA *prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
193 RNA_def_property_ui_text(prop, "File Path", "Path to the archive");
195 RNA_def_property_update(prop, 0, "rna_CacheFileLayer_update");
196
197 prop = RNA_def_property(srna, "hide_layer", PROP_BOOLEAN, PROP_NONE);
199 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CacheFileLayer_hidden_flag_set");
200 RNA_def_property_ui_icon(prop, ICON_HIDE_OFF, -1);
201 RNA_def_property_ui_text(prop, "Hide Layer", "Do not load data from this layer");
202 RNA_def_property_update(prop, 0, "rna_CacheFileLayer_update");
203}
204
206{
207 RNA_def_property_srna(cprop, "CacheFileLayers");
208 StructRNA *srna = RNA_def_struct(brna, "CacheFileLayers", nullptr);
209 RNA_def_struct_sdna(srna, "CacheFile");
210 RNA_def_struct_ui_text(srna, "Cache Layers", "Collection of cache layers");
211
212 PropertyRNA *prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
213 RNA_def_property_struct_type(prop, "CacheFileLayer");
215 prop, "rna_CacheFile_active_layer_get", "rna_CacheFile_active_layer_set", nullptr, nullptr);
217 RNA_def_property_ui_text(prop, "Active Layer", "Active layer of the CacheFile");
218
219 /* Add a layer. */
220 FunctionRNA *func = RNA_def_function(srna, "new", "rna_CacheFile_layer_new");
222 RNA_def_function_ui_description(func, "Add a new layer");
224 func, "filepath", "File Path", 0, "", "File path to the archive used as a layer");
226 /* Return type. */
227 parm = RNA_def_pointer(func, "layer", "CacheFileLayer", "", "Newly created layer");
228 RNA_def_function_return(func, parm);
229
230 /* Remove a layer. */
231 func = RNA_def_function(srna, "remove", "rna_CacheFile_layer_remove");
233 RNA_def_function_ui_description(func, "Remove an existing layer from the cache file");
234 parm = RNA_def_pointer(func, "layer", "CacheFileLayer", "", "Layer to remove");
237}
238
240{
241 StructRNA *srna = RNA_def_struct(brna, "CacheFile", "ID");
242 RNA_def_struct_sdna(srna, "CacheFile");
243 RNA_def_struct_ui_text(srna, "CacheFile", "");
244 RNA_def_struct_ui_icon(srna, ICON_FILE);
245
247
248 PropertyRNA *prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
249 RNA_def_property_ui_text(prop, "File Path", "Path to external displacements file");
251 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
252
253 prop = RNA_def_property(srna, "is_sequence", PROP_BOOLEAN, PROP_NONE);
255 prop, "Sequence", "Whether the cache is separated in a series of files");
256 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
257
258 prop = RNA_def_property(srna, "use_render_procedural", PROP_BOOLEAN, PROP_NONE);
260 prop,
261 "Use Render Engine Procedural",
262 "Display boxes in the viewport as placeholders for the objects, Cycles will use a "
263 "procedural to load the objects during viewport rendering in experimental mode, "
264 "other render engines will also receive a placeholder and should take care of loading the "
265 "Alembic data themselves if possible");
266 RNA_def_property_update(prop, 0, "rna_CacheFile_dependency_update");
267
268 /* ----------------- For Scene time ------------------- */
269
270 prop = RNA_def_property(srna, "override_frame", PROP_BOOLEAN, PROP_NONE);
272 "Override Frame",
273 "Whether to use a custom frame for looking up data in the cache file,"
274 " instead of using the current scene frame");
275 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
276
277 prop = RNA_def_property(srna, "frame", PROP_FLOAT, PROP_NONE);
278 RNA_def_property_float_sdna(prop, nullptr, "frame");
281 "Frame",
282 "The time to use for looking up the data in the cache file,"
283 " or to determine which file to use in a file sequence");
284 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
285
286 prop = RNA_def_property(srna, "frame_offset", PROP_FLOAT, PROP_NONE);
287 RNA_def_property_float_sdna(prop, nullptr, "frame_offset");
290 "Frame Offset",
291 "Subtracted from the current frame to use for "
292 "looking up the data in the cache file, or to "
293 "determine which file to use in a file sequence");
294 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
295
296 /* ----------------- Cache controls ----------------- */
297
298 prop = RNA_def_property(srna, "use_prefetch", PROP_BOOLEAN, PROP_NONE);
300 prop,
301 "Use Prefetch",
302 "When enabled, the Cycles Procedural will preload animation data for faster updates");
303 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
304
305 prop = RNA_def_property(srna, "prefetch_cache_size", PROP_INT, PROP_UNSIGNED);
307 prop,
308 "Prefetch Cache Size",
309 "Memory usage limit in megabytes for the Cycles Procedural cache, if the data does not "
310 "fit within the limit, rendering is aborted");
311 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
312
313 /* ----------------- Axis Conversion ----------------- */
314
315 prop = RNA_def_property(srna, "forward_axis", PROP_ENUM, PROP_NONE);
316 RNA_def_property_enum_sdna(prop, nullptr, "forward_axis");
318 RNA_def_property_ui_text(prop, "Forward", "");
319 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
320
321 prop = RNA_def_property(srna, "up_axis", PROP_ENUM, PROP_NONE);
322 RNA_def_property_enum_sdna(prop, nullptr, "up_axis");
324 RNA_def_property_ui_text(prop, "Up", "");
325 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
326
327 prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
328 RNA_def_property_float_sdna(prop, nullptr, "scale");
329 RNA_def_property_range(prop, 0.0001f, 1000.0f);
331 prop,
332 "Scale",
333 "Value by which to enlarge or shrink the object with respect to the world's origin"
334 " (only applicable through a Transform Cache constraint)");
335 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
336
337 /* object paths */
338 prop = RNA_def_property(srna, "object_paths", PROP_COLLECTION, PROP_NONE);
339 RNA_def_property_collection_sdna(prop, nullptr, "object_paths", nullptr);
341 "rna_CacheFile_object_paths_begin",
342 "rna_iterator_listbase_next",
343 "rna_iterator_listbase_end",
344 "rna_iterator_listbase_get",
345 nullptr,
346 nullptr,
347 nullptr,
348 nullptr);
349 RNA_def_property_struct_type(prop, "CacheObjectPath");
350 RNA_def_property_srna(prop, "CacheObjectPaths");
352 prop, "Object Paths", "Paths of the objects inside the Alembic archive");
353
354 /* ----------------- Alembic Velocity Attribute ----------------- */
355
356 prop = RNA_def_property(srna, "velocity_name", PROP_STRING, PROP_NONE);
358 "Velocity Attribute",
359 "Name of the Alembic attribute used for generating motion blur data");
360 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
362
363 prop = RNA_def_property(srna, "velocity_unit", PROP_ENUM, PROP_NONE);
364 RNA_def_property_enum_sdna(prop, nullptr, "velocity_unit");
367 prop,
368 "Velocity Unit",
369 "Define how the velocity vectors are interpreted with regard to time, 'frame' means "
370 "the delta time is 1 frame, 'second' means the delta time is 1 / FPS");
372 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
374
375 /* ----------------- Alembic Layers ----------------- */
376
377 prop = RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
378 RNA_def_property_collection_sdna(prop, nullptr, "layers", nullptr);
379 RNA_def_property_struct_type(prop, "CacheFileLayer");
381 RNA_def_property_ui_text(prop, "Cache Layers", "Layers of the cache");
382 rna_def_cachefile_layers(brna, prop);
383
384 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
386 RNA_def_property_int_sdna(prop, nullptr, "active_layer");
388 "rna_CacheFile_active_layer_index_get",
389 "rna_CacheFile_active_layer_index_set",
390 "rna_CacheFile_active_layer_index_range");
391
393
395
397}
398
405
406#endif
void BKE_cachefile_remove_layer(CacheFile *cache_file, CacheFileLayer *layer)
Definition cachefile.cc:454
CacheFileLayer * BKE_cachefile_get_active_layer(CacheFile *cache_file)
Definition cachefile.cc:448
CacheFileLayer * BKE_cachefile_add_layer(CacheFile *cache_file, const char filepath[1024])
Definition cachefile.cc:428
void BKE_cachefile_reload(Depsgraph *depsgraph, CacheFile *cache_file)
Definition cachefile.cc:315
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 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)
void DEG_relations_tag_update(Main *bmain)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1026
@ CACHEFILE_LAYER_HIDDEN
@ CACHEFILE_VELOCITY_UNIT_SECOND
@ CACHEFILE_VELOCITY_UNIT_FRAME
#define MAXFRAME
ParameterFlag
Definition RNA_types.hh:510
@ PARM_RNAPTR
Definition RNA_types.hh:513
@ PARM_REQUIRED
Definition RNA_types.hh:511
@ FUNC_USE_REPORTS
Definition RNA_types.hh:805
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:804
@ PROP_FLOAT
Definition RNA_types.hh:152
@ PROP_BOOLEAN
Definition RNA_types.hh:150
@ PROP_ENUM
Definition RNA_types.hh:154
@ PROP_INT
Definition RNA_types.hh:151
@ PROP_STRING
Definition RNA_types.hh:153
@ PROP_POINTER
Definition RNA_types.hh:155
@ PROP_COLLECTION
Definition RNA_types.hh:156
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:469
PropertyFlag
Definition RNA_types.hh:286
@ PROP_THICK_WRAP
Definition RNA_types.hh:397
@ PROP_ANIMATABLE
Definition RNA_types.hh:305
@ PROP_PATH_SUPPORTS_BLEND_RELATIVE
Definition RNA_types.hh:430
@ PROP_EDITABLE
Definition RNA_types.hh:292
@ PROP_NEVER_NULL
Definition RNA_types.hh:351
@ PROP_NONE
Definition RNA_types.hh:221
@ PROP_UNSIGNED
Definition RNA_types.hh:237
@ PROP_FILEPATH
Definition RNA_types.hh:224
#define C
Definition RandGen.cpp:29
#define ND_DRAW
Definition WM_types.hh:458
ReportList * reports
Definition WM_types.hh:1025
#define NC_OBJECT
Definition WM_types.hh:376
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[66]
Definition DNA_ID.h:415
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:4227