Added CElementMatrix
MODIFY
ext/MitsubaLoader/CElementFactory.cpp
ext/MitsubaLoader/CElementFactory.cpp
#include "CElementShapeCube.h"
#include "CElementShapeOBJ.h"
#include "CSimpleElement.h"
+#include "CElementMatrix.h"
namespace irr { namespace ext { namespace MitsubaLoader {
@@ -21,31 +22,57 @@ IElement* CElementFactory::createElement(const char* _el, const char** _atts)
{
return parseScene(_el, _atts);
}
+ else
if (!std::strcmp(_el, "shape"))
{
return parseShape(_el, _atts);
}
+ else
if (!std::strcmp(_el, "float"))
{
return parseSimpleElement(_el, _atts, IElement::Type::FLOAT);
}
+ else
if (!std::strcmp(_el, "integer"))
{
return parseSimpleElement(_el, _atts, IElement::Type::INTEGER);
}
+ else
if (!std::strcmp(_el, "boolean"))
{
return parseSimpleElement(_el, _atts, IElement::Type::BOOLEAN);
}
+ else
if (!std::strcmp(_el, "point"))
{
return parseSimpleElement(_el, _atts, IElement::Type::POINT);
}
+ else
if (!std::strcmp(_el, "string"))
{
return parseSimpleElement(_el, _atts, IElement::Type::STRING);
}
else
+ if (!std::strcmp(_el, "matrix"))
+ {
+ return parseMatrix(_el, _atts, CElementMatrix::Type::ARBITRARY);
+ }
+ else
+ if (!std::strcmp(_el, "translate"))
+ {
+ return parseMatrix(_el, _atts, CElementMatrix::Type::TRANSLATION);
+ }
+ else
+ if (!std::strcmp(_el, "rotate"))
+ {
+ return parseMatrix(_el, _atts, CElementMatrix::Type::ROTATION);
+ }
+ else
+ if (!std::strcmp(_el, "scale"))
+ {
+ return parseMatrix(_el, _atts, CElementMatrix::Type::SCALE);
+ }
+ else
{
ParserLog::mitsubaLoaderError("invalid .xml file structure: element " + std::string(_el) + "is unknown. \n");
return nullptr;
@@ -114,6 +141,11 @@ IElement* CElementFactory::parseSimpleElement(const char* _el, const char** _att
}
}
+IElement* CElementFactory::parseMatrix(const char* _el, const char** _atts, CElementMatrix::Type type)
+{
+ return new CElementMatrix(type);
+}
+
}
}
}
\ No newline at end of file

MODIFY
ext/MitsubaLoader/CElementFactory.h
ext/MitsubaLoader/CElementFactory.h
#include "irr/asset/IAssetManager.h"
#include "IElement.h"
+#include "CElementMatrix.h"
#include <memory>
namespace irr { namespace ext { namespace MitsubaLoader {
-
+class CElementMatrix;
+enum class CElementMatrix::Type;
class CElementFactory
{
@@ -19,6 +21,7 @@ private:
static IElement* parseScene(const char* _el, const char** _atts);
static IElement* parseShape(const char* _el, const char** _atts);
static IElement* parseSimpleElement(const char* _el, const char** _atts, IElement::Type type);
+ static IElement* parseMatrix(const char* _el, const char** _atts, CElementMatrix::Type type);
};
}

ADD
ext/MitsubaLoader/CElementMatrix.cpp
+#include "CElementMatrix.h"
+
+#include "ParserUtil.h"
+#include "CSimpleElement.h"
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+
+bool CElementMatrix::processAttributes(const char** _atts)
+{
+
+ switch (type)
+ {
+ case CElementMatrix::Type::ARBITRARY:
+ for (int i = 0; _atts[i]; i += 2)
+ {
+ if (!std::strcmp(_atts[i], "value"))
+ {
+ std::pair<bool, core::matrix4SIMD> result = getMatrixFromString(_atts[i + 1]);
+ matrix = result.second;
+ return result.first;
+ }
+ else
+ {
+ ParserLog::wrongAttribute(_atts[i], getLogName());
+ false;
+ }
+ }
+ case CElementMatrix::Type::TRANSLATION:
+ _IRR_DEBUG_BREAK_IF(true);
+ case CElementMatrix::Type::ROTATION:
+ _IRR_DEBUG_BREAK_IF(true);
+ case CElementMatrix::Type::SCALE:
+ _IRR_DEBUG_BREAK_IF(true);
+ }
+ //only type is an acceptable argument
+ for (int i = 0; _atts[i]; i += 2)
+ {
+ if (std::strcmp(_atts[i], "type"))
+ {
+ ParserLog::wrongAttribute(_atts[i], getLogName());
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementMatrix::onEndTag(asset::IAssetManager& _assetManager, IElement* _parent)
+{
+ return _parent->processChildData(this);
+}
+
+std::pair<bool, core::matrix4SIMD> CElementMatrix::getMatrixFromString(std::string _str) const
+{
+ std::replace(_str.begin(), _str.end(), ',', ' ');
+
+ float matrixData[16];
+ std::stringstream ss;
+ ss << _str;
+
+ for (int i = 0; i < 16; i++)
+ {
+ float f = std::numeric_limits<float>::quiet_NaN();
+ ss >> f;
+ std::cout << f << std::endl;
+
+ matrixData[i] = f;
+
+ if (isnan(f))
+ {
+ _IRR_DEBUG_BREAK_IF(true);
+ ParserLog::mitsubaLoaderError("Invalid matrix specified.");
+ return std::make_pair(false, core::matrix4SIMD());
+ }
+ }
+
+ return std::make_pair(true, core::matrix4SIMD(matrixData));
+}
+
+}
+}
+}
\ No newline at end of file

MODIFY
ext/MitsubaLoader/CMitsubaLoader.cpp
ext/MitsubaLoader/CMitsubaLoader.cpp
@@ -27,6 +27,8 @@ namespace irr { namespace ext { namespace MitsubaLoader {
- clean up memory dynamically allocated by ParserData::scene
+ - resolve header include conflict (IElement.h needs to include ParserUtil.h (only for ParserLog), and ParserUtil.h needs to include IElement.h)
+
*/

MODIFY
ext/MitsubaLoader/CMitsubaScene.cpp
ext/MitsubaLoader/CMitsubaScene.cpp
@@ -42,34 +42,20 @@ bool CMitsubaScene::processChildData(IElement* _child)
CElementShapeOBJ* shape = static_cast<CElementShapeOBJ*>(_child);
const asset::ICPUMesh* shapeMesh = shape->getMesh();
-
- if (!shapeMesh)
- {
- _IRR_DEBUG_BREAK_IF(true);
- return false;
- }
-
-
- //is it possible that shapeMesh->getMeshBufferCount() > 1 ?
- for (int i = 0; i < shapeMesh->getMeshBufferCount(); i++)
- mesh->addMeshBuffer(shapeMesh->getMeshBuffer(i));
-
-
-
- return true;
+ return appendMesh(shapeMesh);
}
case IElement::Type::SHAPE_CUBE:
+ {
os::Printer::print("Alright! Cube has been added to the scene! \n");
return true;
-
- case IElement::Type::FLOAT:
-
- std::cout << static_cast<CElementFloat*>(_child)->getValueAttribute() << std::endl;
-
+ }
+ case IElement::Type::MATRIX:
+ {
+ os::Printer::print("Alright! Cube has been added to the scene! \n");
+ _IRR_DEBUG_BREAK_IF(true);
return true;
-
-
+ }
default:
ParserLog::wrongChildElement(getLogName(), _child->getLogName());
@@ -77,6 +63,20 @@ bool CMitsubaScene::processChildData(IElement* _child)
}
}
+bool CMitsubaScene::appendMesh(const asset::ICPUMesh* _mesh)
+{
+ if (!_mesh)
+ {
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+
+
+ //is it possible that shapeMesh->getMeshBufferCount() > 1 ?
+ for (int i = 0; i < _mesh->getMeshBufferCount(); i++)
+ mesh->addMeshBuffer(_mesh->getMeshBuffer(i));
+}
+
}
}

MODIFY
ext/MitsubaLoader/CMitsubaScene.h
ext/MitsubaLoader/CMitsubaScene.h
@@ -23,11 +23,12 @@ public:
virtual bool processChildData(IElement* child) override;
asset::SCPUMesh* releaseMesh() { return mesh; mesh = nullptr; }
- //void appendMesh(asset::ICPUMesh* mesh);
+
private:
asset::SCPUMesh* mesh;
+ bool appendMesh(const asset::ICPUMesh* _mesh);
};
}

MODIFY
ext/MitsubaLoader/IElement.h
ext/MitsubaLoader/IElement.h
#include "irr/asset/IAssetManager.h"
#include <iostream>
+
namespace irr { namespace ext { namespace MitsubaLoader {
//TODO: Provide elements with getName member function which will return std::string.
@@ -37,7 +38,8 @@ public:
//other
TRANSFORM,
TEXTURE,
- STRING
+ STRING,
+ MATRIX
};
public:
@@ -57,7 +59,7 @@ public:
{
if (_child != nullptr)
{
- //ParserLog::wrongChildElement(getName(), _child->getName());
+ //ParserLog::wrongChildElement(getLogName(), _child->getName());
return false;
}
return true;

Added CElementMatrix