BKE_mesh: add polygon flipping tools.

Those new functions invert the winding of polygons, effectively inverting their normals.

A helper was also added to allow swapping two items in customdata layers.

Being able to invert normals outside of BMesh area is very important in several places,
like IO scripts or customnormals modifiers...

Reviewers: campbellbarton

Differential Revision: https://developer.blender.org/D1814
This commit is contained in:
2016-02-28 15:29:56 +01:00
parent ea76ec2866
commit 877f441628
6 changed files with 114 additions and 1 deletions

View File

@@ -2356,6 +2356,35 @@ void CustomData_swap_corners(struct CustomData *data, int index, const int *corn
}
}
/**
* Swap two items of given custom data, in all available layers.
*/
void CustomData_swap(struct CustomData *data, const int index_a, const int index_b)
{
int i;
char buff_static[256];
if (index_a == index_b) {
return;
}
for (i = 0; i < data->totlayer; ++i) {
const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type);
const size_t size = typeInfo->size;
const size_t offset_a = size * index_a;
const size_t offset_b = size * index_b;
void *buff = size <= sizeof(buff_static) ? buff_static : MEM_mallocN(size, __func__);
memcpy(buff, POINTER_OFFSET(data->layers[i].data, offset_a), size);
memcpy(POINTER_OFFSET(data->layers[i].data, offset_a), POINTER_OFFSET(data->layers[i].data, offset_b), size);
memcpy(POINTER_OFFSET(data->layers[i].data, offset_b), buff, size);
if (buff != buff_static) {
MEM_freeN(buff);
}
}
}
void *CustomData_get(const CustomData *data, int index, int type)
{
int offset;