Blender V2.61 - r43446
Classes | Defines | Typedefs | Enumerations | Functions | Variables

softbody.c File Reference

#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_lattice_types.h"
#include "DNA_curve_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BLI_ghash.h"
#include "BLI_threads.h"
#include "BKE_curve.h"
#include "BKE_effect.h"
#include "BKE_global.h"
#include "BKE_modifier.h"
#include "BKE_softbody.h"
#include "BKE_DerivedMesh.h"
#include "BKE_pointcache.h"
#include "BKE_deform.h"
#include "PIL_time.h"

Go to the source code of this file.

Classes

struct  BodySpring
struct  BodyFace
struct  ReferenceVert
struct  ReferenceState
struct  SBScratch
struct  SB_thread_context
struct  ccdf_minmax
struct  ccd_Mesh

Defines

#define NLF_BUILD   1
#define NLF_SOLVE   2
#define MID_PRESERVE   1
#define SOFTGOALSNAP   0.999f
#define HEUNWARNLIMIT   1
#define BSF_INTERSECT   1
#define SBF_DOFUZZY   1
#define SBF_OUTOFCOLLISION   2
#define BFF_INTERSECT   1
#define BFF_CLOSEVERT   2

Typedefs

typedef struct BodySpring BodySpring
typedef struct BodyFace BodyFace
typedef struct ReferenceVert ReferenceVert
typedef struct ReferenceState ReferenceState
typedef struct SBScratch SBScratch
typedef struct SB_thread_context SB_thread_context
typedef struct ccdf_minmax ccdf_minmax
typedef struct ccd_Mesh ccd_Mesh

Enumerations

enum  type_spring { SB_EDGE = 1, SB_BEND = 2, SB_STIFFQUAD = 3, SB_HANDLE = 4 }

Functions

static void free_softbody_intern (SoftBody *sb)
static void Vec3PlusStVec (float *v, float s, float *v1)
static float sb_grav_force_scale (Object *UNUSED(ob))
static float sb_fric_force_scale (Object *UNUSED(ob))
static float sb_time_scale (Object *ob)
static float _final_goal (Object *ob, BodyPoint *bp)
static float _final_mass (Object *ob, BodyPoint *bp)
static ccd_Meshccd_mesh_make (Object *ob)
static void ccd_mesh_update (Object *ob, ccd_Mesh *pccd_M)
static void ccd_mesh_free (ccd_Mesh *ccdm)
static void ccd_build_deflector_hash (Scene *scene, Object *vertexowner, GHash *hash)
static void ccd_update_deflector_hash (Scene *scene, Object *vertexowner, GHash *hash)
static int count_mesh_quads (Mesh *me)
static void add_mesh_quad_diag_springs (Object *ob)
static void add_2nd_order_roller (Object *ob, float UNUSED(stiffness), int *counter, int addsprings)
static void add_2nd_order_springs (Object *ob, float stiffness)
static void add_bp_springlist (BodyPoint *bp, int springID)
static void build_bps_springlist (Object *ob)
static void calculate_collision_balls (Object *ob)
static void renew_softbody (Scene *scene, Object *ob, int totpoint, int totspring)
static void free_softbody_baked (SoftBody *sb)
static void free_scratch (SoftBody *sb)
static int are_there_deflectors (Scene *scene, unsigned int layer)
static int query_external_colliders (Scene *scene, Object *me)
static int sb_detect_aabb_collisionCached (float UNUSED(force[3]), unsigned int UNUSED(par_layer), struct Object *vertexowner, float UNUSED(time))
static int sb_detect_face_pointCached (float face_v1[3], float face_v2[3], float face_v3[3], float *damp, float force[3], unsigned int UNUSED(par_layer), struct Object *vertexowner, float time)
static int sb_detect_face_collisionCached (float face_v1[3], float face_v2[3], float face_v3[3], float *damp, float force[3], unsigned int UNUSED(par_layer), struct Object *vertexowner, float time)
static void scan_for_ext_face_forces (Object *ob, float timenow)
static int sb_detect_edge_collisionCached (float edge_v1[3], float edge_v2[3], float *damp, float force[3], unsigned int UNUSED(par_layer), struct Object *vertexowner, float time)
static void _scan_for_ext_spring_forces (Scene *scene, Object *ob, float timenow, int ifirst, int ilast, struct ListBase *do_effector)
static void scan_for_ext_spring_forces (Scene *scene, Object *ob, float timenow)
static void * exec_scan_for_ext_spring_forces (void *data)
static void sb_sfesf_threads_run (Scene *scene, struct Object *ob, float timenow, int totsprings, int *UNUSED(ptr_to_break_func(void)))
static int choose_winner (float *w, float *pos, float *a, float *b, float *c, float *ca, float *cb, float *cc)
static int sb_detect_vertex_collisionCached (float opco[3], float facenormal[3], float *damp, float force[3], unsigned int UNUSED(par_layer), struct Object *vertexowner, float time, float vel[3], float *intrusion)
static int sb_deflect_face (Object *ob, float *actpos, float *facenormal, float *force, float *cf, float time, float *vel, float *intrusion)
static void sb_spring_force (Object *ob, int bpi, BodySpring *bs, float iks, float UNUSED(forcetime), int nl_flags)
static int _softbody_calc_forces_slice_in_a_thread (Scene *scene, Object *ob, float forcetime, float timenow, int ifirst, int ilast, int *UNUSED(ptr_to_break_func(void)), ListBase *do_effector, int do_deflector, float fieldfactor, float windfactor)
static void * exec_softbody_calc_forces (void *data)
static void sb_cf_threads_run (Scene *scene, Object *ob, float forcetime, float timenow, int totpoint, int *UNUSED(ptr_to_break_func(void)), struct ListBase *do_effector, int do_deflector, float fieldfactor, float windfactor)
static void softbody_calc_forcesEx (Scene *scene, Object *ob, float forcetime, float timenow, int UNUSED(nl_flags))
static void softbody_calc_forces (Scene *scene, Object *ob, float forcetime, float timenow, int nl_flags)
static void softbody_apply_forces (Object *ob, float forcetime, int mode, float *err, int mid_flags)
static void softbody_restore_prev_step (Object *ob)
static void softbody_apply_goalsnap (Object *ob)
static void apply_spring_memory (Object *ob)
static void interpolate_exciter (Object *ob, int timescale, int time)
static void get_scalar_from_vertexgroup (Object *ob, int vertID, short groupindex, float *target)
static void springs_from_mesh (Object *ob)
static void mesh_to_softbody (Scene *scene, Object *ob)
static void mesh_faces_to_scratch (Object *ob)
static void reference_to_scratch (Object *ob)
static float globallen (float *v1, float *v2, Object *ob)
static void makelatticesprings (Lattice *lt, BodySpring *bs, int dostiff, Object *ob)
static void lattice_to_softbody (Scene *scene, Object *ob)
static void curve_surf_to_softbody (Scene *scene, Object *ob)
static void softbody_to_object (Object *ob, float(*vertexCos)[3], int numVerts, int local)
static void sb_new_scratch (SoftBody *sb)
SoftBodysbNew (Scene *scene)
void sbFree (SoftBody *sb)
void sbFreeSimulation (SoftBody *sb)
void sbObjectToSoftbody (Object *ob)
static int object_has_edges (Object *ob)
void sbSetInterruptCallBack (int(*f)(void))
static void softbody_update_positions (Object *ob, SoftBody *sb, float(*vertexCos)[3], int numVerts)
void SB_estimate_transform (Object *ob, float lloc[3], float lrot[3][3], float lscale[3][3])
static void softbody_reset (Object *ob, SoftBody *sb, float(*vertexCos)[3], int numVerts)
static void softbody_step (Scene *scene, Object *ob, SoftBody *sb, float dtime)
void sbObjectStep (Scene *scene, Object *ob, float cfra, float(*vertexCos)[3], int numVerts)

Variables

static int(* SB_localInterruptCallBack )(void) = NULL
static float SoftHeunTol = 1.0f
static const int CCD_SAVETY = 190561

Detailed Description

Definition in file softbody.c.


Define Documentation

#define BFF_CLOSEVERT   2

Definition at line 165 of file softbody.c.

Referenced by scan_for_ext_face_forces().

#define BFF_INTERSECT   1

Definition at line 164 of file softbody.c.

Referenced by scan_for_ext_face_forces().

#define BSF_INTERSECT   1
#define HEUNWARNLIMIT   1

Definition at line 154 of file softbody.c.

Referenced by softbody_step().

#define MID_PRESERVE   1

Definition at line 148 of file softbody.c.

Referenced by softbody_apply_forces(), and softbody_step().

#define NLF_BUILD   1

Definition at line 145 of file softbody.c.

Referenced by sb_spring_force(), and softbody_calc_forces().

#define NLF_SOLVE   2

Definition at line 146 of file softbody.c.

Referenced by softbody_calc_forces().

#define SBF_DOFUZZY   1
#define SBF_OUTOFCOLLISION   2

Definition at line 161 of file softbody.c.

Referenced by _softbody_calc_forces_slice_in_a_thread(), and curve_surf_to_softbody().

#define SOFTGOALSNAP   0.999f

Typedef Documentation

typedef struct BodyFace BodyFace
typedef struct BodySpring BodySpring
typedef struct ccd_Mesh ccd_Mesh
typedef struct ccdf_minmax ccdf_minmax
typedef struct ReferenceVert ReferenceVert
typedef struct SBScratch SBScratch

Enumeration Type Documentation

Enumerator:
SB_EDGE 
SB_BEND 
SB_STIFFQUAD 
SB_HANDLE 

Definition at line 92 of file softbody.c.


Function Documentation

static float _final_goal ( Object ob,
BodyPoint bp 
) [static]
static float _final_mass ( Object ob,
BodyPoint bp 
) [static]
static void _scan_for_ext_spring_forces ( Scene scene,
Object ob,
float  timenow,
int  ifirst,
int  ilast,
struct ListBase do_effector 
) [static]
static int _softbody_calc_forces_slice_in_a_thread ( Scene scene,
Object ob,
float  forcetime,
float  timenow,
int  ifirst,
int  ilast,
int *  UNUSEDptr_to_break_func(void),
ListBase do_effector,
int  do_deflector,
float  fieldfactor,
float  windfactor 
) [static]
static void add_2nd_order_roller ( Object ob,
float   UNUSEDstiffness,
int *  counter,
int  addsprings 
) [static]
static void add_2nd_order_springs ( Object ob,
float  stiffness 
) [static]
static void add_bp_springlist ( BodyPoint bp,
int  springID 
) [static]

Definition at line 746 of file softbody.c.

References MEM_callocN(), MEM_freeN(), BodyPoint::nofsprings, NULL, and BodyPoint::springs.

Referenced by build_bps_springlist().

static void add_mesh_quad_diag_springs ( Object ob) [static]
static void apply_spring_memory ( Object ob) [static]
static int are_there_deflectors ( Scene scene,
unsigned int  layer 
) [static]
static void build_bps_springlist ( Object ob) [static]
static void calculate_collision_balls ( Object ob) [static]
static void ccd_build_deflector_hash ( Scene scene,
Object vertexowner,
GHash hash 
) [static]
static void ccd_mesh_free ( ccd_Mesh ccdm) [static]
static ccd_Mesh* ccd_mesh_make ( Object ob) [static]
static void ccd_mesh_update ( Object ob,
ccd_Mesh pccd_M 
) [static]
static void ccd_update_deflector_hash ( Scene scene,
Object vertexowner,
GHash hash 
) [static]
static int choose_winner ( float *  w,
float *  pos,
float *  a,
float *  b,
float *  c,
float *  ca,
float *  cb,
float *  cc 
) [static]

Definition at line 1710 of file softbody.c.

References ABS, copy_v3_v3(), and dot_v3v3().

Referenced by sb_detect_vertex_collisionCached().

static int count_mesh_quads ( Mesh me) [static]

Definition at line 602 of file softbody.c.

References Mesh::mface, Mesh::totface, and MFace::v4.

Referenced by add_mesh_quad_diag_springs().

static void curve_surf_to_softbody ( Scene scene,
Object ob 
) [static]
static void* exec_scan_for_ext_spring_forces ( void *  data) [static]
static void* exec_softbody_calc_forces ( void *  data) [static]
static void free_scratch ( SoftBody sb) [static]
static void free_softbody_baked ( SoftBody sb) [static]

Definition at line 892 of file softbody.c.

References SoftBody::keys, MEM_freeN(), NULL, and SoftBody::totkey.

Referenced by free_softbody_intern().

static void free_softbody_intern ( SoftBody sb) [static]
static void get_scalar_from_vertexgroup ( Object ob,
int  vertID,
short  groupindex,
float *  target 
) [static]
static float globallen ( float *  v1,
float *  v2,
Object ob 
) [static]

Definition at line 3415 of file softbody.c.

References copy_v3_v3(), len_v3v3(), mul_m4_v3(), and Object::obmat.

Referenced by curve_surf_to_softbody(), and makelatticesprings().

static void interpolate_exciter ( Object ob,
int  timescale,
int  time 
) [static]
static void lattice_to_softbody ( Scene scene,
Object ob 
) [static]
static void makelatticesprings ( Lattice lt,
BodySpring bs,
int  dostiff,
Object ob 
) [static]
static void mesh_faces_to_scratch ( Object ob) [static]
static void mesh_to_softbody ( Scene scene,
Object ob 
) [static]
static int object_has_edges ( Object ob) [static]

Definition at line 3760 of file softbody.c.

References Object::data, OB_LATTICE, OB_MESH, and Object::type.

Referenced by sbObjectStep().

static int query_external_colliders ( Scene scene,
Object me 
) [static]

Definition at line 1006 of file softbody.c.

References are_there_deflectors(), and Object::lay.

Referenced by softbody_calc_forces(), softbody_calc_forcesEx(), and softbody_step().

static void reference_to_scratch ( Object ob) [static]
static void renew_softbody ( Scene scene,
Object ob,
int  totpoint,
int  totspring 
) [static]
static void sb_cf_threads_run ( Scene scene,
Object ob,
float  forcetime,
float  timenow,
int  totpoint,
int *  UNUSEDptr_to_break_func(void),
struct ListBase do_effector,
int  do_deflector,
float  fieldfactor,
float  windfactor 
) [static]
static int sb_deflect_face ( Object ob,
float *  actpos,
float *  facenormal,
float *  force,
float *  cf,
float  time,
float *  vel,
float *  intrusion 
) [static]
static int sb_detect_aabb_collisionCached ( float   UNUSEDforce[3],
unsigned int   UNUSEDpar_layer,
struct Object vertexowner,
float   UNUSEDtime 
) [static]
static int sb_detect_edge_collisionCached ( float  edge_v1[3],
float  edge_v2[3],
float *  damp,
float  force[3],
unsigned int   UNUSEDpar_layer,
struct Object vertexowner,
float  time 
) [static]
static int sb_detect_face_collisionCached ( float  face_v1[3],
float  face_v2[3],
float  face_v3[3],
float *  damp,
float  force[3],
unsigned int   UNUSEDpar_layer,
struct Object vertexowner,
float  time 
) [static]
static int sb_detect_face_pointCached ( float  face_v1[3],
float  face_v2[3],
float  face_v3[3],
float *  damp,
float  force[3],
unsigned int   UNUSEDpar_layer,
struct Object vertexowner,
float  time 
) [static]
static int sb_detect_vertex_collisionCached ( float  opco[3],
float  facenormal[3],
float *  damp,
float  force[3],
unsigned int   UNUSEDpar_layer,
struct Object vertexowner,
float  time,
float  vel[3],
float *  intrusion 
) [static]
void SB_estimate_transform ( Object ob,
float  lloc[3],
float  lrot[3][3],
float  lscale[3][3] 
)
static float sb_fric_force_scale ( Object UNUSEDob) [static]
static float sb_grav_force_scale ( Object UNUSEDob) [static]

Definition at line 179 of file softbody.c.

Referenced by _softbody_calc_forces_slice_in_a_thread(), and softbody_calc_forces().

static void sb_new_scratch ( SoftBody sb) [static]
static void sb_sfesf_threads_run ( Scene scene,
struct Object ob,
float  timenow,
int  totsprings,
int *  UNUSEDptr_to_break_func(void) 
) [static]
static void sb_spring_force ( Object ob,
int  bpi,
BodySpring bs,
float  iks,
float   UNUSEDforcetime,
int  nl_flags 
) [static]
static float sb_time_scale ( Object ob) [static]

Definition at line 195 of file softbody.c.

References SoftBody::physics_speed, and Object::soft.

Referenced by softbody_apply_forces().

void sbFree ( SoftBody sb)
void sbFreeSimulation ( SoftBody sb)

Definition at line 3747 of file softbody.c.

References free_softbody_intern().

Referenced by BKE_ptcache_id_reset().

SoftBody* sbNew ( Scene scene) [read]
void sbObjectStep ( Scene scene,
Object ob,
float  cfra,
float(*)  vertexCos[3],
int  numVerts 
)
void sbObjectToSoftbody ( Object ob)

Definition at line 3753 of file softbody.c.

References free_softbody_intern(), and Object::soft.

void sbSetInterruptCallBack ( int(*)(void)  f)

Definition at line 3774 of file softbody.c.

References SB_localInterruptCallBack.

static void scan_for_ext_face_forces ( Object ob,
float  timenow 
) [static]
static void scan_for_ext_spring_forces ( Scene scene,
Object ob,
float  timenow 
) [static]
static void softbody_apply_forces ( Object ob,
float  forcetime,
int  mode,
float *  err,
int  mid_flags 
) [static]
static void softbody_apply_goalsnap ( Object ob) [static]
static void softbody_calc_forces ( Scene scene,
Object ob,
float  forcetime,
float  timenow,
int  nl_flags 
) [static]

Definition at line 2486 of file softbody.c.

References _final_goal(), _final_mass(), ABS, add_v3_v3(), add_v3_v3v3(), SoftBody::aeroedge, SoftBody::balldamp, SoftBody::ballstiff, SoftBody::bpoint, BSF_INTERSECT, SoftBody::bspring, BodySpring::cf, SoftBody::choke, BodyPoint::choke, BodyPoint::choke2, BodyPoint::colball, compare(), copy_v3_v3(), distance(), SoftBody::effector_weights, BodySpring::ext_force, BodySpring::flag, SBScratch::flag, PhysicsSettings::flag, BodyPoint::force, G, EffectorWeights::global_gravity, SoftBody::goalfrict, SoftBody::goalspring, PhysicsSettings::gravity, BodyPoint::impdv, SoftBody::inspring, Object::lay, BodyPoint::loc_flag, madd_v3_v3fl(), SoftBody::mediafrict, mid_v3_v3v3(), mul_v3_fl(), NL_MATRIX, NL_SYSTEM, nlEnd(), NLF_BUILD, NLF_SOLVE, nlGetVariable(), nlPrintMatrix(), nlRightHandSideSet(), nlSolveAdvanced(), BodyPoint::nofsprings, normalize_v3(), NULL, OB_SB_EDGECOLL, OB_SB_EDGES, OB_SB_FACECOLL, OB_SB_GOAL, OB_SB_SELF, BodyPoint::origE, BodyPoint::origS, BodyPoint::origT, pd_point_from_soft(), pdDoEffectors(), pdEndEffectors(), pdInitEffectors(), PHYS_GLOBAL_GRAVITY, Scene::physics_settings, BodyPoint::pos, query_external_colliders(), sb_deflect_face(), sb_detect_aabb_collisionCached(), sb_fric_force_scale(), sb_grav_force_scale(), sb_spring_force(), SBF_DOFUZZY, scan_for_ext_face_forces(), scan_for_ext_spring_forces(), SoftBody::scratch, Object::soft, softbody_calc_forcesEx(), Object::softflag, SOFTGOALSNAP, BodyPoint::springs, sub_v3_v3v3(), SoftBody::totpoint, BodySpring::v1, BodySpring::v2, BodyPoint::vec, and Vec3PlusStVec().

Referenced by softbody_step().

static void softbody_calc_forcesEx ( Scene scene,
Object ob,
float  forcetime,
float  timenow,
int   UNUSEDnl_flags 
) [static]
static void softbody_reset ( Object ob,
SoftBody sb,
float(*)  vertexCos[3],
int  numVerts 
) [static]
static void softbody_restore_prev_step ( Object ob) [static]
static void softbody_step ( Scene scene,
Object ob,
SoftBody sb,
float  dtime 
) [static]
static void softbody_to_object ( Object ob,
float(*)  vertexCos[3],
int  numVerts,
int  local 
) [static]
static void softbody_update_positions ( Object ob,
SoftBody sb,
float(*)  vertexCos[3],
int  numVerts 
) [static]
static void springs_from_mesh ( Object ob) [static]
static void Vec3PlusStVec ( float *  v,
float  s,
float *  v1 
) [static]

Variable Documentation

const int CCD_SAVETY = 190561 [static]

Definition at line 268 of file softbody.c.

Referenced by ccd_mesh_make().

int(* SB_localInterruptCallBack)(void) = NULL [static]

Definition at line 87 of file softbody.c.

Referenced by sbSetInterruptCallBack(), and softbody_step().

float SoftHeunTol = 1.0f [static]

Definition at line 168 of file softbody.c.

Referenced by softbody_step().