look in model directory too, add hotkeys for reloading

master
poikilos 2019-03-09 07:43:36 -05:00
parent b1ad15c3c8
commit 231e438af3
5 changed files with 42 additions and 14 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## [git] - 2019-03-09
(poikilos)
### Added
* hotkeys to reload model/texture
## [git] - 2019-03-07
(poikilos)
### Added

View File

@ -1,6 +1,7 @@
#include "Engine.h"
using std::cout;
using std::wcerr;
using std::endl;
using std::wstring;
using std::wstringstream;
@ -188,10 +189,10 @@ void Engine::loadMesh( const wstring &fileName )
// if (m_LoadedMesh != nullptr) {
//std::wstring fn;
//fn.assign(fileName.c_str());
// std::wcerr << "fileName = " << fn << endl;
// std::wcerr << "fileName = " << fileName << endl;
// wcerr << "fileName = " << fn << endl;
// wcerr << "fileName = " << fileName << endl;
this->m_PreviousPath = fileName;
// std::wcerr << "this->m_PreviousPath = " << this->m_PreviousPath.c_str() << endl;
// wcerr << "this->m_PreviousPath = " << this->m_PreviousPath.c_str() << endl;
// }
if( m_LoadedMesh != nullptr )
m_LoadedMesh->remove();
@ -203,11 +204,19 @@ void Engine::loadMesh( const wstring &fileName )
void Engine::reloadMesh()
{
if (this->m_PreviousPath.length() > 0) {
std::wcerr << "this->m_PreviousPath = " << this->m_PreviousPath.c_str() << endl;
// wcerr << "this->m_PreviousPath = " << this->m_PreviousPath.c_str() << endl;
loadMesh(this->m_PreviousPath);
}
}
void Engine::reloadTexture()
{
if (this->m_PrevTexturePath.length() > 0) {
// wcerr << "this->m_PrevTexturePath = " << this->m_PrevTexturePath.c_str() << endl;
loadTexture(this->m_PrevTexturePath);
}
}
bool Engine::loadTexture(const wstring &fileName)
{
ITexture* texture = this->m_Driver->getTexture(fileName.c_str());

View File

@ -67,6 +67,7 @@ public:
void run();
void loadMesh( const std::wstring &fileName );
void reloadMesh();
void reloadTexture();
bool loadTexture( const std::wstring &fileName );
void setMeshDisplayMode( bool wireframe = false, bool lighting = true );
bool isAnimating();

View File

@ -59,13 +59,17 @@ This is a modernized fork by poikilos (see CHANGELOG.md).
file. However, the program is much easier to use if you associate the
format with b3view (see "Installation" above) so you can just double-
click the file to open b3view automatically.
* To change frame rate in increments of 5 fps, click "Faster" or
"Slower," or use `-` key or `+`/`=` key. By default, the world runs
at 60fps and the animation runs as 30 fps (Irrlicht does interpolation
automatically).
* cycle through textures in `../textures` using `t` key (`e` to go back)
(such as for Minetest mods, where model must be in `modname/models/`
and texture must be in `modname/textures/`)
* `-` / `+`: To change animation frame rate in increments of 5 fps,
click "Faster" or "Slower," or use `-` key or `+`/`=` key. By default,
the scene refreshes at 60fps and the animation runs as 30 fps
(Irrlicht does interpolation automatically).
* `t` / `e`: cycle through textures in `../textures` using `t` key (`e`
to go back) such as for Minetest mods, where model must be in
`modname/models/` and texture must be in `modname/textures/`.
If `../textures` doesn't exist relative to the model file's directory,
the model file's own directory will be used.
* `F5`: Reload last model file
* `r`: Reload last texture file
## Known Issues
* Warn on missing texture.

View File

@ -205,6 +205,9 @@ bool UserInterface::loadNextTexture(int direction)
// std::string path = Utility::toString(texturesPath);
std::wstring path = texturesPath;
if (!fs::is_directory(fs::status(path)))
path = lastDirPath; // cycle textures in model's directory instead
// cerr << "looking for next texture in " << path << endl;
// wcerr << "looking for next texture in " << path << endl;
@ -216,9 +219,9 @@ bool UserInterface::loadNextTexture(int direction)
// std::string nextPath = "";
bool found = false;
if (fs::is_directory(fs::status(texturesPath))) {
if (fs::is_directory(fs::status(path))) {
// for (directory_iterator itr(path); itr != end_itr; ++itr) {
for (const auto & itr : fs::directory_iterator(texturesPath)) {
for (const auto & itr : fs::directory_iterator(path)) {
// std::cout << entry.path() << std::endl;
if (!is_directory(itr.status())) {
// if (!itr.is_directory()) {
@ -239,7 +242,7 @@ bool UserInterface::loadNextTexture(int direction)
if (nextPath.length() > 0) ret = this->m_Engine->loadTexture(nextPath);
wcerr << "chose texture '" << nextPath << "': " << (ret?"OK":"FAIL") << endl;
}
// else wcerr << "no '" << texturesPath << "'" << endl;
// else wcerr << "no '" << path << "'" << endl;
}
}
}
@ -258,6 +261,12 @@ bool UserInterface::OnEvent( const SEvent &event )
else if (event.KeyInput.Key == irr::KEY_KEY_E) {
loadNextTexture(-1);
}
else if (event.KeyInput.Key == irr::KEY_KEY_R) {
m_Engine->reloadTexture();
}
else if (event.KeyInput.Key == irr::KEY_F5) {
m_Engine->reloadMesh();
}
else if (event.KeyInput.Char == L'+' || event.KeyInput.Char == L'=') {
m_Engine->setAnimationFPS(m_Engine->animationFPS() + 5);
// std::wcerr << "m_Engine->animationFPS(): " << m_Engine->animationFPS() << endl;