Merge pull request #80 from Vazquinhos/master

Fixing errors normal generation no triangulation. Remove warnings. Coding Style.
This commit is contained in:
Syoyo Fujita
2016-05-13 21:18:48 +09:00

View File

@@ -1,5 +1,5 @@
//
// Copyright 2012-2015, Syoyo Fujita.
// Copyright 2012-2016, Syoyo Fujita.
//
// Licensed under 2-clause BSD license.
//
@@ -636,22 +636,20 @@ static bool exportFaceGroupToShape(
shape.mesh.num_vertices.push_back(static_cast<unsigned char>(npolys));
shape.mesh.material_ids.push_back(material_id); // per face
}
}
if( normals_calculation && shape.mesh.normals.empty() )
{
const unsigned int nIndexs = shape.mesh.indices.size();
if (normals_calculation && shape.mesh.normals.empty()) {
const size_t nIndexs = shape.mesh.indices.size();
if (nIndexs % 3 == 0) {
shape.mesh.normals.resize(shape.mesh.positions.size());
if( nIndexs % 3 == 0 )
{
for ( register unsigned int iIndices = 0; iIndices < nIndexs; iIndices+=3 )
{
for (register size_t iIndices = 0; iIndices < nIndexs; iIndices += 3) {
float3 v1, v2, v3;
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 v13( v1,v3 );
float3 v12(v1, v2);
float3 v13(v1, v3);
float3 normal = v12.crossproduct(v13);
normal.normalize();
@@ -660,15 +658,13 @@ static bool exportFaceGroupToShape(
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));
}
}
else
{
} else {
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;
err += ss.str();
}
}
}
shape.name = name;
shape.mesh.tags.swap(tags);