Blender V2.61 - r43446

BKE_customdata.h

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