Added CElementSampler
MODIFY
ext/MitsubaLoader/CElementFactory.cpp
ext/MitsubaLoader/CElementFactory.cpp
#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);

ADD
ext/MitsubaLoader/CElementSampler.cpp
+#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

ADD
ext/MitsubaLoader/CElementSampler.h
+#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

MODIFY
ext/MitsubaLoader/CMitsubaLoader.cpp
ext/MitsubaLoader/CMitsubaLoader.cpp
#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();
}
}

MODIFY
ext/MitsubaLoader/CMitsubaLoader.h
ext/MitsubaLoader/CMitsubaLoader.h
@@ -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;

MODIFY
ext/MitsubaLoader/CMitsubaScene.cpp
ext/MitsubaLoader/CMitsubaScene.cpp
#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;
}

MODIFY
ext/MitsubaLoader/CMitsubaScene.h
ext/MitsubaLoader/CMitsubaScene.h
@@ -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;
};
}

MODIFY
ext/MitsubaLoader/CShapeCreator.cpp
ext/MitsubaLoader/CShapeCreator.cpp
@@ -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;

MODIFY
ext/MitsubaLoader/IElement.h
ext/MitsubaLoader/IElement.h
@@ -18,6 +18,7 @@ public:
{
NONE,
SCENE,
+ SAMPLER,
//shapes
SHAPE,

MODIFY
ext/MitsubaLoader/ParserUtil.h
ext/MitsubaLoader/ParserUtil.h
@@ -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",

MODIFY
ext/MitsubaLoader/PropertyElement.cpp
ext/MitsubaLoader/PropertyElement.cpp
@@ -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;
}

MODIFY
ext/MitsubaLoader/Shape.cpp
ext/MitsubaLoader/Shape.cpp
@@ -89,7 +89,7 @@ bool CShape::onEndTag(asset::IAssetManager& _assetManager)
return false;
}
- if (mesh == nullptr)
+ if (mesh.get() == nullptr)
return false;
return true;

MODIFY
ext/MitsubaLoader/Shape.h
ext/MitsubaLoader/Shape.h
@@ -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;
};

Added CElementSampler