load texture on loaded model

master
poikilos 2019-03-07 17:17:42 -05:00
parent 2111fd7651
commit 295e0cc997
4 changed files with 42 additions and 7 deletions

View File

@ -109,6 +109,7 @@ s32 Engine::getNumberOfVertices()
Engine::Engine()
{
this->previousMeshPath = L"";
#if WIN32
m_Device = createDevice( EDT_DIRECT3D9, dimension2d<u32>( 1024, 768 ), 32, false, false, false, nullptr );
#else
@ -168,10 +169,21 @@ void Engine::loadMesh( const wstring &fileName )
if( m_LoadedMesh != nullptr )
m_LoadedMesh->remove();
m_LoadedMesh = m_Scene->addAnimatedMeshSceneNode( m_Scene->getMesh( fileName.c_str() ));
m_LoadedMesh = m_Scene->addAnimatedMeshSceneNode( m_Scene->getMesh( fileName.c_str()));
if (m_LoadedMesh != nullptr) {
this->previousMeshPath = fileName;
}
Utility::dumpMeshInfoToConsole( m_LoadedMesh );
}
void Engine::loadTexture(const wstring &fileName)
{
//TODO: eliminate this?
//if (previousMeshPath.length() > 0)
//m_LoadedMesh = m_Scene->addAnimatedMeshSceneNode( m_Scene->getMesh(previousMeshPath.c_str()));
m_LoadedMesh->setMaterialTexture(0, this->m_Driver->getTexture(fileName.c_str()));
}
void Engine::setMeshDisplayMode( bool wireframe, bool lighting )
{
for( int materialIndex = 0; materialIndex < m_LoadedMesh->getMaterialCount(); materialIndex ++ )

View File

@ -38,6 +38,7 @@ class Engine
{
friend class UserInterface;
friend class View;
wstring previousMeshPath;
private:
IrrlichtDevice *m_Device;
@ -67,8 +68,9 @@ public:
Engine();
~Engine();
void run();
void run();
void loadMesh( const wstring &fileName );
void loadTexture( const wstring &fileName );
void setMeshDisplayMode( bool wireframe = false, bool lighting = true );
};

View File

@ -12,6 +12,7 @@ void UserInterface::setupUserInterface()
// File Menu
IGUIContextMenu *fileMenu = menu->getSubMenu( 0 );
fileMenu->addItem( L"Load", UIC_FILE_LOAD );
fileMenu->addItem( L"LoadTexture", UIC_FILE_LOAD_TEXTURE );
fileMenu->addItem( L"Quit", UIC_FILE_QUIT );
// View Menu
@ -55,6 +56,11 @@ void UserInterface::displayLoadFileDialog()
m_Gui->addFileOpenDialog( L"Select file to load", true, nullptr, UIE_LOADFILEDIALOG );
}
void UserInterface::displayLoadTextureDialog()
{
m_Gui->addFileOpenDialog( L"Select file to load", true, nullptr, UIE_LOADTEXTUREDIALOG );
}
void UserInterface::handleMenuItemPressed( IGUIContextMenu *menu )
{
s32 id = menu->getItemCommandId( menu->getSelectedItem() );
@ -65,6 +71,10 @@ void UserInterface::handleMenuItemPressed( IGUIContextMenu *menu )
displayLoadFileDialog();
break;
case UIC_FILE_LOAD_TEXTURE:
displayLoadTextureDialog();
break;
case UIC_FILE_QUIT:
m_Engine->m_RunEngine = false;
break;
@ -133,6 +143,14 @@ bool UserInterface::OnEvent( const SEvent &event )
}
break;
case UIE_LOADTEXTUREDIALOG:
if( ge->EventType == EGET_FILE_SELECTED )
{
IGUIFileOpenDialog *fileOpenDialog = static_cast<IGUIFileOpenDialog *>( ge->Caller );
m_Engine->loadTexture( fileOpenDialog->getFileName() );
}
break;
default:
break;
}

View File

@ -27,15 +27,17 @@ enum UserInterfaceElements
UIE_LOADFILEDIALOG = 1002,
UIE_FILEMENU = 1003,
UIE_PLAYBACKSTARTSTOPBUTTON = 1004,
UIE_VIEWMENU = 1005
UIE_VIEWMENU = 1005,
UIE_LOADTEXTUREDIALOG = 1006
};
enum UserInterfaceCommands
{
UIC_FILE_LOAD = 1000,
UIC_FILE_QUIT = 1001,
UIC_VIEW_WIREFRAME = 2000,
UIC_VIEW_LIGHTING = 2001
UIC_FILE_LOAD = 1000,
UIC_FILE_QUIT = 1001,
UIC_FILE_LOAD_TEXTURE = 1002,
UIC_VIEW_WIREFRAME = 2000,
UIC_VIEW_LIGHTING = 2001
};
class UserInterface : public IEventReceiver
@ -48,6 +50,7 @@ private:
void setupUserInterface();
void displayLoadFileDialog();
void displayLoadTextureDialog();
void handleMenuItemPressed( IGUIContextMenu *menu );
bool m_WireframeDisplay;