|
Blender
V2.59
|
00001 /* 00002 * 00003 * ***** BEGIN GPL LICENSE BLOCK ***** 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software Foundation, 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 * The Original Code is Copyright (C) 2006 Blender Foundation. 00020 * All rights reserved. 00021 * 00022 * The Original Code is: all of this file. 00023 * 00024 * Contributor(s): Campbell Barton <ideasman42@gmail.com> 00025 * 00026 * ***** END GPL LICENSE BLOCK ***** 00027 */ 00028 00029 #ifndef BKE_POINTCACHE_H 00030 #define BKE_POINTCACHE_H 00031 00036 #include "DNA_ID.h" 00037 #include "DNA_object_force.h" 00038 #include "DNA_boid_types.h" 00039 #include <stdio.h> /* for FILE */ 00040 00041 /* Point cache clearing option, for BKE_ptcache_id_clear, before 00042 * and after are non inclusive (they wont remove the cfra) */ 00043 #define PTCACHE_CLEAR_ALL 0 00044 #define PTCACHE_CLEAR_FRAME 1 00045 #define PTCACHE_CLEAR_BEFORE 2 00046 #define PTCACHE_CLEAR_AFTER 3 00047 00048 /* Point cache reset options */ 00049 #define PTCACHE_RESET_DEPSGRAPH 0 00050 #define PTCACHE_RESET_BAKED 1 00051 #define PTCACHE_RESET_OUTDATED 2 00052 /* #define PTCACHE_RESET_FREE 3 */ /*UNUSED*/ 00053 00054 /* Add the blendfile name after blendcache_ */ 00055 #define PTCACHE_EXT ".bphys" 00056 #define PTCACHE_PATH "blendcache_" 00057 00058 /* File open options, for BKE_ptcache_file_open */ 00059 #define PTCACHE_FILE_READ 0 00060 #define PTCACHE_FILE_WRITE 1 00061 #define PTCACHE_FILE_UPDATE 2 00062 00063 /* PTCacheID types */ 00064 #define PTCACHE_TYPE_SOFTBODY 0 00065 #define PTCACHE_TYPE_PARTICLES 1 00066 #define PTCACHE_TYPE_CLOTH 2 00067 #define PTCACHE_TYPE_SMOKE_DOMAIN 3 00068 #define PTCACHE_TYPE_SMOKE_HIGHRES 4 00069 00070 /* high bits reserved for flags that need to be stored in file */ 00071 #define PTCACHE_TYPEFLAG_COMPRESS (1<<16) 00072 #define PTCACHE_TYPEFLAG_EXTRADATA (1<<17) 00073 00074 #define PTCACHE_TYPEFLAG_TYPEMASK 0x0000FFFF 00075 #define PTCACHE_TYPEFLAG_FLAGMASK 0xFFFF0000 00076 00077 /* PTCache read return code */ 00078 #define PTCACHE_READ_EXACT 1 00079 #define PTCACHE_READ_INTERPOLATED 2 00080 #define PTCACHE_READ_OLD 3 00081 00082 /* Structs */ 00083 struct ClothModifierData; 00084 struct ListBase; 00085 struct Main; 00086 struct Object; 00087 struct ParticleKey; 00088 struct ParticleSystem; 00089 struct PointCache; 00090 struct Scene; 00091 struct SmokeModifierData; 00092 struct SoftBody; 00093 00094 /* temp structure for read/write */ 00095 typedef struct PTCacheData { 00096 unsigned int index; 00097 float loc[3]; 00098 float vel[3]; 00099 float rot[4]; 00100 float ave[3]; 00101 float size; 00102 float times[3]; 00103 struct BoidData boids; 00104 } PTCacheData; 00105 00106 typedef struct PTCacheFile { 00107 FILE *fp; 00108 00109 int frame, old_format; 00110 unsigned int totpoint, type; 00111 unsigned int data_types, flag; 00112 00113 struct PTCacheData data; 00114 void *cur[BPHYS_TOT_DATA]; 00115 } PTCacheFile; 00116 00117 #define PTCACHE_VEL_PER_SEC 1 00118 00119 typedef struct PTCacheID { 00120 struct PTCacheID *next, *prev; 00121 00122 struct Scene *scene; 00123 struct Object *ob; 00124 void *calldata; 00125 unsigned int type; 00126 unsigned int stack_index; 00127 unsigned int flag; 00128 00129 /* flags defined in DNA_object_force.h */ 00130 unsigned int data_types, info_types; 00131 00132 /* copies point data to cache data */ 00133 int (*write_point)(int index, void *calldata, void **data, int cfra); 00134 /* copies cache cata to point data */ 00135 void (*read_point)(int index, void *calldata, void **data, float cfra, float *old_data); 00136 /* interpolated between previously read point data and cache data */ 00137 void (*interpolate_point)(int index, void *calldata, void **data, float cfra, float cfra1, float cfra2, float *old_data); 00138 00139 /* copies point data to cache data */ 00140 int (*write_stream)(PTCacheFile *pf, void *calldata); 00141 /* copies cache cata to point data */ 00142 void (*read_stream)(PTCacheFile *pf, void *calldata); 00143 00144 /* copies custom extradata to cache data */ 00145 void (*write_extra_data)(void *calldata, struct PTCacheMem *pm, int cfra); 00146 /* copies custom extradata to cache data */ 00147 void (*read_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra); 00148 /* copies custom extradata to cache data */ 00149 void (*interpolate_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra, float cfra1, float cfra2); 00150 00151 /* total number of simulated points (the cfra parameter is just for using same function pointer with totwrite) */ 00152 int (*totpoint)(void *calldata, int cfra); 00153 /* number of points written for current cache frame */ 00154 int (*totwrite)(void *calldata, int cfra); 00155 00156 int (*write_header)(PTCacheFile *pf); 00157 int (*read_header)(PTCacheFile *pf); 00158 00159 struct PointCache *cache; 00160 /* used for setting the current cache from ptcaches list */ 00161 struct PointCache **cache_ptr; 00162 struct ListBase *ptcaches; 00163 } PTCacheID; 00164 00165 typedef struct PTCacheBaker { 00166 struct Main *main; 00167 struct Scene *scene; 00168 int bake; 00169 int render; 00170 int anim_init; 00171 int quick_step; 00172 struct PTCacheID *pid; 00173 int (*break_test)(void *data); 00174 void *break_data; 00175 void (*progressbar)(void *data, int num); 00176 void (*progressend)(void *data); 00177 void *progresscontext; 00178 } PTCacheBaker; 00179 00180 /* PTCacheEditKey->flag */ 00181 #define PEK_SELECT 1 00182 #define PEK_TAG 2 00183 #define PEK_HIDE 4 00184 #define PEK_USE_WCO 8 00185 00186 typedef struct PTCacheEditKey{ 00187 float *co; 00188 float *vel; 00189 float *rot; 00190 float *time; 00191 00192 float world_co[3]; 00193 float ftime; 00194 float length; 00195 short flag; 00196 } PTCacheEditKey; 00197 00198 /* PTCacheEditPoint->flag */ 00199 #define PEP_TAG 1 00200 #define PEP_EDIT_RECALC 2 00201 #define PEP_TRANSFORM 4 00202 #define PEP_HIDE 8 00203 00204 typedef struct PTCacheEditPoint { 00205 struct PTCacheEditKey *keys; 00206 int totkey; 00207 short flag; 00208 } PTCacheEditPoint; 00209 00210 typedef struct PTCacheUndo { 00211 struct PTCacheUndo *next, *prev; 00212 struct PTCacheEditPoint *points; 00213 00214 /* particles stuff */ 00215 struct ParticleData *particles; 00216 struct KDTree *emitter_field; 00217 float *emitter_cosnos; 00218 int psys_flag; 00219 00220 /* cache stuff */ 00221 struct ListBase mem_cache; 00222 00223 int totpoint; 00224 char name[64]; 00225 } PTCacheUndo; 00226 00227 typedef struct PTCacheEdit { 00228 ListBase undo; 00229 struct PTCacheUndo *curundo; 00230 PTCacheEditPoint *points; 00231 00232 struct PTCacheID pid; 00233 00234 /* particles stuff */ 00235 struct ParticleSystem *psys; 00236 struct ParticleData *particles; 00237 struct KDTree *emitter_field; 00238 float *emitter_cosnos; /* localspace face centers and normals (average of its verts), from the derived mesh */ 00239 int *mirror_cache; 00240 00241 struct ParticleCacheKey **pathcache; /* path cache (runtime) */ 00242 ListBase pathcachebufs; 00243 00244 int totpoint, totframes, totcached, edited; 00245 00246 unsigned char sel_col[3]; 00247 unsigned char nosel_col[3]; 00248 } PTCacheEdit; 00249 00250 /* Particle functions */ 00251 void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **data, float time); 00252 00253 /**************** Creating ID's ****************************/ 00254 void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb); 00255 void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys); 00256 void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd); 00257 void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd); 00258 00259 void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob, struct Scene *scene, int duplis); 00260 00261 /***************** Global funcs ****************************/ 00262 void BKE_ptcache_remove(void); 00263 00264 /************ ID specific functions ************************/ 00265 void BKE_ptcache_id_clear(PTCacheID *id, int mode, unsigned int cfra); 00266 int BKE_ptcache_id_exist(PTCacheID *id, int cfra); 00267 int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *id, int mode); 00268 void BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale); 00269 int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode); 00270 00271 void BKE_ptcache_update_info(PTCacheID *pid); 00272 00273 /*********** General cache reading/writing ******************/ 00274 00275 /* Size of cache data type. */ 00276 int BKE_ptcache_data_size(int data_type); 00277 00278 /* Is point with indes in memory cache */ 00279 int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, unsigned int index); 00280 00281 /* Memory cache read/write helpers. */ 00282 void BKE_ptcache_mem_pointers_init(struct PTCacheMem *pm); 00283 void BKE_ptcache_mem_pointers_incr(struct PTCacheMem *pm); 00284 int BKE_ptcache_mem_pointers_seek(int point_index, struct PTCacheMem *pm); 00285 00286 /* Copy a specific data type from cache data to point data. */ 00287 void BKE_ptcache_data_get(void **data, int type, int index, void *to); 00288 00289 /* Copy a specific data type from point data to cache data. */ 00290 void BKE_ptcache_data_set(void **data, int type, void *from); 00291 00292 /* Main cache reading call. */ 00293 int BKE_ptcache_read(PTCacheID *pid, float cfra); 00294 00295 /* Main cache writing call. */ 00296 int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra); 00297 00298 /****************** Continue physics ***************/ 00299 void BKE_ptcache_set_continue_physics(struct Main *bmain, struct Scene *scene, int enable); 00300 int BKE_ptcache_get_continue_physics(void); 00301 00302 /******************* Allocate & free ***************/ 00303 struct PointCache *BKE_ptcache_add(struct ListBase *ptcaches); 00304 void BKE_ptcache_free_mem(struct ListBase *mem_cache); 00305 void BKE_ptcache_free(struct PointCache *cache); 00306 void BKE_ptcache_free_list(struct ListBase *ptcaches); 00307 struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new, struct ListBase *ptcaches_old); 00308 00309 /********************** Baking *********************/ 00310 00311 /* Bakes cache with cache_step sized jumps in time, not accurate but very fast. */ 00312 void BKE_ptcache_quick_cache_all(struct Main *bmain, struct Scene *scene); 00313 00314 /* Bake cache or simulate to current frame with settings defined in the baker. */ 00315 void BKE_ptcache_bake(struct PTCacheBaker* baker); 00316 00317 /* Convert disk cache to memory cache. */ 00318 void BKE_ptcache_disk_to_mem(struct PTCacheID *pid); 00319 00320 /* Convert memory cache to disk cache. */ 00321 void BKE_ptcache_mem_to_disk(struct PTCacheID *pid); 00322 00323 /* Convert disk cache to memory cache and vice versa. Clears the cache that was converted. */ 00324 void BKE_ptcache_toggle_disk_cache(struct PTCacheID *pid); 00325 00326 /* Rename all disk cache files with a new name. Doesn't touch the actual content of the files. */ 00327 void BKE_ptcache_disk_cache_rename(struct PTCacheID *pid, char *from, char *to); 00328 00329 /* Loads simulation from external (disk) cache files. */ 00330 void BKE_ptcache_load_external(struct PTCacheID *pid); 00331 00332 /* Set correct flags after successful simulation step */ 00333 void BKE_ptcache_validate(struct PointCache *cache, int framenr); 00334 00335 /* Set correct flags after unsuccessful simulation step */ 00336 void BKE_ptcache_invalidate(struct PointCache *cache); 00337 00338 #endif