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>2015-08-12 19:21:41 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-08-12 19:21:41 +0300
commit487d2cb4f321d9847fb18bd57fbe7ccc3528461f (patch)
treee59219eb3218761a5d56d7f2b25d5da943b924a7 /source/blender/blenkernel/intern/mesh_evaluate.c
parent883b420a5156fe616488f975a6817fde4cab0352 (diff)
Displace Modifier: add an option to displace along (averaged) custom normals, instead of vertex normals.
User suggestion/request from 'boby'.
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_evaluate.c')
-rw-r--r--source/blender/blenkernel/intern/mesh_evaluate.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 3bc0492e179..d4787bd250c 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -1527,6 +1527,38 @@ void BKE_mesh_normals_loop_custom_from_vertices_set(
mpolys, polynors, numPolys, r_clnors_data, true);
}
+/**
+ * Computes average per-vertex normals from given custom loop normals.
+ *
+ * @param clnors The computed custom loop normals.
+ * @param r_vert_clnors The (already allocated) array wher to store averaged per-vertex normals.
+ */
+void BKE_mesh_normals_loop_to_vertex(
+ const int numVerts, const MLoop *mloops, const int numLoops,
+ const float (*clnors)[3], float (*r_vert_clnors)[3])
+{
+ const MLoop *ml;
+ int i;
+
+ int *vert_loops_nbr = MEM_callocN(sizeof(*vert_loops_nbr) * (size_t)numVerts, __func__);
+
+ copy_vn_fl((float *)r_vert_clnors, 3 * numVerts, 0.0f);
+
+ for (i = 0, ml = mloops; i < numLoops; i++, ml++) {
+ const unsigned int v = ml->v;
+
+ add_v3_v3(r_vert_clnors[v], clnors[i]);
+ vert_loops_nbr[v]++;
+ }
+
+ for (i = 0; i < numVerts; i++) {
+ mul_v3_fl(r_vert_clnors[i], 1.0f / (float)vert_loops_nbr[i]);
+ }
+
+ MEM_freeN(vert_loops_nbr);
+}
+
+
#undef LNOR_SPACE_TRIGO_THRESHOLD
/** \} */