Blender V5.0
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_pointcache_types.h" /* for #BPHYS_TOT_DATA */
15
16#include <stdio.h> /* for #FILE */
17
18/* Point cache clearing option, for BKE_ptcache_id_clear, before
19 * and after are non-inclusive (they won't remove the cfra) */
20#define PTCACHE_CLEAR_ALL 0
21#define PTCACHE_CLEAR_FRAME 1
22#define PTCACHE_CLEAR_BEFORE 2
23#define PTCACHE_CLEAR_AFTER 3
24
25/* Point cache reset options */
26#define PTCACHE_RESET_DEPSGRAPH 0
27#define PTCACHE_RESET_BAKED 1
28#define PTCACHE_RESET_OUTDATED 2
29// #define PTCACHE_RESET_FREE 3 /*UNUSED*/
30
31/* Add the blend-file name after `blendcache_`. */
32#define PTCACHE_EXT ".bphys"
33#define PTCACHE_PATH "blendcache_"
34
35/* File open options, for BKE_ptcache_file_open */
36#define PTCACHE_FILE_READ 0
37#define PTCACHE_FILE_WRITE 1
38#define PTCACHE_FILE_UPDATE 2
39
40/* PTCacheID types */
41#define PTCACHE_TYPE_SOFTBODY 0
42#define PTCACHE_TYPE_PARTICLES 1
43#define PTCACHE_TYPE_CLOTH 2
44#define PTCACHE_TYPE_SMOKE_DOMAIN 3
45#define PTCACHE_TYPE_SMOKE_HIGHRES 4
46#define PTCACHE_TYPE_DYNAMICPAINT 5
47#define PTCACHE_TYPE_RIGIDBODY 6
48
49/* high bits reserved for flags that need to be stored in file */
50#define PTCACHE_TYPEFLAG_COMPRESS (1 << 16)
51#define PTCACHE_TYPEFLAG_EXTRADATA (1 << 17)
52
53#define PTCACHE_TYPEFLAG_TYPEMASK 0x0000FFFF
54#define PTCACHE_TYPEFLAG_FLAGMASK 0xFFFF0000
55
56/* PTCache read return code */
57#define PTCACHE_READ_EXACT 1
58#define PTCACHE_READ_INTERPOLATED 2
59#define PTCACHE_READ_OLD 3
60
61/* Structs */
62struct BlendDataReader;
63struct BlendWriter;
67struct ListBase;
68struct Main;
69struct ModifierData;
70struct Object;
71struct ParticleKey;
72struct ParticleSystem;
73struct PointCache;
74struct RigidBodyWorld;
75struct Scene;
76struct SoftBody;
77struct ViewLayer;
78
79/* temp structure for read/write */
80typedef struct PTCacheData {
81 unsigned int index;
82 float loc[3];
83 float vel[3];
84 float rot[4];
85 float ave[3];
86 float size;
87 float times[3];
90
91typedef struct PTCacheFile {
92 FILE *fp;
93
95 unsigned int totpoint, type;
96 unsigned int data_types, flag;
97
101
102#define PTCACHE_VEL_PER_SEC 1
103
104enum {
106};
107
108typedef struct PTCacheID {
109 struct PTCacheID *next, *prev;
110
111 struct Scene *scene;
112 struct ID *owner_id;
113 void *calldata;
114 unsigned int type, file_type;
115 unsigned int stack_index;
116 unsigned int flag;
117
118 unsigned int default_step;
119 unsigned int max_step;
120
122 unsigned int data_types, info_types;
123
125 int (*write_point)(int index, void *calldata, void **data, int cfra);
127 void (*read_point)(int index, void *calldata, void **data, float cfra, const float *old_data);
129 void (*interpolate_point)(int index,
130 void *calldata,
131 void **data,
132 float cfra,
133 float cfra1,
134 float cfra2,
135 const float *old_data);
136
141
143 void (*write_extra_data)(void *calldata, struct PTCacheMem *pm, int cfra);
145 void (*read_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra);
148 void *calldata, struct PTCacheMem *pm, float cfra, float cfra1, float cfra2);
149
154 int (*totpoint)(void *calldata, int cfra);
156 void (*error)(const struct ID *owner_id, void *calldata, const char *message);
158 int (*totwrite)(void *calldata, int cfra);
159
162
168
169typedef struct PTCacheBaker {
170 struct Main *bmain;
171 struct Scene *scene;
173 struct Depsgraph *depsgraph;
174 bool bake;
175 bool render;
179
180 void (*update_progress)(void *data, float progress, int *cancel);
181 void *bake_job;
183
184/* PTCacheEditKey->flag */
185#define PEK_SELECT 1
186#define PEK_TAG 2
187#define PEK_HIDE 4
188#define PEK_USE_WCO 8
189
190typedef struct PTCacheEditKey {
191 float *co;
192 float *vel;
193 float *rot;
194 float *time;
195
196 float world_co[3];
197 float ftime;
198 float length;
199 short flag;
201
202/* PTCacheEditPoint->flag */
203#define PEP_TAG 1
204#define PEP_EDIT_RECALC 2
205#define PEP_TRANSFORM 4
206#define PEP_HIDE 8
207
213
214typedef struct PTCacheUndo {
216
217 /* particles stuff */
219 struct KDTree_3d *emitter_field;
222
223 /* cache stuff */
225
227
228 size_t undo_size;
230
231enum {
232 /* Modifier stack got evaluated during particle edit mode, need to copy
233 * new evaluated particles to the edit struct.
234 */
236};
237
260
261void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **data, float time);
262
263/**************** Creating ID's ****************************/
264
265void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb);
266void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys);
267void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd);
273void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct FluidModifierData *fmd);
275 struct Object *ob,
276 struct DynamicPaintSurface *surface);
277void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw);
278
283PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache);
285 struct Object *ob,
286 struct Scene *scene,
287 int duplis);
288
291 struct Scene &scene,
292 bool duplis,
293 PointCacheIdFn fn);
294
295/****************** Query functions ****************************/
296
300bool BKE_ptcache_object_has(struct Scene *scene, struct Object *ob, int duplis);
301
302/************ ID specific functions ************************/
303
304void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra);
305bool BKE_ptcache_id_exist(PTCacheID *pid, int cfra);
306int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *pid, int mode);
308 struct Scene *scene,
309 float cfra,
310 int *startframe,
311 int *endframe,
312 float *timescale);
313int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode);
314
316
317/*********** General cache reading/writing ******************/
318
322int BKE_ptcache_data_size(int data_type);
323
328int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, unsigned int index);
329
330/* Memory cache read/write helpers. */
331
332void BKE_ptcache_mem_pointers_init(struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA]);
334int BKE_ptcache_mem_pointers_seek(int point_index,
335 struct PTCacheMem *pm,
336 void *cur[BPHYS_TOT_DATA]);
337
342int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old);
343
348int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra);
349
350/******************* Allocate & free ***************/
351
352struct PointCache *BKE_ptcache_add(struct ListBase *ptcaches);
354void BKE_ptcache_free(struct PointCache *cache);
355void BKE_ptcache_free_list(struct ListBase *ptcaches);
357struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new,
358 const struct ListBase *ptcaches_old,
359 int flag);
360
361/********************** Baking *********************/
362
366void BKE_ptcache_quick_cache_all(struct Main *bmain,
367 struct Scene *scene,
368 struct ViewLayer *view_layer);
369
374void BKE_ptcache_bake(struct PTCacheBaker *baker);
375
379void BKE_ptcache_disk_to_mem(struct PTCacheID *pid);
383void BKE_ptcache_mem_to_disk(struct PTCacheID *pid);
392 const char *name_src,
393 const char *name_dst);
394
398void BKE_ptcache_load_external(struct PTCacheID *pid);
402void BKE_ptcache_validate(struct PointCache *cache, int framenr);
406void BKE_ptcache_invalidate(struct PointCache *cache);
407
408/********************** .blend File I/O *********************/
409
410void BKE_ptcache_blend_write(struct BlendWriter *writer, struct ListBase *ptcaches);
412 struct ListBase *ptcaches,
413 struct PointCache **ocache,
414 int force_disk);
int BKE_ptcache_data_size(int data_type)
void BKE_ptcache_mem_pointers_incr(void *cur[BPHYS_TOT_DATA])
void BKE_ptcache_free_mem(struct ListBase *mem_cache)
void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob, struct Scene *scene, int duplis)
struct PointCache * BKE_ptcache_copy_list(struct ListBase *ptcaches_new, const struct ListBase *ptcaches_old, int flag)
bool BKE_ptcache_object_has(struct Scene *scene, struct Object *ob, int duplis)
void BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw)
void BKE_ptcache_quick_cache_all(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer)
void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys)
void BKE_ptcache_update_info(PTCacheID *pid)
void BKE_ptcache_validate(struct PointCache *cache, int framenr)
void BKE_ptcache_bake(struct PTCacheBaker *baker)
void BKE_ptcache_toggle_disk_cache(struct PTCacheID *pid)
void BKE_ptcache_id_from_dynamicpaint(PTCacheID *pid, struct Object *ob, struct DynamicPaintSurface *surface)
int BKE_ptcache_mem_pointers_seek(int point_index, struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA])
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb)
void BKE_ptcache_disk_to_mem(struct PTCacheID *pid)
bool BKE_ptcache_id_exist(PTCacheID *pid, int cfra)
struct PointCache * BKE_ptcache_add(struct ListBase *ptcaches)
@ PTCACHE_FILE_PTCACHE
blender::FunctionRef< bool(PTCacheID &pid, ModifierData *md)> PointCacheIdFn
void BKE_ptcache_blend_read_data(struct BlendDataReader *reader, struct ListBase *ptcaches, struct PointCache **ocache, int force_disk)
void BKE_ptcache_load_external(struct PTCacheID *pid)
PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache)
int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old)
int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, unsigned int index)
void BKE_ptcache_foreach_object_cache(struct Object &ob, struct Scene &scene, bool duplis, PointCacheIdFn fn)
void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **data, float time)
void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd)
int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra)
void BKE_ptcache_mem_to_disk(struct PTCacheID *pid)
void BKE_ptcache_free_list(struct ListBase *ptcaches)
@ PT_CACHE_EDIT_UPDATE_PARTICLE_FROM_EVAL
int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode)
int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *pid, int mode)
void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct FluidModifierData *fmd)
void BKE_ptcache_free(struct PointCache *cache)
void BKE_ptcache_invalidate(struct PointCache *cache)
void BKE_ptcache_disk_cache_rename(struct PTCacheID *pid, const char *name_src, const char *name_dst)
void BKE_ptcache_mem_pointers_init(struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA])
void BKE_ptcache_blend_write(struct BlendWriter *writer, struct ListBase *ptcaches)
#define BPHYS_TOT_DATA
BMesh const char void * data
#define pf(_x, _i)
Prefetch 64.
Definition gim_memory.h:48
Definition DNA_ID.h:414
struct PTCacheID pid
struct Scene * scene
struct Main * bmain
void(* update_progress)(void *data, float progress, int *cancel)
struct Depsgraph * depsgraph
struct ViewLayer * view_layer
struct BoidData boids
float times[3]
unsigned int index
struct PTCacheEditKey * keys
ListBase pathcachebufs
struct ParticleSystemModifierData * psmd
struct ParticleCacheKey ** pathcache
float * emitter_cosnos
PTCacheEditPoint * points
struct ParticleSystem * psys
struct ParticleSystemModifierData * psmd_eval
struct KDTree_3d * emitter_field
struct PTCacheID pid
struct ParticleSystem * psys_eval
void * cur[BPHYS_TOT_DATA]
struct PTCacheData data
unsigned int totpoint
unsigned int flag
unsigned int type
unsigned int data_types
struct PointCache ** cache_ptr
int(* write_stream)(PTCacheFile *pf, void *calldata)
int(* write_point)(int index, void *calldata, void **data, int cfra)
unsigned int data_types
struct ID * owner_id
unsigned int info_types
int(* write_header)(PTCacheFile *pf)
void(* read_point)(int index, void *calldata, void **data, float cfra, const float *old_data)
void * calldata
unsigned int type
struct Scene * scene
void(* interpolate_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra, float cfra1, float cfra2)
unsigned int stack_index
struct ListBase * ptcaches
struct PTCacheID * prev
unsigned int flag
void(* read_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra)
void(* interpolate_point)(int index, void *calldata, void **data, float cfra, float cfra1, float cfra2, const float *old_data)
unsigned int default_step
int(* totpoint)(void *calldata, int cfra)
unsigned int file_type
int(* totwrite)(void *calldata, int cfra)
void(* write_extra_data)(void *calldata, struct PTCacheMem *pm, int cfra)
int(* read_stream)(PTCacheFile *pf, void *calldata)
unsigned int max_step
void(* error)(const struct ID *owner_id, void *calldata, const char *message)
struct PTCacheID * next
int(* read_header)(PTCacheFile *pf)
struct PointCache * cache
float * emitter_cosnos
struct ListBase mem_cache
struct KDTree_3d * emitter_field
struct PTCacheEditPoint * points
struct ParticleData * particles
struct ListBase mem_cache
uint8_t flag
Definition wm_window.cc:145