Blender  V3.3
BKE_pointcache.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2006 Blender Foundation. All rights reserved. */
3 
4 #pragma once
5 
10 #include "DNA_boid_types.h" /* for #BoidData */
11 #include "DNA_pointcache_types.h" /* for #BPHYS_TOT_DATA */
12 
13 #include <stdio.h> /* for #FILE */
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /* Point cache clearing option, for BKE_ptcache_id_clear, before
20  * and after are non-inclusive (they won't remove the cfra) */
21 #define PTCACHE_CLEAR_ALL 0
22 #define PTCACHE_CLEAR_FRAME 1
23 #define PTCACHE_CLEAR_BEFORE 2
24 #define PTCACHE_CLEAR_AFTER 3
25 
26 /* Point cache reset options */
27 #define PTCACHE_RESET_DEPSGRAPH 0
28 #define PTCACHE_RESET_BAKED 1
29 #define PTCACHE_RESET_OUTDATED 2
30 /* #define PTCACHE_RESET_FREE 3 */ /*UNUSED*/
31 
32 /* Add the blend-file name after `blendcache_`. */
33 #define PTCACHE_EXT ".bphys"
34 #define PTCACHE_PATH "blendcache_"
35 
36 /* File open options, for BKE_ptcache_file_open */
37 #define PTCACHE_FILE_READ 0
38 #define PTCACHE_FILE_WRITE 1
39 #define PTCACHE_FILE_UPDATE 2
40 
41 /* PTCacheID types */
42 #define PTCACHE_TYPE_SOFTBODY 0
43 #define PTCACHE_TYPE_PARTICLES 1
44 #define PTCACHE_TYPE_CLOTH 2
45 #define PTCACHE_TYPE_SMOKE_DOMAIN 3
46 #define PTCACHE_TYPE_SMOKE_HIGHRES 4
47 #define PTCACHE_TYPE_DYNAMICPAINT 5
48 #define PTCACHE_TYPE_RIGIDBODY 6
49 #define PTCACHE_TYPE_SIM_PARTICLES 7
50 
51 /* high bits reserved for flags that need to be stored in file */
52 #define PTCACHE_TYPEFLAG_COMPRESS (1 << 16)
53 #define PTCACHE_TYPEFLAG_EXTRADATA (1 << 17)
54 
55 #define PTCACHE_TYPEFLAG_TYPEMASK 0x0000FFFF
56 #define PTCACHE_TYPEFLAG_FLAGMASK 0xFFFF0000
57 
58 /* PTCache read return code */
59 #define PTCACHE_READ_EXACT 1
60 #define PTCACHE_READ_INTERPOLATED 2
61 #define PTCACHE_READ_OLD 3
62 
63 /* Structs */
64 struct BlendDataReader;
65 struct BlendWriter;
66 struct ClothModifierData;
67 struct DynamicPaintSurface;
68 struct FluidModifierData;
69 struct ListBase;
70 struct Main;
71 struct Object;
72 struct ParticleKey;
73 struct ParticleSystem;
74 struct PointCache;
75 struct RigidBodyWorld;
76 struct Scene;
77 struct SoftBody;
78 struct ViewLayer;
79 
80 /* temp structure for read/write */
81 typedef struct PTCacheData {
82  unsigned int index;
83  float loc[3];
84  float vel[3];
85  float rot[4];
86  float ave[3];
87  float size;
88  float times[3];
89  struct BoidData boids;
91 
92 typedef struct PTCacheFile {
93  FILE *fp;
94 
96  unsigned int totpoint, type;
97  unsigned int data_types, flag;
98 
99  struct PTCacheData data;
102 
103 #define PTCACHE_VEL_PER_SEC 1
104 
105 enum {
107 };
108 
109 typedef struct PTCacheID {
110  struct PTCacheID *next, *prev;
111 
112  struct Scene *scene;
113  struct ID *owner_id;
114  void *calldata;
115  unsigned int type, file_type;
116  unsigned int stack_index;
117  unsigned int flag;
118 
119  unsigned int default_step;
120  unsigned int max_step;
121 
122  /* flags defined in DNA_object_force_types.h */
123  unsigned int data_types, info_types;
124 
125  /* copies point data to cache data */
126  int (*write_point)(int index, void *calldata, void **data, int cfra);
127  /* copies cache cata to point data */
128  void (*read_point)(int index, void *calldata, void **data, float cfra, const float *old_data);
129  /* interpolated between previously read point data and cache data */
130  void (*interpolate_point)(int index,
131  void *calldata,
132  void **data,
133  float cfra,
134  float cfra1,
135  float cfra2,
136  const float *old_data);
137 
138  /* copies point data to cache data */
140  /* copies cache cata to point data */
142 
143  /* copies custom extradata to cache data */
144  void (*write_extra_data)(void *calldata, struct PTCacheMem *pm, int cfra);
145  /* copies custom extradata to cache data */
146  void (*read_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra);
147  /* copies custom extradata to cache data */
149  void *calldata, struct PTCacheMem *pm, float cfra, float cfra1, float cfra2);
150 
151  /* Total number of simulated points
152  * (the cfra parameter is just for using same function pointer with totwrite). */
153  int (*totpoint)(void *calldata, int cfra);
154  /* report error if number of points does not match */
155  void (*error)(const struct ID *owner_id, void *calldata, const char *message);
156  /* number of points written for current cache frame */
157  int (*totwrite)(void *calldata, int cfra);
158 
161 
162  struct PointCache *cache;
163  /* used for setting the current cache from ptcaches list */
167 
168 typedef struct PTCacheBaker {
169  struct Main *bmain;
170  struct Scene *scene;
173  int bake;
174  int render;
177  struct PTCacheID pid;
178 
179  void (*update_progress)(void *data, float progress, int *cancel);
180  void *bake_job;
182 
183 /* PTCacheEditKey->flag */
184 #define PEK_SELECT 1
185 #define PEK_TAG 2
186 #define PEK_HIDE 4
187 #define PEK_USE_WCO 8
188 
189 typedef struct PTCacheEditKey {
190  float *co;
191  float *vel;
192  float *rot;
193  float *time;
194 
195  float world_co[3];
196  float ftime;
197  float length;
198  short flag;
200 
201 /* PTCacheEditPoint->flag */
202 #define PEP_TAG 1
203 #define PEP_EDIT_RECALC 2
204 #define PEP_TRANSFORM 4
205 #define PEP_HIDE 8
206 
207 typedef struct PTCacheEditPoint {
209  int totkey;
210  short flag;
212 
213 typedef struct PTCacheUndo {
215 
216  /* particles stuff */
218  struct KDTree_3d *emitter_field;
221 
222  /* cache stuff */
223  struct ListBase mem_cache;
224 
225  int totpoint;
226 
227  size_t undo_size;
229 
230 enum {
231  /* Modifier stack got evaluated during particle edit mode, need to copy
232  * new evaluated particles to the edit struct.
233  */
235 };
236 
237 typedef struct PTCacheEdit {
238  int flags;
239 
241 
242  struct PTCacheID pid;
243 
244  /* particles stuff */
249  struct KDTree_3d *emitter_field;
250  /* Localspace face centers and normals (average of its verts), from the derived mesh. */
253 
254  struct ParticleCacheKey **pathcache; /* path cache (runtime) */
256 
259 
260 void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **data, float time);
261 
262 /**************** Creating ID's ****************************/
263 
264 void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb);
265 void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys);
266 void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd);
272 void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct FluidModifierData *fmd);
274  struct Object *ob,
275  struct DynamicPaintSurface *surface);
276 void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw);
277 
282 PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache);
283 void BKE_ptcache_ids_from_object(struct ListBase *lb,
284  struct Object *ob,
285  struct Scene *scene,
286  int duplis);
287 
288 /****************** Query funcs ****************************/
289 
293 bool BKE_ptcache_object_has(struct Scene *scene, struct Object *ob, int duplis);
294 
295 /************ ID specific functions ************************/
296 void BKE_ptcache_id_clear(PTCacheID *id, int mode, unsigned int cfra);
297 bool BKE_ptcache_id_exist(PTCacheID *id, int cfra);
298 int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *id, int mode);
300  struct Scene *scene,
301  float cfra,
302  int *startframe,
303  int *endframe,
304  float *timescale);
305 int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode);
306 
308 
309 /*********** General cache reading/writing ******************/
310 
314 int BKE_ptcache_data_size(int data_type);
315 
320 int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, unsigned int index);
321 
322 /* Memory cache read/write helpers. */
323 
324 void BKE_ptcache_mem_pointers_init(struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA]);
327  struct PTCacheMem *pm,
328  void *cur[BPHYS_TOT_DATA]);
329 
334 int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old);
335 
340 int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra);
341 
342 /******************* Allocate & free ***************/
343 struct PointCache *BKE_ptcache_add(struct ListBase *ptcaches);
345 void BKE_ptcache_free(struct PointCache *cache);
346 void BKE_ptcache_free_list(struct ListBase *ptcaches);
347 /* returns first point cache */
348 struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new,
349  const struct ListBase *ptcaches_old,
350  int flag);
351 
352 /********************** Baking *********************/
353 
357 void BKE_ptcache_quick_cache_all(struct Main *bmain,
358  struct Scene *scene,
359  struct ViewLayer *view_layer);
360 
365 void BKE_ptcache_bake(struct PTCacheBaker *baker);
366 
370 void BKE_ptcache_disk_to_mem(struct PTCacheID *pid);
374 void BKE_ptcache_mem_to_disk(struct PTCacheID *pid);
378 void BKE_ptcache_toggle_disk_cache(struct PTCacheID *pid);
383  const char *name_src,
384  const char *name_dst);
385 
389 void BKE_ptcache_load_external(struct PTCacheID *pid);
393 void BKE_ptcache_validate(struct PointCache *cache, int framenr);
397 void BKE_ptcache_invalidate(struct PointCache *cache);
398 
399 /********************** .blend File I/O *********************/
400 
401 void BKE_ptcache_blend_write(struct BlendWriter *writer, struct ListBase *ptcaches);
402 void BKE_ptcache_blend_read_data(struct BlendDataReader *reader,
403  struct ListBase *ptcaches,
404  struct PointCache **ocache,
405  int force_disk);
406 
407 #ifdef __cplusplus
408 }
409 #endif
int BKE_ptcache_data_size(int data_type)
Definition: pointcache.c:1707
bool BKE_ptcache_id_exist(PTCacheID *id, int cfra)
Definition: pointcache.c:2742
void BKE_ptcache_mem_pointers_incr(void *cur[BPHYS_TOT_DATA])
Definition: pointcache.c:1772
void BKE_ptcache_free_mem(struct ListBase *mem_cache)
Definition: pointcache.c:3029
void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob, struct Scene *scene, int duplis)
Definition: pointcache.c:1250
struct PTCacheFile PTCacheFile
bool BKE_ptcache_object_has(struct Scene *scene, struct Object *ob, int duplis)
Definition: pointcache.c:1263
void BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
Definition: pointcache.c:2773
void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw)
Definition: pointcache.c:1054
struct PTCacheBaker PTCacheBaker
void BKE_ptcache_quick_cache_all(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer)
Definition: pointcache.c:3124
struct PointCache * BKE_ptcache_copy_list(struct ListBase *ptcaches_new, const struct ListBase *ptcaches_old, int flag)
void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys)
Definition: pointcache.c:900
void BKE_ptcache_update_info(PTCacheID *pid)
Definition: pointcache.c:3687
void BKE_ptcache_validate(struct PointCache *cache, int framenr)
Definition: pointcache.c:3789
@ PTCACHE_FILE_PTCACHE
void BKE_ptcache_bake(struct PTCacheBaker *baker)
Definition: pointcache.c:3156
void BKE_ptcache_toggle_disk_cache(struct PTCacheID *pid)
Definition: pointcache.c:3472
void BKE_ptcache_id_from_dynamicpaint(PTCacheID *pid, struct Object *ob, struct DynamicPaintSurface *surface)
Definition: pointcache.c:1016
struct PTCacheID PTCacheID
int BKE_ptcache_mem_pointers_seek(int point_index, struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA])
Definition: pointcache.c:1782
void BKE_ptcache_id_clear(PTCacheID *id, int mode, unsigned int cfra)
Definition: pointcache.c:2592
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb)
Definition: pointcache.c:864
struct PTCacheEditKey PTCacheEditKey
void BKE_ptcache_disk_to_mem(struct PTCacheID *pid)
Definition: pointcache.c:3421
struct PTCacheEdit PTCacheEdit
void BKE_ptcache_blend_read_data(struct BlendDataReader *reader, struct ListBase *ptcaches, struct PointCache **ocache, int force_disk)
Definition: pointcache.c:3896
int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *id, int mode)
Definition: pointcache.c:2870
@ PT_CACHE_EDIT_UPDATE_PARTICLE_FROM_EVAL
struct PointCache * BKE_ptcache_add(struct ListBase *ptcaches)
Definition: pointcache.c:3014
void BKE_ptcache_load_external(struct PTCacheID *pid)
Definition: pointcache.c:3574
PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache)
Definition: pointcache.c:1092
int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old)
Definition: pointcache.c:2280
int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, unsigned int index)
Definition: pointcache.c:1727
void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **data, float time)
Definition: pointcache.c:257
void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd)
Definition: pointcache.c:962
int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra)
Definition: pointcache.c:2540
void BKE_ptcache_mem_to_disk(struct PTCacheID *pid)
Definition: pointcache.c:3445
void BKE_ptcache_free_list(struct ListBase *ptcaches)
Definition: pointcache.c:3052
int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode)
Definition: pointcache.c:2930
struct PTCacheEditPoint PTCacheEditPoint
void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct FluidModifierData *fmd)
Definition: pointcache.c:999
void BKE_ptcache_free(struct PointCache *cache)
Definition: pointcache.c:3041
struct PTCacheData PTCacheData
void BKE_ptcache_invalidate(struct PointCache *cache)
Definition: pointcache.c:3796
struct PTCacheUndo PTCacheUndo
void BKE_ptcache_disk_cache_rename(struct PTCacheID *pid, const char *name_src, const char *name_dst)
Definition: pointcache.c:3517
void BKE_ptcache_mem_pointers_init(struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA])
Definition: pointcache.c:1762
void BKE_ptcache_blend_write(struct BlendWriter *writer, struct ListBase *ptcaches)
Definition: pointcache.c:3820
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
#define BPHYS_TOT_DATA
double time
Scene scene
SyclQueue void void size_t num_bytes void
struct @211::@212 surface
#define pf(_x, _i)
Prefetch 64.
Definition: gim_memory.h:48
Definition: DNA_ID.h:368
Definition: BKE_main.h:121
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 ave[3]
float vel[3]
float times[3]
float loc[3]
float rot[4]
unsigned int index
struct PTCacheEditKey * keys
ListBase pathcachebufs
struct ParticleSystemModifierData * psmd
struct ParticleCacheKey ** pathcache
float * emitter_cosnos
int * mirror_cache
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
size_t undo_size
float * emitter_cosnos
struct ListBase mem_cache
struct KDTree_3d * emitter_field
struct PTCacheEditPoint * points
struct ParticleData * particles
struct ListBase mem_cache