Merge branch 'master' into patch-1

pull/3961/head
Kim Kulling 2021-06-22 09:42:30 +02:00 committed by GitHub
commit 951d5158c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 15 deletions

View File

@ -118,14 +118,14 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai
ExportScene(); ExportScene();
ExportAnimations(); ExportAnimations();
// export extras // export extras
if(mProperties->HasPropertyCallback("extras")) if(mProperties->HasPropertyCallback("extras"))
{ {
std::function<void*(void*)> ExportExtras = mProperties->GetPropertyCallback("extras"); std::function<void*(void*)> ExportExtras = mProperties->GetPropertyCallback("extras");
mAsset->extras = (rapidjson::Value*)ExportExtras(0); mAsset->extras = (rapidjson::Value*)ExportExtras(0);
} }
AssetWriter writer(*mAsset); AssetWriter writer(*mAsset);
if (isBinary) { if (isBinary) {
@ -515,11 +515,10 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTe
std::string imgId = mAsset->FindUniqueID("", "image"); std::string imgId = mAsset->FindUniqueID("", "image");
texture->source = mAsset->images.Create(imgId); texture->source = mAsset->images.Create(imgId);
if (path[0] == '*') { // embedded const aiTexture* curTex = mScene->GetEmbeddedTexture(path.c_str());
aiTexture* curTex = mScene->mTextures[atoi(&path[1])]; if (curTex != nullptr) { // embedded
texture->source->name = curTex->mFilename.C_Str(); texture->source->name = curTex->mFilename.C_Str();
//basisu: embedded ktx2, bu //basisu: embedded ktx2, bu
if (curTex->achFormatHint[0]) { if (curTex->achFormatHint[0]) {
std::string mimeType = "image/"; std::string mimeType = "image/";
@ -541,7 +540,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTe
mimeType += curTex->achFormatHint; mimeType += curTex->achFormatHint;
texture->source->mimeType = mimeType; texture->source->mimeType = mimeType;
} }
// The asset has its own buffer, see Image::SetData // The asset has its own buffer, see Image::SetData
//basisu: "image/ktx2", "image/basis" as is //basisu: "image/ktx2", "image/basis" as is
texture->source->SetData(reinterpret_cast<uint8_t *>(curTex->pcData), curTex->mWidth, *mAsset); texture->source->SetData(reinterpret_cast<uint8_t *>(curTex->pcData), curTex->mWidth, *mAsset);
@ -554,7 +553,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTe
useBasisUniversal = true; useBasisUniversal = true;
} }
} }
//basisu //basisu
if(useBasisUniversal) { if(useBasisUniversal) {
mAsset->extensionsUsed.KHR_texture_basisu = true; mAsset->extensionsUsed.KHR_texture_basisu = true;

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2021, assimp team Copyright (c) 2006-2021, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -397,22 +395,35 @@ 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 {
if(nullptr==filename) {
return std::make_pair(nullptr, -1);
}
// 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);
if (nullptr == shortFilename) {
return std::make_pair(nullptr, -1);
}
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