limited support for copying texture filename info out of assimp materials (so many different types of texture files possible...)

This commit is contained in:
gered 2011-04-27 17:56:07 -04:00
parent 121d970d37
commit fb95e9f63f
2 changed files with 15 additions and 1 deletions

View file

@ -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];

View file

@ -96,9 +96,12 @@ void WriteMaterials(const std::vector<MeshMaterial> &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<MeshMaterial> &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);