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) Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): Daniel Genrich 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 #ifndef BKE_CLOTH_H 00028 #define BKE_CLOTH_H 00029 00035 #include <float.h> 00036 #include "BLI_math_inline.h" 00037 00038 struct Object; 00039 struct ListBase; 00040 struct Scene; 00041 struct MFace; 00042 struct DerivedMesh; 00043 struct ClothModifierData; 00044 struct CollisionTree; 00045 00046 #define DO_INLINE MALWAYS_INLINE 00047 00048 #define CLOTH_MAX_THREAD 2 00049 00050 /* goal defines */ 00051 #define SOFTGOALSNAP 0.999f 00052 00053 /* This is approximately the smallest number that can be 00054 * represented by a float, given its precision. */ 00055 #define ALMOST_ZERO FLT_EPSILON 00056 00057 /* Bits to or into the ClothVertex.flags. */ 00058 #define CLOTH_VERT_FLAG_PINNED 1 00059 #define CLOTH_VERT_FLAG_COLLISION 2 00060 #define CLOTH_VERT_FLAG_PINNED_EM 3 00061 00072 typedef struct Cloth 00073 { 00074 struct ClothVertex *verts; /* The vertices that represent this cloth. */ 00075 struct LinkNode *springs; /* The springs connecting the mesh. */ 00076 unsigned int numverts; /* The number of verts == m * n. */ 00077 unsigned int numsprings; /* The count of springs. */ 00078 unsigned int numfaces; 00079 unsigned char old_solver_type; /* unused, only 1 solver here */ 00080 unsigned char pad2; 00081 short pad3; 00082 struct BVHTree *bvhtree; /* collision tree for this cloth object */ 00083 struct BVHTree *bvhselftree; /* collision tree for this cloth object */ 00084 struct MFace *mfaces; 00085 struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */ 00086 struct Implicit_Data *implicitEM; /* our implicit solver connects to this pointer */ 00087 struct EdgeHash *edgehash; /* used for selfcollisions */ 00088 int last_frame, pad4; 00089 } Cloth; 00090 00094 typedef struct ClothVertex 00095 { 00096 int flags; /* General flags per vertex. */ 00097 float v [3]; /* The velocity of the point. */ 00098 float xconst [3]; /* constrained position */ 00099 float x [3]; /* The current position of this vertex. */ 00100 float xold [3]; /* The previous position of this vertex.*/ 00101 float tx [3]; /* temporary position */ 00102 float txold [3]; /* temporary old position */ 00103 float tv[3]; /* temporary "velocity", mostly used as tv = tx-txold */ 00104 float mass; /* mass / weight of the vertex */ 00105 float goal; /* goal, from SB */ 00106 float impulse[3]; /* used in collision.c */ 00107 float *xrest; /* temporary valid for building springs */ 00108 unsigned int impulse_count; /* same as above */ 00109 float avg_spring_len; /* average length of connected springs */ 00110 float struct_stiff; 00111 float bend_stiff; 00112 float shear_stiff; 00113 int spring_count; /* how many springs attached? */ 00114 } 00115 ClothVertex; 00116 00120 typedef struct ClothSpring 00121 { 00122 int ij; /* Pij from the paper, one end of the spring. */ 00123 int kl; /* Pkl from the paper, one end of the spring. */ 00124 float restlen; /* The original length of the spring. */ 00125 int matrix_index; /* needed for implicit solver (fast lookup) */ 00126 int type; /* types defined in BKE_cloth.h ("springType") */ 00127 int flags; /* defined in BKE_cloth.h, e.g. deactivated due to tearing */ 00128 float dfdx[3][3]; 00129 float dfdv[3][3]; 00130 float f[3]; 00131 float stiffness; /* stiffness factor from the vertex groups */ 00132 float editrestlen; 00133 } 00134 ClothSpring; 00135 00136 // some macro enhancements for vector treatment 00137 #define VECADDADD(v1,v2,v3) {*(v1)+= *(v2) + *(v3); *(v1+1)+= *(v2+1) + *(v3+1); *(v1+2)+= *(v2+2) + *(v3+2);} 00138 #define VECSUBADD(v1,v2,v3) {*(v1)-= *(v2) + *(v3); *(v1+1)-= *(v2+1) + *(v3+1); *(v1+2)-= *(v2+2) + *(v3+2);} 00139 #define VECADDSUB(v1,v2,v3) {*(v1)+= *(v2) - *(v3); *(v1+1)+= *(v2+1) - *(v3+1); *(v1+2)+= *(v2+2) - *(v3+2);} 00140 #define VECSUBADDSS(v1,v2,aS,v3,bS) {*(v1)-= *(v2)*aS + *(v3)*bS; *(v1+1)-= *(v2+1)*aS + *(v3+1)*bS; *(v1+2)-= *(v2+2)*aS + *(v3+2)*bS;} 00141 #define VECADDSUBSS(v1,v2,aS,v3,bS) {*(v1)+= *(v2)*aS - *(v3)*bS; *(v1+1)+= *(v2+1)*aS - *(v3+1)*bS; *(v1+2)+= *(v2+2)*aS - *(v3+2)*bS;} 00142 #define VECADDSS(v1,v2,aS,v3,bS) {*(v1)= *(v2)*aS + *(v3)*bS; *(v1+1)= *(v2+1)*aS + *(v3+1)*bS; *(v1+2)= *(v2+2)*aS + *(v3+2)*bS;} 00143 #define VECADDS(v1,v2,v3,bS) {*(v1)= *(v2) + *(v3)*bS; *(v1+1)= *(v2+1) + *(v3+1)*bS; *(v1+2)= *(v2+2) + *(v3+2)*bS;} 00144 #define VECSUBMUL(v1,v2,aS) {*(v1)-= *(v2) * aS; *(v1+1)-= *(v2+1) * aS; *(v1+2)-= *(v2+2) * aS;} 00145 #define VECSUBS(v1,v2,v3,bS) {*(v1)= *(v2) - *(v3)*bS; *(v1+1)= *(v2+1) - *(v3+1)*bS; *(v1+2)= *(v2+2) - *(v3+2)*bS;} 00146 #define VECSUBSB(v1,v2, v3,bS) {*(v1)= (*(v2)- *(v3))*bS; *(v1+1)= (*(v2+1) - *(v3+1))*bS; *(v1+2)= (*(v2+2) - *(v3+2))*bS;} 00147 #define VECMULS(v1,aS) {*(v1)*= aS; *(v1+1)*= aS; *(v1+2)*= *aS;} 00148 #define VECADDMUL(v1,v2,aS) {*(v1)+= *(v2) * aS; *(v1+1)+= *(v2+1) * aS; *(v1+2)+= *(v2+2) * aS;} 00149 00150 /* SIMULATION FLAGS: goal flags,.. */ 00151 /* These are the bits used in SimSettings.flags. */ 00152 typedef enum 00153 { 00154 CLOTH_SIMSETTINGS_FLAG_COLLOBJ = ( 1 << 2 ),// object is only collision object, no cloth simulation is done 00155 CLOTH_SIMSETTINGS_FLAG_GOAL = ( 1 << 3 ), // we have goals enabled 00156 CLOTH_SIMSETTINGS_FLAG_TEARING = ( 1 << 4 ),// true if tearing is enabled 00157 CLOTH_SIMSETTINGS_FLAG_SCALING = ( 1 << 8 ), /* is advanced scaling active? */ 00158 CLOTH_SIMSETTINGS_FLAG_CCACHE_EDIT = (1 << 12), /* edit cache in editmode */ 00159 CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS = (1 << 13) /* don't allow spring compression */ 00160 } CLOTH_SIMSETTINGS_FLAGS; 00161 00162 /* COLLISION FLAGS */ 00163 typedef enum 00164 { 00165 CLOTH_COLLSETTINGS_FLAG_ENABLED = ( 1 << 1 ), /* enables cloth - object collisions */ 00166 CLOTH_COLLSETTINGS_FLAG_SELF = ( 1 << 2 ), /* enables selfcollisions */ 00167 } CLOTH_COLLISIONSETTINGS_FLAGS; 00168 00169 /* Spring types as defined in the paper.*/ 00170 typedef enum 00171 { 00172 CLOTH_SPRING_TYPE_STRUCTURAL = ( 1 << 1 ), 00173 CLOTH_SPRING_TYPE_SHEAR = ( 1 << 2 ) , 00174 CLOTH_SPRING_TYPE_BENDING = ( 1 << 3 ), 00175 CLOTH_SPRING_TYPE_GOAL = ( 1 << 4 ), 00176 } CLOTH_SPRING_TYPES; 00177 00178 /* SPRING FLAGS */ 00179 typedef enum 00180 { 00181 CLOTH_SPRING_FLAG_DEACTIVATE = ( 1 << 1 ), 00182 CLOTH_SPRING_FLAG_NEEDED = ( 1 << 2 ), // springs has values to be applied 00183 } CLOTH_SPRINGS_FLAGS; 00184 00185 00187 // collision.c 00189 00190 // needed for implicit.c 00191 int cloth_bvh_objcollision (struct Object *ob, struct ClothModifierData * clmd, float step, float dt ); 00192 00194 00195 00197 // implicit.c 00199 00200 // needed for cloth.c 00201 int implicit_init ( struct Object *ob, struct ClothModifierData *clmd ); 00202 int implicit_free ( struct ClothModifierData *clmd ); 00203 int implicit_solver ( struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors ); 00204 void implicit_set_positions ( struct ClothModifierData *clmd ); 00205 00206 // globally needed 00207 void clmdSetInterruptCallBack ( int ( *f ) ( void ) ); 00209 00210 00212 // cloth.c 00214 00215 // needed for modifier.c 00216 void cloth_free_modifier_extern ( struct ClothModifierData *clmd ); 00217 void cloth_free_modifier ( struct ClothModifierData *clmd ); 00218 void cloth_init ( struct ClothModifierData *clmd ); 00219 struct DerivedMesh *clothModifier_do ( struct ClothModifierData *clmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm); 00220 00221 void cloth_update_normals ( ClothVertex *verts, int nVerts, struct MFace *face, int totface ); 00222 int cloth_uses_vgroup(struct ClothModifierData *clmd); 00223 00224 // needed for collision.c 00225 void bvhtree_update_from_cloth ( struct ClothModifierData *clmd, int moving ); 00226 void bvhselftree_update_from_cloth ( struct ClothModifierData *clmd, int moving ); 00227 00228 // needed for button_object.c 00229 void cloth_clear_cache ( struct Object *ob, struct ClothModifierData *clmd, float framenr ); 00230 00231 // needed for cloth.c 00232 int cloth_add_spring ( struct ClothModifierData *clmd, unsigned int indexA, unsigned int indexB, float restlength, int spring_type); 00233 00235 00236 00237 /* This enum provides the IDs for our solvers. */ 00238 // only one available in the moment 00239 typedef enum 00240 { 00241 CM_IMPLICIT = 0, 00242 } CM_SOLVER_ID; 00243 00244 00245 /* This structure defines how to call the solver. 00246 */ 00247 typedef struct 00248 { 00249 const char *name; 00250 CM_SOLVER_ID id; 00251 int ( *init ) ( struct Object *ob, struct ClothModifierData *clmd ); 00252 int ( *solver ) ( struct Object *ob, float framenr, struct ClothModifierData *clmd, struct ListBase *effectors ); 00253 int ( *free ) ( struct ClothModifierData *clmd ); 00254 } 00255 CM_SOLVER_DEF; 00256 00257 00258 #endif 00259