|
Blender
V2.59
|
00001 /* 00002 * $Id: BKE_customdata.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. 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) 2006 Blender Foundation. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): Ben Batt <benbatt@gmail.com> 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00036 #ifndef BKE_CUSTOMDATA_H 00037 #define BKE_CUSTOMDATA_H 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 00043 struct ID; 00044 struct CustomData; 00045 struct CustomDataLayer; 00046 typedef unsigned int CustomDataMask; 00047 00048 extern const CustomDataMask CD_MASK_BAREMESH; 00049 extern const CustomDataMask CD_MASK_MESH; 00050 extern const CustomDataMask CD_MASK_EDITMESH; 00051 extern const CustomDataMask CD_MASK_DERIVEDMESH; 00052 extern const CustomDataMask CD_MASK_BMESH; 00053 extern const CustomDataMask CD_MASK_FACECORNERS; 00054 00055 /* for ORIGINDEX layer type, indicates no original index for this element */ 00056 #define ORIGINDEX_NONE -1 00057 00058 /* initialises a CustomData object with the same layer setup as source and 00059 * memory space for totelem elements. mask must be an array of length 00060 * CD_NUMTYPES elements, that indicate if a layer can be copied. */ 00061 00062 /* add/copy/merge allocation types */ 00063 #define CD_ASSIGN 0 /* use the data pointer */ 00064 #define CD_CALLOC 1 /* allocate blank memory */ 00065 #define CD_DEFAULT 2 /* allocate and set to default */ 00066 #define CD_REFERENCE 3 /* use data pointers, set layer flag NOFREE */ 00067 #define CD_DUPLICATE 4 /* do a full copy of all layers, only allowed if source 00068 has same number of elements */ 00069 00070 /* initialises a CustomData object with the same layer setup as source. 00071 * mask is a bitfield where (mask & (1 << (layer type))) indicates 00072 * if a layer should be copied or not. alloctype must be one of the above. */ 00073 void CustomData_copy(const struct CustomData *source, struct CustomData *dest, 00074 CustomDataMask mask, int alloctype, int totelem); 00075 00076 /* same as the above, except that this will preserve existing layers, and only 00077 * add the layers that were not there yet */ 00078 void CustomData_merge(const struct CustomData *source, struct CustomData *dest, 00079 CustomDataMask mask, int alloctype, int totelem); 00080 00081 /* frees data associated with a CustomData object (doesn't free the object 00082 * itself, though) 00083 */ 00084 void CustomData_free(struct CustomData *data, int totelem); 00085 00086 /* frees all layers with CD_FLAG_TEMPORARY */ 00087 void CustomData_free_temporary(struct CustomData *data, int totelem); 00088 00089 /* adds a data layer of the given type to the CustomData object, optionally 00090 * backed by an external data array. the different allocation types are 00091 * defined above. returns the data of the layer. 00092 * 00093 * in editmode, use EM_add_data_layer instead of this function 00094 */ 00095 void *CustomData_add_layer(struct CustomData *data, int type, int alloctype, 00096 void *layer, int totelem); 00097 /*same as above but accepts a name */ 00098 void *CustomData_add_layer_named(struct CustomData *data, int type, int alloctype, 00099 void *layer, int totelem, const char *name); 00100 00101 /* frees the active or first data layer with the give type. 00102 * returns 1 on succes, 0 if no layer with the given type is found 00103 * 00104 * in editmode, use EM_free_data_layer instead of this function 00105 */ 00106 int CustomData_free_layer(struct CustomData *data, int type, int totelem, int index); 00107 00108 /* frees the layer index with the give type. 00109 * returns 1 on succes, 0 if no layer with the given type is found 00110 * 00111 * in editmode, use EM_free_data_layer instead of this function 00112 */ 00113 int CustomData_free_layer_active(struct CustomData *data, int type, int totelem); 00114 00115 /* same as above, but free all layers with type */ 00116 void CustomData_free_layers(struct CustomData *data, int type, int totelem); 00117 00118 /* returns 1 if a layer with the specified type exists */ 00119 int CustomData_has_layer(const struct CustomData *data, int type); 00120 00121 /* returns the number of layers with this type */ 00122 int CustomData_number_of_layers(const struct CustomData *data, int type); 00123 00124 /* duplicate data of a layer with flag NOFREE, and remove that flag. 00125 * returns the layer data */ 00126 void *CustomData_duplicate_referenced_layer(struct CustomData *data, int type); 00127 void *CustomData_duplicate_referenced_layer_named(struct CustomData *data, 00128 int type, const char *name); 00129 00130 /* set the CD_FLAG_NOCOPY flag in custom data layers where the mask is 00131 * zero for the layer type, so only layer types specified by the mask 00132 * will be copied 00133 */ 00134 void CustomData_set_only_copy(const struct CustomData *data, 00135 CustomDataMask mask); 00136 00137 /* copies data from one CustomData object to another 00138 * objects need not be compatible, each source layer is copied to the 00139 * first dest layer of correct type (if there is none, the layer is skipped) 00140 * return 1 on success, 0 on failure 00141 */ 00142 void CustomData_copy_data(const struct CustomData *source, 00143 struct CustomData *dest, int source_index, 00144 int dest_index, int count); 00145 void CustomData_em_copy_data(const struct CustomData *source, 00146 struct CustomData *dest, void *src_block, 00147 void **dest_block); 00148 void CustomData_bmesh_copy_data(const struct CustomData *source, 00149 struct CustomData *dest,void *src_block, 00150 void **dest_block); 00151 void CustomData_em_validate_data(struct CustomData *data, void *block, int sub_elements); 00152 00153 /* frees data in a CustomData object 00154 * return 1 on success, 0 on failure 00155 */ 00156 void CustomData_free_elem(struct CustomData *data, int index, int count); 00157 00158 /* interpolates data from one CustomData object to another 00159 * objects need not be compatible, each source layer is interpolated to the 00160 * first dest layer of correct type (if there is none, the layer is skipped) 00161 * if weights == NULL or sub_weights == NULL, they default to all 1's 00162 * 00163 * src_indices gives the source elements to interpolate from 00164 * weights gives the weight for each source element 00165 * sub_weights is an array of matrices of weights for sub-elements (matrices 00166 * should be source->subElems * source->subElems in size) 00167 * count gives the number of source elements to interpolate from 00168 * dest_index gives the dest element to write the interpolated value to 00169 * 00170 * returns 1 on success, 0 on failure 00171 */ 00172 void CustomData_interp(const struct CustomData *source, struct CustomData *dest, 00173 int *src_indices, float *weights, float *sub_weights, 00174 int count, int dest_index); 00175 void CustomData_em_interp(struct CustomData *data, void **src_blocks, 00176 float *weights, float *sub_weights, int count, 00177 void *dest_block); 00178 void CustomData_bmesh_interp(struct CustomData *data, void **src_blocks, 00179 float *weights, float *sub_weights, int count, 00180 void *dest_block); 00181 00182 00183 /* swaps the data in the element corners, to new corners with indices as 00184 specified in corner_indices. for edges this is an array of length 2, for 00185 faces an array of length 4 */ 00186 void CustomData_swap(struct CustomData *data, int index, const int *corner_indices); 00187 00188 /* gets a pointer to the data element at index from the first layer of type 00189 * returns NULL if there is no layer of type 00190 */ 00191 void *CustomData_get(const struct CustomData *data, int index, int type); 00192 void *CustomData_em_get(const struct CustomData *data, void *block, int type); 00193 void *CustomData_em_get_n(const struct CustomData *data, void *block, int type, int n); 00194 void *CustomData_bmesh_get(const struct CustomData *data, void *block, int type); 00195 void *CustomData_bmesh_get_n(const struct CustomData *data, void *block, int type, int n); 00196 00197 /* gets a pointer to the active or first layer of type 00198 * returns NULL if there is no layer of type 00199 */ 00200 void *CustomData_get_layer(const struct CustomData *data, int type); 00201 void *CustomData_get_layer_n(const struct CustomData *data, int type, int n); 00202 void *CustomData_get_layer_named(const struct CustomData *data, int type, 00203 const char *name); 00204 00205 int CustomData_get_layer_index(const struct CustomData *data, int type); 00206 int CustomData_get_named_layer_index(const struct CustomData *data, int type, const char *name); 00207 int CustomData_get_active_layer_index(const struct CustomData *data, int type); 00208 int CustomData_get_render_layer_index(const struct CustomData *data, int type); 00209 int CustomData_get_clone_layer_index(const struct CustomData *data, int type); 00210 int CustomData_get_stencil_layer_index(const struct CustomData *data, int type); 00211 int CustomData_get_active_layer(const struct CustomData *data, int type); 00212 int CustomData_get_render_layer(const struct CustomData *data, int type); 00213 int CustomData_get_clone_layer(const struct CustomData *data, int type); 00214 int CustomData_get_stencil_layer(const struct CustomData *data, int type); 00215 00216 /* copies the data from source to the data element at index in the first 00217 * layer of type 00218 * no effect if there is no layer of type 00219 */ 00220 void CustomData_set(const struct CustomData *data, int index, int type, 00221 void *source); 00222 void CustomData_em_set(struct CustomData *data, void *block, int type, 00223 void *source); 00224 void CustomData_em_set_n(struct CustomData *data, void *block, int type, int n, 00225 void *source); 00226 00227 void CustomData_bmesh_set(const struct CustomData *data, void *block, int type, 00228 void *source); 00229 00230 void CustomData_bmesh_set_n(struct CustomData *data, void *block, int type, int n, 00231 void *source); 00232 00233 /* set the pointer of to the first layer of type. the old data is not freed. 00234 * returns the value of ptr if the layer is found, NULL otherwise 00235 */ 00236 void *CustomData_set_layer(const struct CustomData *data, int type, void *ptr); 00237 void *CustomData_set_layer_n(const struct CustomData *data, int type, int n, void *ptr); 00238 00239 /* sets the nth layer of type as active */ 00240 void CustomData_set_layer_active(struct CustomData *data, int type, int n); 00241 void CustomData_set_layer_render(struct CustomData *data, int type, int n); 00242 void CustomData_set_layer_clone(struct CustomData *data, int type, int n); 00243 void CustomData_set_layer_stencil(struct CustomData *data, int type, int n); 00244 00245 /* same as above but works with an index from CustomData_get_layer_index */ 00246 void CustomData_set_layer_active_index(struct CustomData *data, int type, int n); 00247 void CustomData_set_layer_render_index(struct CustomData *data, int type, int n); 00248 void CustomData_set_layer_clone_index(struct CustomData *data, int type, int n); 00249 void CustomData_set_layer_stencil_index(struct CustomData *data, int type, int n); 00250 00251 /* adds flag to the layer flags */ 00252 void CustomData_set_layer_flag(struct CustomData *data, int type, int flag); 00253 00254 /* alloc/free a block of custom data attached to one element in editmode */ 00255 void CustomData_em_set_default(struct CustomData *data, void **block); 00256 void CustomData_em_free_block(struct CustomData *data, void **block); 00257 00258 void CustomData_bmesh_set_default(struct CustomData *data, void **block); 00259 void CustomData_bmesh_free_block(struct CustomData *data, void **block); 00260 00261 /* copy custom data to/from layers as in mesh/derivedmesh, to editmesh 00262 blocks of data. the CustomData's must not be compatible */ 00263 void CustomData_to_em_block(const struct CustomData *source, 00264 struct CustomData *dest, int index, void **block); 00265 void CustomData_from_em_block(const struct CustomData *source, 00266 struct CustomData *dest, void *block, int index); 00267 void CustomData_to_bmesh_block(const struct CustomData *source, 00268 struct CustomData *dest, int src_index, void **dest_block); 00269 void CustomData_from_bmesh_block(const struct CustomData *source, 00270 struct CustomData *dest, void *src_block, int dest_index); 00271 00272 00273 /* query info over types */ 00274 void CustomData_file_write_info(int type, const char **structname, int *structnum); 00275 int CustomData_sizeof(int type); 00276 00277 /* get the name of a layer type */ 00278 const char *CustomData_layertype_name(int type); 00279 00280 /* make sure the name of layer at index is unique */ 00281 void CustomData_set_layer_unique_name(struct CustomData *data, int index); 00282 00283 /* for file reading compatibility, returns false if the layer was freed, 00284 only after this test passes, layer->data should be assigned */ 00285 int CustomData_verify_versions(struct CustomData *data, int index); 00286 00287 /*BMesh specific customdata stuff*/ 00288 void CustomData_to_bmeshpoly(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata); 00289 void CustomData_from_bmeshpoly(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata, int total); 00290 void CustomData_bmesh_init_pool(struct CustomData *data, int allocsize); 00291 00292 /* External file storage */ 00293 00294 void CustomData_external_add(struct CustomData *data, 00295 struct ID *id, int type, int totelem, const char *filename); 00296 void CustomData_external_remove(struct CustomData *data, 00297 struct ID *id, int type, int totelem); 00298 int CustomData_external_test(struct CustomData *data, int type); 00299 00300 void CustomData_external_write(struct CustomData *data, 00301 struct ID *id, CustomDataMask mask, int totelem, int free); 00302 void CustomData_external_read(struct CustomData *data, 00303 struct ID *id, CustomDataMask mask, int totelem); 00304 void CustomData_external_reload(struct CustomData *data, 00305 struct ID *id, CustomDataMask mask, int totelem); 00306 00307 #ifdef __cplusplus 00308 } 00309 #endif 00310 00311 #endif 00312