MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / extractTexture

Method extractTexture

Engine/source/ts/assimp/assimpShapeLoader.cpp:554–602  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

552}
553
554void AssimpShapeLoader::extractTexture(U32 index, aiTexture* pTex)
555{ // Cache an embedded texture to disk
556 updateProgress(Load_EnumerateScene, "Extracting Textures...", mScene->mNumTextures, index);
557 Con::printf("[Assimp] Extracting Texture %s, W: %d, H: %d, %d of %d, format hint: (%s)", pTex->mFilename.C_Str(),
558 pTex->mWidth, pTex->mHeight, index, mScene->mNumTextures, pTex->achFormatHint);
559
560 // Create the texture filename
561 String cleanFile = AppMaterial::cleanString(TSShapeLoader::getShapePath().getFileName());
562 String texName = String::ToString("%s_cachedTex%d", cleanFile.c_str(), index);
563 Torque::Path texPath = shapePath;
564 texPath.setFileName(texName);
565
566 if (pTex->mHeight == 0)
567 { // Compressed format, write the data directly to disc
568 texPath.setExtension(pTex->achFormatHint);
569 FileStream *outputStream;
570 if ((outputStream = FileStream::createAndOpen(texPath.getFullPath(), Torque::FS::File::Write)) != NULL)
571 {
572 outputStream->setPosition(0);
573 outputStream->write(pTex->mWidth, pTex->pcData);
574 outputStream->close();
575 delete outputStream;
576 }
577 }
578 else
579 { // Embedded pixel data, fill a bitmap and save it.
580 GFXTexHandle shapeTex;
581 shapeTex.set(pTex->mWidth, pTex->mHeight, GFXFormatR8G8B8A8_SRGB, &GFXDynamicTextureSRGBProfile,
582 String::ToString("AssimpShapeLoader (%s:%i)", __FILE__, __LINE__), 1, 0);
583 GFXLockedRect *rect = shapeTex.lock();
584
585 for (U32 y = 0; y < pTex->mHeight; ++y)
586 {
587 for (U32 x = 0; x < pTex->mWidth; ++x)
588 {
589 U32 targetIndex = (y * rect->pitch) + (x * 4);
590 U32 sourceIndex = ((y * pTex->mWidth) + x) * 4;
591 rect->bits[targetIndex] = pTex->pcData[sourceIndex].r;
592 rect->bits[targetIndex + 1] = pTex->pcData[sourceIndex].g;
593 rect->bits[targetIndex + 2] = pTex->pcData[sourceIndex].b;
594 rect->bits[targetIndex + 3] = pTex->pcData[sourceIndex].a;
595 }
596 }
597 shapeTex.unlock();
598
599 texPath.setExtension("png");
600 shapeTex->dumpToDisk("PNG", texPath.getFullPath());
601 }
602}
603
604void AssimpShapeLoader::addNodeToTree(S32 parentItem, aiNode* node, GuiTreeViewCtrl* tree, U32& nodeCount)
605{

Callers

nothing calls this directly

Calls 12

printfFunction · 0.85
C_StrMethod · 0.80
getFileNameMethod · 0.80
dumpToDiskMethod · 0.80
closeMethod · 0.65
c_strMethod · 0.45
setExtensionMethod · 0.45
setPositionMethod · 0.45
writeMethod · 0.45
setMethod · 0.45
lockMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected