------------------------------------------------------------------------------------------------
| 349 | |
| 350 | // ------------------------------------------------------------------------------------------------ |
| 351 | void BlenderImporter::ResolveImage(aiMaterial *out, const Material *mat, const MTex *tex, const Image *img, ConversionData &conv_data) { |
| 352 | (void)mat; |
| 353 | (void)tex; |
| 354 | (void)conv_data; |
| 355 | aiString name; |
| 356 | |
| 357 | // check if the file contents are bundled with the BLEND file |
| 358 | if (img->packedfile) { |
| 359 | name.data[0] = '*'; |
| 360 | name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(AI_MAXLEN - 1), static_cast<int32_t>(conv_data.textures->size())); |
| 361 | |
| 362 | conv_data.textures->push_back(new aiTexture()); |
| 363 | aiTexture *curTex = conv_data.textures->back(); |
| 364 | |
| 365 | // usually 'img->name' will be the original file name of the embedded textures, |
| 366 | // so we can extract the file extension from it. |
| 367 | const size_t nlen = strlen(img->name); |
| 368 | const char *s = img->name + nlen, *e = s; |
| 369 | while (s >= img->name && *s != '.') { |
| 370 | --s; |
| 371 | } |
| 372 | |
| 373 | curTex->achFormatHint[0] = s + 1 > e ? '\0' : (char)::tolower((unsigned char)s[1]); |
| 374 | curTex->achFormatHint[1] = s + 2 > e ? '\0' : (char)::tolower((unsigned char)s[2]); |
| 375 | curTex->achFormatHint[2] = s + 3 > e ? '\0' : (char)::tolower((unsigned char)s[3]); |
| 376 | curTex->achFormatHint[3] = '\0'; |
| 377 | |
| 378 | // tex->mHeight = 0; |
| 379 | curTex->mWidth = img->packedfile->size; |
| 380 | uint8_t *ch = new uint8_t[curTex->mWidth]; |
| 381 | |
| 382 | conv_data.db.reader->SetCurrentPos(static_cast<size_t>(img->packedfile->data->val)); |
| 383 | conv_data.db.reader->CopyAndAdvance(ch, curTex->mWidth); |
| 384 | |
| 385 | curTex->pcData = reinterpret_cast<aiTexel *>(ch); |
| 386 | |
| 387 | LogInfo("Reading embedded texture, original file was ", img->name); |
| 388 | } else { |
| 389 | name = aiString(img->name); |
| 390 | } |
| 391 | |
| 392 | aiTextureType texture_type = aiTextureType_UNKNOWN; |
| 393 | MTex::MapType map_type = tex->mapto; |
| 394 | |
| 395 | if (map_type & MTex::MapType_COL) |
| 396 | texture_type = aiTextureType_DIFFUSE; |
| 397 | else if (map_type & MTex::MapType_NORM) { |
| 398 | if (tex->tex->imaflag & Tex::ImageFlags_NORMALMAP) { |
| 399 | texture_type = aiTextureType_NORMALS; |
| 400 | } else { |
| 401 | texture_type = aiTextureType_HEIGHT; |
| 402 | } |
| 403 | out->AddProperty(&tex->norfac, 1, AI_MATKEY_BUMPSCALING); |
| 404 | } else if (map_type & MTex::MapType_COLSPEC) |
| 405 | texture_type = aiTextureType_SPECULAR; |
| 406 | else if (map_type & MTex::MapType_COLMIR) |
| 407 | texture_type = aiTextureType_REFLECTION; |
| 408 | //else if (map_type & MTex::MapType_REF) |
nothing calls this directly
no test coverage detected