Blender V5.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
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
19namespace blender {
20
22 {CACHEFILE_VELOCITY_UNIT_SECOND, "SECOND", 0, "Second", ""},
23 {CACHEFILE_VELOCITY_UNIT_FRAME, "FRAME", 0, "Frame", ""},
24 {0, nullptr, 0, nullptr, nullptr},
25};
26
27}
28
29#ifdef RNA_RUNTIME
30
31# include "BLI_listbase.hh"
32# include "BLI_math_base_c.hh"
33
34# include "BKE_cachefile.hh"
35# include "BKE_context.hh"
36# include "BKE_report.hh"
37
38# include "DEG_depsgraph.hh"
39# include "DEG_depsgraph_build.hh"
40
41# include "WM_api.hh"
42# include "WM_types.hh"
43
44# ifdef WITH_ALEMBIC
45# include "ABC_alembic.h"
46# endif
47
48namespace blender {
49
50static void rna_CacheFile_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
51{
52 CacheFile *cache_file = static_cast<CacheFile *>(ptr->data);
53
56}
57
58static void rna_CacheFileLayer_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
59{
60 CacheFile *cache_file = id_cast<CacheFile *>(ptr->owner_id);
61
64}
65
66static void rna_CacheFile_object_paths_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
67{
68 CacheFile *cache_file = static_cast<CacheFile *>(ptr->data);
69 rna_iterator_listbase_begin(iter, ptr, &cache_file->object_paths, nullptr);
70}
71
72static PointerRNA rna_CacheFile_active_layer_get(PointerRNA *ptr)
73{
74 CacheFile *cache_file = id_cast<CacheFile *>(ptr->owner_id);
76 *ptr, RNA_CacheFileLayer, BKE_cachefile_get_active_layer(cache_file));
77}
78
79static void rna_CacheFile_active_layer_set(PointerRNA *ptr, PointerRNA value, ReportList *reports)
80{
81 CacheFile *cache_file = id_cast<CacheFile *>(ptr->owner_id);
82 int index = BLI_findindex(&cache_file->layers, value.data);
83 if (index == -1) {
84 BKE_reportf(reports,
86 "Layer '%s' not found in object '%s'",
87 (static_cast<CacheFileLayer *>(value.data))->filepath,
88 cache_file->id.name + 2);
89 return;
90 }
91
92 cache_file->active_layer = index + 1;
93}
94
95static int rna_CacheFile_active_layer_index_get(PointerRNA *ptr)
96{
97 CacheFile *cache_file = id_cast<CacheFile *>(ptr->owner_id);
98 return cache_file->active_layer - 1;
99}
100
101static void rna_CacheFile_active_layer_index_set(PointerRNA *ptr, int value)
102{
103 CacheFile *cache_file = id_cast<CacheFile *>(ptr->owner_id);
104 cache_file->active_layer = value + 1;
105}
106
107static void rna_CacheFile_active_layer_index_range(
108 PointerRNA *ptr, int *min, int *max, int * /*softmin*/, int * /*softmax*/)
109{
110 CacheFile *cache_file = id_cast<CacheFile *>(ptr->owner_id);
111
112 *min = 0;
113 *max = max_ii(0, cache_file->layers.count() - 1);
114}
115
116static void rna_CacheFileLayer_hidden_flag_set(PointerRNA *ptr, const bool value)
117{
118 CacheFileLayer *layer = static_cast<CacheFileLayer *>(ptr->data);
119
120 if (value) {
122 }
123 else {
125 }
126}
127
128static CacheFileLayer *rna_CacheFile_layer_new(CacheFile *cache_file,
129 bContext *C,
130 ReportList *reports,
131 const char *filepath)
132{
133 CacheFileLayer *layer = BKE_cachefile_add_layer(cache_file, filepath);
134 if (layer == nullptr) {
136 reports, RPT_ERROR, "Cannot add a layer to CacheFile '%s'", cache_file->id.name + 2);
137 return nullptr;
138 }
139
140 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
141 BKE_cachefile_reload(depsgraph, cache_file);
143 return layer;
144}
145
146static void rna_CacheFile_layer_remove(CacheFile *cache_file, bContext *C, PointerRNA *layer_ptr)
147{
148 CacheFileLayer *layer = static_cast<CacheFileLayer *>(layer_ptr->data);
150 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
151 BKE_cachefile_reload(depsgraph, cache_file);
153}
154
155} // namespace blender
156
157#else
158
159namespace blender {
160
161/* cachefile.object_paths */
163{
164 StructRNA *srna = RNA_def_struct(brna, "CacheObjectPath", nullptr);
165 RNA_def_struct_sdna(srna, "CacheObjectPath");
166 RNA_def_struct_ui_text(srna, "Object Path", "Path of an object inside of an Alembic archive");
167 RNA_def_struct_ui_icon(srna, ICON_NONE);
168
170
171 PropertyRNA *prop = RNA_def_property(srna, "path", PROP_STRING, PROP_NONE);
172 RNA_def_property_ui_text(prop, "Path", "Object path");
175
177}
178
179/* cachefile.object_paths */
181{
182 RNA_def_property_srna(cprop, "CacheObjectPaths");
183 StructRNA *srna = RNA_def_struct(brna, "CacheObjectPaths", nullptr);
184 RNA_def_struct_sdna(srna, "CacheFile");
185 RNA_def_struct_ui_text(srna, "Object Paths", "Collection of object paths");
186}
187
189{
190 StructRNA *srna = RNA_def_struct(brna, "CacheFileLayer", nullptr);
191 RNA_def_struct_sdna(srna, "CacheFileLayer");
193 srna,
194 "Cache Layer",
195 "Layer of the cache, used to load or override data from the first the first layer");
196
197 PropertyRNA *prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
198 RNA_def_property_ui_text(prop, "File Path", "Path to the archive");
200 RNA_def_property_update(prop, 0, "rna_CacheFileLayer_update");
201
202 prop = RNA_def_property(srna, "hide_layer", PROP_BOOLEAN, PROP_NONE);
204 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CacheFileLayer_hidden_flag_set");
205 RNA_def_property_ui_icon(prop, ICON_HIDE_OFF, -1);
206 RNA_def_property_ui_text(prop, "Hide Layer", "Do not load data from this layer");
207 RNA_def_property_update(prop, 0, "rna_CacheFileLayer_update");
208}
209
211{
212 RNA_def_property_srna(cprop, "CacheFileLayers");
213 StructRNA *srna = RNA_def_struct(brna, "CacheFileLayers", nullptr);
214 RNA_def_struct_sdna(srna, "CacheFile");
215 RNA_def_struct_ui_text(srna, "Cache Layers", "Collection of cache layers");
216
217 PropertyRNA *prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
218 RNA_def_property_struct_type(prop, "CacheFileLayer");
220 prop, "rna_CacheFile_active_layer_get", "rna_CacheFile_active_layer_set", nullptr, nullptr);
222 RNA_def_property_ui_text(prop, "Active Layer", "Active layer of the CacheFile");
223
224 /* Add a layer. */
225 FunctionRNA *func = RNA_def_function(srna, "new", "rna_CacheFile_layer_new");
227 RNA_def_function_ui_description(func, "Add a new layer");
229 func, "filepath", "File Path", 0, "", "File path to the archive used as a layer");
231 /* Return type. */
232 parm = RNA_def_pointer(func, "layer", "CacheFileLayer", "", "Newly created layer");
234 RNA_def_function_return(func, parm);
235
236 /* Remove a layer. */
237 func = RNA_def_function(srna, "remove", "rna_CacheFile_layer_remove");
239 RNA_def_function_ui_description(func, "Remove an existing layer from the cache file");
240 parm = RNA_def_pointer(func, "layer", "CacheFileLayer", "", "Layer to remove");
243}
244
246{
247 StructRNA *srna = RNA_def_struct(brna, "CacheFile", "ID");
248 RNA_def_struct_sdna(srna, "CacheFile");
249 RNA_def_struct_ui_text(srna, "CacheFile", "");
250 RNA_def_struct_ui_icon(srna, ICON_FILE);
251
253
254 PropertyRNA *prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
255 RNA_def_property_ui_text(prop, "File Path", "Path to external displacements file");
257 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
258
259 prop = RNA_def_property(srna, "is_sequence", PROP_BOOLEAN, PROP_NONE);
261 prop, "Sequence", "Whether the cache is separated in a series of files");
262 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
263
264 /* ----------------- For Scene time ------------------- */
265
266 prop = RNA_def_property(srna, "override_frame", PROP_BOOLEAN, PROP_NONE);
268 "Override Frame",
269 "Whether to use a custom frame for looking up data in the cache file,"
270 " instead of using the current scene frame");
271 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
272
273 prop = RNA_def_property(srna, "frame", PROP_FLOAT, PROP_NONE);
274 RNA_def_property_float_sdna(prop, nullptr, "frame");
277 "Frame",
278 "The time to use for looking up the data in the cache file,"
279 " or to determine which file to use in a file sequence");
280 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
281
282 prop = RNA_def_property(srna, "frame_offset", PROP_FLOAT, PROP_NONE);
283 RNA_def_property_float_sdna(prop, nullptr, "frame_offset");
286 "Frame Offset",
287 "Subtracted from the current frame to use for "
288 "looking up the data in the cache file, or to "
289 "determine which file to use in a file sequence");
290 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
291
292 /* ----------------- Axis Conversion ----------------- */
293
294 prop = RNA_def_property(srna, "forward_axis", PROP_ENUM, PROP_NONE);
295 RNA_def_property_enum_sdna(prop, nullptr, "forward_axis");
297 RNA_def_property_ui_text(prop, "Forward", "");
298 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
299
300 prop = RNA_def_property(srna, "up_axis", PROP_ENUM, PROP_NONE);
301 RNA_def_property_enum_sdna(prop, nullptr, "up_axis");
303 RNA_def_property_ui_text(prop, "Up", "");
304 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
305
306 prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
307 RNA_def_property_float_sdna(prop, nullptr, "scale");
308 RNA_def_property_range(prop, 0.0001f, 1000.0f);
310 prop,
311 "Scale",
312 "Value by which to enlarge or shrink the object with respect to the world's origin"
313 " (only applicable through a Transform Cache constraint)");
314 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
315
316 /* object paths */
317 prop = RNA_def_property(srna, "object_paths", PROP_COLLECTION, PROP_NONE);
318 RNA_def_property_collection_sdna(prop, nullptr, "object_paths", nullptr);
320 "rna_CacheFile_object_paths_begin",
321 "rna_iterator_listbase_next",
322 "rna_iterator_listbase_end",
323 "rna_iterator_listbase_get",
324 nullptr,
325 nullptr,
326 nullptr,
327 nullptr);
328 RNA_def_property_struct_type(prop, "CacheObjectPath");
329 RNA_def_property_srna(prop, "CacheObjectPaths");
331 prop, "Object Paths", "Paths of the objects inside the Alembic archive");
332
333 /* ----------------- Alembic Velocity Attribute ----------------- */
334
335 prop = RNA_def_property(srna, "velocity_name", PROP_STRING, PROP_NONE);
337 "Velocity Attribute",
338 "Name of the Alembic attribute used for generating motion blur data");
339 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
341
342 prop = RNA_def_property(srna, "velocity_unit", PROP_ENUM, PROP_NONE);
343 RNA_def_property_enum_sdna(prop, nullptr, "velocity_unit");
346 prop,
347 "Velocity Unit",
348 "Define how the velocity vectors are interpreted with regard to time, 'frame' means "
349 "the delta time is 1 frame, 'second' means the delta time is 1 / FPS");
351 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
353
354 /* ----------------- Alembic Layers ----------------- */
355
356 prop = RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
357 RNA_def_property_collection_sdna(prop, nullptr, "layers", nullptr);
358 RNA_def_property_struct_type(prop, "CacheFileLayer");
360 RNA_def_property_ui_text(prop, "Cache Layers", "Layers of the cache");
361 rna_def_cachefile_layers(brna, prop);
362
363 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
365 RNA_def_property_int_sdna(prop, nullptr, "active_layer");
367 "rna_CacheFile_active_layer_index_get",
368 "rna_CacheFile_active_layer_index_set",
369 "rna_CacheFile_active_layer_index_range");
370
372
374
376}
377
384
385} // namespace blender
386
387#endif
#define BLT_I18NCONTEXT_UNIT
#define BLT_I18NCONTEXT_EDITOR_FILEBROWSER
#define MAXFRAME
#define C
Definition RandGen.cpp:29
#define ND_DRAW
Definition WM_types.hh:502
#define NC_OBJECT
Definition WM_types.hh:392
btScalar max
#define layer
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
CacheFileLayer * BKE_cachefile_get_active_layer(CacheFile *cache_file)
Definition cachefile.cc:433
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
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_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
const EnumPropertyItem rna_enum_velocity_unit_items[]
@ FUNC_USE_REPORTS
@ FUNC_USE_CONTEXT
void RNA_define_lib_overridable(const bool make_overridable)
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)
MINLINE int max_ii(int a, int b)
void BKE_cachefile_remove_layer(CacheFile *cache_file, CacheFileLayer *layer)
Definition cachefile.cc:439
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:588
void rna_def_animdata_common(StructRNA *srna)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
static void rna_def_cachefile(BlenderRNA *brna)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
@ PROP_COLLECTION
Definition RNA_types.hh:216
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
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_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void DEG_id_tag_update(ID *id, unsigned int flags)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
const EnumPropertyItem rna_enum_object_axis_items[]
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
@ CACHEFILE_VELOCITY_UNIT_SECOND
@ CACHEFILE_VELOCITY_UNIT_FRAME
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
static void rna_def_cachefile_layer(BlenderRNA *brna)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void RNA_def_property_override_clear_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_PATH_SUPPORTS_BLEND_RELATIVE
Definition RNA_types.hh:526
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
@ PROP_ANIMATABLE
Definition RNA_types.hh:389
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
static void rna_def_cachefile_object_paths(BlenderRNA *brna, PropertyRNA *cprop)
static void rna_def_alembic_object_path(BlenderRNA *brna)
static void rna_def_cachefile_layers(BlenderRNA *brna, PropertyRNA *cprop)
@ PROP_FILEPATH
Definition RNA_types.hh:284
@ PROP_UNSIGNED
Definition RNA_types.hh:306
CacheFileLayer * BKE_cachefile_add_layer(CacheFile *cache_file, const char filepath[1024])
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, ListBase *lb, IteratorSkipFunc skip)
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop, const bool allow_replace)
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
void RNA_def_cachefile(BlenderRNA *brna)
void BKE_cachefile_reload(Depsgraph *depsgraph, CacheFile *cache_file)
Definition cachefile.cc:317
#define min(a, b)
Definition sort.cc:38