Fix setup of embedded texture loading

pull/4029/head
Kim Kulling 2021-08-28 13:33:25 +02:00
parent 4b1ff645e3
commit 3e090b21f5
3 changed files with 19 additions and 7 deletions

View File

@ -58,6 +58,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "contrib/stb/stb_image.h"
namespace Assimp { namespace Assimp {
namespace D3MF { namespace D3MF {
@ -119,8 +121,11 @@ public:
static bool IsEmbeddedTexture( const std::string &filename ) { static bool IsEmbeddedTexture( const std::string &filename ) {
const std::string extension = BaseImporter::GetExtension(filename); const std::string extension = BaseImporter::GetExtension(filename);
if (extension == "jpg" || extension == "png") { if (extension == "jpg" || extension == "png") {
std::string::size_type pos = filename.find("thumbnail");
if (pos == std::string::npos) {
return false;
}
return true; return true;
} }
@ -232,12 +237,17 @@ void D3MFOpcPackage::LoadEmbeddedTextures(IOStream *fileStream, const std::strin
return; return;
} }
char *data = new char[size]; unsigned char *data = new unsigned char[size];
fileStream->Read(data, 1, size); fileStream->Read(data, 1, size);
aiTexture *texture = new aiTexture; aiTexture *texture = new aiTexture;
texture->mFilename.Set(filename.c_str()); std::string embName = "*" + filename;
texture->mFilename.Set(embName.c_str());
texture->mWidth = static_cast<unsigned int>(size); texture->mWidth = static_cast<unsigned int>(size);
texture->mHeight = 0; texture->mHeight = 0;
texture->achFormatHint[0] = 'p';
texture->achFormatHint[1] = 'n';
texture->achFormatHint[2] = 'g';
texture->achFormatHint[3] = '\0';
texture->pcData = (aiTexel*) data; texture->pcData = (aiTexel*) data;
mEmbeddedTextures.emplace_back(texture); mEmbeddedTextures.emplace_back(texture);
} }

View File

@ -493,7 +493,8 @@ void XmlSerializer::StoreEmbeddedTexture(EmbeddedTexture *tex) {
aiString s; aiString s;
s.Set(ai_to_string(tex->mId).c_str()); s.Set(ai_to_string(tex->mId).c_str());
mat->AddProperty(&s, AI_MATKEY_NAME); mat->AddProperty(&s, AI_MATKEY_NAME);
s.Set(tex->mPath); const std::string name = "*" + tex->mPath;
s.Set(name);
mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(0)); mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(0));
aiColor3D col; aiColor3D col;

View File

@ -325,9 +325,10 @@ int CMaterialManager::FindValidPath(aiString* p_szString)
// first check whether we can directly load the file // first check whether we can directly load the file
FILE* pFile = fopen(p_szString->data,"rb"); FILE* pFile = fopen(p_szString->data,"rb");
if (pFile)fclose(pFile); if (pFile) {
else fclose(pFile);
{ }
else {
// check whether we can use the directory of the asset as relative base // check whether we can use the directory of the asset as relative base
char szTemp[MAX_PATH*2], tmp2[MAX_PATH*2]; char szTemp[MAX_PATH*2], tmp2[MAX_PATH*2];
strcpy(szTemp, g_szFileName); strcpy(szTemp, g_szFileName);