Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a14bbdb

Browse files
committed
Merge pull request tinyobjloader#80 from Vazquinhos/master
Fixing errors normal generation no triangulation. Remove warnings. Coding Style.
2 parents a20e4ed + bfedfbb commit a14bbdb

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

tiny_obj_loader.h

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2012-2015, Syoyo Fujita.
2+
// Copyright 2012-2016, Syoyo Fujita.
33
//
44
// Licensed under 2-clause BSD license.
55
//
@@ -636,38 +636,34 @@ static bool exportFaceGroupToShape(
636636
shape.mesh.num_vertices.push_back(static_cast<unsigned char>(npolys));
637637
shape.mesh.material_ids.push_back(material_id); // per face
638638
}
639+
}
639640

640-
if( normals_calculation && shape.mesh.normals.empty() )
641-
{
642-
const unsigned int nIndexs = shape.mesh.indices.size();
643-
shape.mesh.normals.resize(shape.mesh.positions.size());
644-
if( nIndexs % 3 == 0 )
645-
{
646-
for ( register unsigned int iIndices = 0; iIndices < nIndexs; iIndices+=3 )
647-
{
648-
float3 v1, v2, v3;
649-
memcpy(&v1, &shape.mesh.positions[shape.mesh.indices[iIndices] * 3], sizeof(float3));
650-
memcpy(&v2, &shape.mesh.positions[shape.mesh.indices[iIndices + 1] * 3], sizeof(float3));
651-
memcpy(&v3, &shape.mesh.positions[shape.mesh.indices[iIndices + 2] * 3], sizeof(float3));
652-
653-
float3 v12( v1,v2 );
654-
float3 v13( v1,v3 );
655-
656-
float3 normal = v12.crossproduct(v13);
657-
normal.normalize();
658-
659-
memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices] * 3], &normal, sizeof(float3));
660-
memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices + 1] * 3], &normal, sizeof(float3));
661-
memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices + 2] * 3], &normal, sizeof(float3));
662-
}
663-
}
664-
else
665-
{
666-
std::stringstream ss;
667-
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;
668-
err += ss.str();
669-
}
670-
}
641+
if (normals_calculation && shape.mesh.normals.empty()) {
642+
const size_t nIndexs = shape.mesh.indices.size();
643+
if (nIndexs % 3 == 0) {
644+
shape.mesh.normals.resize(shape.mesh.positions.size());
645+
for (register size_t iIndices = 0; iIndices < nIndexs; iIndices += 3) {
646+
float3 v1, v2, v3;
647+
memcpy(&v1, &shape.mesh.positions[shape.mesh.indices[iIndices] * 3], sizeof(float3));
648+
memcpy(&v2, &shape.mesh.positions[shape.mesh.indices[iIndices + 1] * 3], sizeof(float3));
649+
memcpy(&v3, &shape.mesh.positions[shape.mesh.indices[iIndices + 2] * 3], sizeof(float3));
650+
651+
float3 v12(v1, v2);
652+
float3 v13(v1, v3);
653+
654+
float3 normal = v12.crossproduct(v13);
655+
normal.normalize();
656+
657+
memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices] * 3], &normal, sizeof(float3));
658+
memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices + 1] * 3], &normal, sizeof(float3));
659+
memcpy(&shape.mesh.normals[shape.mesh.indices[iIndices + 2] * 3], &normal, sizeof(float3));
660+
}
661+
} else {
662+
663+
std::stringstream ss;
664+
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;
665+
err += ss.str();
666+
}
671667
}
672668

673669
shape.name = name;

0 commit comments

Comments
 (0)