Assimp не возвращает данные текстуры - PullRequest
0 голосов
/ 29 июня 2019

Я использую Assimp для загрузки 3D-моделей. Мои модели имеют встроенные текстуры («Я думаю»). Но у меня есть две проблемы:

  1. Я не могу найти способ получить путь к файлу текстуры ...
  2. Кажется, что pcData ничего не значит.

Я не могу даже напечатать ширину или высоту текстуры.

печать texturefile Я получаю этот обычный формат *0 *1 и т. Д.

Но когда я пытаюсь напечатать scene->mTextures[atoi(texturefile.C_Str())]->mFileName, я ничего не получаю ... то же самое с текстурой pcData.

вот код:

uint32_t textureCount = scene->mMaterials[i]->GetTextureCount(aiTextureType_DIFFUSE);

for (uint32_t c = 0; c < textureCount ; c++) {
    scene->mMaterials[i]->GetTexture(aiTextureType_DIFFUSE, c, &texturefile);
    std::cout << "\n textureFile : " << texturefile.C_Str() << std::endl;
    std::cout <<"\nTextura : "<< scene->mTextures[atoi(texturefile.C_Str())]<<std::endl;
    aiTexture *texture = scene->mTextures[atoi(texturefile.C_Str())];

    int w = texture->mWidth;
    int h = texture->mHeight;

    if (texture == NULL) {
        std::cout << "\n TextureNull\n";
    }
    else {
        std::cout << "\n textureNotNull\n";
    }

    uint32_t *data = reinterpret_cast<uint32_t* >(texture->pcData);
    createTextureImage(data, w, h, materials[i].texturesImages[c]);

    //createTextureImageView(materials[i].texturesImagesViews[c], materials[i].texturesImages[c]);
    //createTextureSampler(materials[i].texturesSamplers[c]);

    //  void createTextureImage(uint32_t* pixels,int texWidth,int texHeight,VkImage textureImage) {
    }
}

1 Ответ

0 голосов
/ 16 июля 2019

При работе с последним мастером у вас будет работать следующий код:

aiMaterial material = scene->mMaterials[index];
aiString texture_file;
material->Get(AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0), texture_file);
if(auto texture = scene->GetEmbeddedTexture(texture_file.C_Str())) {
   //returned pointer is not null, read texture from memory
} else {
   //regular file, check if it exists and read it
}

В старых версиях вам нужно искать специальный токен:

aiMaterial material = scene->mMaterials[index];
aiString texture_file;
material->Get(AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0), texture_file);
if('*' == texture_file.data[0]) {
  //embedded texture, get index from string and access scene->mTextures
} else {
  //regular file, check if it exists and read it
}

Надеюсь, что это поможетпонять концепцию.

...