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