Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2016-02-28 17:29:56 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2016-02-28 17:29:56 +0300
commit877f44162853664791f0ff4fa93f856384d0eed7 (patch)
treeed924b94bebd5cec0ad5455b7e90d481b63ad80a /source/blender/blenkernel/intern/customdata.c
parentea76ec2866d11156b689287f4190dfe4e79314b2 (diff)
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
Diffstat (limited to 'source/blender/blenkernel/intern/customdata.c')
-rw-r--r--source/blender/blenkernel/intern/customdata.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index c120509b769..1ed7c989075 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -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;