Reloading materials (scripts?)

Problems building or running the engine, queries about how to use features etc.
Post Reply
garry
Gnoblar
Posts: 6
Joined: Fri Apr 11, 2008 10:03 pm

Reloading materials (scripts?)

Post by garry »

Hi, I'm looking for a way to reload materials without restarting my app.

My searching has lead me to a few commands, none of which seem to work. Here they are:

Ogre::ResourceGroupManager::getSingleton().unloadResourceGroup( "General" );
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
Ogre::MaterialManager::getSingleton().reloadAll();

I'm thinking that the problem is that the scripts never get recompiled, is this method looking for changes to textures or something?

Is there a way to force it to reload the scripts, ideally without editing Ogre's base code?

I'm sure I must be missing something, I find it hard to believe that everyone using Ogre is reloading their app to see changes made to their .material files.
User avatar
KamiKage
Kobold
Posts: 25
Joined: Thu Mar 27, 2008 11:02 am
Location: Portugal

Post by KamiKage »

Maybe you should try ResourceGroupManager::clearResourceGroup(). It will put the resources into an unknown state. Unloading them will keep them initialised, which is where the parsing is done.
garry
Gnoblar
Posts: 6
Joined: Fri Apr 11, 2008 10:03 pm

Post by garry »

KamiKage wrote:Maybe you should try ResourceGroupManager::clearResourceGroup(). It will put the resources into an unknown state. Unloading them will keep them initialised, which is where the parsing is done.
Thanks, that does trigger the files to be reparsed, but nothing in the scene changes. I'm guessing I need to reapply the materials to everything right? Since clearResourceGroup actually cleared the materials from the resource group and re-created them, rather than reparsed in place?
User avatar
frankiezafe
Gnoblar
Posts: 12
Joined: Tue Aug 23, 2016 11:27 am
Location: brussels
x 1
Contact:

Re: Reloading materials (scripts?)

Post by frankiezafe »

I had some success with this sequence (hard reset)

Code: Select all

ResourceGroupManager::getSingleton().destroyResourceGroup( "Essential" );
// parsing of the 'resources.cfg' once again, and sending path to 
// ResourceGroupManager::getSingleton().addResourceLocation
setupResources();
ResourceGroupManager::getSingleton().initialiseResourceGroup( "Essential" );
As it concerns the look&feel of the SdkTrayManager, I also had to recreate it:

Code: Select all

delete trayMgr;
trayMgr = new SdkTrayManager("SampleControls", window, inputContext, this);
trayMgr->showFrameStats(TL_BOTTOMLEFT);
trayMgr->showLogo(TL_TOPRIGHT);
It's working nicely with materials, but there is no effect on the .overlay script...
User avatar
frankiezafe
Gnoblar
Posts: 12
Joined: Tue Aug 23, 2016 11:27 am
Location: brussels
x 1
Contact:

Re: Reloading materials (scripts?)

Post by frankiezafe »

[update]

Reloading the style and templates of the overlay at runtime in Ogre 2.0.

After reading these topics: I'm now able to reload all the assets, including the .overlay template.

Code is looking like this:

resources.cfg

Code: Select all

# Resources required by the sample browser and most samples.
[Essential]
# Zip=../media/packs/PolymorphTrays.zip
FileSystem=../media/packs/PolymorphTrays
All resources are usually packed in a zip, unzipped for edition.

C++

Code: Select all

OverlayManager& om = OverlayManager::getSingleton();
ResourceGroupManager& rgm = ResourceGroupManager::getSingleton();

delete trayMgr; // an OgreBites::SdkTrayManager pointer

// destruction of the entities and templates, if i get it right
om.destroyAllOverlayElements( false );
om.destroyAllOverlayElements( true );
// no idea why this must be called...
om.destroyAll();

// destruction of assets
rgm.destroyResourceGroup( "Essential" );
// parsing of the 'resources.cfg' once again
setupResources(); 
rgm.initialiseAllResourceGroups();

// getting the content of the overlay template
DataStreamPtr tmpl = rgm.openResource( "SdkTrays.overlay", "Essential" );
// and forcing OverlayManager to reload it
om.parseScript( tmpl, "Essential" );

// creation of a new SdkTrayManager
trayMgr = new SdkTrayManager("SampleControls", window, inputContext, this);
trayMgr->showFrameStats(TL_BOTTOMLEFT);
trayMgr->showLogo(TL_TOPRIGHT);
It's now easy to edit all the assets for the overlay :)
Post Reply