Added few properties
MODIFY
ext/MitsubaLoader/CElementFactory.cpp
ext/MitsubaLoader/CElementFactory.cpp
#include "../../ext/MitsubaLoader/CElementSensor.h"
#include "../../ext/MitsubaLoader/CElementSampler.h"
#include "../../ext/MitsubaLoader/CElementFilm.h"
+#include "../../ext/MitsubaLoader/CElementEmitter.h"
#include "../../ext/MitsubaLoader/CShapeCreator.h"
#include "../../ext/MitsubaLoader/Shape.h"
@@ -88,6 +89,20 @@ IElement* CElementFactory::createElement(const char* _el, const char** _atts)
return film;
}
else
+ if (!std::strcmp(_el, "emitter"))
+ {
+ CElementEmitter* emitter = new CElementEmitter();
+
+ if (!emitter->processAttributes(_atts))
+ {
+ delete emitter;
+ _IRR_DEBUG_BREAK_IF(true);
+ return nullptr;
+ }
+
+ return emitter;
+ }
+ else
{
ParserLog::invalidXMLFileStructure("element " + std::string(_el) + "is unknown. \n");
_IRR_DEBUG_BREAK_IF(true);

MODIFY
ext/MitsubaLoader/CElementTransform.cpp
ext/MitsubaLoader/CElementTransform.cpp
@@ -34,8 +34,45 @@ bool CElementTransform::onEndTag(asset::IAssetManager& _assetManager)
matrix = core::concatenateBFollowedByA(matrix, CPropertyElementManager::retriveMatrix(property.value));
}
else
+ if (property.type == SPropertyElementData::Type::TRANSLATE)
+ {
+ core::vector3df_SIMD translate = CPropertyElementManager::retriveVector(property.value);
+ core::matrix4SIMD tmpMatrix;
+ tmpMatrix.setTranslation(translate);
+
+ matrix = core::concatenateBFollowedByA(tmpMatrix, matrix);
+ }
+ else
+ if (property.type == SPropertyElementData::Type::ROTATE)
+ {
+ core::vectorSIMDf rotVec = CPropertyElementManager::retriveVector(property.value);
+ core::quaternion rot(rotVec.x, rotVec.y, rotVec.z, rotVec.w);
+
+ //not implemented yet
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ //matrix = core::concatenateBFollowedByA(rot.getMatrix(), matrix);
+ }
+ else
+ if (property.type == SPropertyElementData::Type::SCALE)
+ {
+ core::vector3df_SIMD scale = CPropertyElementManager::retriveVector(property.value);
+ core::matrix4SIMD tmpMatrix;
+ tmpMatrix.setScale(scale);
+
+ matrix = core::concatenateBFollowedByA(tmpMatrix, matrix);
+ }
+ else
+ if (property.type == SPropertyElementData::Type::LOOKAT)
+ {
+ core::matrix4SIMD tmpMatrix = CPropertyElementManager::retriveMatrix(property.value);
+
+ matrix = core::concatenateBFollowedByA(tmpMatrix, matrix);
+ }
+ else
{
ParserLog::invalidXMLFileStructure("wat is this?");
+ _IRR_DEBUG_BREAK_IF(true);
return false;
}
}

MODIFY
ext/MitsubaLoader/CMitsubaLoader.cpp
ext/MitsubaLoader/CMitsubaLoader.cpp
@@ -36,7 +36,9 @@ namespace irr { namespace ext { namespace MitsubaLoader {
its interior has inward-facing normals, which most scattering models in Mitsuba will treat as fully
absorbing. If this is not desirable, consider using the twosided plugin." ...
- - (PropertyElement.cpp) these property elements must be finished: translate, rotate, scale, rgb, srgb, spectrum, vector
+ - (PropertyElement.cpp) these property elements must be finished: rgb, srgb, spectrum, vector
+
+ - rotate doesn't work..
- (PropertyElement.cpp) use regex

MODIFY
ext/MitsubaLoader/IElement.h
ext/MitsubaLoader/IElement.h
@@ -21,6 +21,7 @@ public:
SAMPLER,
FILM,
SENSOR,
+ EMITTER,
//shapes
SHAPE,

MODIFY
ext/MitsubaLoader/ParserUtil.h
ext/MitsubaLoader/ParserUtil.h
@@ -99,7 +99,7 @@ private:
"float", "string", "boolean", "integer",
"rgb", "srgb", "spectrum",
"point", "vector",
- "matrix", "rotate", "translate", "scale",
+ "matrix", "rotate", "translate", "scale", "lookat",
nullptr
};
};

MODIFY
ext/MitsubaLoader/PropertyElement.cpp
ext/MitsubaLoader/PropertyElement.cpp
@@ -52,58 +52,147 @@ std::pair<bool, SPropertyElementData> CPropertyElementManager::createPropertyDat
else if (elName == "translate")
{
result.type = SPropertyElementData::Type::TRANSLATE;
+
+ bool errorOccurred = false;
+ result.value = findAndConvertXYZAttsToSingleString(_atts, errorOccurred, { "name" });
+ return std::make_pair(true, result);
}
else if (elName == "rotate")
{
result.type = SPropertyElementData::Type::ROTATE;
+
+ bool errorOccured = false;
+ const std::string axisStr = findAndConvertXYZAttsToSingleString(_atts, errorOccured, { "name", "angle" });
+
+ if (errorOccured)
+ return std::make_pair(false, SPropertyElementData());
+
+ const core::vector3df_SIMD rotationAxis = core::normalize(retriveVector(axisStr));
+
+ if (rotationAxis.getLengthAsFloat() == 0.0f)
+ {
+ ParserLog::invalidXMLFileStructure("invalid rotation axis");
+ return std::make_pair(false, SPropertyElementData());
}
- else if (elName == "scale")
+
+ float angle = 0.0f;
+
+ for (int i = 0; _atts[i]; i += 2)
{
- result.type = SPropertyElementData::Type::SCALE;
+ if (!std::strcmp(_atts[i], "angle"))
+ {
+ angle = retriveFloatValue(_atts[i + 1]);
}
- else if (elName == "point")
+ }
+
+ core::quaternion resultingQuaternion = core::quaternion::fromAngleAxis(angle, rotationAxis);
+
+ std::stringstream ss;
+ float tmpCoord;
+
+ for (int i = 0; i < 4; i++)
{
- result.type = SPropertyElementData::Type::POINT;
+ tmpCoord = resultingQuaternion.getPointer()[i];
+ ss << tmpCoord << ' ';
+ }
- std::string values[4] = { "0.0", "0.0", "0.0", "0.0" };
- for (int i = 0; _atts[i]; i += 2)
+ result.value = ss.str();
+
+ return std::make_pair(true, result);
+ }
+ else if (elName == "scale")
{
- if (!std::strcmp(_atts[i], "name"))
+ result.type = SPropertyElementData::Type::SCALE;
+
+ bool errorOccured = false;
+ //value should contain only one number here!
+ const std::string val = findStandardValue(_atts, errorOccured, { "name", "x", "y", "z" });
+
+ if (errorOccured)
{
- continue;
+ _IRR_DEBUG_BREAK_IF(true);
+ return std::make_pair(false, SPropertyElementData());
}
- if (!std::strcmp(_atts[i], "value"))
+
+ if (val != "not set")
{
- result.value = _atts[i + 1];
+ result.value = val + ' ' + val + ' ' + val;
return std::make_pair(true, result);
}
- else if (!std::strcmp(_atts[i], "x"))
+
+ result.value = findAndConvertXYZAttsToSingleString(_atts, errorOccured, { "name" });
+
+ if (errorOccured)
{
- values[0] = _atts[i + 1];
+ _IRR_DEBUG_BREAK_IF(true);
+ return std::make_pair(false, SPropertyElementData());
}
- else if (!std::strcmp(_atts[i], "y"))
+
+ return std::make_pair(true, result);
+
+ }
+ else if (elName == "lookat")
{
- values[1] = _atts[i + 1];
+ result.type = SPropertyElementData::Type::LOOKAT;
+
+ std::string originStr = "0.0 0.0 0.0";
+ std::string targetStr = "0.0 0.0 -1.0";
+ std::string upStr = "0.0 1.0 0.0";
+
+ for (int i = 0; _atts[i]; i += 2)
+ {
+ if (!std::strcmp(_atts[i], "origin"))
+ {
+ originStr = _atts[i + 1];
}
- else if (!std::strcmp(_atts[i], "z"))
+ else if (!std::strcmp(_atts[i], "target"))
{
- values[2] = _atts[i + 1];
+ targetStr = _atts[i + 1];
}
- else if (!std::strcmp(_atts[i], "w"))
+ else if (!std::strcmp(_atts[i], "up"))
{
- values[3] = _atts[i + 1];
+ upStr = _atts[i + 1];
}
- else
+ }
+
+ core::vector3df_SIMD origin = retriveVector(originStr);
+ core::vector3df_SIMD target = retriveVector(targetStr);
+ core::vector3df_SIMD up = retriveVector(upStr);
+
+ core::matrix4SIMD lookAt = core::matrix4SIMD::buildCameraLookAtMatrixRH(origin, target, up);
+
+ std::stringstream ss;
+
+ for (int i = 0; i < 16; i++)
{
- _IRR_DEBUG_BREAK_IF(false);
- return std::make_pair(false, SPropertyElementData());
+ ss << lookAt.pointer()[i] << ' ';
}
+
+ result.value = ss.str();
+
+ return std::make_pair(true, result);
}
+ else if (elName == "point")
+ {
+ result.type = SPropertyElementData::Type::POINT;
- result.value = values[0] + ' ' + values[1] + ' ' + values[2] + ' ' + values[3];
+ bool errorOccurred = false;
+ result.value = findStandardValue(_atts, errorOccurred, { "name", "x", "y", "z" });
+ if (errorOccurred)
+ return std::make_pair(false, SPropertyElementData());
+
+ if (result.value != "not set")
return std::make_pair(true, result);
+
+ result.value = findAndConvertXYZAttsToSingleString(_atts, errorOccurred, { "name" });
+
+ if (errorOccurred)
+ return std::make_pair(false, SPropertyElementData());
+
+ return std::make_pair(true, result);
+
}
else if (elName == "vector")
{
@@ -112,7 +201,7 @@ std::pair<bool, SPropertyElementData> CPropertyElementManager::createPropertyDat
}
bool errorOccurred;
- result.value = findStandardValue(_atts, errorOccurred);
+ result.value = findStandardValue(_atts, errorOccurred, { "name" });
if (errorOccurred)
{
@@ -210,7 +299,7 @@ core::vectorSIMDf CPropertyElementManager::retriveVector(const std::string& _dat
{
if (i == 3)
{
- vectorData[3] = 1.0f;
+ vectorData[3] = 0.0f;
break;
}
@@ -223,32 +312,87 @@ core::vectorSIMDf CPropertyElementManager::retriveVector(const std::string& _dat
return core::vectorSIMDf(vectorData);
}
-std::string CPropertyElementManager::findStandardValue(const char** _atts, bool& _errorOccurred)
+std::string CPropertyElementManager::findStandardValue(const char** _atts, bool& _errorOccurred, const core::vector<std::string>& _acceptableAttributes)
{
- std::string value;
- bool isValueSet = false;
+ std::string value = "not set";
for (int i = 0; _atts[i]; i += 2)
{
if (!std::strcmp(_atts[i], "value"))
{
value = _atts[i + 1];
- isValueSet = true;
}
- else if (!std::strcmp(_atts[i], "name"))
+ else
+ {
+ bool acceptableAttrFound = false;
+ const std::string currAttr = _atts[i];
+ for (const std::string& attr : _acceptableAttributes)
{
+ if (currAttr == attr)
+ {
+ acceptableAttrFound = true;
+ break;
+ }
+ }
+
+ if (acceptableAttrFound)
continue;
+
+ ParserLog::invalidXMLFileStructure(std::string(_atts[i]) + "is not an attribute of the property element");
+ _IRR_DEBUG_BREAK_IF(true);
+ _errorOccurred = true;
+ return value;
+ }
+ }
+
+ _errorOccurred = false;
+ return value;
+}
+
+std::string CPropertyElementManager::findAndConvertXYZAttsToSingleString(const char** _atts, bool& _errorOccurred, const core::vector<std::string>& _acceptableAttributes)
+{
+ std::string values[3] = { "0.0", "0.0", "0.0" };
+
+ for (int i = 0; _atts[i]; i += 2)
+ {
+ if (!std::strcmp(_atts[i], "x"))
+ {
+ values[0] = _atts[i + 1];
+ }
+ else if (!std::strcmp(_atts[i], "y"))
+ {
+ values[1] = _atts[i + 1];
+ }
+ else if (!std::strcmp(_atts[i], "z"))
+ {
+ values[2] = _atts[i + 1];
}
else
{
+ bool acceptableAttrFound = false;
+ const std::string currAttr = _atts[i];
+ for (const std::string& attr : _acceptableAttributes)
+ {
+ if (currAttr == attr)
+ {
+ acceptableAttrFound = true;
+ break;
+ }
+ }
+
+ if (acceptableAttrFound)
+ break;
+
ParserLog::invalidXMLFileStructure(std::string(_atts[i]) + "is not an attribute of the property element");
+ _IRR_DEBUG_BREAK_IF(true);
_errorOccurred = true;
- return value;
+ return "";
}
}
- _errorOccurred = isValueSet ? false : true;
- return value;
+ _errorOccurred = false;
+ std::string result = values[0] + ' ' + values[1] + ' ' + values[2];
+ return result;
}
}

MODIFY
ext/MitsubaLoader/PropertyElement.h
ext/MitsubaLoader/PropertyElement.h
@@ -21,6 +21,7 @@ namespace irr { namespace ext { namespace MitsubaLoader {
TRANSLATE,
ROTATE,
SCALE,
+ LOOKAT,
POINT,
VECTOR
};
@@ -42,7 +43,8 @@ public:
static core::vectorSIMDf retriveVector(const std::string& _data);
private:
- static std::string findStandardValue(const char** _atts, bool& _errorOccurred);
+ static std::string findStandardValue(const char** _atts, bool& _errorOccurred, const core::vector<std::string>& _acceptableAttributes);
+ static std::string findAndConvertXYZAttsToSingleString(const char** _atts, bool& _errorOccurred, const core::vector<std::string>& _acceptableAttributes);
};

Added few properties