aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md20
-rw-r--r--src/main.cpp21
2 files changed, 21 insertions, 20 deletions
diff --git a/README.md b/README.md
index 5a885f9..aea419d 100644
--- a/README.md
+++ b/README.md
@@ -6,22 +6,22 @@ To see a list of supported file formats, see https://github.com/assimp/assimp#su
|Type |Description |
|-------|-------------------------------------------------------------------------------------|
-|uint |The magic number, the value will always be 0x036144AF. |
-|uint |Version of the file format. This is backwards compatible but not forwards compatible.|
+|u32 |The magic number, the value will always be 0x036144AF. |
+|u32 |Version of the file format. This is backwards compatible but not forwards compatible.|
|mesh[] |The mesh data. |
mesh:
|Type |Description |
|-----------|------------------------------------------------------------------------------------------------|
-|uint |The number of vertices, normals and optionally texture coordinates. |
+|u32 |The number of vertices, normals and optionally texture coordinates. |
|vec3f[] |A list of vertices. |
|vec3f[] |A list of normals. |
-|uint |1 if the model has texture coordinates, otherwise 0. |
+|u32 |1 if the model has texture coordinates, otherwise 0. |
|vec2f[]* |A list of texture coordinates. The number of texture coordinates matches the number of vertices.|
-|uint |The number of faces. |
+|u32 |The number of faces. |
|face[] |The face indices. |
-|uint |1 if the model has materials, otherwise 0. |
+|u32 |1 if the model has materials, otherwise 0. |
|material[3]|The material data. This is a list of [diffuse, specular, ambient] materials. |
vec2f:
@@ -43,15 +43,15 @@ face:
|Type|Description |
|----|-----------------|
-|uint|The first index. |
-|uint|The second index.|
-|uint|The third index. |
+|u32 |The first index. |
+|u32 |The second index.|
+|u32 |The third index. |
material:
|Type |Description |
|------|---------------------------------------------------------------------------|
-|uint |The number of textures. |
+|u32 |The number of textures. |
|char[]|The filepaths to the textures (relative). This is a null-terminated string.|
## TODO
diff --git a/src/main.cpp b/src/main.cpp
index 6fcd2a3..8bdde7e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,7 @@
#include <assert.h>
#include <stdio.h>
#include <sys/stat.h>
+#include <stdint.h>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
@@ -10,7 +11,7 @@
static void usage();
static void file_write_error_check(FILE *file, const void *data, size_t size);
-static void file_write_uint_error_check(FILE *file, unsigned int value);
+static void file_write_u32_error_check(FILE *file, unsigned int value);
static void process_node(const aiScene *scene, const aiNode *node, FILE *output_file, const std::string &source_dir);
int main(int argc, char **argv) {
@@ -35,8 +36,8 @@ int main(int argc, char **argv) {
perror(destination_filepath);
exit(3);
}
- file_write_uint_error_check(destination_file, 0x036144AF); // magic number
- file_write_uint_error_check(destination_file, 0x00000001); // version
+ file_write_u32_error_check(destination_file, 0x036144AF); // magic number
+ file_write_u32_error_check(destination_file, 0x00000001); // version
std::string source_dir = source_filepath;
source_dir = source_dir.substr(0, source_dir.find_last_of("/"));
@@ -59,7 +60,7 @@ void file_write_error_check(FILE *file, const void *data, size_t size) {
}
}
-void file_write_uint_error_check(FILE *file, unsigned int value) {
+void file_write_u32_error_check(FILE *file, uint32_t value) {
const size_t size = sizeof(value);
if(fwrite(&value, 1, size, file) != size) {
fprintf(stderr, "Error: failed to write %ld bytes to output file, error: %s\n", size, strerror(errno));
@@ -77,11 +78,11 @@ static void process_mesh(const aiScene *scene, const aiMesh *mesh, FILE *output_
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_u32_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);
+ file_write_u32_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));
@@ -89,14 +90,14 @@ static void process_mesh(const aiScene *scene, const aiMesh *mesh, FILE *output_
}
}
- file_write_uint_error_check(output_file, mesh->mNumFaces);
+ file_write_u32_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->mMaterialIndex < scene->mNumMaterials);
+ file_write_u32_error_check(output_file, mesh->mMaterialIndex < scene->mNumMaterials);
if(mesh->mMaterialIndex < scene->mNumMaterials) {
const unsigned int num_texture_types = 3;
const aiTextureType texture_types[num_texture_types] = {
@@ -108,7 +109,7 @@ static void process_mesh(const aiScene *scene, const aiMesh *mesh, FILE *output_
const aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex];
for(unsigned int i = 0; i < num_texture_types; ++i) {
unsigned int num_textures_for_type = material->GetTextureCount(texture_types[i]);
- file_write_uint_error_check(output_file, num_textures_for_type);
+ file_write_u32_error_check(output_file, num_textures_for_type);
for(unsigned int j = 0; j < num_textures_for_type; ++j) {
aiString texture_name;
if(material->GetTexture(texture_types[i], j, &texture_name) == aiReturn_SUCCESS) {
@@ -152,4 +153,4 @@ void process_node(const aiScene *scene, const aiNode *node, FILE *output_file, c
for(unsigned int i = 0; i < node->mNumChildren; ++i) {
process_node(scene, node->mChildren[i], output_file, source_dir);
}
-} \ No newline at end of file
+}