diff options
Diffstat (limited to 'source/blender/blenkernel/BKE_customdata.h')
-rw-r--r-- | source/blender/blenkernel/BKE_customdata.h | 101 |
1 files changed, 39 insertions, 62 deletions
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index f05dfb164cf..010fbb27172 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -10,6 +10,10 @@ #include "BLI_sys_types.h" #include "BLI_utildefines.h" +#ifdef __cplusplus +# include "BLI_span.hh" +# include "BLI_vector.hh" +#endif #include "DNA_customdata_types.h" @@ -24,7 +28,7 @@ struct BlendWriter; struct CustomData; struct CustomData_MeshMasks; struct ID; -typedef uint64_t CustomDataMask; +typedef uint64_t eCustomDataMask; /* A data type large enough to hold 1 element from any custom-data layer type. */ typedef struct { @@ -59,7 +63,7 @@ typedef enum eCDAllocType { CD_DUPLICATE = 4, } eCDAllocType; -#define CD_TYPE_AS_MASK(_type) (CustomDataMask)((CustomDataMask)1 << (CustomDataMask)(_type)) +#define CD_TYPE_AS_MASK(_type) (eCustomDataMask)((eCustomDataMask)1 << (eCustomDataMask)(_type)) void customData_mask_layers__print(const struct CustomData_MeshMasks *mask); @@ -133,7 +137,7 @@ void CustomData_data_add(int type, void *data1, const void *data2); */ void CustomData_copy(const struct CustomData *source, struct CustomData *dest, - CustomDataMask mask, + eCustomDataMask mask, eCDAllocType alloctype, int totelem); @@ -146,7 +150,7 @@ void CustomData_update_typemap(struct CustomData *data); */ bool CustomData_merge(const struct CustomData *source, struct CustomData *dest, - CustomDataMask mask, + eCustomDataMask mask, eCDAllocType alloctype, int totelem); @@ -166,7 +170,7 @@ void CustomData_realloc(struct CustomData *data, int totelem); */ bool CustomData_bmesh_merge(const struct CustomData *source, struct CustomData *dest, - CustomDataMask mask, + eCustomDataMask mask, eCDAllocType alloctype, struct BMesh *bm, char htype); @@ -184,7 +188,7 @@ void CustomData_free(struct CustomData *data, int totelem); /** * Same as above, but only frees layers which matches the given mask. */ -void CustomData_free_typemask(struct CustomData *data, int totelem, CustomDataMask mask); +void CustomData_free_typemask(struct CustomData *data, int totelem, eCustomDataMask mask); /** * Frees all layers with #CD_FLAG_TEMPORARY. @@ -221,6 +225,7 @@ void *CustomData_add_layer_anonymous(struct CustomData *data, * In edit-mode, use #EDBM_data_layer_free instead of this function. */ bool CustomData_free_layer(struct CustomData *data, int type, int totelem, int index); +bool CustomData_free_layer_named(struct CustomData *data, const char *name, const int totelem); /** * Frees the layer index with the give type. @@ -244,7 +249,7 @@ bool CustomData_has_layer(const struct CustomData *data, int type); * Returns the number of layers with this type. */ int CustomData_number_of_layers(const struct CustomData *data, int type); -int CustomData_number_of_layers_typemask(const struct CustomData *data, CustomDataMask mask); +int CustomData_number_of_layers_typemask(const struct CustomData *data, eCustomDataMask mask); /** * Duplicate data of a layer with flag NOFREE, and remove that flag. @@ -272,7 +277,7 @@ void CustomData_duplicate_referenced_layers(CustomData *data, int totelem); * Set the #CD_FLAG_NOCOPY flag in custom data layers where the mask is * zero for the layer type, so only layer types specified by the mask will be copied */ -void CustomData_set_only_copy(const struct CustomData *data, CustomDataMask mask); +void CustomData_set_only_copy(const struct CustomData *data, eCustomDataMask mask); /** * Copies data from one CustomData object to another @@ -305,7 +310,7 @@ void CustomData_bmesh_copy_data_exclude_by_type(const struct CustomData *source, struct CustomData *dest, void *src_block, void **dest_block, - CustomDataMask mask_exclude); + eCustomDataMask mask_exclude); /** * Copies data of a single layer of a given type. @@ -484,7 +489,7 @@ void CustomData_bmesh_free_block_data(struct CustomData *data, void *block); */ void CustomData_bmesh_free_block_data_exclude_by_type(struct CustomData *data, void *block, - CustomDataMask mask_exclude); + eCustomDataMask mask_exclude); /** * Copy custom data to/from layers as in mesh/derived-mesh, to edit-mesh @@ -545,33 +550,11 @@ void CustomData_validate_layer_name(const struct CustomData *data, */ bool CustomData_verify_versions(struct CustomData *data, int index); -/* BMesh specific custom-data stuff. - * - * Needed to convert to/from different face representation (for versioning). */ +/* BMesh specific custom-data stuff. */ -void CustomData_to_bmeshpoly(struct CustomData *fdata, struct CustomData *ldata, int totloop); -void CustomData_from_bmeshpoly(struct CustomData *fdata, struct CustomData *ldata, int total); void CustomData_bmesh_update_active_layers(struct CustomData *fdata, struct CustomData *ldata); -/** - * Update active indices for active/render/clone/stencil custom data layers - * based on indices from fdata layers - * used by do_versions in `readfile.c` when creating pdata and ldata for pre-bmesh - * meshes and needed to preserve active/render/clone/stencil flags set in pre-bmesh files. - */ -void CustomData_bmesh_do_versions_update_active_layers(struct CustomData *fdata, - struct CustomData *ldata); void CustomData_bmesh_init_pool(struct CustomData *data, int totelem, char htype); -#ifndef NDEBUG -/** - * Debug check, used to assert when we expect layers to be in/out of sync. - * - * \param fallback: Use when there are no layers to handle, - * since callers may expect success or failure. - */ -bool CustomData_from_bmeshpoly_test(CustomData *fdata, CustomData *ldata, bool fallback); -#endif - /** * Validate and fix data of \a layer, * if possible (needs relevant callback in layer's type to be defined). @@ -589,14 +572,14 @@ void CustomData_external_remove(struct CustomData *data, struct ID *id, int type bool CustomData_external_test(struct CustomData *data, int type); void CustomData_external_write( - struct CustomData *data, struct ID *id, CustomDataMask mask, int totelem, int free); + struct CustomData *data, struct ID *id, eCustomDataMask mask, int totelem, int free); void CustomData_external_read(struct CustomData *data, struct ID *id, - CustomDataMask mask, + eCustomDataMask mask, int totelem); void CustomData_external_reload(struct CustomData *data, struct ID *id, - CustomDataMask mask, + eCustomDataMask mask, int totelem); /* Mesh-to-mesh transfer data. */ @@ -700,39 +683,33 @@ void CustomData_data_transfer(const struct MeshPairRemap *me_remap, /* .blend file I/O */ +#ifdef __cplusplus + /** * Prepare given custom data for file writing. * - * \param data: the custom-data to tweak for .blend file writing (modified in place). - * \param r_write_layers: contains a reduced set of layers to be written to file, - * use it with #writestruct_at_address() - * (caller must free it if != \a write_layers_buff). - * - * \param write_layers_buff: An optional buffer for r_write_layers (to avoid allocating it). - * \param write_layers_size: The size of pre-allocated \a write_layer_buff. + * \param data: The custom-data to tweak for .blend file writing (modified in place). + * \param layers_to_write: A reduced set of layers to be written to file. * - * \warning After this function has ran, given custom data is no more valid from Blender POV - * (its `totlayer` is invalid). This function shall always be called with localized data - * (as it is in write_meshes()). - * - * \note `data->typemap` is not updated here, since it is always rebuilt on file read anyway. - * This means written `typemap` does not match written layers (as returned by \a r_write_layers). - * Trivial to fix is ever needed. + * \warning This function invalidates the custom data struct by changing the layer counts and the + * #layers pointer, and by invalidating the type map. It expects to work on a shallow copy of + * the struct. */ -void CustomData_blend_write_prepare(struct CustomData *data, - struct CustomDataLayer **r_write_layers, - struct CustomDataLayer *write_layers_buff, - size_t write_layers_size); +void CustomData_blend_write_prepare(CustomData &data, + blender::Vector<CustomDataLayer, 16> &layers_to_write); /** - * \param layers: The layers argument assigned by #CustomData_blend_write_prepare. + * \param layers_to_write: Layers created by #CustomData_blend_write_prepare. */ -void CustomData_blend_write(struct BlendWriter *writer, - struct CustomData *data, - CustomDataLayer *layers, +void CustomData_blend_write(BlendWriter *writer, + CustomData *data, + blender::Span<CustomDataLayer> layers_to_write, int count, - CustomDataMask cddata_mask, - struct ID *id); + eCustomDataMask cddata_mask, + ID *id); + +#endif + void CustomData_blend_read(struct BlendDataReader *reader, struct CustomData *data, int count); #ifndef NDEBUG @@ -751,7 +728,7 @@ void CustomData_debug_info_from_layers(const struct CustomData *data, # include "BLI_cpp_type.hh" namespace blender::bke { -const CPPType *custom_data_type_to_cpp_type(const CustomDataType type); -CustomDataType cpp_type_to_custom_data_type(const CPPType &type); +const CPPType *custom_data_type_to_cpp_type(eCustomDataType type); +eCustomDataType cpp_type_to_custom_data_type(const CPPType &type); } // namespace blender::bke #endif |