From fb95e9f63f1abd6d61662ed876304b6819ad15b9 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 27 Apr 2011 17:56:07 -0400 Subject: [PATCH] limited support for copying texture filename info out of assimp materials (so many different types of texture files possible...) --- AssimpToMesh/src/convert/meshmaterial.h | 8 ++++++++ AssimpToMesh/src/convert/meshutils.cpp | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/AssimpToMesh/src/convert/meshmaterial.h b/AssimpToMesh/src/convert/meshmaterial.h index 7d69c24..9ce4848 100644 --- a/AssimpToMesh/src/convert/meshmaterial.h +++ b/AssimpToMesh/src/convert/meshmaterial.h @@ -13,6 +13,7 @@ struct MeshMaterial MeshMaterial(const aiMaterial *source) { aiString name; + aiString textureFile; aiColor3D ambient; aiColor3D diffuse; aiColor3D specular; @@ -28,8 +29,14 @@ struct MeshMaterial source->Get(AI_MATKEY_SHININESS, shininess); source->Get(AI_MATKEY_OPACITY, opacity); + // TODO: need something better then this, but based on my (limited) testing + // diffuse texture seems to be the most common + source->Get(AI_MATKEY_TEXTURE_DIFFUSE(0), textureFile); + this->name = std::string(name.data, name.length); + this->texture = std::string(textureFile.data, textureFile.length); + this->ambient[0] = ambient.r; this->ambient[1] = ambient.g; this->ambient[2] = ambient.b; @@ -52,6 +59,7 @@ struct MeshMaterial } std::string name; + std::string texture; float ambient[3]; float diffuse[3]; float specular[3]; diff --git a/AssimpToMesh/src/convert/meshutils.cpp b/AssimpToMesh/src/convert/meshutils.cpp index 3cfccad..ceb75bb 100644 --- a/AssimpToMesh/src/convert/meshutils.cpp +++ b/AssimpToMesh/src/convert/meshutils.cpp @@ -96,9 +96,12 @@ void WriteMaterials(const std::vector &materials, FILE *fp) ) * count ); - // add up all the variable length string sizes for the material names + // add up all the variable length string sizes for the material names and texture filenames for (uint32_t i = 0; i < count; ++i) + { size += materials[i].name.length() + 1; // include null terminator + size += materials[i].texture.length() + 1; // ditto + } fputs("MTL", fp); fwrite(&size, 4, 1, fp); @@ -112,6 +115,9 @@ void WriteMaterials(const std::vector &materials, FILE *fp) char ch = '\0'; fwrite(&ch, 1, 1, fp); + fwrite(m->texture.c_str(), m->texture.length(), 1, fp); + fwrite(&ch, 1, 1, fp); + fwrite(&m->ambient[0], sizeof(float), 1, fp); fwrite(&m->ambient[1], sizeof(float), 1, fp); fwrite(&m->ambient[2], sizeof(float), 1, fp);