[Bf-blender-cvs] [1bf6854] master: Collada Exporter: sanitize a bit lnor export.

Bastien Montagne noreply at git.blender.org
Mon May 11 17:24:14 CEST 2015


Commit: 1bf685488cf2990da656bd2a2eeea0088f99a4bf
Author: Bastien Montagne
Date:   Mon May 11 17:22:18 2015 +0200
Branches: master
https://developer.blender.org/rB1bf685488cf2990da656bd2a2eeea0088f99a4bf

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.

===================================================================

M	source/blender/collada/GeometryExporter.cpp

===================================================================

diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp
index b29b4c9..a0eddad 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()) {




More information about the Bf-blender-cvs mailing list