aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md21
-rw-r--r--src/main.cpp23
2 files changed, 34 insertions, 10 deletions
diff --git a/README.md b/README.md
index 26e9e90..100cf7d 100644
--- a/README.md
+++ b/README.md
@@ -17,13 +17,20 @@ mesh:
|uint |The number of vertices, normals and optionally texture coordinates. |
|vec3f[] |A list of vertices. |
|vec3f[] |A list of normals. |
-|uint |The number of faces. Each face has 3 indices of type uint. |
-|uint[] |The face indices. |
|uint |1 if the model has texture coordinates, otherwise 0. |
-|vec3f[]* |A list of texture coordinates. The number of texture coordinates matches the number of vertices.|
+|vec2f[]* |A list of texture coordinates. The number of texture coordinates matches the number of vertices.|
+|uint |The number of faces. |
+|face[] |The face indices. |
|uint |1 if the model has materials, otherwise 0. |
|material[3]|The material data. This is a list of [diffuse, specular, ambient] materials. |
+vec2f:
+
+|Type |Description |
+|-----|----------------|
+|float|The x coordiate.|
+|float|The y coordiate.|
+
vec3f:
|Type |Description |
@@ -32,6 +39,14 @@ vec3f:
|float|The y coordiate.|
|float|The z coordiate.|
+face:
+
+|Type|Description |
+|----|-----------------|
+|uint|The first index. |
+|uint|The second index.|
+|uint|The third index. |
+
material:
|Type |Description |
diff --git a/src/main.cpp b/src/main.cpp
index a679828..87260cb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -64,20 +64,29 @@ void file_write_uint_error_check(FILE *file, unsigned int value) {
}
static void process_mesh(const aiScene *scene, const aiMesh *mesh, FILE *output_file) {
- file_write_uint_error_check(output_file, mesh->mNumVertices);
- file_write_error_check(output_file, &mesh->mVertices, mesh->mNumVertices * sizeof(aiVector3D));
- file_write_error_check(output_file, &mesh->mNormals, mesh->mNumVertices * sizeof(aiVector3D));
+ // TODO: It seems like sometimes the vertice count doesn't match triangles.. excluding the last vertices in the list
+ unsigned int vertice_overflow = mesh->mNumVertices % 3;
+ unsigned int num_vertices = mesh->mNumVertices - vertice_overflow;
+ assert(num_vertices % 3 == 0);
+ file_write_uint_error_check(output_file, num_vertices);
+ file_write_error_check(output_file, mesh->mVertices, num_vertices * sizeof(aiVector3D));
+ file_write_error_check(output_file, mesh->mNormals, num_vertices * sizeof(aiVector3D));
+
+ file_write_uint_error_check(output_file, mesh->mTextureCoords[0] ? 1 : 0);
+ if(mesh->mTextureCoords[0]) {
+ for(unsigned int i = 0; i < num_vertices; ++i) {
+ file_write_error_check(output_file, &mesh->mTextureCoords[0][i].x, sizeof(float));
+ file_write_error_check(output_file, &mesh->mTextureCoords[0][i].y, sizeof(float));
+ }
+ }
file_write_uint_error_check(output_file, mesh->mNumFaces);
for(unsigned int i = 0; i < mesh->mNumFaces; ++i) {
// Should always be 3 since the file was loaded with aiProcess_Triangulate
+ assert(mesh->mFaces[i].mNumIndices == 3);
file_write_error_check(output_file, mesh->mFaces[i].mIndices, 3 * sizeof(unsigned int));
}
- file_write_uint_error_check(output_file, mesh->mTextureCoords[0] ? 1 : 0);
- if(mesh->mTextureCoords[0])
- file_write_error_check(output_file, &mesh->mTextureCoords[0], mesh->mNumVertices * sizeof(aiVector3D));
-
file_write_uint_error_check(output_file, mesh->mMaterialIndex < scene->mNumMaterials);
if(mesh->mMaterialIndex < scene->mNumMaterials) {
const unsigned int num_texture_types = 3;