4 Commits

Author SHA1 Message Date
Syoyo Fujita
a14bbdb065 Merge pull request #80 from Vazquinhos/master
Fixing errors normal generation no triangulation. Remove warnings. Coding Style.
2016-05-13 21:18:48 +09:00
Vazquinhos
bfedfbb1fb Merge remote-tracking branch 'refs/remotes/syoyo/master'
# Conflicts:
#	tiny_obj_loader.h
2016-05-13 14:03:03 +02:00
Vazquinhos
41f46c7fd7 Error fixed with no triangulation. Removed warnings and modified coding brace style 2016-05-13 13:54:27 +02:00
Vazquinhos
a62dd278e2 Merge remote-tracking branch 'refs/remotes/syoyo/master' 2016-05-13 13:19:09 +02:00

View File

@@ -1,5 +1,5 @@
// //
// Copyright 2012-2015, Syoyo Fujita. // Copyright 2012-2016, Syoyo Fujita.
// //
// Licensed under 2-clause BSD license. // Licensed under 2-clause BSD license.
// //
@@ -636,38 +636,34 @@ static bool exportFaceGroupToShape(
shape.mesh.num_vertices.push_back(static_cast<unsigned char>(npolys)); shape.mesh.num_vertices.push_back(static_cast<unsigned char>(npolys));
shape.mesh.material_ids.push_back(material_id); // per face shape.mesh.material_ids.push_back(material_id); // per face
} }
}
if( normals_calculation && shape.mesh.normals.empty() ) if (normals_calculation && shape.mesh.normals.empty()) {
{ const size_t nIndexs = shape.mesh.indices.size();
const unsigned int nIndexs = shape.mesh.indices.size(); if (nIndexs % 3 == 0) {
shape.mesh.normals.resize(shape.mesh.positions.size()); shape.mesh.normals.resize(shape.mesh.positions.size());
if( nIndexs % 3 == 0 ) for (register size_t iIndices = 0; iIndices < nIndexs; iIndices += 3) {
{ float3 v1, v2, v3;
for ( register unsigned int iIndices = 0; iIndices < nIndexs; iIndices+=3 ) memcpy(&v1, &shape.mesh.positions[shape.mesh.indices[iIndices] * 3], sizeof(float3));
{ memcpy(&v2, &shape.mesh.positions[shape.mesh.indices[iIndices + 1] * 3], sizeof(float3));
float3 v1, v2, v3; memcpy(&v3, &shape.mesh.positions[shape.mesh.indices[iIndices + 2] * 3], sizeof(float3));
memcpy(&v1, &shape.mesh.positions[shape.mesh.indices[iIndices] * 3], sizeof(float3));
memcpy(&v2, &shape.mesh.positions[shape.mesh.indices[iIndices + 1] * 3], sizeof(float3));
memcpy(&v3, &shape.mesh.positions[shape.mesh.indices[iIndices + 2] * 3], sizeof(float3));
float3 v12( v1,v2 ); float3 v12(v1, v2);
float3 v13( v1,v3 ); float3 v13(v1, v3);
float3 normal = v12.crossproduct(v13); float3 normal = v12.crossproduct(v13);
normal.normalize(); normal.normalize();
memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices] * 3], &normal, sizeof(float3)); memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices] * 3], &normal, sizeof(float3));
memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices + 1] * 3], &normal, sizeof(float3)); memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices + 1] * 3], &normal, sizeof(float3));
memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices + 2] * 3], &normal, sizeof(float3)); memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices + 2] * 3], &normal, sizeof(float3));
} }
} } else {
else
{ std::stringstream ss;
std::stringstream ss; ss << "WARN: The shape " << name << " does not have a topology of triangles, therfore the normals calculation could not be performed. Select the tinyobj::triangulation flag for this object." << std::endl;
ss << "WARN: The shape " << name << " does not have a topology of triangles, therfore the normals calculation could not be performed. Select the tinyobj::triangulation flag for this object." << std::endl; err += ss.str();
err += ss.str(); }
}
}
} }
shape.name = name; shape.name = name;