I was seeking for a good way to encapsulate the Ogre::Material that are script loaded in my framework custom Material class, but without using a temporary group nor parsing all the materials stored in Ogre::MaterialManager (and filtering by this group), so I started to look at ScriptCompilerListener events.
That was pretty strait-forward to encapsulate the material instances, but I needed to encapsulate Technique and Pass instances too, so I added 2 new events to the script listener (and I don't know why they were not implemented when MaterialTranslator was? Any reason?):
Code: Select all
CreateTechniqueScriptCompilerEvent
Code: Select all
CreatePassScriptCompilerEvent
https://sourceforge.net/tracker/?func=d ... tid=302997
If you don't see what I mean by "encapsulate", here a good sample of what I'm doing (my framework name is obviously Usul

Code: Select all
// Generate Usul::GraphicMaterial/Usul::Technique/Usul::Pass for Ogre's script loaded materials.
bool OgreGraphicsManager::handleEvent(Ogre::ScriptCompiler* compiler, Ogre::ScriptCompilerEvent* evt, void* retval)
{
// Get the type of the resource parsed by the script compiler
bool processed = false;
// Is it a material?
if(evt->mType == Ogre::CreateMaterialScriptCompilerEvent::eventType)
{
// Convert the event.
Ogre::CreateMaterialScriptCompilerEvent* convertedEvent = static_cast<Ogre::CreateMaterialScriptCompilerEvent*>(evt);
// Create a new empty material using usul class
GraphicMaterialDescriptor newGraphicMaterialDesc;
newGraphicMaterialDesc.group = convertedEvent->mResourceGroup;
GraphicMaterial* newGraphicMaterial = this->Create<GraphicMaterial>(newGraphicMaterialDesc, convertedEvent->mName);
// Get the newly created Ogre::Material (in Usul::OgreGraphicMaterial constructor) and return it to the script compiler, it will populate it!
Ogre::Material** retMaterial = (Ogre::Material**)retval;
*retMaterial = static_cast<OgreGraphicMaterial*>(newGraphicMaterial)->GetOgreMaterialPtr().getPointer();
// Tell Ogre that we have create the Ogre::Material, he do not need to do it.
processed = true;
}
// Is it a technique?
if(evt->mType == Ogre::CreateTechniqueScriptCompilerEvent::eventType)
{
// Convert the event.
Ogre::CreateTechniqueScriptCompilerEvent* convertedEvent = static_cast<Ogre::CreateTechniqueScriptCompilerEvent*>(evt);
// Get Usul parent material
GraphicMaterial* parentGraphicMaterial = this->Get<GraphicMaterial>(convertedEvent->mParentMaterial->getName());
// Create a new empty technique using usul class
TechniqueDescriptor newTechniqueDesc;
Technique* newTechnique = parentGraphicMaterial->Create<Technique>(newTechniqueDesc, convertedEvent->mName);
// Get the newly created Ogre::Technique (in Usul::OgreTechnique constructor) and return it to the script compiler, it will populate it!
Ogre::Technique** retTechnique = (Ogre::Technique**)retval;
*retTechnique = static_cast<OgreTechnique*>(newTechnique)->GetOgreTechnique();
// Tell Ogre that we have create the Ogre::Technique, he do not need to do it.
processed = true;
}
// Is it a pass?
if(evt->mType == Ogre::CreatePassScriptCompilerEvent::eventType)
{
// Convert the event.
Ogre::CreatePassScriptCompilerEvent* convertedEvent = static_cast<Ogre::CreatePassScriptCompilerEvent*>(evt);
// Get Usul parent technique
Ogre::Any bindedTechnique = convertedEvent->mParentTechnique->getUserObjectBindings().getUserAny("Usul::OgreTechnique");
if(!bindedTechnique.isEmpty())
{
OgreTechnique* parentTechnique = Ogre::any_cast<OgreTechnique*>(bindedTechnique);
// Create a new empty technique using usul class
PassDescriptor newPassDesc;
Pass* newPass = parentTechnique->Create<Pass>(newPassDesc, convertedEvent->mName);
// Get the newly created Ogre::Technique (in Usul::OgreTechnique constructor) and return it to the script compiler, it will populate it!
Ogre::Pass** retPass = (Ogre::Pass**)retval;
*retPass = static_cast<OgrePass*>(newPass)->GetOgrePass();
// Tell Ogre that we have create the Ogre::Technique, he do not need to do it.
processed = true;
}
}
return processed;
}