Blender V2.61 - r43446

DNA_object_force.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2004-2005 by Blender Foundation
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00034 #ifndef DNA_OBJECT_FORCE_H
00035 #define DNA_OBJECT_FORCE_H
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 #include "DNA_listBase.h"
00042 
00043 /* pd->forcefield:  Effector Fields types */
00044 typedef enum PFieldType {
00045     PFIELD_NULL = 0,    /* (this is used for general effector weight)                           */
00046     PFIELD_FORCE,       /* Force away/towards a point depending on force strength               */
00047     PFIELD_VORTEX,      /* Force around the effector normal                                     */
00048     PFIELD_MAGNET,      /* Force from the cross product of effector normal and point velocity   */
00049     PFIELD_WIND,        /* Force away and towards a point depending which side of the effector  */
00050                         /*   normal the point is                                                */
00051     PFIELD_GUIDE,       /* Force along curve for dynamics, a shaping curve for hair paths       */
00052     PFIELD_TEXTURE,     /* Force based on texture values calculated at point coordinates        */
00053     PFIELD_HARMONIC,    /* Force of a harmonic (damped) oscillator                              */
00054     PFIELD_CHARGE,      /* Force away/towards a point depending on point charge                 */
00055     PFIELD_LENNARDJ,    /* Force due to a Lennard-Jones potential                               */
00056     PFIELD_BOID,        /* Defines predator / goal for boids                                    */
00057     PFIELD_TURBULENCE,  /* Force defined by BLI_gTurbulence                                     */
00058     PFIELD_DRAG,        /* Linear & quadratic drag                                              */
00059     NUM_PFIELD_TYPES
00060 } PFieldType;
00061     
00062 typedef struct PartDeflect {
00063     int   flag;         /* general settings flag                                        */
00064     short deflect;      /* Deflection flag - does mesh deflect particles                */
00065     short forcefield;   /* Force field type, do the vertices attract / repel particles? */
00066     short falloff;      /* fall-off type                                                */
00067     short shape;        /* point, plane or surface                                      */
00068     short tex_mode;     /* texture effector                                             */
00069     short kink, kink_axis; /* for curve guide                                           */
00070     short zdir;
00071     
00072     /* Main effector values */
00073     float f_strength;   /* The strength of the force (+ or - )                  */
00074     float f_damp;       /* Damping ratio of the harmonic effector.              */
00075     float f_flow;       /* How much force is converted into "air flow", i.e.    */
00076                         /* force used as the velocity of surrounding medium.    */
00077 
00078     float f_size;       /* Noise size for noise effector, restlength for harmonic effector */
00079 
00080     /* fall-off */
00081     float f_power;      /* The power law - real gravitation is 2 (square)   */
00082     float maxdist;      /* if indicated, use this maximum                   */
00083     float mindist;      /* if indicated, use this minimum                   */
00084     float f_power_r;    /* radial fall-off power                            */
00085     float maxrad;       /* radial versions of above                         */
00086     float minrad;
00087 
00088     /* particle collisions */
00089     float pdef_damp;    /* Damping factor for particle deflection       */
00090     float pdef_rdamp;   /* Random element of damping for deflection     */
00091     float pdef_perm;    /* Chance of particle passing through mesh      */
00092     float pdef_frict;   /* Friction factor for particle deflection      */
00093     float pdef_rfrict;  /* Random element of friction for deflection    */
00094     float pdef_stickness;/* surface particle stickness                  */
00095 
00096     float absorption;   /* used for forces */
00097     
00098     /* softbody collisions */
00099     float pdef_sbdamp;  /* Damping factor for softbody deflection       */
00100     float pdef_sbift;   /* inner face thickness for softbody deflection */
00101     float pdef_sboft;   /* outer face thickness for softbody deflection */
00102 
00103     /* guide curve, same as for particle child effects */
00104     float clump_fac, clump_pow;
00105     float kink_freq, kink_shape, kink_amp, free_end;
00106 
00107     /* texture effector */
00108     float tex_nabla;    /* Used for calculating partial derivatives */
00109     struct Tex *tex;    /* Texture of the texture effector          */
00110 
00111     /* effector noise */
00112     struct RNG *rng;    /* random noise generator for e.g. wind */
00113     float f_noise;      /* noise of force                       */
00114     int seed;           /* noise random seed                    */
00115 } PartDeflect;
00116 
00117 typedef struct EffectorWeights {
00118     struct Group *group;        /* only use effectors from this group of objects */
00119     
00120     float weight[13];           /* effector type specific weights */
00121     float global_gravity;
00122     short flag, rt[3];
00123 } EffectorWeights;
00124 
00125 /* EffectorWeights->flag */
00126 #define EFF_WEIGHT_DO_HAIR      1
00127 
00128 /* Point cache file data types:
00129  * - used as (1<<flag) so poke jahka if you reach the limit of 15
00130  * - to add new data types update:
00131  *      * BKE_ptcache_data_size()
00132  *      * ptcache_file_init_pointers()
00133 */
00134 #define BPHYS_DATA_INDEX        0
00135 #define BPHYS_DATA_LOCATION     1
00136 #define BPHYS_DATA_SMOKE_LOW    1
00137 #define BPHYS_DATA_VELOCITY     2
00138 #define BPHYS_DATA_SMOKE_HIGH   2
00139 #define BPHYS_DATA_ROTATION     3
00140 #define BPHYS_DATA_DYNAMICPAINT 3
00141 #define BPHYS_DATA_AVELOCITY    4   /* used for particles */
00142 #define BPHYS_DATA_XCONST       4   /* used for cloth */
00143 #define BPHYS_DATA_SIZE         5
00144 #define BPHYS_DATA_TIMES        6
00145 #define BPHYS_DATA_BOIDS        7
00146 
00147 #define BPHYS_TOT_DATA          8
00148 
00149 #define BPHYS_EXTRA_FLUID_SPRINGS   1
00150 
00151 typedef struct PTCacheExtra {
00152     struct PTCacheExtra *next, *prev;
00153     unsigned int type, totdata;
00154     void *data;
00155 } PTCacheExtra;
00156 
00157 typedef struct PTCacheMem {
00158     struct PTCacheMem *next, *prev;
00159     unsigned int frame, totpoint;
00160     unsigned int data_types, flag;
00161 
00162     void *data[8]; /* BPHYS_TOT_DATA */
00163     void *cur[8]; /* BPHYS_TOT_DATA */
00164 
00165     struct ListBase extradata;
00166 } PTCacheMem;
00167 
00168 typedef struct PointCache {
00169     struct PointCache *next, *prev;
00170     int flag;       /* generic flag */
00171     
00172     int step;       /* The number of frames between cached frames.
00173                      * This should probably be an upper bound for a per point adaptive step in the future,
00174                      * buf for now it's the same for all points. Without adaptivity this can effect the perceived
00175                      * simulation quite a bit though. If for example particles are colliding with a horizontal
00176                      * plane (with high damping) they quickly come to a stop on the plane, however there are still
00177                      * forces acting on the particle (gravity and collisions), so the particle velocity isn't necessarily
00178                      * zero for the whole duration of the frame even if the particle seems stationary. If all simulation
00179                      * frames aren't cached (step > 1) these velocities are interpolated into movement for the non-cached
00180                      * frames. The result will look like the point is oscillating around the collision location. So for
00181                      * now cache step should be set to 1 for accurate reproduction of collisions.
00182                      */
00183 
00184     int simframe;   /* current frame of simulation (only if SIMULATION_VALID) */
00185     int startframe; /* simulation start frame */
00186     int endframe;   /* simulation end frame */
00187     int editframe;  /* frame being edited (runtime only) */
00188     int last_exact; /* last exact frame that's cached */
00189 
00190     /* for external cache files */
00191     int totpoint;   /* number of cached points */
00192     int index;  /* modifier stack index */
00193     short compression, rt;
00194     
00195     char name[64];
00196     char prev_name[64];
00197     char info[64];
00198     char path[240]; /* file path, 240 = FILE_MAX */
00199     char *cached_frames;    /* array of length endframe-startframe+1 with flags to indicate cached frames */
00200                             /* can be later used for other per frame flags too if needed */
00201     struct ListBase mem_cache;
00202 
00203     struct PTCacheEdit *edit;
00204     void (*free_edit)(struct PTCacheEdit *edit);    /* free callback */
00205 } PointCache;
00206 
00207 typedef struct SBVertex {
00208     float vec[4];
00209 } SBVertex;
00210 
00211 typedef struct BulletSoftBody {
00212     int flag;               /* various boolean options */
00213     float linStiff;         /* linear stiffness 0..1 */
00214     float   angStiff;       /* angular stiffness 0..1 */
00215     float   volume;         /* volume preservation 0..1 */
00216 
00217     int viterations;        /* Velocities solver iterations */
00218     int piterations;        /* Positions solver iterations */
00219     int diterations;        /* Drift solver iterations */
00220     int citerations;        /* Cluster solver iterations */
00221 
00222     float   kSRHR_CL;       /* Soft vs rigid hardness [0,1] (cluster only) */
00223     float   kSKHR_CL;       /* Soft vs kinetic hardness [0,1] (cluster only) */
00224     float   kSSHR_CL;       /* Soft vs soft hardness [0,1] (cluster only) */
00225     float   kSR_SPLT_CL;    /* Soft vs rigid impulse split [0,1] (cluster only) */
00226 
00227     float   kSK_SPLT_CL;    /* Soft vs rigid impulse split [0,1] (cluster only) */
00228     float   kSS_SPLT_CL;    /* Soft vs rigid impulse split [0,1] (cluster only) */
00229     float   kVCF;           /* Velocities correction factor (Baumgarte) */
00230     float   kDP;            /* Damping coefficient [0,1] */
00231 
00232     float   kDG;            /* Drag coefficient [0,+inf] */
00233     float   kLF;            /* Lift coefficient [0,+inf] */
00234     float   kPR;            /* Pressure coefficient [-inf,+inf] */
00235     float   kVC;            /* Volume conversation coefficient [0,+inf] */
00236 
00237     float   kDF;            /* Dynamic friction coefficient [0,1] */
00238     float   kMT;            /* Pose matching coefficient [0,1] */
00239     float   kCHR;           /* Rigid contacts hardness [0,1] */
00240     float   kKHR;           /* Kinetic contacts hardness [0,1] */
00241 
00242     float   kSHR;           /* Soft contacts hardness [0,1] */
00243     float   kAHR;           /* Anchors hardness [0,1] */
00244     int     collisionflags; /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
00245     int     numclusteriterations;   /* number of iterations to refine collision clusters*/
00246     float   welding;        /* welding limit to remove duplicate/nearby vertices, 0.0..0.01 */
00247     float   margin;         /* margin specific to softbody */
00248 } BulletSoftBody;
00249 
00250 /* BulletSoftBody.flag */
00251 #define OB_BSB_SHAPE_MATCHING   2
00252 #define OB_BSB_UNUSED 4
00253 #define OB_BSB_BENDING_CONSTRAINTS 8
00254 #define OB_BSB_AERO_VPOINT 16 /* aero model, Vertex normals are oriented toward velocity*/
00255 #define OB_BSB_AERO_VTWOSIDE 32 /* aero model, Vertex normals are flipped to match velocity */
00256 
00257 /* BulletSoftBody.collisionflags */
00258 #define OB_BSB_COL_SDF_RS   2 /* SDF based rigid vs soft */
00259 #define OB_BSB_COL_CL_RS    4 /* Cluster based rigid vs soft */
00260 #define OB_BSB_COL_CL_SS    8 /* Cluster based soft vs soft */
00261 #define OB_BSB_COL_VF_SS    16 /* Vertex/Face based soft vs soft */
00262 
00263 
00264 typedef struct SoftBody {
00265     /* dynamic data */
00266     int totpoint, totspring;
00267     struct BodyPoint *bpoint;       /* not saved in file */
00268     struct BodySpring *bspring;     /* not saved in file */
00269     char   pad;
00270     char   msg_lock;
00271     short  msg_value;
00272     
00273     /* part of UI: */
00274     
00275     /* general options */
00276     float nodemass;     /* softbody mass of *vertex* */
00277     char  namedVG_Mass[64]; /* MAX_VGROUP_NAME */ /* along with it introduce mass painting
00278                             starting to fix old bug .. nastyness that VG are indexes 
00279                                 rather find them by name tag to find it -> jow20090613 */
00280     float grav;         /* softbody amount of gravitaion to apply */
00281     float mediafrict;   /* friction to env */
00282     float rklimit;      /* error limit for ODE solver */
00283     float physics_speed;/* user control over simulation speed */
00284     
00285     /* goal */
00286     float goalspring;   /* softbody goal springs */
00287     float goalfrict;    /* softbody goal springs friction */
00288     float mingoal;      /* quick limits for goal */
00289     float maxgoal;
00290     float defgoal;      /* default goal for vertices without vgroup */
00291     short vertgroup;    /* index starting at 1 */
00292     char  namedVG_Softgoal[64]; /* MAX_VGROUP_NAME */ /* starting to fix old bug .. nastyness that VG are indexes 
00293                                 rather find them by name tag to find it -> jow20090613 */
00294   
00295     short fuzzyness;      /* */
00296     
00297     /* springs */
00298     float inspring;     /* softbody inner springs */
00299     float infrict;      /* softbody inner springs friction */
00300     char  namedVG_Spring_K[64]; /* MAX_VGROUP_NAME */ /* along with it introduce Spring_K painting
00301                                    starting to fix old bug .. nastyness that VG are indexes
00302                                    rather find them by name tag to find it -> jow20090613 */
00303     
00304     /* baking */
00305     int sfra, efra;
00306     int interval;
00307     short local, solverflags;       /* local==1: use local coords for baking */
00308     
00309     /* -- these must be kept for backwards compatibility -- */
00310     SBVertex **keys;            /* array of size totpointkey */
00311     int totpointkey, totkey;    /* if totpointkey != totpoint or totkey!- (efra-sfra)/interval -> free keys */
00312     /* ---------------------------------------------------- */
00313     float secondspring;
00314 
00315     /* self collision*/
00316     float colball;      /* fixed collision ball size if > 0 */
00317     float balldamp;     /* cooling down collision response  */
00318     float ballstiff;    /* pressure the ball is loaded with  */
00319     short sbc_mode;
00320     short aeroedge,
00321         minloops,
00322         maxloops,
00323         choke,
00324         solver_ID,
00325         plastic,springpreload
00326         ;   
00327 
00328     struct SBScratch *scratch;  /* scratch pad/cache on live time not saved in file */
00329     float shearstiff;
00330     float inpush;
00331 
00332     struct PointCache *pointcache;
00333     struct ListBase ptcaches;
00334 
00335     struct EffectorWeights *effector_weights;
00336     /* reverse esimated obmatrix .. no need to store in blend file .. how ever who cares */ 
00337     float lcom[3];
00338     float lrot[3][3];
00339     float lscale[3][3];
00340 
00341     int last_frame;
00342 } SoftBody;
00343 
00344 
00345 /* pd->flag: various settings */
00346 #define PFIELD_USEMAX           1
00347 /*#define PDEFLE_DEFORM         2*/         /*UNUSED*/
00348 #define PFIELD_GUIDE_PATH_ADD   4           /* TODO: do_versions for below */
00349 #define PFIELD_PLANAR           8           /* used for do_versions */
00350 #define PDEFLE_KILL_PART        16
00351 #define PFIELD_POSZ             32          /* used for do_versions */
00352 #define PFIELD_TEX_OBJECT       64
00353 #define PFIELD_GLOBAL_CO        64          /* used for turbulence */
00354 #define PFIELD_TEX_2D           128
00355 #define PFIELD_MULTIPLE_SPRINGS 128         /* used for harmonic force */
00356 #define PFIELD_USEMIN           256
00357 #define PFIELD_USEMAXR          512
00358 #define PFIELD_USEMINR          1024
00359 #define PFIELD_TEX_ROOTCO       2048
00360 #define PFIELD_SURFACE          (1<<12)     /* used for do_versions */
00361 #define PFIELD_VISIBILITY       (1<<13)
00362 #define PFIELD_DO_LOCATION      (1<<14)
00363 #define PFIELD_DO_ROTATION      (1<<15)
00364 #define PFIELD_GUIDE_PATH_WEIGHT (1<<16)    /* apply curve weights */
00365 
00366 /* pd->falloff */
00367 #define PFIELD_FALL_SPHERE      0
00368 #define PFIELD_FALL_TUBE        1
00369 #define PFIELD_FALL_CONE        2
00370 
00371 /* pd->shape */
00372 #define PFIELD_SHAPE_POINT      0
00373 #define PFIELD_SHAPE_PLANE      1
00374 #define PFIELD_SHAPE_SURFACE    2
00375 #define PFIELD_SHAPE_POINTS     3
00376 
00377 /* pd->tex_mode */
00378 #define PFIELD_TEX_RGB  0
00379 #define PFIELD_TEX_GRAD 1
00380 #define PFIELD_TEX_CURL 2
00381 
00382 /* pd->zdir */
00383 #define PFIELD_Z_BOTH   0
00384 #define PFIELD_Z_POS    1
00385 #define PFIELD_Z_NEG    2
00386 
00387 /* pointcache->flag */
00388 #define PTCACHE_BAKED               1
00389 #define PTCACHE_OUTDATED            2
00390 #define PTCACHE_SIMULATION_VALID    4
00391 #define PTCACHE_BAKING              8
00392 //#define PTCACHE_BAKE_EDIT         16
00393 //#define PTCACHE_BAKE_EDIT_ACTIVE  32
00394 #define PTCACHE_DISK_CACHE          64
00395 #define PTCACHE_QUICK_CACHE         128
00396 #define PTCACHE_FRAMES_SKIPPED      256
00397 #define PTCACHE_EXTERNAL            512
00398 #define PTCACHE_READ_INFO           1024
00399 /* dont use the filename of the blendfile the data is linked from (write a local cache) */
00400 #define PTCACHE_IGNORE_LIBPATH      2048
00401 /* high resolution cache is saved for smoke for backwards compatibility, so set this flag to know it's a "fake" cache */
00402 #define PTCACHE_FAKE_SMOKE          (1<<12)
00403 #define PTCACHE_IGNORE_CLEAR        (1<<13)
00404 
00405 /* PTCACHE_OUTDATED + PTCACHE_FRAMES_SKIPPED */
00406 #define PTCACHE_REDO_NEEDED         258
00407 
00408 #define PTCACHE_COMPRESS_NO         0
00409 #define PTCACHE_COMPRESS_LZO        1
00410 #define PTCACHE_COMPRESS_LZMA       2
00411 
00412 /* ob->softflag */
00413 #define OB_SB_ENABLE    1       /* deprecated, use modifier */
00414 #define OB_SB_GOAL      2
00415 #define OB_SB_EDGES     4
00416 #define OB_SB_QUADS     8
00417 #define OB_SB_POSTDEF   16
00418 // #define OB_SB_REDO       32
00419 // #define OB_SB_BAKESET    64
00420 // #define OB_SB_BAKEDO 128
00421 // #define OB_SB_RESET      256
00422 #define OB_SB_SELF      512
00423 #define OB_SB_FACECOLL  1024
00424 #define OB_SB_EDGECOLL  2048
00425 /* #define OB_SB_COLLFINAL 4096 */ /* deprecated */
00426 /* #define OB_SB_BIG_UI 8192 */    /* deprecated */
00427 #define OB_SB_AERO_ANGLE    16384
00428 
00429 /* sb->solverflags */
00430 #define SBSO_MONITOR        1 
00431 #define SBSO_OLDERR         2 
00432 #define SBSO_ESTIMATEIPO    4 
00433 
00434 /* sb->sbc_mode */
00435 #define SBC_MODE_MANUAL     0
00436 #define SBC_MODE_AVG        1
00437 #define SBC_MODE_MIN        2
00438 #define SBC_MODE_MAX        3
00439 #define SBC_MODE_AVGMINMAX  4
00440 
00441 #ifdef __cplusplus
00442 }
00443 #endif
00444 
00445 #endif
00446