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) 2004 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): Geoffrey Bantle. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00028 #ifndef BKE_BMESH_H 00029 #define BKE_BMESH_H 00030 00038 #include "DNA_listBase.h" 00039 #include "BLI_utildefines.h" 00040 #include "BLI_ghash.h" 00041 #include "BLI_mempool.h" 00042 #include "BLI_memarena.h" 00043 #include "DNA_image_types.h" 00044 #include "BLI_editVert.h" 00045 #include "BKE_DerivedMesh.h" 00046 //XXX #include "transform.h" 00047 00048 /*forward declerations*/ 00049 struct BME_Vert; 00050 struct BME_Edge; 00051 struct BME_Poly; 00052 struct BME_Loop; 00053 00054 00055 /*Notes on further structure Cleanup: 00056 -Remove the tflags, they belong in custom data layers 00057 -Remove the eflags completely, they are mostly not used 00058 -Remove the selection/vis/bevel weight flag/values ect and move them to custom data 00059 -Remove EID member and move to custom data 00060 -Add a radial cycle length, disk cycle length and loop cycle length attributes to custom data and have eulers maintain/use them if present. 00061 -Move data such as vertex coordinates/normals to custom data and leave pointers in structures to active layer data. 00062 -Remove BME_CycleNode structure? 00063 */ 00064 typedef struct BME_CycleNode{ 00065 struct BME_CycleNode *next, *prev; 00066 void *data; 00067 } BME_CycleNode; 00068 00069 typedef struct BME_Mesh 00070 { 00071 ListBase verts, edges, polys; 00072 /*memory pools used for storing mesh elements*/ 00073 struct BLI_mempool *vpool; 00074 struct BLI_mempool *epool; 00075 struct BLI_mempool *ppool; 00076 struct BLI_mempool *lpool; 00077 /*some scratch arrays used by eulers*/ 00078 struct BME_Vert **vtar; 00079 struct BME_Edge **edar; 00080 struct BME_Loop **lpar; 00081 struct BME_Poly **plar; 00082 int vtarlen, edarlen, lparlen, plarlen; 00083 int totvert, totedge, totpoly, totloop; /*record keeping*/ 00084 int nextv, nexte, nextp, nextl; /*Next element ID for verts/edges/faces/loops. Never reused*/ 00085 struct CustomData vdata, edata, pdata, ldata; /*Custom Data Layer information*/ 00086 } BME_Mesh; 00087 00088 typedef struct BME_Vert 00089 { 00090 struct BME_Vert *next, *prev; 00091 int EID; 00092 float co[3]; 00093 float no[3]; 00094 struct BME_Edge *edge; /*first edge in the disk cycle for this vertex*/ 00095 void *data; /*custom vertex data*/ 00096 int eflag1, eflag2; /*reserved for use by eulers*/ 00097 int tflag1, tflag2; /*reserved for use by tools*/ 00098 unsigned short flag, h; 00099 float bweight; 00100 } BME_Vert; 00101 00102 typedef struct BME_Edge 00103 { 00104 struct BME_Edge *next, *prev; 00105 int EID; 00106 struct BME_Vert *v1, *v2; /*note that order of vertex pointers means nothing to eulers*/ 00107 struct BME_CycleNode d1, d2; /*disk cycle nodes for v1 and v2 respectivley*/ 00108 struct BME_Loop *loop; /*first BME_Loop in the radial cycle around this edge*/ 00109 void *data; /*custom edge data*/ 00110 int eflag1, eflag2; /*reserved for use by eulers*/ 00111 int tflag1, tflag2; /*reserved for use by tools*/ 00112 unsigned short flag, h; 00113 float crease, bweight; 00114 } BME_Edge; 00115 00116 typedef struct BME_Loop 00117 { 00118 struct BME_Loop *next, *prev; /*circularly linked list around face*/ 00119 int EID; 00120 struct BME_CycleNode radial; /*circularly linked list used to find faces around an edge*/ 00121 struct BME_Vert *v; /*vertex that this loop starts at.*/ 00122 struct BME_Edge *e; /*edge this loop belongs to*/ 00123 struct BME_Poly *f; /*face this loop belongs to*/ 00124 void *data; /*custom per face vertex data*/ 00125 int eflag1, eflag2; /*reserved for use by eulers*/ 00126 int tflag1, tflag2; /*reserved for use by tools*/ 00127 unsigned short flag, h; 00128 } BME_Loop; 00129 00130 typedef struct BME_Poly 00131 { 00132 struct BME_Poly *next, *prev; 00133 int EID; 00134 struct BME_Loop *loopbase; /*First editloop around Polygon.*/ 00135 unsigned int len; /*total length of the face. Eulers should preserve this data*/ 00136 void *data; /*custom face data*/ 00137 int eflag1, eflag2; /*reserved for use by eulers*/ 00138 int tflag1, tflag2; /*reserved for use by tools*/ 00139 unsigned short flag, h, mat_nr; 00140 } BME_Poly; 00141 00142 /*EDGE UTILITIES*/ 00143 int BME_verts_in_edge(struct BME_Vert *v1, struct BME_Vert *v2, struct BME_Edge *e); 00144 int BME_vert_in_edge(struct BME_Edge *e, BME_Vert *v); 00145 struct BME_Vert *BME_edge_getothervert(struct BME_Edge *e, struct BME_Vert *v); 00146 00147 /*GENERAL CYCLE*/ 00148 int BME_cycle_length(void *h); 00149 00150 /*DISK CYCLE*/ 00151 struct BME_Edge *BME_disk_nextedge(struct BME_Edge *e, struct BME_Vert *v); 00152 struct BME_CycleNode *BME_disk_getpointer(struct BME_Edge *e, struct BME_Vert *v); 00153 struct BME_Edge *BME_disk_next_edgeflag(struct BME_Edge *e, struct BME_Vert *v, int eflag, int tflag); 00154 int BME_disk_count_edgeflag(struct BME_Vert *v, int eflag, int tflag); 00155 00156 /*RADIAL CYCLE*/ 00157 struct BME_Loop *BME_radial_nextloop(struct BME_Loop *l); 00158 int BME_radial_find_face(struct BME_Edge *e,struct BME_Poly *f); 00159 00160 /*LOOP CYCLE*/ 00161 struct BME_Loop *BME_loop_find_loop(struct BME_Poly *f, struct BME_Vert *v); 00162 00163 /*MESH CREATION/DESTRUCTION*/ 00164 struct BME_Mesh *BME_make_mesh(int allocsize[4]); 00165 void BME_free_mesh(struct BME_Mesh *bm); 00166 /*FULL MESH VALIDATION*/ 00167 int BME_validate_mesh(struct BME_Mesh *bm, int halt); 00168 /*ENTER/EXIT MODELLING LOOP*/ 00169 int BME_model_begin(struct BME_Mesh *bm); 00170 void BME_model_end(struct BME_Mesh *bm); 00171 00172 /*MESH CONSTRUCTION API.*/ 00173 /*MAKE*/ 00174 struct BME_Vert *BME_MV(struct BME_Mesh *bm, float *vec); 00175 struct BME_Edge *BME_ME(struct BME_Mesh *bm, struct BME_Vert *v1, struct BME_Vert *v2); 00176 struct BME_Poly *BME_MF(struct BME_Mesh *bm, struct BME_Vert *v1, struct BME_Vert *v2, struct BME_Edge **elist, int len); 00177 /*KILL*/ 00178 int BME_KV(struct BME_Mesh *bm, struct BME_Vert *v); 00179 int BME_KE(struct BME_Mesh *bm, struct BME_Edge *e); 00180 int BME_KF(struct BME_Mesh *bm, struct BME_Poly *bply); 00181 /*SPLIT*/ 00182 struct BME_Vert *BME_SEMV(struct BME_Mesh *bm, struct BME_Vert *tv, struct BME_Edge *e, struct BME_Edge **re); 00183 struct BME_Poly *BME_SFME(struct BME_Mesh *bm, struct BME_Poly *f, struct BME_Vert *v1, struct BME_Vert *v2, struct BME_Loop **rl); 00184 /*JOIN*/ 00185 int BME_JEKV(struct BME_Mesh *bm, struct BME_Edge *ke, struct BME_Vert *kv); 00186 struct BME_Poly *BME_JFKE(struct BME_Mesh *bm, struct BME_Poly *f1, struct BME_Poly *f2,struct BME_Edge *e); /*no reason to return BME_Poly pointer?*/ 00187 /*NORMAL FLIP(Is its own inverse)*/ 00188 int BME_loop_reverse(struct BME_Mesh *bm, struct BME_Poly *f); 00189 00190 /* bevel tool defines */ 00191 /* element flags */ 00192 #define BME_BEVEL_ORIG 1 00193 #define BME_BEVEL_BEVEL (1<<1) 00194 #define BME_BEVEL_NONMAN (1<<2) 00195 #define BME_BEVEL_WIRE (1<<3) 00196 00197 /* tool options */ 00198 #define BME_BEVEL_SELECT 1 00199 #define BME_BEVEL_VERT (1<<1) 00200 #define BME_BEVEL_RADIUS (1<<2) 00201 #define BME_BEVEL_ANGLE (1<<3) 00202 #define BME_BEVEL_WEIGHT (1<<4) 00203 //~ #define BME_BEVEL_EWEIGHT (1<<4) 00204 //~ #define BME_BEVEL_VWEIGHT (1<<5) 00205 #define BME_BEVEL_PERCENT (1<<6) 00206 #define BME_BEVEL_EMIN (1<<7) 00207 #define BME_BEVEL_EMAX (1<<8) 00208 #define BME_BEVEL_RUNNING (1<<9) 00209 #define BME_BEVEL_RES (1<<10) 00210 00211 typedef struct BME_TransData { 00212 BME_Mesh *bm; /* the bmesh the vert belongs to */ 00213 BME_Vert *v; /* pointer to the vert this tdata applies to */ 00214 float co[3]; /* the original coordinate */ 00215 float org[3]; /* the origin */ 00216 float vec[3]; /* a directional vector; always, always normalize! */ 00217 void *loc; /* a pointer to the data to transform (likely the vert's cos) */ 00218 float factor; /* primary scaling factor; also accumulates number of weighted edges for beveling tool */ 00219 float weight; /* another scaling factor; used primarily for propogating vertex weights to transforms; */ 00220 /* weight is also used across recursive bevels to help with the math */ 00221 float maxfactor; /* the unscaled, original factor (used only by "edge verts" in recursive beveling) */ 00222 float *max; /* the maximum distance this vert can be transformed; negative is infinite 00223 * it points to the "parent" maxfactor (where maxfactor makes little sense) 00224 * where the max limit is stored (limits are stored per-corner) */ 00225 } BME_TransData; 00226 00227 typedef struct BME_TransData_Head { 00228 GHash *gh; /* the hash structure for element lookup */ 00229 MemArena *ma; /* the memory "pool" we will be drawing individual elements from */ 00230 int len; 00231 } BME_TransData_Head; 00232 00233 typedef struct BME_Glob { /* stored in Global G for Transform() purposes */ 00234 BME_Mesh *bm; 00235 BME_TransData_Head *td; 00236 struct TransInfo *Trans; /* a pointer to the global Trans struct */ 00237 int imval[2]; /* for restoring original mouse co when initTransform() is called multiple times */ 00238 int options; 00239 int res; 00240 } BME_Glob; 00241 00242 struct BME_TransData *BME_get_transdata(struct BME_TransData_Head *td, struct BME_Vert *v); 00243 void BME_free_transdata(struct BME_TransData_Head *td); 00244 float *BME_bevel_calc_polynormal(struct BME_Poly *f, struct BME_TransData_Head *td); 00245 struct BME_Mesh *BME_bevel(struct BME_Mesh *bm, float value, int res, int options, int defgrp_index, float angle, BME_TransData_Head **rtd); 00246 00247 /*CONVERSION FUNCTIONS*/ 00248 struct BME_Mesh *BME_editmesh_to_bmesh(EditMesh *em); 00249 void BME_bmesh_to_editmesh(struct BME_Mesh *bm, BME_TransData_Head *td, EditMesh *em); 00250 struct BME_Mesh *BME_derivedmesh_to_bmesh(struct DerivedMesh *dm); 00251 struct DerivedMesh *BME_bmesh_to_derivedmesh(struct BME_Mesh *bm, struct DerivedMesh *dm); 00252 #endif