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