Add GetEmbeddedTextureAndIndex() to aiScene.
It allows the caller to get the index of the embedded texture that is always computed anyway.pull/3945/head
parent
cdc1bf8e10
commit
121c0e7d0c
|
@ -397,22 +397,27 @@ struct aiScene
|
||||||
|
|
||||||
//! Returns an embedded texture
|
//! Returns an embedded texture
|
||||||
const aiTexture* GetEmbeddedTexture(const char* filename) const {
|
const aiTexture* GetEmbeddedTexture(const char* filename) const {
|
||||||
|
return GetEmbeddedTextureAndIndex(filename).first;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Returns an embedded texture and its index
|
||||||
|
std::pair<const aiTexture*, int> GetEmbeddedTextureAndIndex(const char* filename) const {
|
||||||
// lookup using texture ID (if referenced like: "*1", "*2", etc.)
|
// lookup using texture ID (if referenced like: "*1", "*2", etc.)
|
||||||
if ('*' == *filename) {
|
if ('*' == *filename) {
|
||||||
int index = std::atoi(filename + 1);
|
int index = std::atoi(filename + 1);
|
||||||
if (0 > index || mNumTextures <= static_cast<unsigned>(index))
|
if (0 > index || mNumTextures <= static_cast<unsigned>(index))
|
||||||
return nullptr;
|
return std::make_pair(nullptr, -1);
|
||||||
return mTextures[index];
|
return std::make_pair(mTextures[index], index);
|
||||||
}
|
}
|
||||||
// lookup using filename
|
// lookup using filename
|
||||||
const char* shortFilename = GetShortFilename(filename);
|
const char* shortFilename = GetShortFilename(filename);
|
||||||
for (unsigned int i = 0; i < mNumTextures; i++) {
|
for (unsigned int i = 0; i < mNumTextures; i++) {
|
||||||
const char* shortTextureFilename = GetShortFilename(mTextures[i]->mFilename.C_Str());
|
const char* shortTextureFilename = GetShortFilename(mTextures[i]->mFilename.C_Str());
|
||||||
if (strcmp(shortTextureFilename, shortFilename) == 0) {
|
if (strcmp(shortTextureFilename, shortFilename) == 0) {
|
||||||
return mTextures[i];
|
return std::make_pair(mTextures[i], i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return std::make_pair(nullptr, -1);
|
||||||
}
|
}
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue