MCPcopy Create free account
hub / github.com/assimp/assimp / ReplaceCurrentTexture

Method ReplaceCurrentTexture

tools/assimp_view/Display.cpp:283–382  ·  view source on GitHub ↗

------------------------------------------------------------------------------- Replace the currently selected texture by another one

Source from the content-addressed store, hash-verified

281//-------------------------------------------------------------------------------
282// Replace the currently selected texture by another one
283int CDisplay::ReplaceCurrentTexture(const char* szPath) {
284 ai_assert(nullptr != szPath);
285
286 // well ... try to load it
287 IDirect3DTexture9* piTexture = nullptr;
288 aiString szString;
289 strcpy(szString.data,szPath);
290 szString.length = static_cast<ai_uint32>(strlen(szPath));
291 CMaterialManager::Instance().LoadTexture(&piTexture,&szString);
292
293 if (!piTexture) {
294 CLogDisplay::Instance().AddEntry("[ERROR] Unable to load this texture",
295 D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
296 return 0;
297 }
298
299 // we must also change the icon of the corresponding tree
300 // view item if the default texture was previously set
301 TVITEMEX tvi;
302 tvi.mask = TVIF_SELECTEDIMAGE | TVIF_IMAGE;
303 tvi.iImage = m_aiImageList[AI_VIEW_IMGLIST_MATERIAL];
304 tvi.iSelectedImage = m_aiImageList[AI_VIEW_IMGLIST_MATERIAL];
305
306 TreeView_SetItem(GetDlgItem(g_hDlg,IDC_TREE1),
307 m_pcCurrentTexture->hTreeItem);
308
309 // update all meshes referencing this material
310 for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
311 {
312 if (this->m_pcCurrentTexture->iMatIndex != g_pcAsset->pcScene->mMeshes[i]->mMaterialIndex)
313 continue;
314
315 AssetHelper::MeshHelper* pcMesh = g_pcAsset->apcMeshes[i];
316 IDirect3DTexture9** tex = nullptr;
317 const char* tex_string = nullptr;
318
319 switch (this->m_pcCurrentTexture->iType)
320 {
321 case aiTextureType_DIFFUSE:
322 tex = &pcMesh->piDiffuseTexture;
323 tex_string = "DIFFUSE_TEXTURE";
324 break;
325 case aiTextureType_AMBIENT:
326 tex = &pcMesh->piAmbientTexture;
327 tex_string = "AMBIENT_TEXTURE";
328 break;
329 case aiTextureType_SPECULAR:
330 tex = &pcMesh->piSpecularTexture;
331 tex_string = "SPECULAR_TEXTURE";
332 break;
333 case aiTextureType_EMISSIVE:
334 tex = &pcMesh->piEmissiveTexture;
335 tex_string = "EMISSIVE_TEXTURE";
336 break;
337 case aiTextureType_LIGHTMAP:
338 tex = &pcMesh->piLightmapTexture;
339 tex_string = "LIGHTMAP_TEXTURE";
340 break;

Callers 2

HandleTreeViewPopup2Method · 0.95
MessageProcFunction · 0.80

Calls 6

InstanceClass · 0.85
LoadTextureMethod · 0.80
HMtoNMIfNecessaryMethod · 0.80
SetTextureMethod · 0.80
AddEntryMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected