4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2006 Blender Foundation.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): Ben Batt <benbatt@gmail.com>
27 * ***** END GPL LICENSE BLOCK *****
30 /* CustomData interface, see also DNA_customdata_types.h. */
32 #ifndef BKE_CUSTOMDATA_H
33 #define BKE_CUSTOMDATA_H
36 struct CustomDataLayer;
37 typedef int CustomDataMask;
39 extern const CustomDataMask CD_MASK_BAREMESH;
40 extern const CustomDataMask CD_MASK_MESH;
41 extern const CustomDataMask CD_MASK_EDITMESH;
42 extern const CustomDataMask CD_MASK_DERIVEDMESH;
44 /* for ORIGINDEX layer type, indicates no original index for this element */
45 #define ORIGINDEX_NONE -1
47 /* initialises a CustomData object with the same layer setup as source and
48 * memory space for totelem elements. mask must be an array of length
49 * CD_NUMTYPES elements, that indicate if a layer can be copied. */
51 /* add/copy/merge allocation types */
52 #define CD_ASSIGN 0 /* use the data pointer */
53 #define CD_CALLOC 1 /* allocate blank memory */
54 #define CD_DEFAULT 2 /* allocate and set to default */
55 #define CD_REFERENCE 3 /* use data pointers, set layer flag NOFREE */
56 #define CD_DUPLICATE 4 /* do a full copy of all layers, only allowed if source
57 has same number of elements */
59 /* initialises a CustomData object with the same layer setup as source.
60 * mask is a bitfield where (mask & (1 << (layer type))) indicates
61 * if a layer should be copied or not. alloctype must be one of the above. */
62 void CustomData_copy(const struct CustomData *source, struct CustomData *dest,
63 CustomDataMask mask, int alloctype, int totelem);
65 /* same as the above, except that this will preserve existing layers, and only
66 * add the layers that were not there yet */
67 void CustomData_merge(const struct CustomData *source, struct CustomData *dest,
68 CustomDataMask mask, int alloctype, int totelem);
70 /* frees data associated with a CustomData object (doesn't free the object
73 void CustomData_free(struct CustomData *data, int totelem);
75 /* frees all layers with CD_FLAG_TEMPORARY */
76 void CustomData_free_temporary(struct CustomData *data, int totelem);
78 /* adds a data layer of the given type to the CustomData object, optionally
79 * backed by an external data array. the different allocation types are
80 * defined above. returns the data of the layer.
82 * in editmode, use EM_add_data_layer instead of this function
84 void *CustomData_add_layer(struct CustomData *data, int type, int alloctype,
85 void *layer, int totelem);
86 /*same as above but accepts a name */
87 void *CustomData_add_layer_named(struct CustomData *data, int type, int alloctype,
88 void *layer, int totelem, char *name);
90 /* frees the active or first data layer with the give type.
91 * returns 1 on succes, 0 if no layer with the given type is found
93 * in editmode, use EM_free_data_layer instead of this function
95 int CustomData_free_layer(struct CustomData *data, int type, int totelem, int index);
97 /* frees the layer index with the give type.
98 * returns 1 on succes, 0 if no layer with the given type is found
100 * in editmode, use EM_free_data_layer instead of this function
102 int CustomData_free_layer_active(struct CustomData *data, int type, int totelem);
104 /* same as above, but free all layers with type */
105 void CustomData_free_layers(struct CustomData *data, int type, int totelem);
107 /* returns 1 if a layer with the specified type exists */
108 int CustomData_has_layer(const struct CustomData *data, int type);
110 /* returns the number of layers with this type */
111 int CustomData_number_of_layers(const struct CustomData *data, int type);
113 /* duplicate data of a layer with flag NOFREE, and remove that flag.
114 * returns the layer data */
115 void *CustomData_duplicate_referenced_layer(struct CustomData *data, int type);
117 /* set the CD_FLAG_NOCOPY flag in custom data layers where the mask is
118 * zero for the layer type, so only layer types specified by the mask
121 void CustomData_set_only_copy(const struct CustomData *data,
122 CustomDataMask mask);
124 /* copies data from one CustomData object to another
125 * objects need not be compatible, each source layer is copied to the
126 * first dest layer of correct type (if there is none, the layer is skipped)
127 * return 1 on success, 0 on failure
129 void CustomData_copy_data(const struct CustomData *source,
130 struct CustomData *dest, int source_index,
131 int dest_index, int count);
132 void CustomData_em_copy_data(const struct CustomData *source,
133 struct CustomData *dest, void *src_block,
136 /* frees data in a CustomData object
137 * return 1 on success, 0 on failure
139 void CustomData_free_elem(struct CustomData *data, int index, int count);
141 /* interpolates data from one CustomData object to another
142 * objects need not be compatible, each source layer is interpolated to the
143 * first dest layer of correct type (if there is none, the layer is skipped)
144 * if weights == NULL or sub_weights == NULL, they default to all 1's
146 * src_indices gives the source elements to interpolate from
147 * weights gives the weight for each source element
148 * sub_weights is an array of matrices of weights for sub-elements (matrices
149 * should be source->subElems * source->subElems in size)
150 * count gives the number of source elements to interpolate from
151 * dest_index gives the dest element to write the interpolated value to
153 * returns 1 on success, 0 on failure
155 void CustomData_interp(const struct CustomData *source, struct CustomData *dest,
156 int *src_indices, float *weights, float *sub_weights,
157 int count, int dest_index);
158 void CustomData_em_interp(struct CustomData *data, void **src_blocks,
159 float *weights, float *sub_weights, int count,
162 /* swaps the data in the element corners, to new corners with indices as
163 specified in corner_indices. for edges this is an array of length 2, for
164 faces an array of length 4 */
165 void CustomData_swap(struct CustomData *data, int index, int *corner_indices);
167 /* gets a pointer to the data element at index from the first layer of type
168 * returns NULL if there is no layer of type
170 void *CustomData_get(const struct CustomData *data, int index, int type);
171 void *CustomData_em_get(const struct CustomData *data, void *block, int type);
173 /* gets a pointer to the active or first layer of type
174 * returns NULL if there is no layer of type
176 void *CustomData_get_layer(const struct CustomData *data, int type);
177 void *CustomData_get_layer_n(const struct CustomData *data, int type, int n);
179 int CustomData_get_layer_index(const struct CustomData *data, int type);
180 int CustomData_get_named_layer_index(const struct CustomData *data, int type, char *name);
181 int CustomData_get_active_layer_index(const struct CustomData *data, int type);
183 /* copies the data from source to the data element at index in the first
185 * no effect if there is no layer of type
187 void CustomData_set(const struct CustomData *data, int index, int type,
189 void CustomData_em_set(struct CustomData *data, void *block, int type,
192 /* set the pointer of to the first layer of type. the old data is not freed.
193 * returns the value of ptr if the layer is found, NULL otherwise
195 void *CustomData_set_layer(const struct CustomData *data, int type, void *ptr);
197 /* sets the nth layer of type as active */
198 void CustomData_set_layer_active(struct CustomData *data, int type, int n);
200 /* adds flag to the layer flags */
201 void CustomData_set_layer_flag(struct CustomData *data, int type, int flag);
203 /* alloc/free a block of custom data attached to one element in editmode */
204 void CustomData_em_set_default(struct CustomData *data, void **block);
205 void CustomData_em_free_block(struct CustomData *data, void **block);
207 /* copy custom data to/from layers as in mesh/derivedmesh, to editmesh
208 blocks of data. the CustomData's must not be compatible */
209 void CustomData_to_em_block(const struct CustomData *source,
210 struct CustomData *dest, int index, void **block);
211 void CustomData_from_em_block(const struct CustomData *source,
212 struct CustomData *dest, void *block, int index);
214 /* query info over types */
215 void CustomData_file_write_info(int type, char **structname, int *structnum);
216 int CustomData_sizeof(int type);
218 /* get the name of a layer type */
219 const char *CustomData_layertype_name(int type);
221 /* make sure the name of layer at index is unique */
222 void CustomData_set_layer_unique_name(struct CustomData *data, int index);
224 /* for file reading compatibility, returns false if the layer was freed,
225 only after this test passes, layer->data should be assigned */
226 int CustomData_verify_versions(struct CustomData *data, int index);