|
1 | 1 | //
|
2 |
| -// Copyright 2012-2015, Syoyo Fujita. |
| 2 | +// Copyright 2012-2016, Syoyo Fujita. |
3 | 3 | //
|
4 | 4 | // Licensed under 2-clause BSD license.
|
5 | 5 | //
|
@@ -636,38 +636,34 @@ static bool exportFaceGroupToShape(
|
636 | 636 | shape.mesh.num_vertices.push_back(static_cast<unsigned char>(npolys));
|
637 | 637 | shape.mesh.material_ids.push_back(material_id); // per face
|
638 | 638 | }
|
| 639 | + } |
639 | 640 |
|
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 | + } |
671 | 667 | }
|
672 | 668 |
|
673 | 669 | shape.name = name;
|
|
0 commit comments