namespace for both types

This commit is contained in:
David Carlier
2018-07-29 17:15:29 +01:00
parent 3928570ce4
commit bc432345a4
2 changed files with 21 additions and 13 deletions
+8 -4
View File
@@ -43,10 +43,7 @@ const char* bmfHead = "BMF ";
namespace render { namespace render {
struct UV { namespace bmf {
float u, v;
};
struct VertexIndex { struct VertexIndex {
unsigned a, b, c; unsigned a, b, c;
@@ -57,7 +54,14 @@ struct VertexIndex {
return memcmp(this, &other, sizeof(unsigned) * 3) < 0; return memcmp(this, &other, sizeof(unsigned) * 3) < 0;
} }
}; };
}
using namespace bmf;
struct UV {
float u, v;
};
void loadBinaryMesh(const char* filename, Mesh& mesh) { void loadBinaryMesh(const char* filename, Mesh& mesh) {
static_assert(sizeof(vec3f) == 12, "vec3f must be the size of 3 floats"); static_assert(sizeof(vec3f) == 12, "vec3f must be the size of 3 floats");
+13 -9
View File
@@ -9,15 +9,19 @@
namespace render { namespace render {
namespace obj {
struct VertexIndex { struct VertexIndex {
unsigned int a, b, c; int a, b, c;
VertexIndex(unsigned int A, unsigned int B, unsigned int C) : a(A), b(B), c(C) {} VertexIndex(int A, int B, int C) : a(A), b(B), c(C) {}
bool operator<(const VertexIndex& other) const { bool operator<(const VertexIndex& other) const {
return memcmp(this, &other, sizeof(int) * 3) < 0; return memcmp(this, &other, sizeof(int) * 3) < 0;
} }
}; };
}
using namespace obj;
void loadMeshOBJ(const char* filename, Mesh& mesh) { void loadMeshOBJ(const char* filename, Mesh& mesh) {
// Read all the appropriate separate data arrays // Read all the appropriate separate data arrays
@@ -74,11 +78,11 @@ void loadMeshOBJ(const char* filename, Mesh& mesh) {
case 'f': case 'f':
// Face // Face
int vertsThisLine = 3; int vertsThisLine = 3;
unsigned int vertexIndex[4]; int vertexIndex[4];
unsigned int uvIndex[4]; int uvIndex[4];
unsigned int normalIndex[4]; int normalIndex[4];
unsigned int elemIndex[4]; int elemIndex[4];
int items = sscanf(line.c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d", int items = sscanf(line.c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d",
&vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[0], &uvIndex[0], &normalIndex[0],
@@ -87,9 +91,9 @@ void loadMeshOBJ(const char* filename, Mesh& mesh) {
&vertexIndex[3], &uvIndex[3], &normalIndex[3]); &vertexIndex[3], &uvIndex[3], &normalIndex[3]);
vertsThisLine = items / 3; vertsThisLine = items / 3;
size_t vertCount = vertices.size(); int vertCount = (int)vertices.size();
size_t normCount = normals.size(); int normCount = (int)normals.size();
size_t uvCount = ucoord.size(); int uvCount = (int)ucoord.size();
for(int i = 0; i < vertsThisLine; ++i) { for(int i = 0; i < vertsThisLine; ++i) {
if(vertexIndex[i] > 0) if(vertexIndex[i] > 0)