Blender V5.3
BKE_pointcache.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include "BLI_function_ref.hh"
12
13#include "DNA_boid_types.h" /* for #BoidData */
14#include "DNA_listBase.h"
15#include "DNA_particle_types.h" /* for KDTree3d */
16#include "DNA_pointcache_types.h" /* for #BPHYS_TOT_DATA */
17
18#include <stdio.h> /* for #FILE */
19
20namespace blender {
21
22/* Point cache clearing option, for BKE_ptcache_id_clear, before
23 * and after are non-inclusive (they won't remove the cfra) */
24#define PTCACHE_CLEAR_ALL 0
25#define PTCACHE_CLEAR_FRAME 1
26#define PTCACHE_CLEAR_BEFORE 2
27#define PTCACHE_CLEAR_AFTER 3
28
29/* Point cache reset options */
30#define PTCACHE_RESET_DEPSGRAPH 0
31#define PTCACHE_RESET_BAKED 1
32#define PTCACHE_RESET_OUTDATED 2
33// #define PTCACHE_RESET_FREE 3 /*UNUSED*/
34
35/* Add the blend-file name after `blendcache_`. */
36#define PTCACHE_EXT ".bphys"
37#define PTCACHE_PATH "blendcache_"
38
39/* File open options, for BKE_ptcache_file_open */
40#define PTCACHE_FILE_READ 0
41#define PTCACHE_FILE_WRITE 1
42#define PTCACHE_FILE_UPDATE 2
43
44/* PTCacheID types */
45#define PTCACHE_TYPE_SOFTBODY 0
46#define PTCACHE_TYPE_PARTICLES 1
47#define PTCACHE_TYPE_CLOTH 2
48#define PTCACHE_TYPE_SMOKE_DOMAIN 3
49#define PTCACHE_TYPE_SMOKE_HIGHRES 4
50#define PTCACHE_TYPE_DYNAMICPAINT 5
51#define PTCACHE_TYPE_RIGIDBODY 6
52
53/* high bits reserved for flags that need to be stored in file */
54#define PTCACHE_TYPEFLAG_COMPRESS (1 << 16)
55#define PTCACHE_TYPEFLAG_EXTRADATA (1 << 17)
56
57#define PTCACHE_TYPEFLAG_TYPEMASK 0x0000FFFF
58#define PTCACHE_TYPEFLAG_FLAGMASK 0xFFFF0000
59
60/* PTCache read return code */
61#define PTCACHE_READ_EXACT 1
62#define PTCACHE_READ_INTERPOLATED 2
63#define PTCACHE_READ_OLD 3
64
65/* Structs */
66struct BlendDataReader;
67struct BlendWriter;
68struct ClothModifierData;
69struct DynamicPaintSurface;
70struct FluidModifierData;
71struct LinkData;
72struct Main;
73struct ModifierData;
74struct Object;
75struct ParticleKey;
76struct ParticleSystem;
77struct PointCache;
78struct PTCacheMem;
79struct RigidBodyWorld;
80struct Scene;
81struct SoftBody;
82struct ViewLayer;
83
84/* temp structure for read/write */
86 unsigned int index;
87 float loc[3];
88 float vel[3];
89 float rot[4];
90 float ave[3];
91 float size;
92 float times[3];
94};
95
97 FILE *fp;
98
100 unsigned int totpoint, type;
101 unsigned int data_types, flag;
102
105};
106
107#define PTCACHE_VEL_PER_SEC 1
108
109enum {
111};
112
113struct PTCacheID {
114 struct PTCacheID *next, *prev;
115
116 struct Scene *scene;
117 struct ID *owner_id;
118 void *calldata;
119 unsigned int type, file_type;
120 unsigned int stack_index;
121 unsigned int flag;
122
123 unsigned int default_step;
124 unsigned int max_step;
125
127 unsigned int data_types, info_types;
128
130 int (*write_point)(int index, void *calldata, void **data, int cfra);
132 void (*read_point)(int index, void *calldata, void **data, float cfra, const float *old_data);
135 void *calldata,
136 void **data,
137 float cfra,
138 float cfra1,
139 float cfra2,
140 const float *old_data);
141
146
148 void (*write_extra_data)(void *calldata, struct PTCacheMem *pm, int cfra);
150 void (*read_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra);
153 void *calldata, struct PTCacheMem *pm, float cfra, float cfra1, float cfra2);
154
159 int (*totpoint)(void *calldata, int cfra);
161 void (*error)(const struct ID *owner_id, void *calldata, const char *message);
163 int (*totwrite)(void *calldata, int cfra);
164
167
171 ListBaseT<PointCache> *ptcaches;
172};
173
175 struct Main *bmain;
176 struct Scene *scene;
178 struct Depsgraph *depsgraph;
179 bool bake;
180 bool render;
184
185 void (*update_progress)(void *data, float progress, int *cancel);
186 void *bake_job;
187};
188
189/* PTCacheEditKey->flag */
190#define PEK_SELECT 1
191#define PEK_TAG 2
192#define PEK_HIDE 4
193#define PEK_USE_WCO 8
194
196 float *co;
197 float *vel;
198 float *rot;
199 float *time;
200
201 float world_co[3];
202 float ftime;
203 float length;
204 short flag;
205};
206
207/* PTCacheEditPoint->flag */
208#define PEP_TAG 1
209#define PEP_EDIT_RECALC 2
210#define PEP_TRANSFORM 4
211#define PEP_HIDE 8
212
216 short flag;
217};
218
221
222 /* particles stuff */
227
228 /* cache stuff */
229 ListBaseT<PTCacheMem> mem_cache;
230
232
233 size_t undo_size;
234};
235
236enum {
237 /* Modifier stack got evaluated during particle edit mode, need to copy
238 * new evaluated particles to the edit struct.
239 */
241};
242
265
266void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **data, float time);
267
268/**************** Creating ID's ****************************/
269
270void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb);
271void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys);
272void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd);
278void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct FluidModifierData *fmd);
280 struct Object *ob,
281 struct DynamicPaintSurface *surface);
282void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw);
283
288PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache);
289void BKE_ptcache_ids_from_object(ListBaseT<PTCacheID> *lb,
290 struct Object *ob,
291 struct Scene *scene,
292 int duplis);
293
296 struct Scene &scene,
297 bool duplis,
299
300/****************** Query functions ****************************/
301
305bool BKE_ptcache_object_has(struct Scene *scene, struct Object *ob, int duplis);
306
307/************ ID specific functions ************************/
308
309void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra);
310bool BKE_ptcache_id_exist(PTCacheID *pid, int cfra);
311int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *pid, int mode);
313 struct Scene *scene,
314 float cfra,
315 int *startframe,
316 int *endframe,
317 float *timescale);
318int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode);
319
321
330
331/*********** General cache reading/writing ******************/
332
336int BKE_ptcache_data_size(int data_type);
337
342int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, unsigned int index);
343
344/* Memory cache read/write helpers. */
345
346void BKE_ptcache_mem_pointers_init(struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA]);
348int BKE_ptcache_mem_pointers_seek(int point_index,
349 struct PTCacheMem *pm,
350 void *cur[BPHYS_TOT_DATA]);
351
356int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old);
357
362int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra);
363
364/******************* Allocate & free ***************/
365
366struct PointCache *BKE_ptcache_add(ListBaseT<PointCache> *ptcaches);
367void BKE_ptcache_free_mem(ListBaseT<PTCacheMem> *mem_cache);
368void BKE_ptcache_free(struct PointCache *cache);
369void BKE_ptcache_free_list(ListBaseT<PointCache> *ptcaches);
371struct PointCache *BKE_ptcache_copy_list(ListBaseT<PointCache> *ptcaches_new,
372 const ListBaseT<PointCache> *ptcaches_old,
373 int flag);
374
375/********************** Baking *********************/
376
380void BKE_ptcache_quick_cache_all(struct Main *bmain,
381 struct Scene *scene,
382 struct ViewLayer *view_layer);
383
388void BKE_ptcache_bake(struct PTCacheBaker *baker);
389
393void BKE_ptcache_disk_to_mem(struct PTCacheID *pid);
397void BKE_ptcache_mem_to_disk(struct PTCacheID *pid);
406 const char *name_src,
407 const char *name_dst);
408
412void BKE_ptcache_load_external(struct PTCacheID *pid);
416void BKE_ptcache_validate(struct PointCache *cache, int framenr);
420void BKE_ptcache_invalidate(struct PointCache *cache);
421
422/********************** .blend File I/O *********************/
423
424void BKE_ptcache_blend_write(struct BlendWriter *writer, ListBaseT<PointCache> *ptcaches);
426 ListBaseT<PointCache> *ptcaches,
427 struct PointCache **ocache,
428 int force_disk);
429
430} // namespace blender
const char * dirname(char *path)
These structs are the foundation for all linked lists in the library system.
Definition scene.h:133
#define pf(_x, _i)
Prefetch 64.
Definition gim_memory.h:48
BMesh Iterators.
int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old)
void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
int BKE_ptcache_path(PTCacheID *pid, char *dirname)
int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode)
void BKE_ptcache_disk_to_mem(struct PTCacheID *pid)
int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *pid, int mode)
int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, unsigned int index)
void BKE_ptcache_load_external(struct PTCacheID *pid)
void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct FluidModifierData *fmd)
bool BKE_ptcache_id_exist(PTCacheID *pid, int cfra)
bool BKE_ptcache_object_has(struct Scene *scene, struct Object *ob, int duplis)
@ PTCACHE_FILE_PTCACHE
void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd)
void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw)
KDTree< VecBase< float, 3 > > KDTree3d
void BKE_ptcache_free(struct PointCache *cache)
void BKE_ptcache_blend_read_data(struct BlendDataReader *reader, ListBaseT< PointCache > *ptcaches, struct PointCache **ocache, int force_disk)
void BKE_ptcache_quick_cache_all(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer)
void BKE_ptcache_mem_pointers_incr(void *cur[BPHYS_TOT_DATA])
int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra)
BMesh const char void * data
@ PT_CACHE_EDIT_UPDATE_PARTICLE_FROM_EVAL
void BKE_ptcache_bake(struct PTCacheBaker *baker)
void BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
void BKE_ptcache_ids_from_object(ListBaseT< PTCacheID > *lb, struct Object *ob, struct Scene *scene, int duplis)
void BKE_ptcache_id_from_dynamicpaint(PTCacheID *pid, struct Object *ob, struct DynamicPaintSurface *surface)
void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **data, float time)
void BKE_ptcache_validate(struct PointCache *cache, int framenr)
void BKE_ptcache_foreach_object_cache(struct Object &ob, struct Scene &scene, bool duplis, PointCacheIdFn fn)
void BKE_ptcache_free_mem(ListBaseT< PTCacheMem > *mem_cache)
void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys)
void BKE_ptcache_free_list(ListBaseT< PointCache > *ptcaches)
void BKE_ptcache_mem_to_disk(struct PTCacheID *pid)
struct PointCache * BKE_ptcache_add(ListBaseT< PointCache > *ptcaches)
struct PointCache * BKE_ptcache_copy_list(ListBaseT< PointCache > *ptcaches_new, const ListBaseT< PointCache > *ptcaches_old, int flag)
void BKE_ptcache_blend_write(struct BlendWriter *writer, ListBaseT< PointCache > *ptcaches)
PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache)
void BKE_ptcache_update_info(PTCacheID *pid)
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb)
void BKE_ptcache_disk_cache_rename(struct PTCacheID *pid, const char *name_src, const char *name_dst)
int BKE_ptcache_data_size(int data_type)
int BKE_ptcache_mem_pointers_seek(int point_index, struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA])
void BKE_ptcache_toggle_disk_cache(struct PTCacheID *pid)
void BKE_ptcache_invalidate(struct PointCache *cache)
void BKE_ptcache_mem_pointers_init(struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA])
FunctionRef< bool(PTCacheID &pid, ModifierData *md)> PointCacheIdFn
struct PTCacheID pid
struct Depsgraph * depsgraph
void(*) update_progress(void *data, float progress, int *cancel)
struct ViewLayer * view_layer
struct BoidData boids
struct PTCacheEditKey * keys
struct PTCacheID pid
ListBaseT< LinkData > pathcachebufs
PTCacheEditPoint * points
struct ParticleSystemModifierData * psmd
struct ParticleSystem * psys
struct ParticleSystem * psys_eval
struct ParticleSystemModifierData * psmd_eval
struct ParticleCacheKey ** pathcache
struct PTCacheData data
void * cur[BPHYS_TOT_DATA]
struct Scene * scene
int(*) totwrite(void *calldata, int cfra)
unsigned int stack_index
void(*) read_extra_data(void *calldata, struct PTCacheMem *pm, float cfra)
int(*) read_stream(PTCacheFile *pf, void *calldata)
void(*) write_extra_data(void *calldata, struct PTCacheMem *pm, int cfra)
struct PointCache * cache
void(*) interpolate_point(int index, void *calldata, void **data, float cfra, float cfra1, float cfra2, const float *old_data)
struct PTCacheID * prev
unsigned int max_step
void(*) interpolate_extra_data(void *calldata, struct PTCacheMem *pm, float cfra, float cfra1, float cfra2)
unsigned int default_step
struct PointCache ** cache_ptr
int(*) write_header(PTCacheFile *pf)
struct PTCacheID * next
void(*) error(const struct ID *owner_id, void *calldata, const char *message)
int(*) read_header(PTCacheFile *pf)
unsigned int file_type
int(*) totpoint(void *calldata, int cfra)
void(*) read_point(int index, void *calldata, void **data, float cfra, const float *old_data)
int(*) write_point(int index, void *calldata, void **data, int cfra)
ListBaseT< PointCache > * ptcaches
int(*) write_stream(PTCacheFile *pf, void *calldata)
unsigned int info_types
unsigned int data_types
struct ParticleData * particles
eParticleSystem_Flag psys_flag
struct PTCacheEditPoint * points
ListBaseT< PTCacheMem > mem_cache