message: Finished all shape types

diff:
#include "../../ext/MitsubaLoader/CElementTransform.h"
#include "../../ext/MitsubaLoader/CElementColor.h"
#include "../../ext/MitsubaLoader/CElementShapePLY.h"
+#include "../../ext/MitsubaLoader/CElementShapeRectangle.h"
+#include "../../ext/MitsubaLoader/CElementShapeDisk.h"
namespace irr { namespace ext { namespace MitsubaLoader {
@@ -132,6 +134,14 @@ IElement* CElementFactory::parseShape(const char* _el, const char** _atts)
{
return new CElementShapeCylinder();
}
+ else if (!std::strcmp(_atts[i + 1], "rectangle"))
+ {
+ return new CElementShapeRectangle();
+ }
+ else if (!std::strcmp(_atts[i + 1], "disk"))
+ {
+ return new CElementShapeDisk();
+ }
else
{
ParserLog::mitsubaLoaderError(std::string(_atts[i + 1]) + "is not a type of shape element. \n");

diff:
@@ -12,6 +12,7 @@ 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"))
@@ -27,6 +28,7 @@ bool CElementMatrix::processAttributes(const char** _atts)
return false;
}
}
+ }
case CElementMatrix::Type::TRANSLATION:
_IRR_DEBUG_BREAK_IF(true);
case CElementMatrix::Type::ROTATION:

diff:
@@ -24,7 +24,7 @@ bool CElementShapeCube::processAttributes(const char** _atts)
bool CElementShapeCube::onEndTag(asset::IAssetManager& _assetManager, IElement* _parent)
{
- mesh = _assetManager.getGeometryCreator()->createCubeMesh(core::vector3df(2.0f, 2.0f, 2.0f));
+ mesh = _assetManager.getGeometryCreator()->createCubeMesh(core::vector3df(1.0f, 1.0f, 1.0f));
if (!mesh)
return false;

diff:
@@ -26,7 +26,7 @@ bool CElementShapeCylinder::onEndTag(asset::IAssetManager& _assetManager, IEleme
{
const float cylinderHeight = (p0 - p1).getLengthAsFloat();
- mesh = _assetManager.getGeometryCreator()->createCylinderMesh(radius,cylinderHeight,32);
+ mesh = _assetManager.getGeometryCreator()->createCylinderMesh(radius,cylinderHeight,32,0xffffffff,false);
if (!mesh)
return false;

diff:
+#include "../../ext/MitsubaLoader/CElementShapeDisk.h"
+
+#include "../../ext/MitsubaLoader/ParserUtil.h"
+#include "../../ext/MitsubaLoader/CElementTransform.h"
+#include "../../ext/MitsubaLoader/CSimpleElement.h"
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+
+bool CElementShapeDisk::processAttributes(const char** _atts)
+{
+ //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 CElementShapeDisk::onEndTag(asset::IAssetManager& _assetManager, IElement* _parent)
+{
+ mesh = _assetManager.getGeometryCreator()->createDiskMesh(1.0f, 64);
+
+ if (!mesh)
+ return false;
+
+ if (flipNormalsFlag)
+ flipNormals(_assetManager);
+
+ return _parent->processChildData(this);
+}
+
+bool CElementShapeDisk::processChildData(IElement* _child)
+{
+ switch (_child->getType())
+ {
+ case IElement::Type::TRANSFORM:
+ {
+ CElementTransform* transformElement = static_cast<CElementTransform*>(_child);
+
+ if (transformElement->getName() == "toWorld")
+ this->transform = static_cast<CElementTransform*>(_child)->getMatrix();
+ else
+ ParserLog::mitsubaLoaderError("Unqueried attribute '" + transformElement->getName() + "' in element 'shape'");
+
+ return true;
+ }
+ case IElement::Type::BOOLEAN:
+ {
+ CElementBoolean* boolElement = static_cast<CElementBoolean*>(_child);
+ const std::string elementName = boolElement->getNameAttribute();
+
+ if (elementName == "flipNormals")
+ {
+ flipNormalsFlag = boolElement->getValueAttribute();
+ }
+ else
+ {
+ //warning
+ ParserLog::mitsubaLoaderError("Unqueried attribute " + elementName + " in element \"shape\"");
+ }
+
+ return true;
+ }
+ default:
+ ParserLog::wrongChildElement(getLogName(), _child->getLogName());
+ return false;
+ }
+}
+
+}
+}
+}
\ No newline at end of file

diff:
@@ -38,7 +38,6 @@ bool CElementShapeOBJ::onEndTag(asset::IAssetManager& _assetManager, IElement* _
return false;
}
- //getAssetInHierarchy?
mesh = static_cast<asset::ICPUMesh*>(_assetManager.getAsset(fileName, asset::IAssetLoader::SAssetLoadParams()));
if (!mesh)

diff:
+#include "../../ext/MitsubaLoader/CElementShapeRectangle.h"
+
+#include "../../ext/MitsubaLoader/ParserUtil.h"
+#include "../../ext/MitsubaLoader/CElementTransform.h"
+#include "../../ext/MitsubaLoader/CSimpleElement.h"
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+
+bool CElementShapeRectangle::processAttributes(const char** _atts)
+{
+ //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 CElementShapeRectangle::onEndTag(asset::IAssetManager& _assetManager, IElement* _parent)
+{
+ mesh = _assetManager.getGeometryCreator()->createRectangleMesh(core::vector2df_SIMD(1.0f, 1.0f));
+
+ if (!mesh)
+ return false;
+
+ if (flipNormalsFlag)
+ flipNormals(_assetManager);
+
+ return _parent->processChildData(this);
+}
+
+bool CElementShapeRectangle::processChildData(IElement* _child)
+{
+ switch (_child->getType())
+ {
+ case IElement::Type::TRANSFORM:
+ {
+ CElementTransform* transformElement = static_cast<CElementTransform*>(_child);
+
+ if (transformElement->getName() == "toWorld")
+ this->transform = static_cast<CElementTransform*>(_child)->getMatrix();
+ else
+ ParserLog::mitsubaLoaderError("Unqueried attribute '" + transformElement->getName() + "' in element 'shape'");
+
+ return true;
+ }
+ case IElement::Type::BOOLEAN:
+ {
+ CElementBoolean* boolElement = static_cast<CElementBoolean*>(_child);
+ const std::string elementName = boolElement->getNameAttribute();
+
+ if (elementName == "flipNormals")
+ {
+ flipNormalsFlag = boolElement->getValueAttribute();
+ }
+ else
+ {
+ //warning
+ ParserLog::mitsubaLoaderError("Unqueried attribute " + elementName + " in element \"shape\"");
+ }
+
+ return true;
+ }
+ default:
+ ParserLog::wrongChildElement(getLogName(), _child->getLogName());
+ return false;
+ }
+}
+
+}
+}
+}
\ No newline at end of file

diff:
@@ -95,7 +95,7 @@ bool CMitsubaScene::appendMesh(const asset::ICPUMesh* _mesh, const core::matrix4
submesh->setAttribute(pos,submesh->getPositionAttributeIx(), i);
submesh->setAttribute(normal, asset::E_VERTEX_ATTRIBUTE_ID::EVAI_ATTR3, i);
- pos = submesh->getPosition(i);
+
}
mesh->addMeshBuffer(submesh);

diff:
@@ -34,7 +34,8 @@ public:
STRING,
MATRIX,
MATERIAL,
- COLOR
+ COLOR,
+ MEDIUM
};
public:

diff:
@@ -28,7 +28,7 @@ public:
inline bool isParsingSuspended() const { return isParsingSuspendedFlag; }
private:
- static constexpr const char* unsElements[] = { "integrator", "emitter", "ref", "bsdf", "sensor", nullptr };
+ static constexpr const char* unsElements[] = { "integrator", "emitter", "ref", "bsdf", "sensor", "medium", nullptr };
bool isParsingSuspendedFlag;
std::string notSupportedElement;

diff:
@@ -644,18 +644,6 @@ asset::ICPUMesh* CGeometryCreator::createDiskMesh(float radius, uint32_t tessela
asset::ICPUBuffer* vertices = new asset::ICPUBuffer(vertexCount * vertexSize);
DiskVertex* ptr = (DiskVertex*)vertices->getPointer();
-
- /*
- example:
- v1 v0 v7
- \ | /
- v2 -- s -- v6
- / | \
- v3 v4 v5
-
- */
-
-
const core::vectorSIMDf v0(0.0f, radius, 0.0f, 0.0f);
core::matrix3x4SIMD rotation;

original_message: Finished all shape types


message: Delete CElementColor.cpp

change_type: DELETE

diff:
-#include "../../ext/MitsubaLoader/CElementColor.h"
-
-#include "../../ext/MitsubaLoader/ParserUtil.h"
-#include "../../ext/MitsubaLoader/CElementTransform.h"
-#include "../../ext/MitsubaLoader/CSimpleElement.h"
-
-namespace irr { namespace ext { namespace MitsubaLoader {
-
-bool CElementColor::processAttributes(const char** _atts)
-{
- bool isNameSet = false;
-
- for (int i = 0; _atts[i]; i += 2)
- {
- if (!std::strcmp(_atts[i], "name"))
- {
- nameAttr = _atts[i + 1];
- isNameSet = true;
- }
-
-
- if (!std::strcmp(_atts[i], "value"))
- {
- bool isColorValid = false;
- std::tie(isColorValid, color) = retriveColorFromValueAttribute(_atts[i + 1]);
-
- if (!isColorValid)
- {
- _IRR_DEBUG_BREAK_IF(true);
- return false;
- }
- }
- }
-
- return isNameSet;
-}
-
-bool CElementColor::onEndTag(asset::IAssetManager& _assetManager, IElement* _parent)
-{
- return _parent->processChildData(this);
-}
-
-std::pair<bool, core::vector3df_SIMD> CElementColor::retriveColorFromValueAttribute(std::string value)
-{
- std::replace(value.begin(), value.end(), ',', ' ');
-
- float r = std::numeric_limits<float>::quiet_NaN();
- float g = std::numeric_limits<float>::quiet_NaN();
- float b = std::numeric_limits<float>::quiet_NaN();
-
- std::stringstream ss;
- ss << value;
-
- if (value[0] == '#')
- {
- //TODO: process hex rgb value
- _IRR_DEBUG_BREAK_IF(true);
- return std::make_pair(false, core::vector3df_SIMD());
- }
- else
- {
- ss >> r;
- ss >> g;
- ss >> b;
-
- if (!isnan(r) && isnan(g) && isnan(b))
- {
- return std::make_pair(true, core::vector3df_SIMD(r));
- }
- else if (!isnan(r) && !isnan(g) && !isnan(b))
- {
- return std::make_pair(true, core::vector3df_SIMD(r, g, b));
- }
- else if (isnan(r) && isnan(g) && isnan(b))
- {
- return std::make_pair(false, core::vector3df_SIMD());
- }
- else
- {
- return std::make_pair(false, core::vector3df_SIMD());
- }
- }
-
-
-
-}
-
-}
-}
-}
\ No newline at end of file

license: Apache License 2.0

repo: buildaworldnet/irrlichtbaw

original_message: Delete CElementColor.cpp


message: Delete old bsdf files

diff:
-#ifndef __BSDF_UTIL_H_INCLUDED__
-#define __BSDF_UTIL_H_INCLUDED__
-
-
-
-#endif
\ No newline at end of file

diff:
-#include "../../ext/MitsubaLoader/bsdf/CElementBSDFDiffuse.h"
-
-#include "../../ext/MitsubaLoader/ParserUtil.h"
-#include "../../ext/MitsubaLoader/CSimpleElement.h"
-#include "../../ext/MitsubaLoader/CElementTransform.h"
-#include "irr/asset/IMeshManipulator.h"
-
-namespace irr { namespace ext { namespace MitsubaLoader {
-
-bool CElementBSDFDiffuse::processAttributes(const char** _atts)
-{
- //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 CElementBSDFDiffuse::onEndTag(asset::IAssetManager& _assetManager, IElement* _parent)
-{
- return _parent->processChildData(this);
-}
-
-bool CElementBSDFDiffuse::processChildData(IElement* _child)
-{
- switch (_child->getType())
- {
- case IElement::Type::COLOR:
- {
- CElementString* stringElement = static_cast<CElementString*>(_child);
- std::string elementName = stringElement->getNameAttribute();
-
- if (elementName == "filename")
- {
-
- }
- else
- {
- ParserLog::mitsubaLoaderError("Unqueried attribute " + elementName + " in element \"shape\"");
- }
-
- return true;
- }
- case IElement::Type::TEXTURE:
- {
- CElementFloat* floatElement = static_cast<CElementFloat*>(_child);
- std::string elementName = floatElement->getNameAttribute();
-
- if (elementName == "maxSmoothAngle")
- {
- }
- else
- {
- //warning
- ParserLog::mitsubaLoaderError("Unqueried attribute " + elementName + " in element \"shape\"");
- }
-
- return true;
-
- }
- case IElement::Type::BOOLEAN:
- {
- CElementBoolean* boolElement = static_cast<CElementBoolean*>(_child);
- std::string elementName = boolElement->getNameAttribute();
-
- if (elementName == "faceNormals")
- {
-
- }
- else if (elementName == "flipNormals")
- {
-
- }
- else if (elementName == "flipTexCoords")
- {
-
- }
- else if (elementName == "collapse")
- {
-
- }
- else
- {
- //warning
- ParserLog::mitsubaLoaderError("Unqueried attribute " + elementName + " in element \"shape\"");
- }
-
- return true;
- }
- default:
- ParserLog::wrongChildElement(getLogName(), _child->getLogName());
- return false;
- }
-}
-
-}
-}
-}
\ No newline at end of file

diff:
-#ifndef __C_ELEMENT_BSDF_DIFFUSE_H_INCLUDED__
-#define __C_ELEMENT_BSDF_DIFFUSE_H_INCLUDED__
-
-#include "../../../ext/MitsubaLoader/CSimpleElement.h"
-
-
-
-namespace irr { namespace ext { namespace MitsubaLoader {
-
-class CElementBSDFDiffuse : public IElement
-{
-public:
- CElementBSDFDiffuse()
- :usesTexture(false) {};
-
- virtual bool processAttributes(const char** _args) override;
- virtual bool onEndTag(asset::IAssetManager& _assetManager, IElement* _parent) override;
- virtual IElement::Type getType() const override { return IElement::Type::MATERIAL; };
- virtual std::string getLogName() const override { return "BSDF_diffuse"; };
- virtual bool processChildData(IElement* child) override;
-
-private:
- bool usesTexture;
- union
- {
- //TODO: texture
- core::vectorSIMDf color;
- };
-
-};
-
-
-}
-}
-}
-
-#endif
\ No newline at end of file

original_message: Delete old bsdf files


message: Added new ctor to asset::SAssetBunlde

change_type: MODIFY

diff:
#include "irr/core/Types.h"
#include "irr/core/refctd_dynamic_array.h"
-namespace irr { namespace asset
+namespace irr {
+ namespace asset
{
class IAssetManager;
@@ -101,17 +102,13 @@ class SAssetBundle
public:
SAssetBundle(std::initializer_list<core::smart_refctd_ptr<IAsset>> _contents = {}) : m_contents(new contents_container_t(_contents), core::dont_grab)
{
- auto allSameTypeAndNotNull = [&_contents] {
- if (_contents.size()==0ull)
- return true;
- if (!*_contents.begin())
- return false;
- IAsset::E_TYPE t = (*_contents.begin())->getAssetType();
- for (const auto& ast : _contents)
- if (!ast || ast->getAssetType() != t)
- return false;
- return true;
- };
+ assert(allSameTypeAndNotNull());
+ }
+
+ template<class container_t = core::vector<core::smart_refctd_ptr<IAsset>>>
+ SAssetBundle(container_t&& _contents) : m_contents(new contents_container_t(_contents.size(), nullptr), core::dont_grab)
+ {
+ std::move(_contents.begin(), _contents.end(), m_contents->begin());
assert(allSameTypeAndNotNull());
}
@@ -153,8 +150,22 @@ private:
std::string m_cacheKey;
bool m_isCached = false;
core::smart_refctd_ptr<contents_container_t> m_contents;
+
+ bool allSameTypeAndNotNull()
+ {
+ if (m_contents->size() == 0ull)
+ return true;
+ if (!*m_contents->begin())
+ return false;
+ IAsset::E_TYPE t = (*m_contents->begin())->getAssetType();
+ for (const auto& ast : *m_contents)
+ if (!ast || ast->getAssetType() != t)
+ return false;
+ return true;
+ }
};
-}}
+ }
+}
#endif // __IRR_I_ASSET_H_INCLUDED__
\ No newline at end of file

original_message: Added new ctor to asset::SAssetBunlde


message: Added CElementSampler

diff:
#include "../../ext/MitsubaLoader/ParserUtil.h"
#include "../../ext/MitsubaLoader/IElement.h"
#include "../../ext/MitsubaLoader/CElementTransform.h"
+#include "../../ext/MitsubaLoader/CElementSampler.h"
#include "../../ext/MitsubaLoader/CShapeCreator.h"
#include "../../ext/MitsubaLoader/Shape.h"
@@ -42,6 +43,19 @@ IElement* CElementFactory::createElement(const char* _el, const char** _atts)
return transform;
}
else
+ if (!std::strcmp(_el, "sampler"))
+ {
+ CElementSampler* sampler = new CElementSampler();
+
+ if (!sampler->processAttributes(_atts))
+ {
+ delete sampler;
+ return nullptr;
+ }
+
+ return sampler;
+ }
+ else
{
ParserLog::invalidXMLFileStructure("element " + std::string(_el) + "is unknown. \n");
_IRR_DEBUG_BREAK_IF(true);

change_type: ADD

diff:
+#include "../../ext/MitsubaLoader/CElementSampler.h"
+#include "../../ext/MitsubaLoader/ParserUtil.h"
+#include "../../ext/MitsubaLoader/PropertyElement.h"
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+bool CElementSampler::processAttributes(const char** _atts)
+{
+ static const core::unordered_map<std::string, ESamplerType> acceptableTypes = {
+ std::make_pair("independed", ESamplerType::INDEPENDEND),
+ std::make_pair("stratified", ESamplerType::STRATIFIED),
+ std::make_pair("ldsampler", ESamplerType::LDSAMPLER),
+ std::make_pair("halton", ESamplerType::HALTON),
+ std::make_pair("hammersley", ESamplerType::HAMMERSLEY),
+ std::make_pair("sobol", ESamplerType::SOBOL)
+ };
+
+ //only type is an acceptable argument
+ for (int i = 0; _atts[i]; i += 2)
+ {
+ if (std::strcmp(_atts[i], "type"))
+ {
+ ParserLog::invalidXMLFileStructure(std::string(_atts[i]) + " is not attribute of shape element.");
+ return false;
+ }
+ else
+ {
+ auto samplerType = acceptableTypes.find(_atts[i + 1]);
+ if (samplerType == acceptableTypes.end())
+ {
+ ParserLog::invalidXMLFileStructure("unknown type");
+ _IRR_DEBUG_BREAK_IF(false);
+ return false;
+ }
+
+ data.type = samplerType->second;
+ }
+ }
+
+ return true;
+}
+
+bool CElementSampler::onEndTag(asset::IAssetManager& _assetManager)
+{
+ bool dimensionSet = false;
+ bool scrambleSet = false;
+
+ for (const auto& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::INTEGER &&
+ property.name == "sampleCount")
+ {
+ data.sampleCount = CPropertyElementManager::retriveIntValue(property.value);
+ }
+ else
+ if (property.type == SPropertyElementData::Type::INTEGER &&
+ property.name == "dimension")
+ {
+ data.dimension = CPropertyElementManager::retriveIntValue(property.value);
+ dimensionSet = true;
+ }
+ else
+ if (property.type == SPropertyElementData::Type::INTEGER &&
+ property.name == "scramble")
+ {
+ data.scramble = CPropertyElementManager::retriveIntValue(property.value);
+ scrambleSet = true;
+ }
+ else
+ {
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+
+ //validation
+ switch (data.type)
+ {
+ case ESamplerType::NONE:
+ {
+ ParserLog::invalidXMLFileStructure(getLogName() + ": type not specified");
+
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ case ESamplerType::INDEPENDEND:
+ {
+ if (dimensionSet || scrambleSet)
+ {
+ ParserLog::invalidXMLFileStructure("eeeeee");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+
+ data.dimension = 0;
+
+ return true;
+ }
+ case ESamplerType::STRATIFIED:
+ case ESamplerType::LDSAMPLER:
+ {
+ if (scrambleSet)
+ {
+ ParserLog::invalidXMLFileStructure("eeeeee");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+
+ return true;
+ }
+ case ESamplerType::HALTON:
+ case ESamplerType::HAMMERSLEY:
+ case ESamplerType::SOBOL:
+ {
+ if (dimensionSet)
+ {
+ ParserLog::invalidXMLFileStructure("eeeeee");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+
+ //default value
+ if (!scrambleSet)
+ data.scramble = (data.type == ESamplerType::SOBOL) ? 0 : -1;
+
+ return true;
+ }
+
+ }
+
+ return true;
+}
+
+}
+}
+}
\ No newline at end of file

diff:
+#ifndef __C_ELEMENT_SAMPLER_H_INCLUDED__
+#define __C_ELEMENT_SAMPLER_H_INCLUDED__
+
+#include "../../ext/MitsubaLoader/IElement.h"
+#include "irrlicht.h"
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+enum class ESamplerType
+{
+ NONE,
+ INDEPENDEND,
+ STRATIFIED,
+ LDSAMPLER,
+ HALTON,
+ HAMMERSLEY,
+ SOBOL
+};
+
+struct SSamplerMetadata
+{
+ ESamplerType type;
+ int sampleCount;
+ union
+ {
+ int dimension;
+ int scramble;
+ };
+};
+
+class CElementSampler : public IElement
+{
+public:
+ CElementSampler()
+ :data({ESamplerType::NONE, 4, 4}) {};
+
+ virtual bool processAttributes(const char** _atts) override;
+ virtual bool onEndTag(asset::IAssetManager& _assetManager) override;
+ virtual IElement::Type getType() const override { return IElement::Type::SAMPLER; }
+ virtual std::string getLogName() const override { return "sampler"; }
+
+ SSamplerMetadata getMetadata() const { return data; };
+
+private:
+ SSamplerMetadata data;
+
+};
+
+
+
+}
+}
+}
+
+#endif
\ No newline at end of file

diff:
#include "../../ext/MitsubaLoader/CMitsubaScene.h"
#include "IrrlichtDevice.h"
+#include "C:\IrrlichtBAW\IrrlichtBAW\include\irr\asset\IAssetLoader.h"
#include <stack>
#include <chrono>
@@ -37,6 +38,14 @@ namespace irr { namespace ext { namespace MitsubaLoader {
- (PropertyElement.cpp) these property elements must be finished: translate, rotate, scale, rgb, srgb, spectrum, vector
+ - (PropertyElement.cpp) use regex
+
+ - srgb -> rgb
+
+ - process value of rgb and srgb property correctly when value is in hex
+
+ - <integer> property value validation
+
*/
@@ -64,7 +73,8 @@ const char** CMitsubaLoader::getAssociatedFileExtensions() const
return ext;
}
-asset::IAsset* CMitsubaLoader::loadAsset(io::IReadFile* _file, const SAssetLoadParams& _params, IAssetLoaderOverride* _override, uint32_t _hierarchyLevel)
+
+asset::SAssetBundle CMitsubaLoader::loadAsset(io::IReadFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel)
{
//TODO: error handling
XML_Parser parser = XML_ParserCreate(nullptr);
@@ -87,11 +97,7 @@ asset::IAsset* CMitsubaLoader::loadAsset(io::IReadFile* _file, const SAssetLoadP
case XML_STATUS_ERROR:
{
std::cout << "Parse status: XML_STATUS_ERROR\n";
-
- asset::ICPUMesh* mesh = parserManager.getScene().releaseMesh();
-
- delete mesh;
- return nullptr;
+ return {};
}
break;
case XML_STATUS_OK:
@@ -105,7 +111,8 @@ asset::IAsset* CMitsubaLoader::loadAsset(io::IReadFile* _file, const SAssetLoadP
XML_ParserFree(parser);
- return parserManager.getScene().releaseMesh();
+
+ return parserManager.getScene().releaseMeshes();
}
}

diff:
@@ -36,8 +36,7 @@ public:
//virtual uint64_t getSupportedAssetTypesBitfield() const { return 0; }
//! Loads an asset from an opened file, returns nullptr in case of failure.
- virtual asset::IAsset* loadAsset(io::IReadFile* _file, const SAssetLoadParams& _params, IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) override;
-
+ virtual asset::SAssetBundle loadAsset(io::IReadFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) override;
private:
IrrlichtDevice* m_device;
asset::IAssetManager& m_assetManager;

diff:
#include "../../ext/MitsubaLoader/Shape.h"
#include "../../include/matrix4SIMD.h"
+#include "../../ext/MitsubaLoader/CElementSampler.h"
namespace irr { namespace ext { namespace MitsubaLoader {
@@ -30,8 +31,6 @@ bool CMitsubaScene::processAttributes(const char** _atts)
bool CMitsubaScene::onEndTag(asset::IAssetManager& _assetManager)
{
- mesh->recalculateBoundingBox();
-
return true;
}
@@ -49,58 +48,17 @@ bool CMitsubaScene::processChildData(IElement* _child)
return false;
}
- const asset::ICPUMesh* shapeMesh = shape->getMesh();
- return appendMesh(shapeMesh, shape->getTransformMatrix());
- }
- default:
- ParserLog::invalidXMLFileStructure(_child->getLogName() + " is not a child element of the scene element");
- return true;
- }
+ const core::smart_refctd_ptr<asset::ICPUMesh> shapeMesh = shape->getMesh();
+ meshes.push_back(core::smart_refctd_ptr<asset::ICPUMesh>(shapeMesh));
return true;
}
-
-bool CMitsubaScene::appendMesh(const asset::ICPUMesh* _mesh, const core::matrix4SIMD& _transform)
-{
- if (!_mesh)
- {
+ default:
+ ParserLog::invalidXMLFileStructure(_child->getLogName() + " is not a child element of the scene element");
_IRR_DEBUG_BREAK_IF(true);
return false;
}
-
- _mesh->grab();
-
- for (int i = 0; i < _mesh->getMeshBufferCount(); i++)
- {
- //here vertex positions and normals are premultiplied with world transfrom matrix
- //TODO: skip this step if transform is identity matrix
-
- asset::ICPUMeshBuffer* submesh = _mesh->getMeshBuffer(i);
-
- core::matrix4SIMD normalTransform; //normalTransform = transpose(inverse(_transform));
- _transform.getInverseTransform(normalTransform);
- normalTransform = normalTransform.getTransposed();
-
- const size_t vxCount = submesh->calcVertexCount();
- for (int i = 0; i < vxCount; i++)
- {
- core::vectorSIMDf pos = submesh->getPosition(i);
- core::vectorSIMDf normal;
- submesh->getAttribute(normal, asset::E_VERTEX_ATTRIBUTE_ID::EVAI_ATTR3, i);
-
- _transform.transformVect(pos);
- normalTransform.transformVect(normal);
-
- submesh->setAttribute(pos,submesh->getPositionAttributeIx(), i);
- submesh->setAttribute(normal, asset::E_VERTEX_ATTRIBUTE_ID::EVAI_ATTR3, i);
-
-
- }
-
- mesh->addMeshBuffer(submesh);
- }
-
return true;
}

diff:
@@ -13,23 +13,16 @@ namespace irr { namespace ext { namespace MitsubaLoader {
class CMitsubaScene : public IElement
{
public:
- //! Constructor
- CMitsubaScene()
- :mesh(new asset::SCPUMesh) {}
-
virtual bool processAttributes(const char** _arguments) override;
virtual bool onEndTag(asset::IAssetManager& assetManager) override;
virtual IElement::Type getType() const override { return IElement::Type::SCENE; };
virtual std::string getLogName() const override { return "scene"; };
virtual bool processChildData(IElement* child) override;
- asset::SCPUMesh* releaseMesh() { return mesh; mesh = nullptr; }
-
+ asset::SAssetBundle releaseMeshes() { return asset::SAssetBundle(std::move(meshes)); }
private:
- asset::SCPUMesh* mesh;
-
- bool appendMesh(const asset::ICPUMesh* _mesh, const core::matrix4SIMD& _transform);
+ core::vector<core::smart_refctd_ptr<asset::ICPUMesh>> meshes;
};
}

diff:
@@ -298,7 +298,8 @@ asset::ICPUMesh* CShapeCreator::createOBJ(asset::IAssetManager& _assetManager, c
return nullptr;
}
- asset::ICPUMesh* mesh = static_cast<asset::ICPUMesh*>(_assetManager.getAsset(fileName, asset::IAssetLoader::SAssetLoadParams()));
+ asset::SAssetBundle bundle = _assetManager.getAsset(fileName, asset::IAssetLoader::SAssetLoadParams());
+ asset::ICPUMesh* mesh = static_cast<asset::ICPUMesh*>(bundle.getContents().first->get());
if (mesh == nullptr)
return nullptr;

diff:
@@ -18,6 +18,7 @@ public:
{
NONE,
SCENE,
+ SAMPLER,
//shapes
SHAPE,

diff:
@@ -92,7 +92,7 @@ private:
ParserFlowController pfc;
static constexpr const char* propertyElements[] = {
- "float", "string", "boolean", "int",
+ "float", "string", "boolean", "integer",
"rgb", "srgb", "spectrum",
"point", "vector",
"matrix", "rotate", "translate", "scale",

diff:
@@ -136,7 +136,7 @@ int CPropertyElementManager::retriveIntValue(const std::string& _data)
std::stringstream ss;
ss << _data;
- int result = std::numeric_limits<int>::quiet_NaN();
+ int result = 0;
ss >> result;
return result;
@@ -206,7 +206,7 @@ core::vectorSIMDf CPropertyElementManager::retriveVector(const std::string& _dat
{
if (i == 3)
{
- vectorData[3] = 0.0f;
+ vectorData[3] = 1.0f;
break;
}

diff:
@@ -89,7 +89,7 @@ bool CShape::onEndTag(asset::IAssetManager& _assetManager)
return false;
}
- if (mesh == nullptr)
+ if (mesh.get() == nullptr)
return false;
return true;

diff:
@@ -12,7 +12,7 @@ public:
CShape()
: mesh(nullptr) {};
- inline asset::ICPUMesh* getMesh() { return mesh; }
+ inline core::smart_refctd_ptr<asset::ICPUMesh> getMesh() { return mesh; }
inline core::matrix4SIMD& getTransformMatrix() { return transform; }
inline const core::matrix4SIMD& getTransformMatrix() const { return transform; }
@@ -34,7 +34,7 @@ protected:
protected:
std::string type;
- asset::ICPUMesh* mesh;
+ core::smart_refctd_ptr<asset::ICPUMesh> mesh;
core::matrix4SIMD transform;
};

original_message: Added CElementSampler


message: Added CElementFilm

diff:
#include "../../ext/MitsubaLoader/IElement.h"
#include "../../ext/MitsubaLoader/CElementTransform.h"
#include "../../ext/MitsubaLoader/CElementSampler.h"
+#include "../../ext/MitsubaLoader/CElementFilm.h"
#include "../../ext/MitsubaLoader/CShapeCreator.h"
#include "../../ext/MitsubaLoader/Shape.h"
@@ -37,6 +38,7 @@ IElement* CElementFactory::createElement(const char* _el, const char** _atts)
if (!transform->processAttributes(_atts))
{
delete transform;
+ _IRR_DEBUG_BREAK_IF(true);
return nullptr;
}
@@ -50,12 +52,27 @@ IElement* CElementFactory::createElement(const char* _el, const char** _atts)
if (!sampler->processAttributes(_atts))
{
delete sampler;
+ _IRR_DEBUG_BREAK_IF(true);
return nullptr;
}
return sampler;
}
else
+ if (!std::strcmp(_el, "film"))
+ {
+ CElementFilm* film = new CElementFilm();
+
+ if (!film->processAttributes(_atts))
+ {
+ delete film;
+ _IRR_DEBUG_BREAK_IF(true);
+ return nullptr;
+ }
+
+ return film;
+ }
+ else
{
ParserLog::invalidXMLFileStructure("element " + std::string(_el) + "is unknown. \n");
_IRR_DEBUG_BREAK_IF(true);

diff:
+#include "../../ext/MitsubaLoader/CElementFilm.h"
+#include "../../ext/MitsubaLoader/ParserUtil.h"
+#include "../../ext/MitsubaLoader/PropertyElement.h"
+
+#include <functional>
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+bool CElementFilm::processAttributes(const char** _atts)
+{
+ static const core::unordered_map<std::string, EFilmType> acceptableTypes = {
+ std::make_pair("hdrfilm", EFilmType::HDR_FILM),
+ std::make_pair("tiledhdrfilm", EFilmType::TILED_HDR_FILM),
+ std::make_pair("ldrfilm", EFilmType::LDR_FILM),
+ std::make_pair("mfilm", EFilmType::M_FILM)
+ };
+
+ //only type is an acceptable argument
+ for (int i = 0; _atts[i]; i += 2)
+ {
+ if (std::strcmp(_atts[i], "type"))
+ {
+ ParserLog::invalidXMLFileStructure(std::string(_atts[i]) + " is not attribute of shape element.");
+ return false;
+ }
+ else
+ {
+ auto samplerType = acceptableTypes.find(_atts[i + 1]);
+ if (samplerType == acceptableTypes.end())
+ {
+ ParserLog::invalidXMLFileStructure("unknown type");
+ _IRR_DEBUG_BREAK_IF(false);
+ return false;
+ }
+
+ data.type = samplerType->second;
+
+ //set default values
+ switch (data.type)
+ {
+ case EFilmType::HDR_FILM:
+ {
+ data.hdrFilmData.fileFormat = EHDRFileFormat::OPENEXR;
+ data.hdrFilmData.componentFormat = EComponentFormat::FLOAT16;
+ data.hdrFilmData.attachLog = true;
+ data.hdrFilmData.banner = true;
+ data.hdrFilmData.highQualityEdges = false;
+ }
+ break;
+ case EFilmType::TILED_HDR_FILM:
+ {
+ data.tiledHdrFilmData.componentFormat = EComponentFormat::FLOAT16;
+ }
+ break;
+ case EFilmType::LDR_FILM:
+ {
+ data.ldrFilmData.fileFormat = ELDRFileFormat::PNG;
+ data.ldrFilmData.tonemapMethod = ETonemapMethod::GAMMA;
+ data.ldrFilmData.gamma = -1.0f;
+ data.ldrFilmData.exposure = 0;
+ data.ldrFilmData.key = 0.18f;
+ data.ldrFilmData.burn = 0.0f;
+ data.ldrFilmData.banner = true;
+ data.ldrFilmData.highQualityEdges = false;
+ }
+ break;
+ case EFilmType::M_FILM:
+ {
+ data.width = 1;
+ data.height = 1;
+ data.pixelFormat = EPixelFormat::LUMINANCE;
+
+ data.mFilmData.fileFormat = EMFileFormat::MATLAB;
+ data.mFilmData.digits = 4;
+ data.mFilmData.variable = "data";
+ data.mFilmData.highQualityEdges = true;
+ }
+ break;
+ }
+ }
+ }
+
+ return true;
+}
+
+bool CElementFilm::onEndTag(asset::IAssetManager& _assetManager)
+{
+ switch (data.type)
+ {
+ case EFilmType::HDR_FILM:
+ return processHDRFilmProperties();
+
+ case EFilmType::TILED_HDR_FILM:
+ return processTiledHDRFilmProperties();
+
+ case EFilmType::LDR_FILM:
+ return processLDRFilmProperties();
+
+ case EFilmType::M_FILM:
+ return processMFilmProperties();
+
+ default:
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+}
+
+bool CElementFilm::processSharedDataProperty(const SPropertyElementData& _property)
+{
+ if (_property.type == SPropertyElementData::Type::INTEGER)
+ {
+ if (_property.name == "width")
+ {
+ data.width = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "height")
+ {
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "cropOffsetX")
+ {
+ data.isCropUsed = true;
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "cropOffsetY")
+ {
+ data.isCropUsed = true;
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "cropWidth")
+ {
+ data.isCropUsed = true;
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "cropHeight")
+ {
+ data.isCropUsed = true;
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (_property.type == SPropertyElementData::Type::STRING &&
+ _property.name == "pixelFormat")
+ {
+ if (_property.value == "luminance") data.pixelFormat = EPixelFormat::LUMINANCE; else
+ if (_property.value == "luminanceAlpha") data.pixelFormat = EPixelFormat::LUMINANCE_ALPHA; else
+ if (_property.value == "rgb") data.pixelFormat = EPixelFormat::RGB; else
+ if (_property.value == "rgba") data.pixelFormat = EPixelFormat::RGBA; else
+ if (_property.value == "xyz") data.pixelFormat = EPixelFormat::XYZ; else
+ if (_property.value == "xyza") data.pixelFormat = EPixelFormat::XYZA; else
+ if (_property.value == "spectrum") data.pixelFormat = EPixelFormat::SPECTRUM; else
+ if (_property.value == "spectrumAlpha") data.pixelFormat = EPixelFormat::SPECTRUM_ALPHA; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unkown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+
+ return true;
+}
+
+bool CElementFilm::processHDRFilmProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "fileFormat")
+ {
+ if (property.value == "openexr") data.hdrFilmData.fileFormat = EHDRFileFormat::OPENEXR; else
+ if (property.value == "rgbe") data.hdrFilmData.fileFormat = EHDRFileFormat::RGBE; else
+ if (property.value == "pfm") data.hdrFilmData.fileFormat = EHDRFileFormat::PFM; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "componentFormat")
+ {
+ if (property.value == "float16") data.hdrFilmData.componentFormat = EComponentFormat::FLOAT16; else
+ if (property.value == "float32") data.hdrFilmData.componentFormat = EComponentFormat::FLOAT32; else
+ if (property.value == "uint32") data.hdrFilmData.componentFormat = EComponentFormat::UINT32; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::BOOLEAN)
+ {
+ if (property.name == "attachLog")
+ {
+ data.hdrFilmData.attachLog = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else if (property.name == "banner")
+ {
+ data.hdrFilmData.banner = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else if (property.name == "hightQualityEdges")
+ {
+ data.hdrFilmData.highQualityEdges = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementFilm::processTiledHDRFilmProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "componentFormat")
+ {
+ if (property.value == "float16") data.tiledHdrFilmData.componentFormat = EComponentFormat::FLOAT16; else
+ if (property.value == "float32") data.tiledHdrFilmData.componentFormat = EComponentFormat::FLOAT32; else
+ if (property.value == "uint32") data.tiledHdrFilmData.componentFormat = EComponentFormat::UINT32;
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if (!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementFilm::processLDRFilmProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "fileFormat")
+ {
+ if (property.value == "png") data.ldrFilmData.fileFormat = ELDRFileFormat::PNG; else
+ if (property.value == "jpeg") data.ldrFilmData.fileFormat = ELDRFileFormat::JPEG; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "tonemapMethod")
+ {
+ if (property.value == "gamma") data.ldrFilmData.tonemapMethod = ETonemapMethod::GAMMA; else
+ if (property.value == "reinhard") data.ldrFilmData.tonemapMethod = ETonemapMethod::REINHARD; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::BOOLEAN)
+ {
+ if (property.name == "banner")
+ {
+ data.ldrFilmData.banner = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else if (property.name == "hightQualityEdges")
+ {
+ data.ldrFilmData.highQualityEdges = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::FLOAT)
+ {
+ if (property.name == "gamma")
+ {
+ data.ldrFilmData.gamma = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "exposure")
+ {
+ data.ldrFilmData.exposure = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "key")
+ {
+ data.ldrFilmData.key = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "burn")
+ {
+ data.ldrFilmData.burn = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementFilm::processMFilmProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING)
+ {
+ if (property.name == "fileFormat")
+ {
+ if (property.value == "matlab") data.mFilmData.fileFormat = EMFileFormat::MATLAB; else
+ if (property.value == "mathematica") data.mFilmData.fileFormat = EMFileFormat::MATHEMATICA; else
+ if (property.value == "numpy") data.mFilmData.fileFormat = EMFileFormat::NUMPY; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if (property.name == "variable")
+ {
+ data.mFilmData.variable = property.value;
+ }
+ else if(property.name != "pixelFormat")
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::INTEGER &&
+ property.name == "digits")
+ {
+ data.mFilmData.digits = CPropertyElementManager::retriveIntValue(property.value);
+ }
+ else
+ if (property.type == SPropertyElementData::Type::BOOLEAN &&
+ property.name == "highQualityEdges")
+ {
+ data.mFilmData.highQualityEdges = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+}
+}
+}
\ No newline at end of file

diff:
+#ifndef __C_ELEMENT_FILM_H_INCLUDED__
+#define __C_ELEMENT_FILM_H_INCLUDED__
+
+#include "../../ext/MitsubaLoader/IElement.h"
+#include "irrlicht.h"
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+ /*The options are float16, float32, or
+ uint32. (Default: float16).*/
+
+enum class ETonemapMethod
+{
+ GAMMA,
+ REINHARD
+};
+
+enum class EComponentFormat
+{
+ FLOAT16,
+ FLOAT32,
+ UINT32
+};
+
+enum class EHDRFileFormat
+{
+ OPENEXR,
+ RGBE,
+ PFM
+};
+
+enum class ELDRFileFormat
+{
+ PNG,
+ JPEG
+};
+
+enum class EMFileFormat
+{
+ MATLAB,
+ MATHEMATICA,
+ NUMPY
+};
+
+enum class EFilmType
+{
+ NONE,
+ HDR_FILM,
+ TILED_HDR_FILM,
+ LDR_FILM,
+ M_FILM
+};
+
+enum class EPixelFormat
+{
+ LUMINANCE,
+ LUMINANCE_ALPHA,
+ RGB,
+ RGBA,
+ XYZ,
+ XYZA,
+ SPECTRUM,
+ SPECTRUM_ALPHA
+};
+
+struct SFilmMetadata
+{
+ SFilmMetadata()
+ :type(EFilmType::NONE) {};
+
+ SFilmMetadata(const SFilmMetadata& other)
+ :type(other.type), width(other.width), height(other.height),
+ isCropUsed(other.isCropUsed), cropOffsetX(other.cropOffsetX), cropOffsetY(other.cropOffsetY),
+ cropWidth(other.cropWidth), cropHeight(other.cropHeight), pixelFormat(other.pixelFormat)
+ {
+ switch (other.type)
+ {
+ case EFilmType::HDR_FILM:
+ hdrFilmData = other.hdrFilmData;
+ case EFilmType::TILED_HDR_FILM:
+ tiledHdrFilmData = other.tiledHdrFilmData;
+ case EFilmType::LDR_FILM:
+ ldrFilmData = other.ldrFilmData;
+ case EFilmType::M_FILM:
+ mFilmData = other.mFilmData;
+ }
+ }
+
+ ~SFilmMetadata()
+ {
+
+ }
+
+ EFilmType type;
+
+ int width = 768;
+ int height = 576;
+
+ bool isCropUsed = false;
+ int cropOffsetX = 0.0f;
+ int cropOffsetY = 0.0f;
+ int cropWidth = 0.0f;
+ int cropHeight = 0.0f;
+
+ //rfilter
+
+ EPixelFormat pixelFormat = EPixelFormat::RGB;
+
+ union
+ {
+ struct HdrFilmData
+ {
+ EHDRFileFormat fileFormat;
+ EComponentFormat componentFormat;
+ bool attachLog;
+ bool banner;
+ bool highQualityEdges;
+ } hdrFilmData;
+
+ struct TiledHdrFilmData
+ {
+ EComponentFormat componentFormat;
+ } tiledHdrFilmData;
+
+ struct LdrFilmData
+ {
+ ELDRFileFormat fileFormat;
+ ETonemapMethod tonemapMethod;
+ float gamma;
+ float exposure;
+ float key;
+ float burn;
+ bool banner;
+ bool highQualityEdges;
+
+ } ldrFilmData;
+
+ struct MFilmData
+ {
+ EMFileFormat fileFormat;
+ int digits;
+ std::string variable;
+ bool highQualityEdges;
+
+ } mFilmData;
+ };
+};
+
+class CElementFilm : public IElement
+{
+public:
+ virtual bool processAttributes(const char** _atts) override;
+ virtual bool onEndTag(asset::IAssetManager& _assetManager) override;
+ virtual IElement::Type getType() const override { return IElement::Type::SAMPLER; }
+ virtual std::string getLogName() const override { return "sampler"; }
+
+ SFilmMetadata getMetadata() const { return data; };
+
+private:
+ bool processSharedDataProperty(const SPropertyElementData& _property);
+ bool processHDRFilmProperties();
+ bool processTiledHDRFilmProperties();
+ bool processLDRFilmProperties();
+ bool processMFilmProperties();
+
+private:
+ SFilmMetadata data;
+
+};
+
+
+
+}
+}
+}
+
+#endif
\ No newline at end of file

diff:
@@ -7,7 +7,7 @@ namespace irr { namespace ext { namespace MitsubaLoader {
bool CElementSampler::processAttributes(const char** _atts)
{
static const core::unordered_map<std::string, ESamplerType> acceptableTypes = {
- std::make_pair("independed", ESamplerType::INDEPENDEND),
+ std::make_pair("independent", ESamplerType::INDEPENDENT),
std::make_pair("stratified", ESamplerType::STRATIFIED),
std::make_pair("ldsampler", ESamplerType::LDSAMPLER),
std::make_pair("halton", ESamplerType::HALTON),
@@ -83,7 +83,7 @@ bool CElementSampler::onEndTag(asset::IAssetManager& _assetManager)
_IRR_DEBUG_BREAK_IF(true);
return false;
}
- case ESamplerType::INDEPENDEND:
+ case ESamplerType::INDEPENDENT:
{
if (dimensionSet || scrambleSet)
{

diff:
@@ -9,7 +9,7 @@ namespace irr { namespace ext { namespace MitsubaLoader {
enum class ESamplerType
{
NONE,
- INDEPENDEND,
+ INDEPENDENT,
STRATIFIED,
LDSAMPLER,
HALTON,

diff:
@@ -55,8 +55,7 @@ bool CMitsubaScene::processChildData(IElement* _child)
}
default:
ParserLog::invalidXMLFileStructure(_child->getLogName() + " is not a child element of the scene element");
- _IRR_DEBUG_BREAK_IF(true);
- return false;
+ return true;
}
return true;

original_message: Added CElementFilm


message: Added CElementSensor

diff:
#include "../../ext/MitsubaLoader/ParserUtil.h"
#include "../../ext/MitsubaLoader/IElement.h"
#include "../../ext/MitsubaLoader/CElementTransform.h"
+#include "../../ext/MitsubaLoader/CElementSensor.h"
#include "../../ext/MitsubaLoader/CElementSampler.h"
#include "../../ext/MitsubaLoader/CElementFilm.h"
#include "../../ext/MitsubaLoader/CShapeCreator.h"
@@ -45,6 +46,20 @@ IElement* CElementFactory::createElement(const char* _el, const char** _atts)
return transform;
}
else
+ if (!std::strcmp(_el, "sensor"))
+ {
+ CElementSensor* sensor = new CElementSensor();
+
+ if (!sensor->processAttributes(_atts))
+ {
+ delete sensor;
+ _IRR_DEBUG_BREAK_IF(true);
+ return nullptr;
+ }
+
+ return sensor;
+ }
+ else
if (!std::strcmp(_el, "sampler"))
{
CElementSampler* sampler = new CElementSampler();

diff:
@@ -77,13 +77,54 @@ struct SFilmMetadata
{
case EFilmType::HDR_FILM:
hdrFilmData = other.hdrFilmData;
+ break;
+
+ case EFilmType::TILED_HDR_FILM:
+ tiledHdrFilmData = other.tiledHdrFilmData;
+ break;
+
+ case EFilmType::LDR_FILM:
+ ldrFilmData = other.ldrFilmData;
+ break;
+
+ case EFilmType::M_FILM:
+ mFilmData = other.mFilmData;
+ break;
+ }
+ }
+
+ SFilmMetadata& operator=(const SFilmMetadata& other)
+ {
+ type = other.type;
+ width = other.width;
+ height = other.height;
+ isCropUsed = other.isCropUsed;
+ cropOffsetX = other.cropOffsetX;
+ cropOffsetY = other.cropOffsetY;
+ cropWidth = other.cropWidth;
+ cropHeight = other.cropHeight;
+ pixelFormat = other.pixelFormat;
+
+ switch (other.type)
+ {
+ case EFilmType::HDR_FILM:
+ hdrFilmData = other.hdrFilmData;
+ break;
+
case EFilmType::TILED_HDR_FILM:
tiledHdrFilmData = other.tiledHdrFilmData;
+ break;
+
case EFilmType::LDR_FILM:
ldrFilmData = other.ldrFilmData;
+ break;
+
case EFilmType::M_FILM:
mFilmData = other.mFilmData;
+ break;
}
+
+ return *this;
}
~SFilmMetadata()
@@ -151,8 +192,8 @@ class CElementFilm : public IElement
public:
virtual bool processAttributes(const char** _atts) override;
virtual bool onEndTag(asset::IAssetManager& _assetManager) override;
- virtual IElement::Type getType() const override { return IElement::Type::SAMPLER; }
- virtual std::string getLogName() const override { return "sampler"; }
+ virtual IElement::Type getType() const override { return IElement::Type::FILM; }
+ virtual std::string getLogName() const override { return "film"; }
SFilmMetadata getMetadata() const { return data; };

diff:
+#include "../../ext/MitsubaLoader/CElementSensor.h"
+#include "../../ext/MitsubaLoader/CElementTransform.h"
+#include "../../ext/MitsubaLoader/ParserUtil.h"
+#include "../../ext/MitsubaLoader/PropertyElement.h"
+
+
+#include <functional>
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+bool CElementSensor::processAttributes(const char** _atts)
+{
+ static const core::unordered_map<std::string, ESensorType> acceptableTypes = {
+ std::make_pair("perspective", ESensorType::PERSPECTIVE),
+ std::make_pair("thinlens", ESensorType::THINLENS),
+ std::make_pair("orthographic", ESensorType::ORTHOGRAPHIC),
+ std::make_pair("telecentric", ESensorType::TELECENTRIC),
+ std::make_pair("spherical", ESensorType::SPHERICAL),
+ std::make_pair("irradiancemeter", ESensorType::IRRADIANCEMETER),
+ std::make_pair("radiancemeter", ESensorType::RADIANCEMETER),
+ std::make_pair("fluencemeter", ESensorType::FLUENCEMETER)
+ };
+
+ //only type is an acceptable argument
+ for (int i = 0; _atts[i]; i += 2)
+ {
+ if (std::strcmp(_atts[i], "type"))
+ {
+ ParserLog::invalidXMLFileStructure(std::string(_atts[i]) + " is not attribute of shape element.");
+ return false;
+ }
+ else
+ {
+ auto samplerType = acceptableTypes.find(_atts[i + 1]);
+ if (samplerType == acceptableTypes.end())
+ {
+ ParserLog::invalidXMLFileStructure("unknown type");
+ _IRR_DEBUG_BREAK_IF(false);
+ return false;
+ }
+
+ data.type = samplerType->second;
+
+ //set default values
+ switch (data.type)
+ {
+ case ESensorType::PERSPECTIVE:
+ {
+ data.perspectiveData.focalLength = "50mm";
+ data.perspectiveData.fovAxis = EFOVAxis::X;
+ data.perspectiveData.fov = 0.0f;
+ data.perspectiveData.nearClip = 0.01f;
+ data.perspectiveData.nearClip = 10000.0f;
+
+ }
+ break;
+ case ESensorType::THINLENS:
+ {
+ data.thinlensData.focalLength = "50mm";
+ data.thinlensData.fovAxis = EFOVAxis::X;
+ data.thinlensData.fov = 0.0f;
+ data.thinlensData.nearClip = 0.01f;
+ data.thinlensData.nearClip = 10000.0f;
+ data.thinlensData.apertureRadius = 0.0f;
+ data.thinlensData.focusDistance = 0.0f;
+ }
+ break;
+ case ESensorType::ORTHOGRAPHIC:
+ {
+ data.thinlensData.nearClip = 0.01f;
+ data.thinlensData.nearClip = 10000.0f;
+ }
+ break;
+ case ESensorType::TELECENTRIC:
+ {
+ data.thinlensData.nearClip = 0.01f;
+ data.thinlensData.nearClip = 10000.0f;
+ data.thinlensData.apertureRadius = 0.0f;
+ data.thinlensData.focusDistance = 0.0f;
+ }
+ break;
+ default:
+ assert(true);
+ }
+ }
+ }
+
+ return true;
+}
+
+bool CElementSensor::processChildData(IElement* _child)
+{
+ switch (_child->getType())
+ {
+ case IElement::Type::FILM:
+ {
+ data.filmData = static_cast<CElementFilm*>(_child)->getMetadata();
+ return true;
+ }
+
+ case IElement::Type::SAMPLER:
+ {
+ data.samperData = static_cast<CElementSampler*>(_child)->getMetadata();
+ return true;
+ }
+ case IElement::Type::TRANSFORM:
+ {
+ transform = static_cast<CElementTransform*>(_child)->getMatrix();
+ return true;
+ }
+ default:
+ {
+ ParserLog::invalidXMLFileStructure(_child->getLogName() + "is not a child of sensor element");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+}
+
+bool CElementSensor::onEndTag(asset::IAssetManager& _assetManager)
+{
+ switch (data.type)
+ {
+ case ESensorType::PERSPECTIVE:
+ data.perspectiveData.toWorld = transform;
+ return processPerspectiveSensorProperties();
+
+ case ESensorType::THINLENS:
+ data.thinlensData.toWorld = transform;
+ return processThinlensSensorProperties();
+
+ case ESensorType::ORTHOGRAPHIC:
+ data.orthographicData.toWorld = transform;
+ return processOrthographicSensorProperties();
+
+ case ESensorType::TELECENTRIC:
+ data.telecentricData.toWorld = transform;
+ return processTelecentricSensorProperties();
+
+ case ESensorType::SPHERICAL:
+ data.sphericalData.toWorld = transform;
+ return true;
+
+ case ESensorType::IRRADIANCEMETER:
+ return true;
+
+ case ESensorType::RADIANCEMETER:
+ data.telecentricData.toWorld = transform;
+ return true;
+
+ case ESensorType::FLUENCEMETER:
+ data.telecentricData.toWorld = transform;
+ return true;
+
+ default:
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+}
+
+bool CElementSensor::processSharedDataProperty(const SPropertyElementData& _property)
+{
+ if (_property.type == SPropertyElementData::Type::FLOAT)
+ {
+ if (_property.name == "shutterOpen")
+ {
+ data.shutterOpen = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "shutterClose")
+ {
+ data.shutterClose = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unkown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+
+ return true;
+}
+
+bool CElementSensor::processPerspectiveSensorProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "focalLength")
+ {
+ data.perspectiveData.focalLength = property.value;
+ }
+ else
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "fovAxis")
+ {
+ if (property.value == "x") data.perspectiveData.fovAxis = EFOVAxis::X; else
+ if (property.value == "y") data.perspectiveData.fovAxis = EFOVAxis::Y; else
+ if (property.value == "diagonal") data.perspectiveData.fovAxis = EFOVAxis::DIAGONAL; else
+ if (property.value == "smaller") data.perspectiveData.fovAxis = EFOVAxis::SMALLER; else
+ if (property.value == "larger") data.perspectiveData.fovAxis = EFOVAxis::LARGER; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::FLOAT)
+ {
+ if (property.name == "fov")
+ {
+ data.perspectiveData.fov = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "nearClip")
+ {
+ data.perspectiveData.nearClip = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "farClip")
+ {
+ data.perspectiveData.farClip = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementSensor::processThinlensSensorProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "focalLength")
+ {
+ data.perspectiveData.focalLength = property.value;
+ }
+ else
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "fovAxis")
+ {
+ if (property.value == "x") data.thinlensData.fovAxis = EFOVAxis::X; else
+ if (property.value == "y") data.thinlensData.fovAxis = EFOVAxis::Y; else
+ if (property.value == "diagonal") data.thinlensData.fovAxis = EFOVAxis::DIAGONAL; else
+ if (property.value == "smaller") data.thinlensData.fovAxis = EFOVAxis::SMALLER; else
+ if (property.value == "larger") data.thinlensData.fovAxis = EFOVAxis::LARGER; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::FLOAT)
+ {
+ if (property.name == "fov")
+ {
+ data.thinlensData.fov = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "nearClip")
+ {
+ data.thinlensData.nearClip = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "farClip")
+ {
+ data.thinlensData.farClip = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "apertureRadius")
+ {
+ data.thinlensData.apertureRadius = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "focusDistance")
+ {
+ data.thinlensData.focusDistance = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementSensor::processOrthographicSensorProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::FLOAT)
+ {
+
+ if (property.name == "nearClip")
+ {
+ data.perspectiveData.nearClip = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "farClip")
+ {
+ data.perspectiveData.farClip = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementSensor::processTelecentricSensorProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::FLOAT)
+ {
+
+ if (property.name == "nearClip")
+ {
+ data.perspectiveData.nearClip = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "farClip")
+ {
+ data.perspectiveData.farClip = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "apertureRadius")
+ {
+ data.telecentricData.apertureRadius = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "focusDistance")
+ {
+ data.telecentricData.focusDistance = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+}
+}
+}
\ No newline at end of file

diff:
+#ifndef __C_ELEMENT_SENSOR_H_INCLUDED__
+#define __C_ELEMENT_SENSOR_H_INCLUDED__
+
+#include "../../ext/MitsubaLoader/IElement.h"
+#include "../../ext/MitsubaLoader/CElementFilm.h"
+#include "../../ext/MitsubaLoader/CElementSampler.h"
+
+#include "irrlicht.h"
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+enum class ESensorType
+{
+ NONE,
+ PERSPECTIVE,
+ THINLENS,
+ ORTHOGRAPHIC,
+ TELECENTRIC,
+ SPHERICAL,
+ IRRADIANCEMETER,
+ RADIANCEMETER,
+ FLUENCEMETER
+};
+
+enum class EFOVAxis
+{
+ X,
+ Y,
+ DIAGONAL,
+ SMALLER,
+ LARGER
+};
+
+struct SSensorMetadata
+{
+ SSensorMetadata()
+ :type(ESensorType::NONE) {};
+
+ SSensorMetadata(const SSensorMetadata& other)
+ : type(other.type), shutterOpen(other.shutterOpen), shutterClose(other.shutterClose)
+ {
+ switch (other.type)
+ {
+ case ESensorType::PERSPECTIVE:
+ perspectiveData = other.perspectiveData;
+ break;
+
+ case ESensorType::THINLENS:
+ thinlensData = other.thinlensData;
+ break;
+
+ case ESensorType::ORTHOGRAPHIC:
+ perspectiveData = other.perspectiveData;
+ break;
+
+ case ESensorType::TELECENTRIC:
+ telecentricData = other.telecentricData;
+ break;
+
+ case ESensorType::SPHERICAL:
+ sphericalData = other.sphericalData;
+ break;
+
+ case ESensorType::RADIANCEMETER:
+ radiancemeterData = other.radiancemeterData;
+ break;
+
+ case ESensorType::FLUENCEMETER:
+ fluencemeterData = other.fluencemeterData;
+ break;
+
+ default:
+ assert(false);
+ }
+ }
+
+ ~SSensorMetadata()
+ {
+
+ }
+
+ SSamplerMetadata samperData;
+ SFilmMetadata filmData;
+
+ ESensorType type;
+
+ float shutterOpen = 0.0f;
+ float shutterClose = 0.0f;
+
+ union
+ {
+ struct PerspectiveData
+ {
+ core::matrix4SIMD toWorld;
+ std::string focalLength;
+ EFOVAxis fovAxis;
+ float fov;
+ float nearClip;
+ float farClip;
+
+ } perspectiveData;
+
+ struct ThinlensData
+ {
+ core::matrix4SIMD toWorld;
+ std::string focalLength;
+ EFOVAxis fovAxis;
+ float fov;
+ float nearClip;
+ float farClip;
+ float apertureRadius;
+ float focusDistance;
+
+ } thinlensData;
+
+ struct OrthographicData
+ {
+ core::matrix4SIMD toWorld;
+ float nearClip;
+ float farClip;
+
+ } orthographicData;
+
+ struct TelecentricData
+ {
+ core::matrix4SIMD toWorld;
+ float nearClip;
+ float farClip;
+ float apertureRadius;
+ float focusDistance;
+
+ } telecentricData;
+
+ struct SphericalData
+ {
+ core::matrix4SIMD toWorld;
+
+ } sphericalData;
+
+ struct RadiancemeterData
+ {
+ core::matrix4SIMD toWorld;
+
+ } radiancemeterData;
+
+ struct FluencemeterData
+ {
+ core::matrix4SIMD toWorld;
+
+ } fluencemeterData;
+ };
+};
+
+class CElementSensor : public IElement
+{
+public:
+ virtual bool processAttributes(const char** _atts) override;
+ virtual bool processChildData(IElement* _child) override;
+ virtual bool onEndTag(asset::IAssetManager& _assetManager) override;
+ virtual IElement::Type getType() const override { return IElement::Type::SENSOR; }
+ virtual std::string getLogName() const override { return "sensor"; }
+
+ SSensorMetadata getMetadata() { return data; }
+
+private:
+ bool processSharedDataProperty(const SPropertyElementData& _property);
+ bool processPerspectiveSensorProperties();
+ bool processThinlensSensorProperties();
+ bool processOrthographicSensorProperties();
+ bool processTelecentricSensorProperties();
+
+private:
+ SSensorMetadata data;
+ core::matrix4SIMD transform;
+
+};
+
+
+
+}
+}
+}
+
+#endif
\ No newline at end of file

diff:
@@ -19,6 +19,8 @@ public:
NONE,
SCENE,
SAMPLER,
+ FILM,
+ SENSOR,
//shapes
SHAPE,

diff:
@@ -28,7 +28,11 @@ public:
inline bool isParsingSuspended() const { return isParsingSuspendedFlag; }
private:
- static constexpr const char* unsElements[] = { "integrator", "emitter", "ref", "bsdf", "sensor", "medium", nullptr };
+ static constexpr const char* unsElements[] =
+ {
+ "integrator", "emitter", "ref", "bsdf",
+ "rfilter", "medium", "include", nullptr
+ };
bool isParsingSuspendedFlag;
std::string notSupportedElement;

diff:
@@ -115,7 +115,11 @@ std::pair<bool, SPropertyElementData> CPropertyElementManager::createPropertyDat
result.value = findStandardValue(_atts, errorOccurred);
if (errorOccurred)
+ {
+ _IRR_DEBUG_BREAK_IF(true);
return std::make_pair(false, SPropertyElementData());
+ }
+
return std::make_pair(true, result);
}

original_message: Added CElementSensor


message: Added few properties

diff:
#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);

diff:
@@ -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;
}
}

diff:
@@ -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

diff:
@@ -21,6 +21,7 @@ public:
SAMPLER,
FILM,
SENSOR,
+ EMITTER,
//shapes
SHAPE,

diff:
@@ -99,7 +99,7 @@ private:
"float", "string", "boolean", "integer",
"rgb", "srgb", "spectrum",
"point", "vector",
- "matrix", "rotate", "translate", "scale",
+ "matrix", "rotate", "translate", "scale", "lookat",
nullptr
};
};

diff:
@@ -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;
}
}

diff:
@@ -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);
};

original_message: Added few properties


message: Added CElementEmitter

diff:
+#include "../../ext/MitsubaLoader/CElementEmitter.h"
+#include "../../ext/MitsubaLoader/CElementTransform.h"
+#include "../../ext/MitsubaLoader/ParserUtil.h"
+#include "../../ext/MitsubaLoader/PropertyElement.h"
+
+
+#include <functional>
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+bool CElementEmitter::processAttributes(const char** _atts)
+{
+ static const core::unordered_map<std::string, EEmitterType> acceptableTypes = {
+ std::make_pair("point", EEmitterType::POINT),
+ std::make_pair("area", EEmitterType::AREA),
+ std::make_pair("spot", EEmitterType::SPOT),
+ std::make_pair("directional", EEmitterType::DIRECTIONAL),
+ std::make_pair("collimated", EEmitterType::COLLIMATED),
+ std::make_pair("sky", EEmitterType::SKY),
+ std::make_pair("sunsky", EEmitterType::SUNSKY),
+ std::make_pair("envmap", EEmitterType::ENVMAP),
+ std::make_pair("constant", EEmitterType::CONSTANT)
+ };
+
+ //only type is an acceptable argument
+ for (int i = 0; _atts[i]; i += 2)
+ {
+ if (std::strcmp(_atts[i], "type"))
+ {
+ ParserLog::invalidXMLFileStructure(std::string(_atts[i]) + " is not attribute of shape element.");
+ return false;
+ }
+ else
+ {
+ auto samplerType = acceptableTypes.find(_atts[i + 1]);
+ if (samplerType == acceptableTypes.end())
+ {
+ ParserLog::invalidXMLFileStructure("unknown type");
+ _IRR_DEBUG_BREAK_IF(false);
+ return false;
+ }
+
+ data.type = samplerType->second;
+
+ //set default values
+ switch (data.type)
+ {
+ case EEmitterType::POINT:
+ {
+ data.pointData.position = core::vector3df_SIMD(0.0f);
+ data.pointData.intensity = video::SColorf(1.0f);
+ data.pointData.samplingWeight = 1.0f;
+
+ }
+ break;
+ case EEmitterType::AREA:
+ {
+ data.areaData.radiance = video::SColorf(1.0f);
+ data.areaData.samplingWeight = 1.0f;
+ }
+ break;
+ case EEmitterType::SPOT:
+ {
+ data.spotData.intensity = video::SColorf(1.0f);
+ data.spotData.cutoffAngle = 20.0f;
+ data.spotData.beamWidth = 20.0f * (3.0f / 4.0f);
+ data.spotData.samplingWeight = 1.0f;
+ }
+ break;
+ case EEmitterType::DIRECTIONAL:
+ {
+ data.directionalData.direction = core::vector3df_SIMD(0.0f,-1.0f, 0.0f);
+ data.directionalData.irradiance = video::SColorf(1.0f);
+ data.directionalData.samplingWeight = 1.0f;
+ }
+ break;
+ case EEmitterType::COLLIMATED:
+ {
+ data.collimatedData.power = video::SColorf(1.0f);
+ data.collimatedData.samplingWeight = 1.0f;
+ }
+ break;
+ case EEmitterType::SKY:
+ case EEmitterType::SUN:
+ case EEmitterType::SUNSKY:
+ case EEmitterType::ENVMAP:
+ {
+ ParserLog::invalidXMLFileStructure("not supported yet.");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ break;
+ case EEmitterType::CONSTANT:
+ {
+ data.constantData.radiance = video::SColorf(1.0f);
+ data.constantData.samplingWeight = 1.0f;
+ }
+ break;
+ default:
+ assert(false);
+ }
+ }
+ }
+
+ return true;
+}
+
+bool CElementEmitter::processChildData(IElement* _child)
+{
+ switch (_child->getType())
+ {
+ case IElement::Type::TRANSFORM:
+ {
+ transform = static_cast<CElementTransform*>(_child)->getMatrix();
+ return true;
+ }
+ default:
+ {
+ ParserLog::invalidXMLFileStructure(_child->getLogName() + "is not a child of sensor element");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+}
+
+bool CElementEmitter::onEndTag(asset::IAssetManager& _assetManager)
+{
+ switch (data.type)
+ {
+ case EEmitterType::POINT:
+ return processPointEmitterProperties();
+
+ case EEmitterType::AREA:
+ return processAreaEmitterProperties();
+
+ case EEmitterType::SPOT:
+ return processSpotEmitterProperties();
+
+ case EEmitterType::DIRECTIONAL:
+ return processDirectionalEmitterProperties();
+
+ case EEmitterType::COLLIMATED:
+ return processCollimatedEmitterProperties();
+
+ case EEmitterType::SKY:
+ case EEmitterType::SUN:
+ case EEmitterType::SUNSKY:
+ case EEmitterType::ENVMAP:
+ ParserLog::invalidXMLFileStructure("not supported yet.");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+
+ case EEmitterType::CONSTANT:
+ return processConstantEmitterProperties();
+
+ default:
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+}
+
+bool CElementEmitter::processSharedDataProperty(const SPropertyElementData& _property)
+{
+ if (_property.type == SPropertyElementData::Type::FLOAT)
+ {
+ if (_property.name == "shutterOpen")
+ {
+ data.shutterOpen = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "shutterClose")
+ {
+ data.shutterClose = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unkown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+
+ return true;
+}
+
+bool CElementEmitter::processPointEmitterProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::POINT &&
+ property.name == "position")
+ {
+ data.pointData.position = CPropertyElementManager::retriveVector(property.value);
+ }
+ else
+ if ((property.type == SPropertyElementData::Type::RGB ||
+ property.type == SPropertyElementData::Type::SRGB) &&
+ property.name == "intensity")
+ {
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ else
+ if (property.type == SPropertyElementData::Type::FLOAT &&
+ property.name == "samplingWeight")
+ {
+ data.pointData.samplingWeight = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementEmitter::processAreaEmitterProperties()
+{
+ _IRR_DEBUG_BREAK_IF(true);
+ return true;
+}
+
+bool CElementEmitter::processSpotEmitterProperties()
+{
+ _IRR_DEBUG_BREAK_IF(true);
+ return true;
+}
+
+bool CElementEmitter::processDirectionalEmitterProperties()
+{
+ _IRR_DEBUG_BREAK_IF(true);
+ return true;
+}
+
+
+bool CElementEmitter::processCollimatedEmitterProperties()
+{
+ _IRR_DEBUG_BREAK_IF(true);
+ return true;
+}
+
+bool CElementEmitter::processConstantEmitterProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if ((property.type == SPropertyElementData::Type::RGB ||
+ property.type == SPropertyElementData::Type::SRGB) &&
+ property.name == "radiance")
+ {
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ else
+ if (property.type == SPropertyElementData::Type::FLOAT &&
+ property.name == "samplingWeight")
+ {
+ data.constantData.samplingWeight = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+}
+}
+}
\ No newline at end of file

diff:
+#ifndef __C_ELEMENT_EMITTER_H_INCLUDED__
+#define __C_ELEMENT_EMITTER_H_INCLUDED__
+
+#include "../../ext/MitsubaLoader/IElement.h"
+#include "irrlicht.h"
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+enum class EEmitterType
+{
+ NONE,
+ POINT,
+ AREA,
+ SPOT,
+ DIRECTIONAL,
+ COLLIMATED,
+ SKY,
+ SUN,
+ SUNSKY,
+ ENVMAP,
+ CONSTANT
+};
+
+struct SEmitterMetadata
+{
+ SEmitterMetadata()
+ :type(EEmitterType::NONE) {};
+
+ SEmitterMetadata(const SEmitterMetadata& other)
+ : type(other.type), shutterOpen(other.shutterOpen), shutterClose(other.shutterClose)
+ {
+ switch (other.type)
+ {
+ case EEmitterType::POINT:
+ pointData = other.pointData;
+ break;
+
+ case EEmitterType::AREA:
+ areaData = other.areaData;
+ break;
+
+ case EEmitterType::SPOT:
+ spotData = other.spotData;
+ break;
+
+ case EEmitterType::DIRECTIONAL:
+ directionalData = other.directionalData;
+ break;
+
+ case EEmitterType::COLLIMATED:
+ collimatedData = other.collimatedData;
+ break;
+
+ case EEmitterType::SKY:
+ skyData = other.skyData;
+ break;
+
+ case EEmitterType::SUN:
+ sunData = other.sunData;
+ break;
+
+ case EEmitterType::SUNSKY:
+ sunskyData = other.sunskyData;
+ break;
+
+ case EEmitterType::ENVMAP:
+ envmapData = other.envmapData;
+ break;
+
+ case EEmitterType::CONSTANT:
+ constantData = other.constantData;
+ break;
+
+ default:
+ assert(false);
+ }
+ }
+
+ ~SEmitterMetadata()
+ {
+
+ }
+
+ EEmitterType type;
+
+ float shutterOpen = 0.0f;
+ float shutterClose = 0.0f;
+
+ union
+ {
+ struct PointData
+ {
+ core::vector3df_SIMD position;
+ video::SColorf intensity;
+ float samplingWeight;
+
+ } pointData;
+
+ struct AreaData
+ {
+ video::SColorf radiance;
+ float samplingWeight;
+
+ } areaData;
+
+ struct SpotData
+ {
+ core::matrix4SIMD toWorld;
+ video::SColorf intensity;
+ float cutoffAngle;
+ float beamWidth;
+ //texture
+ float samplingWeight;
+
+ } spotData;
+
+ struct DirectionalData
+ {
+ core::matrix4SIMD toWorld;
+ video::SColorf irradiance;
+ core::vector3df_SIMD direction;
+ float samplingWeight;
+
+ } directionalData;
+
+ struct CollimatedData
+ {
+ core::matrix4SIMD toWorld;
+ video::SColorf power;
+ float samplingWeight;
+
+ } collimatedData;
+
+ struct SkyData
+ {
+ core::matrix4SIMD toWorld;
+ float samplingWeight;
+ float turbidity;
+ video::SColorf albedo;
+ int day;
+ int month;
+ int year;
+ float second;
+ float minute;
+ float hour;
+ float latitude;
+ float longitude;
+ float timezone;
+ core::vector3df_SIMD sunDirection;
+ float stretch;
+ int resolution;
+ float scale;
+
+ } skyData;
+
+ struct SunData
+ {
+ float samplingWeight;
+ float turbidity;
+ int day;
+ int month;
+ int year;
+ float second;
+ float minute;
+ float hour;
+ float latitude;
+ float longitude;
+ float timezone;
+ core::vector3df_SIMD sunDirection;
+ float scale;
+ float sunRadiusScale;
+
+ } sunData;
+
+ struct SunskyData
+ {
+ float turbidity;
+ video::SColorf albedo;
+ int day;
+ int month;
+ int year;
+ float second;
+ float minute;
+ float hour;
+ float latitude;
+ float longitude;
+ float timezone;
+ core::vector3df_SIMD sunDirection;
+ float stretch;
+ float sunScale;
+ float skyScale;
+ float sunRadiusScale;
+ int resolution;
+
+ } sunskyData;
+
+ struct EnvmapData
+ {
+ core::matrix4SIMD toWorld;
+ std::string filename;
+ float scale;
+ float gamma;
+ bool cache;
+ float samplingWeight;
+
+ } envmapData;
+
+ struct ConstantData
+ {
+ video::SColorf radiance;
+ float samplingWeight;
+
+ } constantData;
+ };
+};
+
+class CElementEmitter : public IElement
+{
+public:
+ virtual bool processAttributes(const char** _atts) override;
+ virtual bool processChildData(IElement* _child) override;
+ virtual bool onEndTag(asset::IAssetManager& _assetManager) override;
+ virtual IElement::Type getType() const override { return IElement::Type::EMITTER; }
+ virtual std::string getLogName() const override { return "emitter"; }
+
+ SEmitterMetadata getMetadata() { return data; }
+
+private:
+ bool processSharedDataProperty(const SPropertyElementData& _property);
+ bool processPointEmitterProperties();
+ bool processAreaEmitterProperties();
+ bool processSpotEmitterProperties();
+ bool processDirectionalEmitterProperties();
+ bool processCollimatedEmitterProperties();
+ bool processConstantEmitterProperties();
+
+private:
+ SEmitterMetadata data;
+ core::matrix4SIMD transform;
+
+};
+
+
+
+}
+}
+}
+
+#endif
\ No newline at end of file

original_message: Added CElementEmitter


message: Filling out over half of indicies of refraction


message:
Complete IoR table
Can't find anything about "d-C"

diff:
@@ -167,7 +167,7 @@ CElementBSDF::AllConductor::AllConductor(const std::string& material) : RoughSpe
static const core::unordered_map<std::string, std::pair<SPropertyElementData,SPropertyElementData>, core::CaseInsensitiveHash, core::CaseInsensitiveEquals> NamedConductors =
{
#define SPECTRUM_MACRO(R,G,B,X,Y,Z) {SPropertyElementData(SPropertyElementData::Type::RGB,core::vectorSIMDf(R,G,B)),SPropertyElementData(SPropertyElementData::Type::RGB,core::vectorSIMDf(X,Y,Z))}
- //{"a-C", SPECTRUM_MACRO(,,, ,,)},
+ {"a-C", SPECTRUM_MACRO(1.6855f, 1.065f, 1.727f, 0.0f, 0.009f, 0.0263f)}, // there is no "a-C", but "a-C:H, data from palik"
{"Ag", SPECTRUM_MACRO(0.059481f, 0.055090f, 0.046878f, 4.1367f, 3.4574f, 2.8028f)},
{"Al", SPECTRUM_MACRO(1.3404f, 0.95151f, 0.68603f, 7.3509f, 6.4542f, 5.6351f)},
{"AlAs", SPECTRUM_MACRO(3.1451f, 3.2636f, 3.4543f, 0.0012319f, 0.0039041f, 0.012940f)},
@@ -176,55 +176,55 @@ CElementBSDF::AllConductor::AllConductor(const std::string& material) : RoughSpe
{"Be", SPECTRUM_MACRO(3.3884f, 3.2860f, 3.1238f, 3.1692f, 3.1301f, 3.1246f)},
{"Be_palik", SPECTRUM_MACRO(3.46f, 3.30f, 3.19f, 3.18f, 3.18f, 3.16f)},
{"Cr", SPECTRUM_MACRO(3.2246f, 2.6791f, 2.1411f, 4.2684f, 4.1664f, 3.9300f)},
- {"CsI", SPECTRUM_MACRO(1.7834f, 1.7978f, 1.8182f, 0.0f, 0.0f, 0.0f)}, // note it's a crystall, so there is no extinction
+ {"CsI", SPECTRUM_MACRO(1.7834f, 1.7978f, 1.8182f, 0.0f, 0.0f, 0.0f)},
{"CsI_palik", SPECTRUM_MACRO(1.78006f, 1.79750f, 1.82315, 0.0f, 0.0f, 0.0f)},
{"Cu", SPECTRUM_MACRO(0.32075f,1.09860f,1.2469f, 3.17900f,2.59220f,2.4562)},
{"Cu_palik", SPECTRUM_MACRO(0.32000f, 1.04f, 1.16f, 3.15000f, 2.59f, 2.4f)},
- //{"Cu20", SPECTRUM_MACRO(,,, ,,)},
- //{"Cu20_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"Cu20", SPECTRUM_MACRO(2.975f, 3.17f, 3.075f, 0.122f, 0.23f, 0.525f)}, // out of range beyond 2.5 um refractiveindex.info and similar websites, so data applied is same as from palik's data
+ {"Cu20_palik", SPECTRUM_MACRO(2.975f, 3.17f, 3.075f, 0.122f, 0.23f, 0.525f)},
//{"d-C", SPECTRUM_MACRO(,,, ,,)},
//{"d-C_palik", SPECTRUM_MACRO(,,, ,,)},
{"Hg", SPECTRUM_MACRO(1.8847f, 1.4764f, 1.1306f, 5.1147f, 4.5410f, 3.9896f)},
{"Hg_palik", SPECTRUM_MACRO(1.850f, 1.460f, 1.100f, 5.100f, 4.600f, 3.990f)},
//{"HgTe", SPECTRUM_MACRO(,,, ,,)}, // lack of length wave range for our purpose https://www.researchgate.net/publication/3714159_Dispersion_of_refractive_index_in_degenerate_mercury_cadmium_telluride
- //{"HgTe_palik", SPECTRUM_MACRO(,,, ,,)},
+ //{"HgTe_palik", SPECTRUM_MACRO(,,, ,,)}, // the same in palik (wavelength beyond 2 um)
{"Ir", SPECTRUM_MACRO(2.4200f, 2.0795f, 1.7965f, 5.0665f, 4.6125f, 4.1120f)},
{"Ir_palik", SPECTRUM_MACRO(2.44f, 2.17f, 1.87f, 4.52f, 4.24f, 3.79f)},
{"K", SPECTRUM_MACRO(0.052350f, 0.048270f, 0.042580f, 1.6732f, 1.3919f, 1.1195f)},
{"K_palik", SPECTRUM_MACRO(0.0525f, 0.0483f, 0.0427f, 1.67f, 1.39f, 1.12f)},
{"Li", SPECTRUM_MACRO(0.14872f, 0.14726f, 0.19236f, 2.9594f, 2.5129f, 2.1144f)},
- //{"Li_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"Li_palik", SPECTRUM_MACRO(0.218f, 0.2093f, 0.229f, 2.848f, 2.369f, 2.226f)},
{"MgO", SPECTRUM_MACRO(1.7357f, 1.7419f, 1.7501f, 0.0f, 0.0f, 0.0f)},
- //{"MgO_palik", SPECTRUM_MACRO(,,, ,,)},
- {"Mo", SPECTRUM_MACRO(0.76709f, 0.57441f, 0.46711f, 8.5005f, 7.2352f, 6.1383f)},
- //{"Mo_palik", SPECTRUM_MACRO(,,, ,,)},
- //{"Na_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"MgO_palik", SPECTRUM_MACRO(1.7355f, 1.7414f, 1.74975f, 0.0f, 0.0f, 1.55f)}, // Handbook of optical constants of solids vol 2 page 951, weird k compoment alone, no measurements and resoults
+ {"Mo", SPECTRUM_MACRO(0.76709f, 0.57441f, 0.46711f, 8.5005f, 7.2352f, 6.1383f)}, // https://refractiveindex.info/?shelf=main&book=Mo&page=Werner comparing with palik - weird
+ {"Mo_palik", SPECTRUM_MACRO(3.68f, 3.77f, 3.175f, 3.51f, 3.624f, 3.56f)},
+ {"Na_palik", SPECTRUM_MACRO(0.0522f, 0.061f, 0.0667f, 2.535f, 2.196f, 1.861f)},
{"Nb", SPECTRUM_MACRO(2.2775f, 2.2225f, 2.0050f, 3.2500f, 3.1325f, 3.0100f)},
- //{"Nb_palik", SPECTRUM_MACRO(,,, ,,)},
- //{"Ni_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"Nb_palik", SPECTRUM_MACRO(2.869f, 2.9235f, 2.738f, 2.867f, 2.8764f, 2.8983f)},
+ {"Ni_palik", SPECTRUM_MACRO(1.921f, 1.744f, 1.651f, 3.615f, 3.168f, 2.753f)},
{"Rh", SPECTRUM_MACRO(2.8490f, 2.6410f, 2.4310f, 3.5450f, 3.3150f, 3.1190f)},
- //{"Rh_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"Rh_palik", SPECTRUM_MACRO(2.092f, 1.934f, 1.8256f, 5.472f, 4.902f, 4.5181f)},
{"Se", SPECTRUM_MACRO(1.4420f, 1.4759f, 1.4501f, 0.018713f, 0.10233f, 0.18418f)},
- //{"Se_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"Se_palik", SPECTRUM_MACRO(3.346f, 3.013f, 3.068f, 0.6402f, 0.6711f, 0.553f)},
{"SiC", SPECTRUM_MACRO(2.6398f, 2.6677f, 2.7069f, 0.0f, 0.0f, 0.0f)},
- //{"SiC_palik", SPECTRUM_MACRO(,,, ,,)},
- //{"SnTe", SPECTRUM_MACRO(,,, ,,)},
- //{"SnTe_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"SiC_palik", SPECTRUM_MACRO(2.6412f, 2.6684f, 2.7077f, 0.0f, 0.0f, 0.0f)},
+ {"SnTe", SPECTRUM_MACRO(3.059f, 1.813f, 1.687f, 5.144f, 4.177f, 3.555f)}, // no data except palik's resources, so data same as palik
+ {"SnTe_palik", SPECTRUM_MACRO(3.059f, 1.813f, 1.687f, 5.144f, 4.177f, 3.555f)},
{"Ta", SPECTRUM_MACRO(1.0683f, 1.1379f, 1.2243f, 5.5047f, 4.7432f, 4.0988f)},
- //{"Ta_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"Ta_palik", SPECTRUM_MACRO(1.839f, 2.5875f, 2.8211f, 1.997f, 1.8683f, 2.0514f)},
{"Te", SPECTRUM_MACRO(4.1277f, 3.2968f, 2.6239f, 2.5658f, 2.8789f, 2.7673f)},
- //{"Te_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"Te_palik", SPECTRUM_MACRO(5.8101f, 4.5213f, 3.3682f, 2.9428f, 3.7289f, 3.6783f)},
{"ThF4", SPECTRUM_MACRO(1.5113f, 1.5152f, 1.5205f, 0.0f, 0.0f, 0.0f)},
- //{"ThF4_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"ThF4_palik", SPECTRUM_MACRO(1.520f, 1.5125f, 1.524f, 0.0f, 0.0f, 0.0f)},
{"TiC", SPECTRUM_MACRO(3.0460f, 2.9815f, 2.8864f, 2.6585f, 2.4714f, 2.3987f)},
- //{"TiC_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"TiC_palik", SPECTRUM_MACRO(3.0454f, 2.9763, 2.8674f, 2.6589f, 2.4695f, 2.3959f)},
{"TiO2", SPECTRUM_MACRO(2.1362f, 2.1729f, 2.2298f, 0.0f, 0.0f, 0.0f)},
{"TiO2_palik", SPECTRUM_MACRO(2.5925f, 2.676f, 2.78f, 0.0f, 0.0f, 0.0f)},
{"VC", SPECTRUM_MACRO(3.0033f, 2.8936f, 2.8138f, 2.4981f, 2.3046f, 2.1913f)},
- //{"VC_palik", SPECTRUM_MACRO(,,, ,,)},
- //{"V_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"VC_palik", SPECTRUM_MACRO(3.0038f, 2.8951f, 2.8184f, 2.4923f, 2.3107f, 2.1902f)},
+ {"V_palik", SPECTRUM_MACRO(3.512f, 3.671f, 3.2178f, 2.9337, 3.069f, 3.3667f)},
{"VN", SPECTRUM_MACRO(2.3429f, 2.2268f, 2.1550f, 2.4506f, 2.1345f, 1.8753f)},
- //{"VN_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"VN_palik", SPECTRUM_MACRO(2.3418f, 2.2239f, 2.1539f, 2.4498f, 2.1371f, 1.8776f)},
{"W", SPECTRUM_MACRO(0.96133f, 1.5474f, 2.1930f, 6.2902f, 5.1052f, 5.0325f)},
{"none", SPECTRUM_MACRO(0.f,0.f,0.f, 0.f,0.f,0.f)}
#undef SPECTRUM_MACRO


message: Complete diamond (cubic) index

diff:
@@ -167,7 +167,7 @@ CElementBSDF::AllConductor::AllConductor(const std::string& material) : RoughSpe
static const core::unordered_map<std::string, std::pair<SPropertyElementData,SPropertyElementData>, core::CaseInsensitiveHash, core::CaseInsensitiveEquals> NamedConductors =
{
#define SPECTRUM_MACRO(R,G,B,X,Y,Z) {SPropertyElementData(SPropertyElementData::Type::RGB,core::vectorSIMDf(R,G,B)),SPropertyElementData(SPropertyElementData::Type::RGB,core::vectorSIMDf(X,Y,Z))}
- {"a-C", SPECTRUM_MACRO(1.6855f, 1.065f, 1.727f, 0.0f, 0.009f, 0.0263f)}, // there is no "a-C", but "a-C:H, data from palik"
+ {"a-C", SPECTRUM_MACRO(1.6855f, 1.065f, 1.727f, 0.0f, 0.009f, 0.0263f)}, // there is no "a-C", but "a-C:H; data from palik"
{"Ag", SPECTRUM_MACRO(0.059481f, 0.055090f, 0.046878f, 4.1367f, 3.4574f, 2.8028f)},
{"Al", SPECTRUM_MACRO(1.3404f, 0.95151f, 0.68603f, 7.3509f, 6.4542f, 5.6351f)},
{"AlAs", SPECTRUM_MACRO(3.1451f, 3.2636f, 3.4543f, 0.0012319f, 0.0039041f, 0.012940f)},
@@ -182,8 +182,8 @@ CElementBSDF::AllConductor::AllConductor(const std::string& material) : RoughSpe
{"Cu_palik", SPECTRUM_MACRO(0.32000f, 1.04f, 1.16f, 3.15000f, 2.59f, 2.4f)},
{"Cu20", SPECTRUM_MACRO(2.975f, 3.17f, 3.075f, 0.122f, 0.23f, 0.525f)}, // out of range beyond 2.5 um refractiveindex.info and similar websites, so data applied is same as from palik's data
{"Cu20_palik", SPECTRUM_MACRO(2.975f, 3.17f, 3.075f, 0.122f, 0.23f, 0.525f)},
- //{"d-C", SPECTRUM_MACRO(,,, ,,)},
- //{"d-C_palik", SPECTRUM_MACRO(,,, ,,)},
+ {"d-C", SPECTRUM_MACRO(2.4123f, 2.4246f, 2.4349f, 0.0f, 0.0f, 0.0f)},
+ {"d-C_palik", SPECTRUM_MACRO(2.4137f, 2.4272f, 2.4446f, 0.0f, 0.0f, 0.0f)},
{"Hg", SPECTRUM_MACRO(1.8847f, 1.4764f, 1.1306f, 5.1147f, 4.5410f, 3.9896f)},
{"Hg_palik", SPECTRUM_MACRO(1.850f, 1.460f, 1.100f, 5.100f, 4.600f, 3.990f)},
//{"HgTe", SPECTRUM_MACRO(,,, ,,)}, // lack of length wave range for our purpose https://www.researchgate.net/publication/3714159_Dispersion_of_refractive_index_in_degenerate_mercury_cadmium_telluride

original_message: Complete diamond (cubic) index


message: Fix Maya and Modified Maya rotation

diff:
@@ -202,14 +202,14 @@ void CSceneNodeAnimatorCameraMaya::animateNode(IDummyTransformationSceneNode *no
}
else
{
- nRotX += (RotateStart.X - MousePos.X) * RotateSpeed;
- nRotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
+ nRotX += (MousePos.X - RotateStart.X) * RotateSpeed;
+ nRotY += (MousePos.Y - RotateStart.Y) * RotateSpeed;
}
}
else if (Rotating)
{
- RotX += (RotateStart.X - MousePos.X) * RotateSpeed;
- RotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
+ RotX += (MousePos.X - RotateStart.X) * RotateSpeed;
+ RotY += (MousePos.Y - RotateStart.Y) * RotateSpeed;
nRotX = RotX;
nRotY = RotY;
Rotating = false;

diff:
@@ -251,16 +251,16 @@ namespace irr
}
else
{
- nRotX += (RotateStart.X - MousePos.X) * RotateSpeed;
- nRotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
+ nRotX += (MousePos.X - RotateStart.X) * RotateSpeed;
+ nRotY += (MousePos.Y - RotateStart.Y) * RotateSpeed;
}
}
else
{
if (Rotating)
{
- RotX += (RotateStart.X - MousePos.X) * RotateSpeed;
- RotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
+ RotX += (MousePos.X - RotateStart.X) * RotateSpeed;
+ RotY += (MousePos.Y - RotateStart.Y) * RotateSpeed;
nRotX = RotX;
nRotY = RotY;

original_message: Fix Maya and Modified Maya rotation


message: Fix operations dependent on hand orientation

diff:
@@ -162,7 +162,10 @@ void CSceneNodeAnimatorCameraMaya::animateNode(IDummyTransformationSceneNode *no
core::vector3df_SIMD pos,tvectX;
pos.getAsVector3df() = camera->getPosition();
tvectX = pos - target;
+ if (camera->getLeftHanded())
tvectX = normalize(cross(tvectX,upVector));
+ else
+ tvectX = normalize(cross(upVector, tvectX));
const SViewFrustum* const va = camera->getViewFrustum();
core::vector3df_SIMD tvectY = (va->getFarLeftDown() - va->getFarRightDown());
@@ -191,6 +194,14 @@ void CSceneNodeAnimatorCameraMaya::animateNode(IDummyTransformationSceneNode *no
// Rotation ------------------------------------
+ auto getValueDependentOnHandOrientation = [&](const float& expression)
+ {
+ if (camera->getLeftHanded())
+ return expression;
+ else
+ return -expression;
+ };
+
if (isMouseKeyDown(0) && !Zooming)
{
if (!Rotating)
@@ -202,14 +213,14 @@ void CSceneNodeAnimatorCameraMaya::animateNode(IDummyTransformationSceneNode *no
}
else
{
- nRotX += (MousePos.X - RotateStart.X) * RotateSpeed;
- nRotY += (MousePos.Y - RotateStart.Y) * RotateSpeed;
+ nRotX += getValueDependentOnHandOrientation((RotateStart.X - MousePos.X) * RotateSpeed);
+ nRotY += getValueDependentOnHandOrientation((RotateStart.Y - MousePos.Y) * RotateSpeed);
}
}
else if (Rotating)
{
- RotX += (MousePos.X - RotateStart.X) * RotateSpeed;
- RotY += (MousePos.Y - RotateStart.Y) * RotateSpeed;
+ RotX += getValueDependentOnHandOrientation((RotateStart.X - MousePos.X) * RotateSpeed);
+ RotY += getValueDependentOnHandOrientation((RotateStart.Y - MousePos.Y) * RotateSpeed);
nRotX = RotX;
nRotY = RotY;
Rotating = false;

diff:
@@ -184,7 +184,10 @@ namespace irr
tvectX -= camera->getTarget();
core::vectorSIMDf other = tvectX;
+ if(camera->getLeftHanded())
tvectX = core::normalize(core::cross(tvectX,camera->getUpVector()));
+ else
+ tvectX = core::normalize(core::cross(camera->getUpVector(), tvectX));
core::vectorSIMDf tvectY = va->getFarLeftDown() - va->getFarRightDown();
if (camera->getUpVector().Y<0.f)
@@ -238,6 +241,15 @@ namespace irr
}
// Rotation ------------------------------------
+
+ auto getValueDependentOnHandOrientation = [&](const float& expression)
+ {
+ if (camera->getLeftHanded())
+ return expression;
+ else
+ return -expression;
+ };
+
if (isMouseKeyDown(0) && !(StepZooming || Zooming))
{
if (!Rotating)
@@ -247,20 +259,19 @@ namespace irr
Rotating = true;
nRotX = RotX;
nRotY = RotY;
-
}
else
{
- nRotX += (MousePos.X - RotateStart.X) * RotateSpeed;
- nRotY += (MousePos.Y - RotateStart.Y) * RotateSpeed;
+ nRotX += getValueDependentOnHandOrientation((RotateStart.X - MousePos.X) * RotateSpeed);
+ nRotY += getValueDependentOnHandOrientation((RotateStart.Y - MousePos.Y) * RotateSpeed);
}
}
else
{
if (Rotating)
{
- RotX += (MousePos.X - RotateStart.X) * RotateSpeed;
- RotY += (MousePos.Y - RotateStart.Y) * RotateSpeed;
+ RotX += getValueDependentOnHandOrientation((RotateStart.X - MousePos.X) * RotateSpeed);
+ RotY += getValueDependentOnHandOrientation((RotateStart.Y - MousePos.Y) * RotateSpeed);
nRotX = RotX;
nRotY = RotY;


message: Use core::mix

diff:
@@ -196,10 +196,7 @@ void CSceneNodeAnimatorCameraMaya::animateNode(IDummyTransformationSceneNode *no
auto getValueDependentOnHandOrientation = [&](const float& expression)
{
- if (camera->getLeftHanded())
- return expression;
- else
- return -expression;
+ return core::mix<float, bool>(-expression, expression, camera->getLeftHanded());
};
if (isMouseKeyDown(0) && !Zooming)

diff:
@@ -241,13 +241,9 @@ namespace irr
}
// Rotation ------------------------------------
-
auto getValueDependentOnHandOrientation = [&](const float& expression)
{
- if (camera->getLeftHanded())
- return expression;
- else
- return -expression;
+ return core::mix<float, bool>(-expression, expression, camera->getLeftHanded());
};
if (isMouseKeyDown(0) && !(StepZooming || Zooming))

original_message: Use core::mix