Blender V4.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
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#ifdef __cplusplus
19extern "C" {
20#endif
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;
71struct ListBase;
72struct Main;
73struct ModifierData;
74struct Object;
75struct ParticleKey;
76struct ParticleSystem;
77struct PointCache;
78struct RigidBodyWorld;
79struct Scene;
80struct SoftBody;
81struct ViewLayer;
82
83/* temp structure for read/write */
84typedef struct PTCacheData {
85 unsigned int index;
86 float loc[3];
87 float vel[3];
88 float rot[4];
89 float ave[3];
90 float size;
91 float times[3];
94
95typedef struct PTCacheFile {
96 FILE *fp;
97
99 unsigned int totpoint, type;
100 unsigned int data_types, flag;
101
102 struct PTCacheData data;
105
106#define PTCACHE_VEL_PER_SEC 1
107
108enum {
110};
111
112typedef struct PTCacheID {
113 struct PTCacheID *next, *prev;
114
115 struct Scene *scene;
116 struct ID *owner_id;
117 void *calldata;
118 unsigned int type, file_type;
119 unsigned int stack_index;
120 unsigned int flag;
121
122 unsigned int default_step;
123 unsigned int max_step;
124
126 unsigned int data_types, info_types;
127
129 int (*write_point)(int index, void *calldata, void **data, int cfra);
131 void (*read_point)(int index, void *calldata, void **data, float cfra, const float *old_data);
133 void (*interpolate_point)(int index,
134 void *calldata,
135 void **data,
136 float cfra,
137 float cfra1,
138 float cfra2,
139 const float *old_data);
140
145
147 void (*write_extra_data)(void *calldata, struct PTCacheMem *pm, int cfra);
149 void (*read_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra);
152 void *calldata, struct PTCacheMem *pm, float cfra, float cfra1, float cfra2);
153
158 int (*totpoint)(void *calldata, int cfra);
160 void (*error)(const struct ID *owner_id, void *calldata, const char *message);
162 int (*totwrite)(void *calldata, int cfra);
163
166
172
173typedef struct PTCacheBaker {
174 struct Main *bmain;
175 struct Scene *scene;
177 struct Depsgraph *depsgraph;
178 bool bake;
179 bool render;
183
184 void (*update_progress)(void *data, float progress, int *cancel);
185 void *bake_job;
187
188/* PTCacheEditKey->flag */
189#define PEK_SELECT 1
190#define PEK_TAG 2
191#define PEK_HIDE 4
192#define PEK_USE_WCO 8
193
194typedef struct PTCacheEditKey {
195 float *co;
196 float *vel;
197 float *rot;
198 float *time;
199
200 float world_co[3];
201 float ftime;
202 float length;
203 short flag;
205
206/* PTCacheEditPoint->flag */
207#define PEP_TAG 1
208#define PEP_EDIT_RECALC 2
209#define PEP_TRANSFORM 4
210#define PEP_HIDE 8
211
217
218typedef struct PTCacheUndo {
220
221 /* particles stuff */
223 struct KDTree_3d *emitter_field;
226
227 /* cache stuff */
229
231
232 size_t undo_size;
234
235enum {
236 /* Modifier stack got evaluated during particle edit mode, need to copy
237 * new evaluated particles to the edit struct.
238 */
240};
241
264
265void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **data, float time);
266
267/**************** Creating ID's ****************************/
268
269void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb);
270void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys);
271void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd);
277void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct FluidModifierData *fmd);
279 struct Object *ob,
280 struct DynamicPaintSurface *surface);
281void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw);
282
287PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache);
289 struct Object *ob,
290 struct Scene *scene,
291 int duplis);
292
295 struct Scene &scene,
296 bool duplis,
297 PointCacheIdFn fn);
298
299/****************** Query functions ****************************/
300
304bool BKE_ptcache_object_has(struct Scene *scene, struct Object *ob, int duplis);
305
306/************ ID specific functions ************************/
307
308void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra);
309bool BKE_ptcache_id_exist(PTCacheID *pid, int cfra);
310int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *pid, int mode);
312 struct Scene *scene,
313 float cfra,
314 int *startframe,
315 int *endframe,
316 float *timescale);
317int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode);
318
320
321/*********** General cache reading/writing ******************/
322
326int BKE_ptcache_data_size(int data_type);
327
332int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, unsigned int index);
333
334/* Memory cache read/write helpers. */
335
336void BKE_ptcache_mem_pointers_init(struct PTCacheMem *pm, void *cur[BPHYS_TOT_DATA]);
338int BKE_ptcache_mem_pointers_seek(int point_index,
339 struct PTCacheMem *pm,
340 void *cur[BPHYS_TOT_DATA]);
341
346int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old);
347
352int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra);
353
354/******************* Allocate & free ***************/
355
356struct PointCache *BKE_ptcache_add(struct ListBase *ptcaches);
358void BKE_ptcache_free(struct PointCache *cache);
359void BKE_ptcache_free_list(struct ListBase *ptcaches);
361struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new,
362 const struct ListBase *ptcaches_old,
363 int flag);
364
365/********************** Baking *********************/
366
370void BKE_ptcache_quick_cache_all(struct Main *bmain,
371 struct Scene *scene,
372 struct ViewLayer *view_layer);
373
378void BKE_ptcache_bake(struct PTCacheBaker *baker);
379
383void BKE_ptcache_disk_to_mem(struct PTCacheID *pid);
387void BKE_ptcache_mem_to_disk(struct PTCacheID *pid);
396 const char *name_src,
397 const char *name_dst);
398
402void BKE_ptcache_load_external(struct PTCacheID *pid);
406void BKE_ptcache_validate(struct PointCache *cache, int framenr);
410void BKE_ptcache_invalidate(struct PointCache *cache);
411
412/********************** .blend File I/O *********************/
413
414void BKE_ptcache_blend_write(struct BlendWriter *writer, struct ListBase *ptcaches);
416 struct ListBase *ptcaches,
417 struct PointCache **ocache,
418 int force_disk);
419
420#ifdef __cplusplus
421}
422#endif
int BKE_ptcache_data_size(int data_type)
void BKE_ptcache_mem_pointers_incr(void *cur[BPHYS_TOT_DATA])
@ PT_CACHE_EDIT_UPDATE_PARTICLE_FROM_EVAL
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 PTCacheFile PTCacheFile
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)
struct PTCacheBaker PTCacheBaker
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)
struct PTCacheID PTCacheID
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)
struct PTCacheEditKey PTCacheEditKey
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)
struct PTCacheEdit PTCacheEdit
void BKE_ptcache_blend_read_data(struct BlendDataReader *reader, struct ListBase *ptcaches, struct PointCache **ocache, int force_disk)
@ PTCACHE_FILE_PTCACHE
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)
int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode)
struct PTCacheEditPoint PTCacheEditPoint
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)
struct PTCacheData PTCacheData
void BKE_ptcache_invalidate(struct PointCache *cache)
struct PTCacheUndo PTCacheUndo
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
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define pf(_x, _i)
Prefetch 64.
Definition gim_memory.h:48
Definition DNA_ID.h:413
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]
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:138