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