Merge pull request #80 from Vazquinhos/master
Fixing errors normal generation no triangulation. Remove warnings. Coding Style.
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user