now unsupported elements will be omitted by parser
MODIFY
ext/MitsubaLoader/ParserUtil.cpp
ext/MitsubaLoader/ParserUtil.cpp
#include "../../ext/MitsubaLoader/ParserUtil.h"
#include "../../ext/MitsubaLoader/CElementFactory.h"
+
#include "irrlicht.h"
namespace irr { namespace ext { namespace MitsubaLoader {
@@ -34,14 +35,23 @@ void ParserLog::mitsubaLoaderError(const std::string& errorMessage)
//or os::Printer::log ?
os::Printer::print(message);
- _IRR_DEBUG_BREAK_IF(true);
+ //_IRR_DEBUG_BREAK_IF(true);
}
void elementHandlerStart(void* _data, const char* _el, const char** _atts)
{
-
ParserData* data = static_cast<ParserData*>(_data);
+ if (!data->pfc.suspendParsingIfElNotSupported(_el))
+ {
+ ParserLog::mitsubaLoaderError(std::string(_el) + " is not supported");
+ return;
+ }
+
+ if (data->pfc.isParsingSuspended())
+ return;
+
+
std::unique_ptr<IElement> element(CElementFactory::createElement(_el, _atts));
if (!element)
@@ -89,9 +99,14 @@ void elementHandlerStart(void* _data, const char* _el, const char** _atts)
void elementHandlerEnd(void* _data, const char* _el)
{
-
ParserData* data = static_cast<ParserData*>(_data);
+ if (data->pfc.isParsingSuspended())
+ {
+ data->pfc.checkForUnsuspend(_el);
+ return;
+ }
+
if (data->elements.empty())
{
data->scene->onEndTag(data->assetManager, nullptr);
@@ -113,6 +128,31 @@ void elementHandlerEnd(void* _data, const char* _el)
}
}
+void ParserFlowController::checkForUnsuspend(const char* _el)
+{
+ if (!std::strcmp(notSupportedElement.c_str(), _el))
+ {
+ isParsingSuspendedFlag = false;
+ notSupportedElement.clear();
+ }
+}
+
+bool ParserFlowController::suspendParsingIfElNotSupported(const char* _el)
+{
+ for (int i = 0; unsElements[i]; i++)
+ {
+ if (!std::strcmp(unsElements[i], _el))
+ {
+ isParsingSuspendedFlag = true;
+ notSupportedElement = _el;
+
+ return false;
+ }
+ }
+
+ return true;
+}
+
}
}
}
\ No newline at end of file

MODIFY
ext/MitsubaLoader/ParserUtil.h
ext/MitsubaLoader/ParserUtil.h
namespace irr { namespace ext { namespace MitsubaLoader {
+//now unsupported elements (like <sensor> (for now), for example) and its children elements will be ignored
+class ParserFlowController
+{
+public:
+ ParserFlowController()
+ :isParsingSuspendedFlag(false) {};
+
+ bool suspendParsingIfElNotSupported(const char* _el);
+ void checkForUnsuspend(const char* _el);
+
+ inline bool isParsingSuspended() const { return isParsingSuspendedFlag; }
+
+private:
+ static constexpr const char* unsElements[] = { "integrator", "emitter", "ref", "bsdf", "sensor", nullptr };
+ bool isParsingSuspendedFlag;
+ std::string notSupportedElement;
+
+};
+
+class ParserLog
+{
+public:
+ /*prints this message:
+ Mitsuba loader error:
+ Invalid .xml file structure: attribute 'attribName' is not declared for element 'elementName' */
+ static void wrongAttribute(const std::string& attribName, const std::string& elementName);
+
+ /*prints this message:
+ Mitsuba loader error:
+ Invalid .xml file structure: 'parentName' is not a parent of 'wrongChildName' */
+ static void wrongChildElement(const std::string& parentName, const std::string& childName);
+
+ /*prints this message:
+ Mitsuba loader error:
+ Invalid .xml file structure: message */
+ static void mitsubaLoaderError(const std::string& errorMessage);
+
+};
+
//struct, which will be passed to expat handlers as user data (first argument) see: XML_StartElementHandler or XML_EndElementHandler in expat.h
struct ParserData
@@ -40,26 +79,8 @@ struct ParserData
core::vector<std::unique_ptr<IElement>> elements;
XML_Parser parser;
-};
-
-class ParserLog
-{
-public:
- /*prints this message:
- Mitsuba loader error:
- Invalid .xml file structure: attribute 'attribName' is not declared for element 'elementName' */
- static void wrongAttribute(const std::string& attribName, const std::string& elementName);
-
- /*prints this message:
- Mitsuba loader error:
- Invalid .xml file structure: 'parentName' is not a parent of 'wrongChildName' */
- static void wrongChildElement(const std::string& parentName, const std::string& childName);
-
- /*prints this message:
- Mitsuba loader error:
- Invalid .xml file structure: message */
- static void mitsubaLoaderError(const std::string& errorMessage);
+ ParserFlowController pfc;
};
void elementHandlerStart(void* _data, const char* _el, const char** _atts);

now unsupported elements will be omitted by parser