Import/export of embedded texture names for the glTF/glTF2 format

pull/2969/head
Loïc 2020-01-29 14:04:41 +01:00
parent 26179cd4d2
commit 194d31002d
4 changed files with 6 additions and 0 deletions

View File

@ -353,6 +353,8 @@ void glTFExporter::GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& pr
if (path[0] == '*') { // embedded if (path[0] == '*') { // embedded
aiTexture* tex = mScene->mTextures[atoi(&path[1])]; aiTexture* tex = mScene->mTextures[atoi(&path[1])];
prop.texture->source->name = tex->mFilename.C_Str();
uint8_t* data = reinterpret_cast<uint8_t*>(tex->pcData); uint8_t* data = reinterpret_cast<uint8_t*>(tex->pcData);
prop.texture->source->SetData(data, tex->mWidth, *mAsset); prop.texture->source->SetData(data, tex->mWidth, *mAsset);

View File

@ -680,6 +680,7 @@ void glTFImporter::ImportEmbeddedTextures(glTF::Asset& r)
size_t length = img.GetDataLength(); size_t length = img.GetDataLength();
void* data = img.StealData(); void* data = img.StealData();
tex->mFilename = img.name;
tex->mWidth = static_cast<unsigned int>(length); tex->mWidth = static_cast<unsigned int>(length);
tex->mHeight = 0; tex->mHeight = 0;
tex->pcData = reinterpret_cast<aiTexel*>(data); tex->pcData = reinterpret_cast<aiTexel*>(data);

View File

@ -352,6 +352,8 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTe
if (path[0] == '*') { // embedded if (path[0] == '*') { // embedded
aiTexture* tex = mScene->mTextures[atoi(&path[1])]; aiTexture* tex = mScene->mTextures[atoi(&path[1])];
texture->source->name = tex->mFilename.C_Str();
// The asset has its own buffer, see Image::SetData // The asset has its own buffer, see Image::SetData
texture->source->SetData(reinterpret_cast<uint8_t*> (tex->pcData), tex->mWidth, *mAsset); texture->source->SetData(reinterpret_cast<uint8_t*> (tex->pcData), tex->mWidth, *mAsset);

View File

@ -1248,6 +1248,7 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) {
size_t length = img.GetDataLength(); size_t length = img.GetDataLength();
void *data = img.StealData(); void *data = img.StealData();
tex->mFilename = img.name;
tex->mWidth = static_cast<unsigned int>(length); tex->mWidth = static_cast<unsigned int>(length);
tex->mHeight = 0; tex->mHeight = 0;
tex->pcData = reinterpret_cast<aiTexel *>(data); tex->pcData = reinterpret_cast<aiTexel *>(data);