Browse Source

MeshTools: got rid of Point2D/3D in favor of Vector2/Vector3.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
3de3a6861e
  1. 2
      src/MeshTools/CombineIndexedArrays.h
  2. 10
      src/MeshTools/GenerateFlatNormals.cpp
  3. 4
      src/MeshTools/GenerateFlatNormals.h
  4. 2
      src/MeshTools/Test/GenerateFlatNormalsTest.cpp

2
src/MeshTools/CombineIndexedArrays.h

@ -106,7 +106,7 @@ of some STL functions like shown below. Also if one index array is shader by
more than one attribute array, just pass the index array more times. Example:
@code
std::vector<std::uint32_t> vertexIndices;
std::vector<Point3D> positions;
std::vector<Vector3> positions;
std::vector<std::uint32_t> normalTextureIndices;
std::vector<Vector3> normals;
std::vector<Vector2> textureCoordinates;

10
src/MeshTools/GenerateFlatNormals.cpp

@ -15,12 +15,12 @@
#include "GenerateFlatNormals.h"
#include "Math/Point3D.h"
#include "Math/Vector3.h"
#include "MeshTools/Clean.h"
namespace Magnum { namespace MeshTools {
std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> generateFlatNormals(const std::vector<std::uint32_t>& indices, const std::vector<Point3D>& positions) {
std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> generateFlatNormals(const std::vector<std::uint32_t>& indices, const std::vector<Vector3>& positions) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>>()));
/* Create normal for every triangle (assuming counterclockwise winding) */
@ -29,8 +29,8 @@ std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> generateFlatNormals
std::vector<Vector3> normals;
normals.reserve(indices.size()/3);
for(std::size_t i = 0; i != indices.size(); i += 3) {
Vector3 normal = Vector3::cross(positions[indices[i+2]].xyz()-positions[indices[i+1]].xyz(),
positions[indices[i]].xyz()-positions[indices[i+1]].xyz()).normalized();
Vector3 normal = Vector3::cross(positions[indices[i+2]]-positions[indices[i+1]],
positions[indices[i]]-positions[indices[i+1]]).normalized();
/* Use the same normal for all three vertices of the face */
normalIndices.push_back(normals.size());
@ -40,7 +40,7 @@ std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> generateFlatNormals
}
/* Clean duplicate normals and return */
clean(normalIndices, normals);
MeshTools::clean(normalIndices, normals);
return std::make_tuple(normalIndices, normals);
}

4
src/MeshTools/GenerateFlatNormals.h

@ -39,7 +39,7 @@ For each face generates one normal vector, removes duplicates before
returning. Example usage:
@code
std::vector<std::uint32_t> vertexIndices;
std::vector<Point3D> positions;
std::vector<Vector3> positions;
std::vector<std::uint32_t> normalIndices;
std::vector<Vector3> normals;
@ -51,7 +51,7 @@ use the same indices.
@attention Index count must be divisible by 3, otherwise zero length result
is generated.
*/
std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector<std::uint32_t>& indices, const std::vector<Point3D>& positions);
std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector<std::uint32_t>& indices, const std::vector<Vector3>& positions);
}}

2
src/MeshTools/Test/GenerateFlatNormalsTest.cpp

@ -16,7 +16,7 @@
#include <sstream>
#include <TestSuite/Tester.h>
#include "Math/Point3D.h"
#include "Math/Vector3.h"
#include "MeshTools/GenerateFlatNormals.h"
namespace Magnum { namespace MeshTools { namespace Test {

Loading…
Cancel
Save