diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-05-11 18:22:18 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-05-11 18:22:18 +0300 |
commit | 1bf685488cf2990da656bd2a2eeea0088f99a4bf (patch) | |
tree | 65a57148d7498ad3e343681c045bd86460c0d497 | |
parent | 2c4736e6db50ad74d591aa39b922c3d923cc1cfe (diff) |
Collada Exporter: sanitize a bit lnor export.
In case `BKE_mesh_calc_normals_split()` would fail, exporter would read
uninitialized random mem... Should not happen, but better be safe than sorry.
-rw-r--r-- | source/blender/collada/GeometryExporter.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp index b29b4c9c484..a0eddadfe78 100644 --- a/source/blender/collada/GeometryExporter.cpp +++ b/source/blender/collada/GeometryExporter.cpp @@ -606,7 +606,7 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals, std::vector< MVert *verts = me->mvert; MLoop *mloops = me->mloop; - float(*lnors)[3]; + float(*lnors)[3] = NULL; bool use_custom_normals = false; BKE_mesh_calc_normals_split(me); @@ -630,14 +630,19 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals, std::vector< last_normal_index++; } - MLoop *mloop = mloops + mpoly->loopstart; BCPolygonNormalsIndices poly_indices; for (int loop_index = 0; loop_index < mpoly->totloop; loop_index++) { unsigned int loop_idx = mpoly->loopstart + loop_index; if (use_vertex_normals) { - float normalized[3]; - normalize_v3_v3(normalized, lnors[loop_idx]); + + if (use_custom_normals) { + normalize_v3_v3(normalized, lnors[loop_idx]); + } + else { + normal_short_to_float_v3(normalized, verts[mloops[loop_index].v].no); + normalize_v3(normalized); + } Normal n = { normalized[0], normalized[1], normalized[2] }; if (shared_normal_indices.find(n) != shared_normal_indices.end()) { |