message: Add loader flags, CBufferLoaderBIN and first flipping around X axie

diff:
@@ -25,15 +25,33 @@ public:
ECF_DUPLICATE_REFERENCES = 0xffffffffffffffffull
};
+ //! Parameter flags for a loader
+ /**
+ These are extra flags that have an impact on extraordinary tasks while loading.
+ E_LOADER_PARAMETER_FLAGS::ELPF_NONE is default and means that there is nothing to perform.
+ E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES specifies that a mesh will be flipped in such
+ a way that it'll look correctly in right-handed camera system. If it isn't set, compatibility with
+ left-handed coordinate camera is assumed.
+ E_LOADER_PARAMETER_FLAGS::ELPF_DONT_COMPILE_GLSL means that GLSL won't be compiled to SPIR-V if it is loaded or generated.
+ */
+
+ enum E_LOADER_PARAMETER_FLAGS : uint64_t
+ {
+ ELPF_NONE = 0, //!< default value, it doesn't do anything
+ ELPF_RIGHT_HANDED_MESHES = 0x1, //!< specifies that a mesh will be flipped in such a way that it'll look correctly in right-handed camera system
+ ELPF_DONT_COMPILE_GLSL = 0x2 //!< it states that GLSL won't be compiled to SPIR-V if it is loaded or generated
+ };
+
struct SAssetLoadParams
{
- SAssetLoadParams(const size_t& _decryptionKeyLen = 0u, const uint8_t* _decryptionKey = nullptr, const E_CACHING_FLAGS& _cacheFlags = ECF_CACHE_EVERYTHING)
- : decryptionKeyLen(_decryptionKeyLen), decryptionKey(_decryptionKey), cacheFlags(_cacheFlags)
+ SAssetLoadParams(const size_t& _decryptionKeyLen = 0u, const uint8_t* _decryptionKey = nullptr, const E_CACHING_FLAGS& _cacheFlags = ECF_CACHE_EVERYTHING, const E_LOADER_PARAMETER_FLAGS& _loaderFlags = ELPF_NONE)
+ : decryptionKeyLen(_decryptionKeyLen), decryptionKey(_decryptionKey), cacheFlags(_cacheFlags), loaderFlags(_loaderFlags)
{
}
size_t decryptionKeyLen;
const uint8_t* decryptionKey;
const E_CACHING_FLAGS cacheFlags;
+ const E_LOADER_PARAMETER_FLAGS loaderFlags; //!< Flags having an impact on extraordinary tasks during loading process
};
//! Struct for keeping the state of the current loadoperation for safe threading

diff:
@@ -66,6 +66,7 @@ set(IRRLICHT_SRCS_COMMON
${IRR_ROOT_PATH}/src/irr/asset/CPLYMeshFileLoader.cpp
${IRR_ROOT_PATH}/src/irr/asset/CSTLMeshFileLoader.cpp
${IRR_ROOT_PATH}/src/irr/asset/CXMeshFileLoader.cpp
+ ${IRR_ROOT_PATH}/src/irr/asset/CBufferLoaderBIN.cpp
# Mesh writers
${IRR_ROOT_PATH}/src/irr/asset/CBAWMeshWriter.cpp

diff:
+#include "CBufferLoaderBIN.h"
+
+namespace irr
+{
+ namespace asset
+ {
+ asset::SAssetBundle CBufferLoaderBIN::loadAsset(io::IReadFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel)
+ {
+ if (!_file)
+ return {};
+
+ SContext ctx(_file->getSize());
+ ctx.file = _file;
+
+ ctx.file->read(ctx.sourceCodeBuffer.get(), ctx.file->getSize());
+
+ return SAssetBundle({std::move(ctx.sourceCodeBuffer)});
+ }
+
+ bool CBufferLoaderBIN::isALoadableFileFormat(io::IReadFile* _file) const
+ {
+ return true; // validation if needed
+ }
+ }
+}
\ No newline at end of file

diff:
+// Copyright (C) 2009-2012 Gaz Davidson
+// This file is part of the "Irrlicht Engine".
+// For conditions of distribution and use, see copyright notice in irrlicht.h
+
+#pragma once
+
+#include "irr/asset/IAssetLoader.h"
+#include "irr/asset/ICPUMeshBuffer.h"
+
+namespace irr
+{
+ namespace asset
+ {
+ //! Binaryloader capable of loading source code in binary format
+ class CBufferLoaderBIN : public asset::IAssetLoader
+ {
+ protected:
+ ~CBufferLoaderBIN();
+
+ public:
+ virtual bool isALoadableFileFormat(io::IReadFile* _file) const override;
+
+ virtual const char** getAssociatedFileExtensions() const override
+ {
+ static const char* extensions[]{ "bin", nullptr };
+ return extensions;
+ }
+
+ virtual uint64_t getSupportedAssetTypesBitfield() const override { return asset::IAsset::ET_BUFFER; }
+
+ virtual asset::SAssetBundle loadAsset(io::IReadFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) override;
+
+ private:
+ struct SContext
+ {
+ SContext(const size_t& sizeInBytes) : sourceCodeBuffer(core::make_smart_refctd_ptr<ICPUBuffer>(sizeInBytes)) {}
+ io::IReadFile* file;
+ core::smart_refctd_ptr<ICPUBuffer> sourceCodeBuffer;
+ };
+
+ void loadEntireSourceCode(SContext& _ctx);
+ };
+ }
+}

diff:
@@ -75,8 +75,26 @@ asset::SAssetBundle CSTLMeshFileLoader::loadAsset(io::IReadFile* _file, const as
{
core::vectorSIMDf n;
getNextVector(_file, n, binary);
- normals.push_back(core::normalize(n));
+
+ auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
+ {
+ switch (_params.loaderFlags)
+ {
+ case E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES:
+ {
+ performOnRightHanded();
+ break;
}
+ default:
+ {
+ performOnLeftHanded();
+ break;
+ }
+ }
+ };
+
+ performActionBasedOnOrientationSystem([&]() {n.z = -n.z;}, [&]() {});
+ normals.push_back(core::normalize(n));
if (!binary)
{
@@ -94,9 +112,10 @@ asset::SAssetBundle CSTLMeshFileLoader::loadAsset(io::IReadFile* _file, const as
return {};
}
getNextVector(_file, p[i], binary);
+ performActionBasedOnOrientationSystem([&]() {p[i].z = -p[i].z; }, [&]() {});
}
for (uint32_t i = 0u; i < 3u; ++i) // seems like in STL format vertices are ordered in clockwise manner...
- positions.push_back(p[2u-i]);
+ performActionBasedOnOrientationSystem([&]() {positions.push_back(p[i]); }, [&]() {positions.push_back(p[2u - i]); });
}
if (!binary)


message: Add a few corrections

change_type: MODIFY

diff:
@@ -12,7 +12,7 @@ namespace irr
SContext ctx(_file->getSize());
ctx.file = _file;
- ctx.file->read(ctx.sourceCodeBuffer.get(), ctx.file->getSize());
+ ctx.file->read(ctx.sourceCodeBuffer.get()->getPointer(), ctx.file->getSize());
return SAssetBundle({std::move(ctx.sourceCodeBuffer)});
}

diff:
@@ -12,23 +12,23 @@ namespace irr
namespace asset
{
//! Binaryloader capable of loading source code in binary format
- class CBufferLoaderBIN : public asset::IAssetLoader
+ class CBufferLoaderBIN final : public asset::IAssetLoader
{
protected:
~CBufferLoaderBIN();
public:
- virtual bool isALoadableFileFormat(io::IReadFile* _file) const override;
+ bool isALoadableFileFormat(io::IReadFile* _file) const override;
- virtual const char** getAssociatedFileExtensions() const override
+ const char** getAssociatedFileExtensions() const override
{
static const char* extensions[]{ "bin", nullptr };
return extensions;
}
- virtual uint64_t getSupportedAssetTypesBitfield() const override { return asset::IAsset::ET_BUFFER; }
+ uint64_t getSupportedAssetTypesBitfield() const override { return asset::IAsset::ET_BUFFER; }
- virtual asset::SAssetBundle loadAsset(io::IReadFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) override;
+ asset::SAssetBundle loadAsset(io::IReadFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) override;
private:
struct SContext
@@ -37,8 +37,6 @@ namespace irr
io::IReadFile* file;
core::smart_refctd_ptr<ICPUBuffer> sourceCodeBuffer;
};
-
- void loadEntireSourceCode(SContext& _ctx);
};
}
}

diff:
@@ -78,22 +78,13 @@ asset::SAssetBundle CSTLMeshFileLoader::loadAsset(io::IReadFile* _file, const as
auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
{
- switch (_params.loaderFlags)
- {
- case E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES:
- {
+ if(_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
performOnRightHanded();
- break;
- }
- default:
- {
+ else
performOnLeftHanded();
- break;
- }
- }
};
- performActionBasedOnOrientationSystem([&]() {n.z = -n.z;}, [&]() {});
+ performActionBasedOnOrientationSystem([&]() {n.x = -n.x;}, [&]() {});
normals.push_back(core::normalize(n));
if (!binary)

license: Apache License 2.0

repo: buildaworldnet/irrlichtbaw

original_message: Add a few corrections


message: Correct CSTL x flipping, add flipping in COBJMeshFileLoader

diff:
@@ -104,6 +104,15 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(io::IReadFile* _file, const as
std::string grpName, mtlName;
bool mtlChanged=false;
bool submeshLoadedFromCache = false;
+
+ auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
+ {
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performOnRightHanded();
+ else
+ performOnLeftHanded();
+ };
+
while(bufPtr != bufEnd)
{
switch(bufPtr[0])
@@ -131,6 +140,7 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(io::IReadFile* _file, const as
{
core::vector3df vec;
bufPtr = readVec3(bufPtr, vec, bufEnd);
+ performActionBasedOnOrientationSystem([&]() {vec.X = -vec.X;}, [&]() {});
vertexBuffer.push_back(vec);
}
break;
@@ -139,6 +149,7 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(io::IReadFile* _file, const as
{
core::vector3df vec;
bufPtr = readVec3(bufPtr, vec, bufEnd);
+ performActionBasedOnOrientationSystem([&]() {vec.X = -vec.X; }, [&]() {});
normalsBuffer.push_back(vec);
}
break;
@@ -314,10 +325,23 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(io::IReadFile* _file, const as
for ( uint32_t i = 1; i < faceCorners.size() - 1; ++i )
{
// Add a triangle
+ performActionBasedOnOrientationSystem
+ (
+ [&]()
+ {
+ currMtl->Indices.push_back(faceCorners[0]);
+ currMtl->Indices.push_back(faceCorners[i]);
+ currMtl->Indices.push_back(faceCorners[i + 1]);
+ },
+
+ [&]()
+ {
currMtl->Indices.push_back(faceCorners[i + 1]);
currMtl->Indices.push_back(faceCorners[i]);
currMtl->Indices.push_back(faceCorners[0]);
}
+ );
+ }
faceCorners.resize(0); // fast clear
faceCorners.reserve(32);
}

diff:
@@ -103,7 +103,7 @@ asset::SAssetBundle CSTLMeshFileLoader::loadAsset(io::IReadFile* _file, const as
return {};
}
getNextVector(_file, p[i], binary);
- performActionBasedOnOrientationSystem([&]() {p[i].z = -p[i].z; }, [&]() {});
+ performActionBasedOnOrientationSystem([&]() {p[i].x = -p[i].x; }, [&]() {});
}
for (uint32_t i = 0u; i < 3u; ++i) // seems like in STL format vertices are ordered in clockwise manner...
performActionBasedOnOrientationSystem([&]() {positions.push_back(p[i]); }, [&]() {positions.push_back(p[2u - i]); });


message: Flip CPLYMeshFileLoader

diff:
@@ -249,13 +249,13 @@ asset::SAssetBundle CPLYMeshFileLoader::loadAsset(io::IReadFile* _file, const as
{
// loop through vertex properties
for (uint32_t j=0; j < ctx.ElementList[i]->Count; ++j)
- hasNormals &= readVertex(ctx, *ctx.ElementList[i], attribs);
+ hasNormals &= readVertex(ctx, *ctx.ElementList[i], attribs, _params);
}
else if (ctx.ElementList[i]->Name == "face")
{
// read faces
for (uint32_t j=0; j < ctx.ElementList[i]->Count; ++j)
- readFace(ctx, *ctx.ElementList[i], indices);
+ readFace(ctx, *ctx.ElementList[i], indices, _params);
}
else
{
@@ -297,8 +297,16 @@ asset::SAssetBundle CPLYMeshFileLoader::loadAsset(io::IReadFile* _file, const as
return SAssetBundle({mesh});
}
+static void performActionBasedOnOrientationSystem(const asset::IAssetLoader::SAssetLoadParams& _params, std::function<void()> performOnRightHanded, std::function<void()> performOnLeftHanded)
+{
+ if (_params.loaderFlags & IAssetLoader::ELPF_RIGHT_HANDED_MESHES)
+ performOnRightHanded();
+ else
+ performOnLeftHanded();
+}
+
-bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _outAttribs[4])
+bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _outAttribs[4], const asset::IAssetLoader::SAssetLoadParams& _params)
{
if (!_ctx.IsBinaryFile)
getNextLine(_ctx);
@@ -315,6 +323,7 @@ bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element,
if (Element.Properties[i].Name == "x")
{
attribs[E_POS].second.X = getFloat(_ctx, t);
+ performActionBasedOnOrientationSystem(_params, [&]() {attribs[E_POS].second.X = -attribs[E_POS].second.X;}, [&]() {});
attribs[E_POS].first = true;
}
else if (Element.Properties[i].Name == "y")
@@ -330,6 +339,7 @@ bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element,
else if (Element.Properties[i].Name == "nx")
{
attribs[E_NORM].second.X = getFloat(_ctx, t);
+ performActionBasedOnOrientationSystem(_params, [&]() {attribs[E_NORM].second.X = -attribs[E_NORM].second.X;}, [&]() {});
attribs[E_NORM].first = result=true;
}
else if (Element.Properties[i].Name == "ny")
@@ -389,7 +399,7 @@ bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element,
}
-bool CPLYMeshFileLoader::readFace(SContext& _ctx, const SPLYElement &Element, core::vector<uint32_t>& _outIndices)
+bool CPLYMeshFileLoader::readFace(SContext& _ctx, const SPLYElement &Element, core::vector<uint32_t>& _outIndices, const asset::IAssetLoader::SAssetLoadParams& _params)
{
if (!_ctx.IsBinaryFile)
getNextLine(_ctx);
@@ -407,18 +417,42 @@ bool CPLYMeshFileLoader::readFace(SContext& _ctx, const SPLYElement &Element, co
c = getInt(_ctx, Element.Properties[i].Data.List.ItemType);
int32_t j = 3;
+ performActionBasedOnOrientationSystem
+ (_params,
+ [&]()
+ {
+ _outIndices.push_back(c);
+ _outIndices.push_back(b);
+ _outIndices.push_back(a);
+ },
+ [&]()
+ {
_outIndices.push_back(a);
_outIndices.push_back(b);
_outIndices.push_back(c);
+ }
+ );
for (; j < count; ++j)
{
b = c;
c = getInt(_ctx, Element.Properties[i].Data.List.ItemType);
+ performActionBasedOnOrientationSystem
+ (_params,
+ [&]()
+ {
+ _outIndices.push_back(b);
+ _outIndices.push_back(c);
+ _outIndices.push_back(a);
+ },
+ [&]()
+ {
_outIndices.push_back(a);
_outIndices.push_back(c);
_outIndices.push_back(b);
}
+ );
+ }
}
else if (Element.Properties[i].Name == "intensity")
{

diff:
@@ -158,8 +158,8 @@ private:
void fillBuffer(SContext& _ctx);
E_PLY_PROPERTY_TYPE getPropertyType(const char* typeString) const;
- bool readVertex(SContext& _ctx, const SPLYElement &Element, core::vector<core::vectorSIMDf> _attribs[4]);
- bool readFace(SContext& _ctx, const SPLYElement &Element, core::vector<uint32_t>& _outIndices);
+ bool readVertex(SContext& _ctx, const SPLYElement &Element, core::vector<core::vectorSIMDf> _attribs[4], const asset::IAssetLoader::SAssetLoadParams& _params);
+ bool readFace(SContext& _ctx, const SPLYElement &Element, core::vector<uint32_t>& _outIndices, const asset::IAssetLoader::SAssetLoadParams& _params);
void skipElement(SContext& _ctx, const SPLYElement &Element);
void skipProperty(SContext& _ctx, const SPLYProperty &Property);
float getFloat(SContext& _ctx, E_PLY_PROPERTY_TYPE t);

original_message: Flip CPLYMeshFileLoader


message: Flip CXMeshFileLoader

diff:
@@ -88,7 +88,7 @@ asset::SAssetBundle CXMeshFileLoader::loadAsset(io::IReadFile* _file, const asse
ctx.AnimatedMesh = new asset::CCPUSkinnedMesh();
asset::ICPUMesh* retVal = nullptr;
- if (load(ctx, _file))
+ if (load(ctx, _file, _params))
{
ctx.AnimatedMesh->finalize();
if (ctx.AnimatedMesh->isStatic())
@@ -225,12 +225,12 @@ core::matrix4x3 getGlobalMatrix_evil(asset::ICPUSkinnedMesh::SJoint* joint)
}
-bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file)
+bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file, const asset::IAssetLoader::SAssetLoadParams& _params)
{
if (!readFileIntoMemory(_ctx, file))
return false;
- if (!parseFile(_ctx))
+ if (!parseFile(_ctx, _params))
return false;
for (uint32_t n=0; n<_ctx.Meshes.size(); ++n)
@@ -690,9 +690,9 @@ bool CXMeshFileLoader::readFileIntoMemory(SContext& _ctx, io::IReadFile* file)
//! Parses the file
-bool CXMeshFileLoader::parseFile(SContext& _ctx)
+bool CXMeshFileLoader::parseFile(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params)
{
- while(parseDataObject(_ctx))
+ while(parseDataObject(_ctx, _params))
{
// loop
}
@@ -702,7 +702,7 @@ bool CXMeshFileLoader::parseFile(SContext& _ctx)
//! Parses the next Data object in the file
-bool CXMeshFileLoader::parseDataObject(SContext& _ctx)
+bool CXMeshFileLoader::parseDataObject(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params)
{
std::string objectName = getNextToken(_ctx);
@@ -719,7 +719,7 @@ bool CXMeshFileLoader::parseDataObject(SContext& _ctx)
else
if (objectName == "Frame")
{
- return parseDataObjectFrame( _ctx, 0 );
+ return parseDataObjectFrame( _ctx, 0, _params);
}
else
if (objectName == "Mesh")
@@ -732,7 +732,7 @@ bool CXMeshFileLoader::parseDataObject(SContext& _ctx)
//mesh->Buffer=AnimatedMesh->addMeshBuffer();
_ctx.Meshes.push_back(mesh);
- return parseDataObjectMesh(_ctx, *mesh);
+ return parseDataObjectMesh(_ctx, *mesh, _params);
}
else
if (objectName == "AnimationSet")
@@ -796,7 +796,7 @@ bool CXMeshFileLoader::parseDataObjectTemplate(SContext& _ctx)
}
-bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *Parent)
+bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *Parent, const asset::IAssetLoader::SAssetLoadParams& _params)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading frame", ELL_DEBUG);
@@ -878,7 +878,7 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
if (objectName == "Frame")
{
- if (!parseDataObjectFrame(_ctx, joint))
+ if (!parseDataObjectFrame(_ctx, joint, _params))
return false;
}
else
@@ -905,7 +905,7 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
_ctx.Meshes.push_back(mesh);
- if (!parseDataObjectMesh(_ctx, *mesh))
+ if (!parseDataObjectMesh(_ctx, *mesh, _params))
return false;
}
else
@@ -952,7 +952,7 @@ bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core:
}
-bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh)
+bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params)
{
std::string name;
@@ -970,6 +970,14 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh)
os::Printer::log("CXFileReader: Reading mesh", name, ELL_DEBUG);
#endif
+ auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
+ {
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performOnRightHanded();
+ else
+ performOnLeftHanded();
+ };
+
// read vertex count
const uint32_t nVertices = readInt(_ctx);
@@ -978,6 +986,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh)
for (uint32_t n=0; n<nVertices; ++n)
{
readVector3(_ctx, mesh.Vertices[n].Pos);
+ performActionBasedOnOrientationSystem([&]() {mesh.Vertices[n].Pos.X = -mesh.Vertices[n].Pos.X; }, [&]() {});
}
if (!checkForTwoFollowingSemicolons(_ctx))
@@ -1018,19 +1027,48 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh)
polygonfaces[f] = readInt(_ctx);
for (uint32_t jk=0; jk<triangles; ++jk)
+ {
+ performActionBasedOnOrientationSystem
+ (
+ [&]()
+ {
+ mesh.Indices[currentIndex++] = polygonfaces[jk + 2];
+ mesh.Indices[currentIndex++] = polygonfaces[jk + 1];
+ mesh.Indices[currentIndex++] = polygonfaces[0];
+ },
+ [&]()
{
mesh.Indices[currentIndex++] = polygonfaces[0];
mesh.Indices[currentIndex++] = polygonfaces[jk + 1];
mesh.Indices[currentIndex++] = polygonfaces[jk + 2];
}
+ );
+ }
// TODO: change face indices in material list
}
else
{
- mesh.Indices[currentIndex++] = readInt(_ctx);
- mesh.Indices[currentIndex++] = readInt(_ctx);
- mesh.Indices[currentIndex++] = readInt(_ctx);
+ std::array<uint32_t, 3> indicies;
+ for (auto& it : indicies)
+ it = readInt(_ctx);
+
+ performActionBasedOnOrientationSystem
+ (
+ [&]()
+ {
+ mesh.Indices[currentIndex++] = indicies[2];
+ mesh.Indices[currentIndex++] = indicies[1];
+ mesh.Indices[currentIndex++] = indicies[0];
+ },
+ [&]()
+ {
+ mesh.Indices[currentIndex++] = indicies[0];
+ mesh.Indices[currentIndex++] = indicies[1];
+ mesh.Indices[currentIndex++] = indicies[2];
+ }
+ );
+
mesh.IndexCountPerFace[k] = 3;
}
}
@@ -1065,7 +1103,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh)
if (objectName == "MeshNormals")
{
- if (!parseDataObjectMeshNormals(_ctx, mesh))
+ if (!parseDataObjectMeshNormals(_ctx, mesh, performActionBasedOnOrientationSystem))
return false;
}
else
@@ -1437,7 +1475,7 @@ bool CXMeshFileLoader::parseDataObjectSkinMeshHeader(SContext& _ctx, SXMesh& mes
}
-bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh)
+bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: reading mesh normals", ELL_DEBUG);
@@ -1489,11 +1527,23 @@ bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh)
if (indexcount == 3)
{
// default, only one triangle in this face
- for (uint32_t h=0; h<3; ++h)
+ std::array<uint32_t, 3> tmpNormals;
+ for(auto& it : tmpNormals)
+ it = readInt(_ctx);
+
+ performActionBasedOnOrientationSystem
+ (
+ [&]()
+ {
+ for(uint32_t it = 3; it > 0; --it)
+ mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[tmpNormals[it - 1]]);
+ },
+ [&]()
{
- const uint32_t normalnum = readInt(_ctx);
- mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[normalnum]);
+ for(auto& it : tmpNormals)
+ mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[it]);
}
+ );
}
else
{
@@ -1503,11 +1553,23 @@ bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh)
polygonfaces[h] = readInt(_ctx);
for (uint32_t jk=0; jk<triangles; ++jk)
+ {
+ performActionBasedOnOrientationSystem
+ (
+ [&]()
+ {
+ mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 2]]);
+ mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 1]]);
+ mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[0]]);
+ },
+ [&]()
{
mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[0]]);
mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 1]]);
mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 2]]);
}
+ );
+ }
}
}

diff:
@@ -163,27 +163,27 @@ private:
asset::IAssetLoader::IAssetLoaderOverride* loaderOverride;
};
- bool load(SContext& _ctx, io::IReadFile* file);
+ bool load(SContext& _ctx, io::IReadFile* file, const asset::IAssetLoader::SAssetLoadParams& _params);
bool readFileIntoMemory(SContext& _ctx, io::IReadFile* file);
- bool parseFile(SContext& _ctx);
+ bool parseFile(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params);
- bool parseDataObject(SContext& _ctx);
+ bool parseDataObject(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params);
bool parseDataObjectTemplate(SContext& _ctx);
- bool parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *parent);
+ bool parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *parent, const asset::IAssetLoader::SAssetLoadParams& _params);
bool parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat);
- bool parseDataObjectMesh(SContext& _ctx, SXMesh &mesh);
+ bool parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params);
bool parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh);
bool parseDataObjectSkinMeshHeader(SContext& _ctx, SXMesh &mesh);
- bool parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh);
+ bool parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem);
bool parseDataObjectMeshTextureCoords(SContext& _ctx, SXMesh &mesh);

original_message: Flip CXMeshFileLoader


message: Fix CXLoader

diff:
@@ -1495,7 +1495,10 @@ bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh,
// read normals
for (uint32_t i = 0; i < nNormals; ++i)
+ {
readVector3(_ctx, normals[i]);
+ performActionBasedOnOrientationSystem([&]() {normals[i].X = -normals[i].X;}, [&]() {});
+ }
if (!checkForTwoFollowingSemicolons(_ctx))
{
@@ -1529,21 +1532,7 @@ bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh,
// default, only one triangle in this face
std::array<uint32_t, 3> tmpNormals;
for(auto& it : tmpNormals)
- it = readInt(_ctx);
-
- performActionBasedOnOrientationSystem
- (
- [&]()
- {
- for(uint32_t it = 3; it > 0; --it)
- mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[tmpNormals[it - 1]]);
- },
- [&]()
- {
- for(auto& it : tmpNormals)
- mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[it]);
- }
- );
+ mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[it = readInt(_ctx)]);
}
else
{
@@ -1553,23 +1542,11 @@ bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh,
polygonfaces[h] = readInt(_ctx);
for (uint32_t jk=0; jk<triangles; ++jk)
- {
- performActionBasedOnOrientationSystem
- (
- [&]()
- {
- mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 2]]);
- mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 1]]);
- mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[0]]);
- },
- [&]()
{
mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[0]]);
mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 1]]);
mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[polygonfaces[jk + 2]]);
}
- );
- }
}
}

original_message: Fix CXLoader


message: Make CSTL and COBJ Loaders flipping work

diff:
@@ -325,23 +325,10 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(io::IReadFile* _file, const as
for ( uint32_t i = 1; i < faceCorners.size() - 1; ++i )
{
// Add a triangle
- performActionBasedOnOrientationSystem
- (
- [&]()
- {
- currMtl->Indices.push_back(faceCorners[0]);
- currMtl->Indices.push_back(faceCorners[i]);
- currMtl->Indices.push_back(faceCorners[i + 1]);
- },
-
- [&]()
- {
currMtl->Indices.push_back(faceCorners[i + 1]);
currMtl->Indices.push_back(faceCorners[i]);
currMtl->Indices.push_back(faceCorners[0]);
}
- );
- }
faceCorners.resize(0); // fast clear
faceCorners.reserve(32);
}

diff:
@@ -227,8 +227,7 @@ asset::SAssetBundle CPLYMeshFileLoader::loadAsset(io::IReadFile* _file, const as
getNextLine(ctx);
word = getNextWord(ctx);
}
- }
- while (readingHeader && continueReading);
+ } while (readingHeader && continueReading);
// now to read the actual data from the file
if (continueReading)
@@ -249,13 +248,13 @@ asset::SAssetBundle CPLYMeshFileLoader::loadAsset(io::IReadFile* _file, const as
{
// loop through vertex properties
for (uint32_t j = 0; j < ctx.ElementList[i]->Count; ++j)
- hasNormals &= readVertex(ctx, *ctx.ElementList[i], attribs, _params);
+ hasNormals &= readVertex(ctx, *ctx.ElementList[i], attribs);
}
else if (ctx.ElementList[i]->Name == "face")
{
// read faces
for (uint32_t j = 0; j < ctx.ElementList[i]->Count; ++j)
- readFace(ctx, *ctx.ElementList[i], indices, _params);
+ readFace(ctx, *ctx.ElementList[i], indices);
}
else
{
@@ -265,8 +264,6 @@ asset::SAssetBundle CPLYMeshFileLoader::loadAsset(io::IReadFile* _file, const as
}
}
- if (!genVertBuffersForMBuffer(mb.get(), attribs))
- return {};
if (indices.size())
{
auto idxBuf = core::make_smart_refctd_ptr<asset::ICPUBuffer>(indices.size() * sizeof(uint32_t));
@@ -284,29 +281,25 @@ asset::SAssetBundle CPLYMeshFileLoader::loadAsset(io::IReadFile* _file, const as
}
mb->setMeshDataAndFormat(std::move(desc));
+
+ if (!genVertBuffersForMBuffer(mb.get(), attribs))
+ return {};
+
mb->recalculateBoundingBox();
//if (!hasNormals)
// SceneManager->getMeshManipulator()->recalculateNormals(mb);
mesh = core::make_smart_refctd_ptr<CCPUMesh>();
mesh->addMeshBuffer(std::move(mb));
- mesh->recalculateBoundingBox();
+ mesh->recalculateBoundingBox(true);
}
}
return SAssetBundle({ mesh });
}
-static void performActionBasedOnOrientationSystem(const asset::IAssetLoader::SAssetLoadParams& _params, std::function<void()> performOnRightHanded, std::function<void()> performOnLeftHanded)
-{
- if (_params.loaderFlags & IAssetLoader::ELPF_RIGHT_HANDED_MESHES)
- performOnRightHanded();
- else
- performOnLeftHanded();
-}
-
-bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _outAttribs[4], const asset::IAssetLoader::SAssetLoadParams& _params)
+ bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _outAttribs[4])
{
if (!_ctx.IsBinaryFile)
getNextLine(_ctx);
@@ -323,7 +316,6 @@ bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element,
if (Element.Properties[i].Name == "x")
{
attribs[E_POS].second.X = getFloat(_ctx, t);
- performActionBasedOnOrientationSystem(_params, [&]() {attribs[E_POS].second.X = -attribs[E_POS].second.X;}, [&]() {});
attribs[E_POS].first = true;
}
else if (Element.Properties[i].Name == "y")
@@ -339,7 +331,6 @@ bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element,
else if (Element.Properties[i].Name == "nx")
{
attribs[E_NORM].second.X = getFloat(_ctx, t);
- performActionBasedOnOrientationSystem(_params, [&]() {attribs[E_NORM].second.X = -attribs[E_NORM].second.X;}, [&]() {});
attribs[E_NORM].first = result = true;
}
else if (Element.Properties[i].Name == "ny")
@@ -399,7 +390,7 @@ bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element,
}
-bool CPLYMeshFileLoader::readFace(SContext& _ctx, const SPLYElement &Element, core::vector<uint32_t>& _outIndices, const asset::IAssetLoader::SAssetLoadParams& _params)
+ bool CPLYMeshFileLoader::readFace(SContext& _ctx, const SPLYElement& Element, core::vector<uint32_t>& _outIndices)
{
if (!_ctx.IsBinaryFile)
getNextLine(_ctx);
@@ -417,42 +408,18 @@ bool CPLYMeshFileLoader::readFace(SContext& _ctx, const SPLYElement &Element, co
c = getInt(_ctx, Element.Properties[i].Data.List.ItemType);
int32_t j = 3;
- performActionBasedOnOrientationSystem
- (_params,
- [&]()
- {
- _outIndices.push_back(c);
- _outIndices.push_back(b);
- _outIndices.push_back(a);
- },
- [&]()
- {
_outIndices.push_back(a);
_outIndices.push_back(b);
_outIndices.push_back(c);
- }
- );
for (; j < count; ++j)
{
b = c;
c = getInt(_ctx, Element.Properties[i].Data.List.ItemType);
- performActionBasedOnOrientationSystem
- (_params,
- [&]()
- {
- _outIndices.push_back(b);
- _outIndices.push_back(c);
- _outIndices.push_back(a);
- },
- [&]()
- {
_outIndices.push_back(a);
_outIndices.push_back(c);
_outIndices.push_back(b);
}
- );
- }
}
else if (Element.Properties[i].Name == "intensity")
{
@@ -616,6 +583,8 @@ bool CPLYMeshFileLoader::genVertBuffersForMBuffer(asset::ICPUMeshBuffer* _mbuf,
auto desc = _mbuf->getMeshDataAndFormat();
auto buf = core::make_smart_refctd_ptr<asset::ICPUBuffer>(_attribs[E_POS].size() * stride);
+ memcpy(buf->getPointer(), _attribs[E_POS].data(), buf->getSize());
+
if (sizes[E_POS])
desc->setVertexAttrBuffer(core::smart_refctd_ptr(buf), asset::EVAI_ATTR0, asset::EF_R32G32B32_SFLOAT, stride, offsets[E_POS]);
if (sizes[E_COL])
@@ -946,4 +915,3 @@ uint32_t CPLYMeshFileLoader::getInt(SContext& _ctx, E_PLY_PROPERTY_TYPE t)
} // end namespace irr
#endif // _IRR_COMPILE_WITH_PLY_LOADER_
-

diff:
@@ -158,8 +158,8 @@ private:
void fillBuffer(SContext& _ctx);
E_PLY_PROPERTY_TYPE getPropertyType(const char* typeString) const;
- bool readVertex(SContext& _ctx, const SPLYElement &Element, core::vector<core::vectorSIMDf> _attribs[4], const asset::IAssetLoader::SAssetLoadParams& _params);
- bool readFace(SContext& _ctx, const SPLYElement &Element, core::vector<uint32_t>& _outIndices, const asset::IAssetLoader::SAssetLoadParams& _params);
+ bool readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _attribs[4]);
+ bool readFace(SContext& _ctx, const SPLYElement& Element, core::vector<uint32_t>& _outIndices);
void skipElement(SContext& _ctx, const SPLYElement& Element);
void skipProperty(SContext& _ctx, const SPLYProperty& Property);
float getFloat(SContext& _ctx, E_PLY_PROPERTY_TYPE t);
@@ -173,4 +173,3 @@ private:
} // end namespace irr
#endif
-

diff:
@@ -72,10 +72,6 @@ asset::SAssetBundle CSTLMeshFileLoader::loadAsset(io::IReadFile* _file, const as
}
}
- {
- core::vectorSIMDf n;
- getNextVector(_file, n, binary);
-
auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
{
if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
@@ -84,8 +80,12 @@ asset::SAssetBundle CSTLMeshFileLoader::loadAsset(io::IReadFile* _file, const as
performOnLeftHanded();
};
+ {
+ core::vectorSIMDf n;
+ getNextVector(_file, n, binary);
performActionBasedOnOrientationSystem([&]() {n.x = -n.x; }, [&]() {});
normals.push_back(core::normalize(n));
+ }
if (!binary)
{
@@ -106,7 +106,7 @@ asset::SAssetBundle CSTLMeshFileLoader::loadAsset(io::IReadFile* _file, const as
performActionBasedOnOrientationSystem([&]() {p[i].x = -p[i].x; }, [&]() {});
}
for (uint32_t i = 0u; i < 3u; ++i) // seems like in STL format vertices are ordered in clockwise manner...
- performActionBasedOnOrientationSystem([&]() {positions.push_back(p[i]); }, [&]() {positions.push_back(p[2u - i]); });
+ positions.push_back(p[2u - i]);
}
if (!binary)

diff:
@@ -11,7 +11,6 @@ namespace irr
{
namespace asset
{
-
//! Meshloader capable of loading STL meshes.
class CSTLMeshFileLoader : public asset::IAssetLoader
{


message: Fix memory leaks, make CX's flipping work

diff:
@@ -88,7 +88,15 @@ asset::SAssetBundle CXMeshFileLoader::loadAsset(io::IReadFile* _file, const asse
ctx.AnimatedMesh = new asset::CCPUSkinnedMesh();
asset::ICPUMesh* retVal = nullptr;
- if (load(ctx, _file, _params))
+ auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
+ {
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performOnRightHanded();
+ else
+ performOnLeftHanded();
+ };
+
+ if (load(ctx, _file, performActionBasedOnOrientationSystem))
{
ctx.AnimatedMesh->finalize();
if (ctx.AnimatedMesh->isStatic())
@@ -225,12 +233,12 @@ core::matrix4x3 getGlobalMatrix_evil(asset::ICPUSkinnedMesh::SJoint* joint)
}
-bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file, const asset::IAssetLoader::SAssetLoadParams& _params)
+bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file, orientationFunction performActionBasedOnOrientationSystem)
{
if (!readFileIntoMemory(_ctx, file))
return false;
- if (!parseFile(_ctx, _params))
+ if (!parseFile(_ctx, performActionBasedOnOrientationSystem))
return false;
for (uint32_t n=0; n<_ctx.Meshes.size(); ++n)
@@ -412,7 +420,7 @@ bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file, const asset::IA
else
buffer->setIndexType(asset::EIT_16BIT);
- buffer->setMeshDataAndFormat(std::move(desc));
+ //buffer->setMeshDataAndFormat(std::move(desc));
if (i>0)
{
@@ -606,6 +614,10 @@ bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file, const asset::IA
}
}
desc->setIndexBuffer(std::move(ixbuf));
+
+ for (i = 0; i < mesh->Buffers.size(); ++i)
+ mesh->Buffers[i]->setMeshDataAndFormat(core::smart_refctd_ptr<ICPUMeshDataFormatDesc>(desc));
+
delete [] cumBaseVertex;
delete [] vCountArray;
}
@@ -690,9 +702,9 @@ bool CXMeshFileLoader::readFileIntoMemory(SContext& _ctx, io::IReadFile* file)
//! Parses the file
-bool CXMeshFileLoader::parseFile(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params)
+bool CXMeshFileLoader::parseFile(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem)
{
- while(parseDataObject(_ctx, _params))
+ while(parseDataObject(_ctx, performActionBasedOnOrientationSystem))
{
// loop
}
@@ -702,7 +714,7 @@ bool CXMeshFileLoader::parseFile(SContext& _ctx, const asset::IAssetLoader::SAss
//! Parses the next Data object in the file
-bool CXMeshFileLoader::parseDataObject(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params)
+bool CXMeshFileLoader::parseDataObject(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem)
{
std::string objectName = getNextToken(_ctx);
@@ -719,7 +731,7 @@ bool CXMeshFileLoader::parseDataObject(SContext& _ctx, const asset::IAssetLoader
else
if (objectName == "Frame")
{
- return parseDataObjectFrame( _ctx, 0, _params);
+ return parseDataObjectFrame( _ctx, 0 , performActionBasedOnOrientationSystem);
}
else
if (objectName == "Mesh")
@@ -732,12 +744,12 @@ bool CXMeshFileLoader::parseDataObject(SContext& _ctx, const asset::IAssetLoader
//mesh->Buffer=AnimatedMesh->addMeshBuffer();
_ctx.Meshes.push_back(mesh);
- return parseDataObjectMesh(_ctx, *mesh, _params);
+ return parseDataObjectMesh(_ctx, *mesh, performActionBasedOnOrientationSystem);
}
else
if (objectName == "AnimationSet")
{
- return parseDataObjectAnimationSet(_ctx);
+ return parseDataObjectAnimationSet(_ctx, performActionBasedOnOrientationSystem);
}
else
if (objectName == "Material")
@@ -796,7 +808,7 @@ bool CXMeshFileLoader::parseDataObjectTemplate(SContext& _ctx)
}
-bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *Parent, const asset::IAssetLoader::SAssetLoadParams& _params)
+bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *Parent, orientationFunction performActionBasedOnOrientationSystem)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading frame", ELL_DEBUG);
@@ -878,13 +890,13 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
if (objectName == "Frame")
{
- if (!parseDataObjectFrame(_ctx, joint, _params))
+ if (!parseDataObjectFrame(_ctx, joint, performActionBasedOnOrientationSystem))
return false;
}
else
if (objectName == "FrameTransformMatrix")
{
- if (!parseDataObjectTransformationMatrix(_ctx, joint->LocalMatrix))
+ if (!parseDataObjectTransformationMatrix(_ctx, joint->LocalMatrix, performActionBasedOnOrientationSystem))
return false;
//joint->LocalAnimatedMatrix
@@ -905,7 +917,7 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
_ctx.Meshes.push_back(mesh);
- if (!parseDataObjectMesh(_ctx, *mesh, _params))
+ if (!parseDataObjectMesh(_ctx, *mesh, performActionBasedOnOrientationSystem))
return false;
}
else
@@ -920,7 +932,7 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
}
-bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat)
+bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat, orientationFunction performActionBasedOnOrientationSystem)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading Transformation Matrix", ELL_DEBUG);
@@ -933,7 +945,7 @@ bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core:
return false;
}
- readMatrix(_ctx, mat);
+ readMatrix(_ctx, mat, performActionBasedOnOrientationSystem);
if (!checkForOneFollowingSemicolons(_ctx))
{
@@ -952,7 +964,7 @@ bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core:
}
-bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params)
+bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem)
{
std::string name;
@@ -970,14 +982,6 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const a
os::Printer::log("CXFileReader: Reading mesh", name, ELL_DEBUG);
#endif
- auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
- {
- if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
- performOnRightHanded();
- else
- performOnLeftHanded();
- };
-
// read vertex count
const uint32_t nVertices = readInt(_ctx);
@@ -1027,48 +1031,19 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const a
polygonfaces[f] = readInt(_ctx);
for (uint32_t jk=0; jk<triangles; ++jk)
- {
- performActionBasedOnOrientationSystem
- (
- [&]()
- {
- mesh.Indices[currentIndex++] = polygonfaces[jk + 2];
- mesh.Indices[currentIndex++] = polygonfaces[jk + 1];
- mesh.Indices[currentIndex++] = polygonfaces[0];
- },
- [&]()
{
mesh.Indices[currentIndex++] = polygonfaces[0];
mesh.Indices[currentIndex++] = polygonfaces[jk+1];
mesh.Indices[currentIndex++] = polygonfaces[jk+2];
}
- );
- }
// TODO: change face indices in material list
}
else
{
- std::array<uint32_t, 3> indicies;
- for (auto& it : indicies)
- it = readInt(_ctx);
-
- performActionBasedOnOrientationSystem
- (
- [&]()
- {
- mesh.Indices[currentIndex++] = indicies[2];
- mesh.Indices[currentIndex++] = indicies[1];
- mesh.Indices[currentIndex++] = indicies[0];
- },
- [&]()
- {
- mesh.Indices[currentIndex++] = indicies[0];
- mesh.Indices[currentIndex++] = indicies[1];
- mesh.Indices[currentIndex++] = indicies[2];
- }
- );
-
+ mesh.Indices[currentIndex++] = readInt(_ctx);
+ mesh.Indices[currentIndex++] = readInt(_ctx);
+ mesh.Indices[currentIndex++] = readInt(_ctx);
mesh.IndexCountPerFace[k] = 3;
}
}
@@ -1324,7 +1299,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const a
{
//mesh.SkinWeights.push_back(SXSkinWeight());
//if (!parseDataObjectSkinWeights(mesh.SkinWeights.back()))
- if (!parseDataObjectSkinWeights(_ctx, mesh))
+ if (!parseDataObjectSkinWeights(_ctx, mesh, performActionBasedOnOrientationSystem))
return false;
}
else
@@ -1339,7 +1314,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const a
}
-bool CXMeshFileLoader::parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh)
+bool CXMeshFileLoader::parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading mesh skin weights", ELL_DEBUG);
@@ -1423,7 +1398,7 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh)
// transforms the mesh vertices to the space of the bone
// When concatenated to the bone's transform, this provides the
// world space coordinates of the mesh as affected by the bone
- readMatrix(_ctx, joint->GlobalInversedMatrix);
+ readMatrix(_ctx, joint->GlobalInversedMatrix, performActionBasedOnOrientationSystem);
if (!checkForOneFollowingSemicolons(_ctx))
{
@@ -1530,9 +1505,11 @@ bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh,
if (indexcount == 3)
{
// default, only one triangle in this face
- std::array<uint32_t, 3> tmpNormals;
- for(auto& it : tmpNormals)
- mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[it = readInt(_ctx)]);
+ for (uint32_t h=0; h<3; ++h)
+ {
+ const uint32_t normalnum = readInt(_ctx);
+ mesh.Vertices[mesh.Indices[normalidx++]].Normal.set(normals[normalnum]);
+ }
}
else
{
@@ -1841,7 +1818,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(SContext& _ctx, video::SCPUMateri
}
-bool CXMeshFileLoader::parseDataObjectAnimationSet(SContext& _ctx)
+bool CXMeshFileLoader::parseDataObjectAnimationSet(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading animation set", ELL_DEBUG);
@@ -1875,7 +1852,7 @@ bool CXMeshFileLoader::parseDataObjectAnimationSet(SContext& _ctx)
else
if (objectName == "Animation")
{
- if (!parseDataObjectAnimation(_ctx))
+ if (!parseDataObjectAnimation(_ctx, performActionBasedOnOrientationSystem))
return false;
}
else
@@ -1889,7 +1866,7 @@ bool CXMeshFileLoader::parseDataObjectAnimationSet(SContext& _ctx)
}
-bool CXMeshFileLoader::parseDataObjectAnimation(SContext& _ctx)
+bool CXMeshFileLoader::parseDataObjectAnimation(SContext& _ctx, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: reading animation", ELL_DEBUG);
@@ -1926,7 +1903,7 @@ bool CXMeshFileLoader::parseDataObjectAnimation(SContext& _ctx)
else
if (objectName == "AnimationKey")
{
- if (!parseDataObjectAnimationKey(_ctx, &animationDump))
+ if (!parseDataObjectAnimationKey(_ctx, &animationDump, performActionBasedOnOrientationSystem))
return false;
}
else
@@ -2008,7 +1985,7 @@ bool CXMeshFileLoader::parseDataObjectAnimation(SContext& _ctx)
}
-bool CXMeshFileLoader::parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *joint)
+bool CXMeshFileLoader::parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *joint, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: reading animation key", ELL_DEBUG);
@@ -2130,7 +2107,7 @@ bool CXMeshFileLoader::parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSk
// read matrix
core::matrix4x3 mat4x3;
- readMatrix(_ctx, mat4x3);
+ readMatrix(_ctx, mat4x3, performActionBasedOnOrientationSystem);
//mat=joint->LocalMatrix*mat;
if (!checkForOneFollowingSemicolons(_ctx))
@@ -2651,12 +2628,23 @@ bool CXMeshFileLoader::readRGBA(SContext& _ctx, video::SColor& color)
// read matrix from list of floats
-bool CXMeshFileLoader::readMatrix(SContext& _ctx, core::matrix4x3& mat)
+bool CXMeshFileLoader::readMatrix(SContext& _ctx, core::matrix4x3& mat, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
{
for (uint32_t j=0u; j<4u; j++)
{
for (uint32_t i = 0u; i < 3u; i++)
+ performActionBasedOnOrientationSystem
+ (
+ [&]()
+ {
+ constexpr uint32_t xPosID = 0;
+ mat(i, j) = (i == xPosID ? readFloat(_ctx) : -readFloat(_ctx));
+ },
+ [&]()
+ {
mat(i, j) = readFloat(_ctx);
+ }
+ );
readFloat(_ctx);
}
return checkForOneFollowingSemicolons(_ctx);
@@ -2667,4 +2655,3 @@ bool CXMeshFileLoader::readMatrix(SContext& _ctx, core::matrix4x3& mat)
} // end namespace irr
#endif // _IRR_COMPILE_WITH_X_LOADER_
-

diff:
@@ -163,27 +163,29 @@ private:
asset::IAssetLoader::IAssetLoaderOverride* loaderOverride;
};
- bool load(SContext& _ctx, io::IReadFile* file, const asset::IAssetLoader::SAssetLoadParams& _params);
+ using orientationFunction = std::function<void(std::function<void()>, std::function<void()>)>;
+
+ bool load(SContext& _ctx, io::IReadFile* file, orientationFunction performActionBasedOnOrientationSystem);
bool readFileIntoMemory(SContext& _ctx, io::IReadFile* file);
- bool parseFile(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params);
+ bool parseFile(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem);
- bool parseDataObject(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params);
+ bool parseDataObject(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem);
bool parseDataObjectTemplate(SContext& _ctx);
- bool parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *parent, const asset::IAssetLoader::SAssetLoadParams& _params);
+ bool parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *parent, orientationFunction performActionBasedOnOrientationSystem);
- bool parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat);
+ bool parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat, orientationFunction performActionBasedOnOrientationSystem);
- bool parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params);
+ bool parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem);
- bool parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh);
+ bool parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem);
bool parseDataObjectSkinMeshHeader(SContext& _ctx, SXMesh &mesh);
- bool parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem);
+ bool parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem);
bool parseDataObjectMeshTextureCoords(SContext& _ctx, SXMesh &mesh);
@@ -193,11 +195,11 @@ private:
bool parseDataObjectMaterial(SContext& _ctx, video::SCPUMaterial& material);
- bool parseDataObjectAnimationSet(SContext& _ctx);
+ bool parseDataObjectAnimationSet(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem);
- bool parseDataObjectAnimation(SContext& _ctx);
+ bool parseDataObjectAnimation(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem);
- bool parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *joint);
+ bool parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *joint, orientationFunction performActionBasedOnOrientationSystem);
bool parseDataObjectTextureFilename(SContext& _ctx, std::string& texturename);
@@ -236,7 +238,7 @@ private:
float readFloat(SContext& _ctx);
bool readVector2(SContext& _ctx, core::vector2df& vec);
bool readVector3(SContext& _ctx, core::vector3df& vec);
- bool readMatrix(SContext& _ctx, core::matrix4x3& mat);
+ bool readMatrix(SContext& _ctx, core::matrix4x3& mat, orientationFunction performActionBasedOnOrientationSystem);
bool readRGB(SContext& _ctx, video::SColor& color);
bool readRGBA(SContext& _ctx, video::SColor& color);


message: Make CPLYMeshFileLoader work

diff:
@@ -240,6 +240,15 @@ namespace irr
core::vector<uint32_t> indices;
bool hasNormals = true;
+
+ auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
+ {
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performOnRightHanded();
+ else
+ performOnLeftHanded();
+ };
+
// loop through each of the elements
for (uint32_t i = 0; i < ctx.ElementList.size(); ++i)
{
@@ -248,7 +257,7 @@ namespace irr
{
// loop through vertex properties
for (uint32_t j = 0; j < ctx.ElementList[i]->Count; ++j)
- hasNormals &= readVertex(ctx, *ctx.ElementList[i], attribs);
+ hasNormals &= readVertex(ctx, *ctx.ElementList[i], attribs, performActionBasedOnOrientationSystem);
}
else if (ctx.ElementList[i]->Name == "face")
{
@@ -299,7 +308,7 @@ namespace irr
}
- bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _outAttribs[4])
+ bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _outAttribs[4], std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
{
if (!_ctx.IsBinaryFile)
getNextLine(_ctx);
@@ -384,7 +393,14 @@ namespace irr
for (size_t i = 0u; i < 4u; ++i)
if (attribs[i].first)
+ {
+ if (i == E_POS)
+ performActionBasedOnOrientationSystem([&]() { attribs[E_POS].second.X = -attribs[E_POS].second.X; }, [&]() {});
+ else if(i == E_NORM)
+ performActionBasedOnOrientationSystem([&]() { attribs[E_NORM].second.X = -attribs[E_NORM].second.X; }, [&]() {});
+
_outAttribs[i].push_back(attribs[i].second);
+ }
return result;
}

diff:
@@ -158,7 +158,7 @@ namespace irr
void fillBuffer(SContext& _ctx);
E_PLY_PROPERTY_TYPE getPropertyType(const char* typeString) const;
- bool readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _attribs[4]);
+ bool readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _attribs[4], std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem);
bool readFace(SContext& _ctx, const SPLYElement& Element, core::vector<uint32_t>& _outIndices);
void skipElement(SContext& _ctx, const SPLYElement& Element);
void skipProperty(SContext& _ctx, const SPLYProperty& Property);

original_message: Make CPLYMeshFileLoader work


message:
Remove std::function, fix CXLoader bug
Matricies in CXLoader shouldn't be flipped

diff:
@@ -105,14 +105,6 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(io::IReadFile* _file, const as
bool mtlChanged=false;
bool submeshLoadedFromCache = false;
- auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
- {
- if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
- performOnRightHanded();
- else
- performOnLeftHanded();
- };
-
while(bufPtr != bufEnd)
{
switch(bufPtr[0])
@@ -140,7 +132,8 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(io::IReadFile* _file, const as
{
core::vector3df vec;
bufPtr = readVec3(bufPtr, vec, bufEnd);
- performActionBasedOnOrientationSystem([&]() {vec.X = -vec.X;}, [&]() {});
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performActionBasedOnOrientationSystem<float>(vec.X, [](float& varToFlip) {varToFlip = -varToFlip;});
vertexBuffer.push_back(vec);
}
break;
@@ -149,7 +142,8 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(io::IReadFile* _file, const as
{
core::vector3df vec;
bufPtr = readVec3(bufPtr, vec, bufEnd);
- performActionBasedOnOrientationSystem([&]() {vec.X = -vec.X; }, [&]() {});
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performActionBasedOnOrientationSystem<float>(vec.X, [](float& varToFlip) {varToFlip = -varToFlip;});
normalsBuffer.push_back(vec);
}
break;

diff:
@@ -236,6 +236,12 @@ private:
IAssetManager* AssetManager;
io::IFileSystem* FileSystem;
+
+ template<typename aType>
+ static inline void performActionBasedOnOrientationSystem(aType& varToHandle, void (*performOnCertainOrientation)(aType& varToHandle))
+ {
+ performOnCertainOrientation(varToHandle);
+ }
};
} // end namespace asset

diff:
@@ -241,14 +241,6 @@ asset::SAssetBundle CPLYMeshFileLoader::loadAsset(io::IReadFile* _file, const as
bool hasNormals = true;
- auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
- {
- if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
- performOnRightHanded();
- else
- performOnLeftHanded();
- };
-
// loop through each of the elements
for (uint32_t i=0; i<ctx.ElementList.size(); ++i)
{
@@ -257,7 +249,7 @@ asset::SAssetBundle CPLYMeshFileLoader::loadAsset(io::IReadFile* _file, const as
{
// loop through vertex properties
for (uint32_t j=0; j<ctx.ElementList[i]->Count; ++j)
- hasNormals &= readVertex(ctx, *ctx.ElementList[i], attribs, performActionBasedOnOrientationSystem);
+ hasNormals &= readVertex(ctx, *ctx.ElementList[i], attribs, _params);
}
else if (ctx.ElementList[i]->Name == "face")
{
@@ -308,7 +300,7 @@ asset::SAssetBundle CPLYMeshFileLoader::loadAsset(io::IReadFile* _file, const as
}
-bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _outAttribs[4], std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
+bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element, core::vector<core::vectorSIMDf> _outAttribs[4], const asset::IAssetLoader::SAssetLoadParams& _params)
{
if (!_ctx.IsBinaryFile)
getNextLine(_ctx);
@@ -393,11 +385,14 @@ bool CPLYMeshFileLoader::readVertex(SContext& _ctx, const SPLYElement& Element,
for (size_t i = 0u; i < 4u; ++i)
if (attribs[i].first)
+ {
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
{
if (i == E_POS)
- performActionBasedOnOrientationSystem([&]() { attribs[E_POS].second.X = -attribs[E_POS].second.X; }, [&]() {});
+ performActionBasedOnOrientationSystem<float>(attribs[E_POS].second.X, [](float& varToFlip) { varToFlip = -varToFlip; });
else if (i == E_NORM)
- performActionBasedOnOrientationSystem([&]() { attribs[E_NORM].second.X = -attribs[E_NORM].second.X; }, [&]() {});
+ performActionBasedOnOrientationSystem<float>(attribs[E_NORM].second.X, [](float& varToFlip) { varToFlip = -varToFlip; });
+ }
_outAttribs[i].push_back(attribs[i].second);
}

diff:
@@ -158,7 +158,7 @@ private:
void fillBuffer(SContext& _ctx);
E_PLY_PROPERTY_TYPE getPropertyType(const char* typeString) const;
- bool readVertex(SContext& _ctx, const SPLYElement &Element, core::vector<core::vectorSIMDf> _attribs[4], std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem);
+ bool readVertex(SContext& _ctx, const SPLYElement &Element, core::vector<core::vectorSIMDf> _attribs[4], const asset::IAssetLoader::SAssetLoadParams& _params);
bool readFace(SContext& _ctx, const SPLYElement &Element, core::vector<uint32_t>& _outIndices);
void skipElement(SContext& _ctx, const SPLYElement &Element);
void skipProperty(SContext& _ctx, const SPLYProperty &Property);
@@ -167,6 +167,12 @@ private:
void moveForward(SContext& _ctx, uint32_t bytes);
bool genVertBuffersForMBuffer(asset::ICPUMeshBuffer* _mbuf, const core::vector<core::vectorSIMDf> _attribs[4]) const;
+
+ template<typename aType>
+ static inline void performActionBasedOnOrientationSystem(aType& varToHandle, void (*performOnCertainOrientation)(aType& varToHandle))
+ {
+ performOnCertainOrientation(varToHandle);
+ }
};
} // end namespace scene

diff:
@@ -72,18 +72,11 @@ namespace irr
}
}
- auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
- {
- if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
- performOnRightHanded();
- else
- performOnLeftHanded();
- };
-
{
core::vectorSIMDf n;
getNextVector(_file, n, binary);
- performActionBasedOnOrientationSystem([&]() {n.x = -n.x; }, [&]() {});
+ if(_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performActionBasedOnOrientationSystem<float>(n.x, [](float& varToFlip) {varToFlip = -varToFlip;});
normals.push_back(core::normalize(n));
}
@@ -103,7 +96,8 @@ namespace irr
return {};
}
getNextVector(_file, p[i], binary);
- performActionBasedOnOrientationSystem([&]() {p[i].x = -p[i].x; }, [&]() {});
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performActionBasedOnOrientationSystem<float>(p[i].x, [](float& varToFlip){varToFlip = -varToFlip; });
}
for (uint32_t i = 0u; i < 3u; ++i) // seems like in STL format vertices are ordered in clockwise manner...
positions.push_back(p[2u - i]);

diff:
@@ -38,6 +38,12 @@ private:
//! Read 3d vector of floats
void getNextVector(io::IReadFile* file, core::vectorSIMDf& vec, bool binary) const;
+
+ template<typename aType>
+ static inline void performActionBasedOnOrientationSystem(aType& varToHandle, void (*performOnCertainOrientation)(aType& varToHandle))
+ {
+ performOnCertainOrientation(varToHandle);
+ }
};
} // end namespace scene

diff:
@@ -88,15 +88,7 @@ asset::SAssetBundle CXMeshFileLoader::loadAsset(io::IReadFile* _file, const asse
ctx.AnimatedMesh = new asset::CCPUSkinnedMesh();
asset::ICPUMesh* retVal = nullptr;
- auto performActionBasedOnOrientationSystem = [&](auto performOnRightHanded, auto performOnLeftHanded = [&](void) {})
- {
- if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
- performOnRightHanded();
- else
- performOnLeftHanded();
- };
-
- if (load(ctx, _file, performActionBasedOnOrientationSystem))
+ if (load(ctx, _file, _params))
{
ctx.AnimatedMesh->finalize();
if (ctx.AnimatedMesh->isStatic())
@@ -233,12 +225,12 @@ core::matrix4x3 getGlobalMatrix_evil(asset::ICPUSkinnedMesh::SJoint* joint)
}
-bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file, orientationFunction performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::load(SContext& _ctx, io::IReadFile* file, const asset::IAssetLoader::SAssetLoadParams& _params)
{
if (!readFileIntoMemory(_ctx, file))
return false;
- if (!parseFile(_ctx, performActionBasedOnOrientationSystem))
+ if (!parseFile(_ctx, _params))
return false;
for (uint32_t n=0; n<_ctx.Meshes.size(); ++n)
@@ -702,9 +694,9 @@ bool CXMeshFileLoader::readFileIntoMemory(SContext& _ctx, io::IReadFile* file)
//! Parses the file
-bool CXMeshFileLoader::parseFile(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseFile(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params)
{
- while(parseDataObject(_ctx, performActionBasedOnOrientationSystem))
+ while(parseDataObject(_ctx, _params))
{
// loop
}
@@ -714,7 +706,7 @@ bool CXMeshFileLoader::parseFile(SContext& _ctx, orientationFunction performActi
//! Parses the next Data object in the file
-bool CXMeshFileLoader::parseDataObject(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseDataObject(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params)
{
std::string objectName = getNextToken(_ctx);
@@ -731,7 +723,7 @@ bool CXMeshFileLoader::parseDataObject(SContext& _ctx, orientationFunction perfo
else
if (objectName == "Frame")
{
- return parseDataObjectFrame( _ctx, 0 , performActionBasedOnOrientationSystem);
+ return parseDataObjectFrame( _ctx, 0 , _params);
}
else
if (objectName == "Mesh")
@@ -744,12 +736,12 @@ bool CXMeshFileLoader::parseDataObject(SContext& _ctx, orientationFunction perfo
//mesh->Buffer=AnimatedMesh->addMeshBuffer();
_ctx.Meshes.push_back(mesh);
- return parseDataObjectMesh(_ctx, *mesh, performActionBasedOnOrientationSystem);
+ return parseDataObjectMesh(_ctx, *mesh, _params);
}
else
if (objectName == "AnimationSet")
{
- return parseDataObjectAnimationSet(_ctx, performActionBasedOnOrientationSystem);
+ return parseDataObjectAnimationSet(_ctx, _params);
}
else
if (objectName == "Material")
@@ -808,7 +800,7 @@ bool CXMeshFileLoader::parseDataObjectTemplate(SContext& _ctx)
}
-bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *Parent, orientationFunction performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *Parent, const asset::IAssetLoader::SAssetLoadParams& _params)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading frame", ELL_DEBUG);
@@ -890,13 +882,13 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
if (objectName == "Frame")
{
- if (!parseDataObjectFrame(_ctx, joint, performActionBasedOnOrientationSystem))
+ if (!parseDataObjectFrame(_ctx, joint, _params))
return false;
}
else
if (objectName == "FrameTransformMatrix")
{
- if (!parseDataObjectTransformationMatrix(_ctx, joint->LocalMatrix, performActionBasedOnOrientationSystem))
+ if (!parseDataObjectTransformationMatrix(_ctx, joint->LocalMatrix, _params))
return false;
//joint->LocalAnimatedMatrix
@@ -917,7 +909,7 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
_ctx.Meshes.push_back(mesh);
- if (!parseDataObjectMesh(_ctx, *mesh, performActionBasedOnOrientationSystem))
+ if (!parseDataObjectMesh(_ctx, *mesh, _params))
return false;
}
else
@@ -932,7 +924,7 @@ bool CXMeshFileLoader::parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMe
}
-bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat, orientationFunction performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat, const asset::IAssetLoader::SAssetLoadParams& _params)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading Transformation Matrix", ELL_DEBUG);
@@ -945,7 +937,7 @@ bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core:
return false;
}
- readMatrix(_ctx, mat, performActionBasedOnOrientationSystem);
+ readMatrix(_ctx, mat, _params);
if (!checkForOneFollowingSemicolons(_ctx))
{
@@ -964,7 +956,7 @@ bool CXMeshFileLoader::parseDataObjectTransformationMatrix(SContext& _ctx, core:
}
-bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params)
{
std::string name;
@@ -990,7 +982,8 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, orienta
for (uint32_t n=0; n<nVertices; ++n)
{
readVector3(_ctx, mesh.Vertices[n].Pos);
- performActionBasedOnOrientationSystem([&]() {mesh.Vertices[n].Pos.X = -mesh.Vertices[n].Pos.X; }, [&]() {});
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performActionBasedOnOrientationSystem<float>(mesh.Vertices[n].Pos.X, [](float& varToFlip) {varToFlip = -varToFlip;});
}
if (!checkForTwoFollowingSemicolons(_ctx))
@@ -1078,7 +1071,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, orienta
if (objectName == "MeshNormals")
{
- if (!parseDataObjectMeshNormals(_ctx, mesh, performActionBasedOnOrientationSystem))
+ if (!parseDataObjectMeshNormals(_ctx, mesh, _params))
return false;
}
else
@@ -1299,7 +1292,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, orienta
{
//mesh.SkinWeights.push_back(SXSkinWeight());
//if (!parseDataObjectSkinWeights(mesh.SkinWeights.back()))
- if (!parseDataObjectSkinWeights(_ctx, mesh, performActionBasedOnOrientationSystem))
+ if (!parseDataObjectSkinWeights(_ctx, mesh, _params))
return false;
}
else
@@ -1314,7 +1307,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, orienta
}
-bool CXMeshFileLoader::parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading mesh skin weights", ELL_DEBUG);
@@ -1398,7 +1391,7 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh,
// transforms the mesh vertices to the space of the bone
// When concatenated to the bone's transform, this provides the
// world space coordinates of the mesh as affected by the bone
- readMatrix(_ctx, joint->GlobalInversedMatrix, performActionBasedOnOrientationSystem);
+ readMatrix(_ctx, joint->GlobalInversedMatrix, _params);
if (!checkForOneFollowingSemicolons(_ctx))
{
@@ -1450,7 +1443,7 @@ bool CXMeshFileLoader::parseDataObjectSkinMeshHeader(SContext& _ctx, SXMesh& mes
}
-bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: reading mesh normals", ELL_DEBUG);
@@ -1472,7 +1465,9 @@ bool CXMeshFileLoader::parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh,
for (uint32_t i=0; i<nNormals; ++i)
{
readVector3(_ctx, normals[i]);
- performActionBasedOnOrientationSystem([&]() {normals[i].X = -normals[i].X; }, [&]() {});
+
+ if (_params.loaderFlags & E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES)
+ performActionBasedOnOrientationSystem<float>(normals[i].X, [](float& varToFlip) {varToFlip = -varToFlip; });
}
if (!checkForTwoFollowingSemicolons(_ctx))
@@ -1818,7 +1813,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(SContext& _ctx, video::SCPUMateri
}
-bool CXMeshFileLoader::parseDataObjectAnimationSet(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseDataObjectAnimationSet(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading animation set", ELL_DEBUG);
@@ -1852,7 +1847,7 @@ bool CXMeshFileLoader::parseDataObjectAnimationSet(SContext& _ctx, orientationFu
else
if (objectName == "Animation")
{
- if (!parseDataObjectAnimation(_ctx, performActionBasedOnOrientationSystem))
+ if (!parseDataObjectAnimation(_ctx, _params))
return false;
}
else
@@ -1866,7 +1861,7 @@ bool CXMeshFileLoader::parseDataObjectAnimationSet(SContext& _ctx, orientationFu
}
-bool CXMeshFileLoader::parseDataObjectAnimation(SContext& _ctx, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseDataObjectAnimation(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: reading animation", ELL_DEBUG);
@@ -1903,7 +1898,7 @@ bool CXMeshFileLoader::parseDataObjectAnimation(SContext& _ctx, std::function<vo
else
if (objectName == "AnimationKey")
{
- if (!parseDataObjectAnimationKey(_ctx, &animationDump, performActionBasedOnOrientationSystem))
+ if (!parseDataObjectAnimationKey(_ctx, &animationDump, _params))
return false;
}
else
@@ -1985,7 +1980,7 @@ bool CXMeshFileLoader::parseDataObjectAnimation(SContext& _ctx, std::function<vo
}
-bool CXMeshFileLoader::parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *joint, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *joint, const asset::IAssetLoader::SAssetLoadParams& _params)
{
#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: reading animation key", ELL_DEBUG);
@@ -2107,7 +2102,7 @@ bool CXMeshFileLoader::parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSk
// read matrix
core::matrix4x3 mat4x3;
- readMatrix(_ctx, mat4x3, performActionBasedOnOrientationSystem);
+ readMatrix(_ctx, mat4x3, _params);
//mat=joint->LocalMatrix*mat;
if (!checkForOneFollowingSemicolons(_ctx))
@@ -2628,23 +2623,12 @@ bool CXMeshFileLoader::readRGBA(SContext& _ctx, video::SColor& color)
// read matrix from list of floats
-bool CXMeshFileLoader::readMatrix(SContext& _ctx, core::matrix4x3& mat, std::function<void(std::function<void()>, std::function<void()>)> performActionBasedOnOrientationSystem)
+bool CXMeshFileLoader::readMatrix(SContext& _ctx, core::matrix4x3& mat, const asset::IAssetLoader::SAssetLoadParams& _params)
{
for (uint32_t j=0u; j<4u; j++)
{
for (uint32_t i = 0u; i < 3u; i++)
- performActionBasedOnOrientationSystem
- (
- [&]()
- {
- constexpr uint32_t xPosID = 0;
- mat(i, j) = (i == xPosID ? readFloat(_ctx) : -readFloat(_ctx));
- },
- [&]()
- {
mat(i, j) = readFloat(_ctx);
- }
- );
readFloat(_ctx);
}
return checkForOneFollowingSemicolons(_ctx);

diff:
@@ -163,29 +163,27 @@ private:
asset::IAssetLoader::IAssetLoaderOverride* loaderOverride;
};
- using orientationFunction = std::function<void(std::function<void()>, std::function<void()>)>;
-
- bool load(SContext& _ctx, io::IReadFile* file, orientationFunction performActionBasedOnOrientationSystem);
+ bool load(SContext& _ctx, io::IReadFile* file, const asset::IAssetLoader::SAssetLoadParams& _params);
bool readFileIntoMemory(SContext& _ctx, io::IReadFile* file);
- bool parseFile(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseFile(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params);
- bool parseDataObject(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseDataObject(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params);
bool parseDataObjectTemplate(SContext& _ctx);
- bool parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *parent, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseDataObjectFrame(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *parent, const asset::IAssetLoader::SAssetLoadParams& _params);
- bool parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseDataObjectTransformationMatrix(SContext& _ctx, core::matrix4x3 &mat, const asset::IAssetLoader::SAssetLoadParams& _params);
- bool parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseDataObjectMesh(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params);
- bool parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseDataObjectSkinWeights(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params);
bool parseDataObjectSkinMeshHeader(SContext& _ctx, SXMesh &mesh);
- bool parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseDataObjectMeshNormals(SContext& _ctx, SXMesh &mesh, const asset::IAssetLoader::SAssetLoadParams& _params);
bool parseDataObjectMeshTextureCoords(SContext& _ctx, SXMesh &mesh);
@@ -195,11 +193,11 @@ private:
bool parseDataObjectMaterial(SContext& _ctx, video::SCPUMaterial& material);
- bool parseDataObjectAnimationSet(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseDataObjectAnimationSet(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params);
- bool parseDataObjectAnimation(SContext& _ctx, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseDataObjectAnimation(SContext& _ctx, const asset::IAssetLoader::SAssetLoadParams& _params);
- bool parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *joint, orientationFunction performActionBasedOnOrientationSystem);
+ bool parseDataObjectAnimationKey(SContext& _ctx, asset::ICPUSkinnedMesh::SJoint *joint, const asset::IAssetLoader::SAssetLoadParams& _params);
bool parseDataObjectTextureFilename(SContext& _ctx, std::string& texturename);
@@ -238,12 +236,18 @@ private:
float readFloat(SContext& _ctx);
bool readVector2(SContext& _ctx, core::vector2df& vec);
bool readVector3(SContext& _ctx, core::vector3df& vec);
- bool readMatrix(SContext& _ctx, core::matrix4x3& mat, orientationFunction performActionBasedOnOrientationSystem);
+ bool readMatrix(SContext& _ctx, core::matrix4x3& mat, const asset::IAssetLoader::SAssetLoadParams& _params);
bool readRGB(SContext& _ctx, video::SColor& color);
bool readRGBA(SContext& _ctx, video::SColor& color);
IAssetManager* AssetManager;
io::IFileSystem* FileSystem;
+
+ template<typename aType>
+ static inline void performActionBasedOnOrientationSystem(aType& varToHandle, void (*performOnCertainOrientation)(aType& varToHandle))
+ {
+ performOnCertainOrientation(varToHandle);
+ }
};
} // end namespace asset


message: Add writerFlags as enum, make pseudo code

diff:
@@ -24,15 +24,30 @@ enum E_WRITER_FLAGS : uint32_t
EWF_BINARY = 1u<<2u
};
+//! Parameter flags for a loader
+/**
+ These are extra flags that have an impact on extraordinary tasks while writing to file.
+ E_LOADER_PARAMETER_FLAGS::ELPF_NONE is default and means that there is nothing to perform.
+ E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES specifies that a mesh will be flipped,
+ if current flag responsible for orientation is signed as left handed. If it isn't,
+ no flipping will be performed, because there will be no need for that.
+*/
+
+enum E_WRITER_PARAMETER_FLAGS : uint64_t
+{
+ ELPF_NONE = 0, //!< default value, it doesn't do anything
+ ELPF_RIGHT_HANDED_MESHES = 0x1, //!< specifies that a mesh will be flipped in such a way that it'll look correctly in right-handed camera system
+};
+
class IAssetWriter : public virtual core::IReferenceCounted
{
public:
struct SAssetWriteParams
{
- SAssetWriteParams(IAsset* _asset, const E_WRITER_FLAGS& _flags = EWF_NONE, const float& _compressionLevel = 0.f, const size_t& _encryptionKeyLen = 0, const uint8_t* _encryptionKey = nullptr, const void* _userData = nullptr) :
+ SAssetWriteParams(IAsset* _asset, const E_WRITER_FLAGS& _flags = EWF_NONE, const float& _compressionLevel = 0.f, const size_t& _encryptionKeyLen = 0, const uint8_t* _encryptionKey = nullptr, const void* _userData = nullptr, const E_WRITER_PARAMETER_FLAGS& _writerFlags = ELPF_NONE, const irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS& _loaderFlagsUsedForWriting = irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS::ELPF_NONE) :
rootAsset(_asset), flags(_flags), compressionLevel(_compressionLevel),
encryptionKeyLen(_encryptionKeyLen), encryptionKey(_encryptionKey),
- userData(_userData)
+ userData(_userData), writerFlags(_writerFlags), loaderFlagsUsedForWriting(_loaderFlagsUsedForWriting)
{
}
@@ -42,6 +57,8 @@ public:
size_t encryptionKeyLen;
const uint8_t* encryptionKey;
const void* userData;
+ const E_WRITER_PARAMETER_FLAGS writerFlags;
+ const irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS loaderFlagsUsedForWriting;
};
//! Struct for keeping the state of the current write operation for safe threading

diff:
@@ -150,6 +150,42 @@ bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, const asset::ICPUMesh
for (uint32_t i=0; i<mesh->getMeshBufferCount(); ++i)
{
asset::ICPUMeshBuffer* buffer = mesh->getMeshBuffer(i);
+
+ /*
+ pseudo code that has to be applied in binary and ASCII writing
+
+ if(WRITER_RIGHTHANDED)
+ {
+ if(LOADER_RIGHTANDED)
+ {
+ // do nothing
+ }
+ else
+ {
+ if(buffer == bufferPos || buffer == bufferNorm)
+ for(auto& it : buffer)
+ {
+ buffer.something.X = -buffer.something.X;
+ }
+ }
+ }
+ else
+ {
+ if(LOADER_LEFTHANDED)
+ {
+ // do nothing
+ }
+ else
+ {
+ if(buffer == bufferPos || buffer == bufferNorm)
+ for(auto& it : buffer)
+ {
+ buffer.something.X = -buffer.something.X;
+ }
+ }
+ }
+ */
+
if (buffer&&buffer->getMeshDataAndFormat())
{
asset::E_INDEX_TYPE type = buffer->getIndexType();


message: Fix semantic

diff:
@@ -35,8 +35,8 @@ enum E_WRITER_FLAGS : uint32_t
enum E_WRITER_PARAMETER_FLAGS : uint64_t
{
- ELPF_NONE = 0, //!< default value, it doesn't do anything
- ELPF_RIGHT_HANDED_MESHES = 0x1, //!< specifies that a mesh will be flipped in such a way that it'll look correctly in right-handed camera system
+ EWPF_NONE = 0, //!< default value, it doesn't do anything
+ EWPF_RIGHT_HANDED_MESHES = 0x1, //!< specifies that a mesh will be flipped in such a way that it'll look correctly in right-handed camera system
};
class IAssetWriter : public virtual core::IReferenceCounted
@@ -44,7 +44,7 @@ class IAssetWriter : public virtual core::IReferenceCounted
public:
struct SAssetWriteParams
{
- SAssetWriteParams(IAsset* _asset, const E_WRITER_FLAGS& _flags = EWF_NONE, const float& _compressionLevel = 0.f, const size_t& _encryptionKeyLen = 0, const uint8_t* _encryptionKey = nullptr, const void* _userData = nullptr, const E_WRITER_PARAMETER_FLAGS& _writerFlags = ELPF_NONE, const irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS& _loaderFlagsUsedForWriting = irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS::ELPF_NONE) :
+ SAssetWriteParams(IAsset* _asset, const E_WRITER_FLAGS& _flags = EWF_NONE, const float& _compressionLevel = 0.f, const size_t& _encryptionKeyLen = 0, const uint8_t* _encryptionKey = nullptr, const void* _userData = nullptr, const E_WRITER_PARAMETER_FLAGS& _writerFlags = EWPF_NONE, const irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS& _loaderFlagsUsedForWriting = irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS::ELPF_NONE) :
rootAsset(_asset), flags(_flags), compressionLevel(_compressionLevel),
encryptionKeyLen(_encryptionKeyLen), encryptionKey(_encryptionKey),
userData(_userData), writerFlags(_writerFlags), loaderFlagsUsedForWriting(_loaderFlagsUsedForWriting)

original_message: Fix semantic


message: Create CSTLWriter flipping dependency

diff:
@@ -24,30 +24,32 @@ enum E_WRITER_FLAGS : uint32_t
EWF_BINARY = 1u<<2u
};
+class IAssetWriter : public virtual core::IReferenceCounted
+{
+public:
+
//! Parameter flags for a loader
/**
These are extra flags that have an impact on extraordinary tasks while writing to file.
E_LOADER_PARAMETER_FLAGS::ELPF_NONE is default and means that there is nothing to perform.
- E_LOADER_PARAMETER_FLAGS::ELPF_RIGHT_HANDED_MESHES specifies that a mesh will be flipped,
- if current flag responsible for orientation is signed as left handed. If it isn't,
- no flipping will be performed, because there will be no need for that.
+ E_LOADER_PARAMETER_FLAGS::EWPF_MESH_IS_RIGHT_HANDED specifies that a mesh will be flipped,
+ if current E_LOADER_PARAMETER_FLAGS::EWPF_WRITE_RIGHT_HANDED responsible for orientation is signed as left handed.
+ If it isn't, no flipping will be performed, because there will be no need for that.
*/
enum E_WRITER_PARAMETER_FLAGS : uint64_t
{
EWPF_NONE = 0, //!< default value, it doesn't do anything
- EWPF_RIGHT_HANDED_MESHES = 0x1, //!< specifies that a mesh will be flipped in such a way that it'll look correctly in right-handed camera system
+ EWPF_MESH_IS_RIGHT_HANDED = 0x1, //!< specifies the incoming orientation of loaded mesh we want to write
+ EWPF_WRITE_RIGHT_HANDED = 0x2 //!< specifies the output handness orientation. There will be no flipping applied if incoming orientation matches output orientation - in case where EWPF_MESH_IS_RIGHT_HANDED and EWPF_WRITE_RIGHT_HANDED are both attached
};
-class IAssetWriter : public virtual core::IReferenceCounted
-{
-public:
struct SAssetWriteParams
{
- SAssetWriteParams(IAsset* _asset, const E_WRITER_FLAGS& _flags = EWF_NONE, const float& _compressionLevel = 0.f, const size_t& _encryptionKeyLen = 0, const uint8_t* _encryptionKey = nullptr, const void* _userData = nullptr, const E_WRITER_PARAMETER_FLAGS& _writerFlags = EWPF_NONE, const irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS& _loaderFlagsUsedForWriting = irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS::ELPF_NONE) :
+ SAssetWriteParams(IAsset* _asset, const E_WRITER_FLAGS& _flags = EWF_NONE, const float& _compressionLevel = 0.f, const size_t& _encryptionKeyLen = 0, const uint8_t* _encryptionKey = nullptr, const void* _userData = nullptr, const E_WRITER_PARAMETER_FLAGS& _writerFlags = EWPF_NONE) :
rootAsset(_asset), flags(_flags), compressionLevel(_compressionLevel),
encryptionKeyLen(_encryptionKeyLen), encryptionKey(_encryptionKey),
- userData(_userData), writerFlags(_writerFlags), loaderFlagsUsedForWriting(_loaderFlagsUsedForWriting)
+ userData(_userData), writerFlags(_writerFlags)
{
}
@@ -58,7 +60,6 @@ public:
const uint8_t* encryptionKey;
const void* userData;
const E_WRITER_PARAMETER_FLAGS writerFlags;
- const irr::asset::IAssetLoader::E_LOADER_PARAMETER_FLAGS loaderFlagsUsedForWriting;
};
//! Struct for keeping the state of the current write operation for safe threading

diff:
@@ -55,15 +55,15 @@ bool CSTLMeshWriter::writeAsset(io::IWriteFile* _file, const SAssetWriteParams&
const asset::E_WRITER_FLAGS flags = _override->getAssetWritingFlags(ctx, mesh, 0u);
if (flags & asset::EWF_BINARY)
- return writeMeshBinary(file, mesh);
+ return writeMeshBinary(file, mesh, _params);
else
- return writeMeshASCII(file, mesh);
+ return writeMeshASCII(file, mesh, _params);
}
namespace
{
template <class I>
-inline void writeFacesBinary(asset::ICPUMeshBuffer* buffer, const bool& noIndices, io::IWriteFile* file, asset::E_VERTEX_ATTRIBUTE_ID _colorVaid)
+inline void writeFacesBinary(asset::ICPUMeshBuffer* buffer, const bool& noIndices, io::IWriteFile* file, asset::E_VERTEX_ATTRIBUTE_ID _colorVaid, const irr::asset::IAssetWriter::SAssetWriteParams& _params)
{
bool hasColor = buffer->getMeshDataAndFormat()->getMappedBuffer(_colorVaid);
const asset::E_FORMAT colorType = buffer->getMeshDataAndFormat()->getAttribFormat(_colorVaid);
@@ -112,6 +112,30 @@ inline void writeFacesBinary(asset::ICPUMeshBuffer* buffer, const bool& noIndice
}
}
+ auto flipVectors = [&]()
+ {
+ for(uint8_t i = 0; i < 3; ++i)
+ v[i].X = -v[i].X;
+ };
+
+ if (_params.writerFlags & IAssetWriter::EWPF_WRITE_RIGHT_HANDED)
+ {
+ if (_params.writerFlags & IAssetWriter::EWPF_MESH_IS_RIGHT_HANDED)
+ {
+ // do nothing
+ }
+ else
+ flipVectors();
+ }
+ else
+ {
+ if (!(_params.writerFlags & IAssetWriter::EWPF_MESH_IS_RIGHT_HANDED))
+ {
+ // do nothing
+ }
+ else
+ flipVectors();
+ }
const core::plane3dSIMDf plane(v[0], v[1], v[2]);
file->write(&plane, 12);
@@ -123,7 +147,7 @@ inline void writeFacesBinary(asset::ICPUMeshBuffer* buffer, const bool& noIndice
}
}
-bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, const asset::ICPUMesh* mesh)
+bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, const asset::ICPUMesh* mesh, const SAssetWriteParams& _params)
{
// write STL MESH header
const char headerTxt[] = "Irrlicht-baw Engine";
@@ -150,42 +174,6 @@ bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, const asset::ICPUMesh
for (uint32_t i=0; i<mesh->getMeshBufferCount(); ++i)
{
asset::ICPUMeshBuffer* buffer = mesh->getMeshBuffer(i);
-
- /*
- pseudo code that has to be applied in binary and ASCII writing
-
- if(WRITER_RIGHTHANDED)
- {
- if(LOADER_RIGHTANDED)
- {
- // do nothing
- }
- else
- {
- if(buffer == bufferPos || buffer == bufferNorm)
- for(auto& it : buffer)
- {
- buffer.something.X = -buffer.something.X;
- }
- }
- }
- else
- {
- if(LOADER_LEFTHANDED)
- {
- // do nothing
- }
- else
- {
- if(buffer == bufferPos || buffer == bufferNorm)
- for(auto& it : buffer)
- {
- buffer.something.X = -buffer.something.X;
- }
- }
- }
- */
-
if (buffer&&buffer->getMeshDataAndFormat())
{
asset::E_INDEX_TYPE type = buffer->getIndexType();
@@ -193,15 +181,15 @@ bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, const asset::ICPUMesh
type = asset::EIT_UNKNOWN;
if (type== asset::EIT_16BIT)
{
- writeFacesBinary<uint16_t>(buffer, false, file, asset::EVAI_ATTR1);
+ writeFacesBinary<uint16_t>(buffer, false, file, asset::EVAI_ATTR1, _params);
}
else if (type== asset::EIT_32BIT)
{
- writeFacesBinary<uint32_t>(buffer, false, file, asset::EVAI_ATTR1);
+ writeFacesBinary<uint32_t>(buffer, false, file, asset::EVAI_ATTR1, _params);
}
else
{
- writeFacesBinary<uint16_t>(buffer, true, file, asset::EVAI_ATTR1); //template param doesn't matter if there's no indices
+ writeFacesBinary<uint16_t>(buffer, true, file, asset::EVAI_ATTR1, _params); //template param doesn't matter if there's no indices
}
}
}
@@ -209,7 +197,7 @@ bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, const asset::ICPUMesh
}
-bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, const asset::ICPUMesh* mesh)
+bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, const asset::ICPUMesh* mesh, const SAssetWriteParams& _params)
{
// write STL MESH header
const char headerTxt[] = "Irrlicht-baw Engine ";
@@ -239,7 +227,8 @@ bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, const asset::ICPUMesh*
writeFaceText(file,
buffer->getPosition(((uint16_t*)buffer->getIndices())[j]),
buffer->getPosition(((uint16_t*)buffer->getIndices())[j+1]),
- buffer->getPosition(((uint16_t*)buffer->getIndices())[j+2])
+ buffer->getPosition(((uint16_t*)buffer->getIndices())[j+2]),
+ _params
);
}
}
@@ -251,7 +240,8 @@ bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, const asset::ICPUMesh*
writeFaceText(file,
buffer->getPosition(((uint32_t*)buffer->getIndices())[j]),
buffer->getPosition(((uint32_t*)buffer->getIndices())[j+1]),
- buffer->getPosition(((uint32_t*)buffer->getIndices())[j+2])
+ buffer->getPosition(((uint32_t*)buffer->getIndices())[j+2]),
+ _params
);
}
}
@@ -262,8 +252,9 @@ bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, const asset::ICPUMesh*
{
writeFaceText(file,
buffer->getPosition(j),
- buffer->getPosition(j+1),
- buffer->getPosition(j+2)
+ buffer->getPosition(j+1ul),
+ buffer->getPosition(j+2ul),
+ _params
);
}
}
@@ -290,21 +281,54 @@ void CSTLMeshWriter::getVectorAsStringLine(const core::vectorSIMDf& v, core::str
void CSTLMeshWriter::writeFaceText(io::IWriteFile* file,
const core::vectorSIMDf& v1,
const core::vectorSIMDf& v2,
- const core::vectorSIMDf& v3)
+ const core::vectorSIMDf& v3,
+ const SAssetWriteParams& _params)
{
+ auto normal = core::plane3dSIMDf(v1, v2, v3).getNormal();
+ core::vectorSIMDf vertex1 = v1;
+ core::vectorSIMDf vertex2 = v2;
+ core::vectorSIMDf vertex3 = v3;
core::stringc tmp;
+
+ auto flipVectors = [&]()
+ {
+ vertex1.X = -vertex1.X;
+ vertex2.X = -vertex2.X;
+ vertex3.X = -vertex3.X;
+ normal = core::plane3dSIMDf(vertex1, vertex2, vertex3).getNormal();
+ };
+
+ if(_params.writerFlags & IAssetWriter::EWPF_WRITE_RIGHT_HANDED)
+ {
+ if(_params.writerFlags & IAssetWriter::EWPF_MESH_IS_RIGHT_HANDED)
+ {
+ // do nothing
+ }
+ else
+ flipVectors();
+ }
+ else
+ {
+ if (!(_params.writerFlags & IAssetWriter::EWPF_MESH_IS_RIGHT_HANDED))
+ {
+ // do nothing
+ }
+ else
+ flipVectors();
+ }
+
file->write("facet normal ",13);
- getVectorAsStringLine(core::plane3dSIMDf(v1, v2, v3).getNormal(), tmp);
+ getVectorAsStringLine(normal, tmp);
file->write(tmp.c_str(),tmp.size());
file->write(" outer loop\n",13);
file->write(" vertex ",11);
- getVectorAsStringLine(v1, tmp);
+ getVectorAsStringLine(vertex1, tmp);
file->write(tmp.c_str(),tmp.size());
file->write(" vertex ",11);
- getVectorAsStringLine(v2, tmp);
+ getVectorAsStringLine(vertex2, tmp);
file->write(tmp.c_str(),tmp.size());
file->write(" vertex ",11);
- getVectorAsStringLine(v3, tmp);
+ getVectorAsStringLine(vertex3, tmp);
file->write(tmp.c_str(),tmp.size());
file->write(" endloop\n",10);
file->write("endfacet\n",9);

diff:
@@ -38,17 +38,17 @@ namespace asset
protected:
// write binary format
- bool writeMeshBinary(io::IWriteFile* file, const asset::ICPUMesh* mesh);
+ bool writeMeshBinary(io::IWriteFile* file, const asset::ICPUMesh* mesh, const SAssetWriteParams& _params);
// write text format
- bool writeMeshASCII(io::IWriteFile* file, const asset::ICPUMesh* mesh);
+ bool writeMeshASCII(io::IWriteFile* file, const asset::ICPUMesh* mesh, const SAssetWriteParams& _params);
// create vector output with line end into string
void getVectorAsStringLine(const core::vectorSIMDf& v, core::stringc& s) const;
// write face information to file
void writeFaceText(io::IWriteFile* file, const core::vectorSIMDf& v1,
- const core::vectorSIMDf& v2, const core::vectorSIMDf& v3);
+ const core::vectorSIMDf& v2, const core::vectorSIMDf& v3, const SAssetWriteParams& _params);
};
} // end namespace

original_message: Create CSTLWriter flipping dependency


message: Make CSTLWriter work

diff:
@@ -284,10 +284,10 @@ void CSTLMeshWriter::writeFaceText(io::IWriteFile* file,
const core::vectorSIMDf& v3,
const SAssetWriteParams& _params)
{
- auto normal = core::plane3dSIMDf(v1, v2, v3).getNormal();
- core::vectorSIMDf vertex1 = v1;
+ core::vectorSIMDf vertex1 = v3;
core::vectorSIMDf vertex2 = v2;
- core::vectorSIMDf vertex3 = v3;
+ core::vectorSIMDf vertex3 = v1;
+ core::vector3df_SIMD normal = core::plane3dSIMDf(vertex1, vertex2, vertex3).getNormal();
core::stringc tmp;
auto flipVectors = [&]()

original_message: Make CSTLWriter work


message: Fix on bin CSTLWriting, forgot XD

diff:
@@ -112,10 +112,17 @@ inline void writeFacesBinary(asset::ICPUMeshBuffer* buffer, const bool& noIndice
}
}
+ core::vectorSIMDf normal = core::plane3dSIMDf(v[0], v[1], v[2]).getNormal();
+ core::vectorSIMDf vertex1 = v[2];
+ core::vectorSIMDf vertex2 = v[1];
+ core::vectorSIMDf vertex3 = v[0];
+
auto flipVectors = [&]()
{
- for(uint8_t i = 0; i < 3; ++i)
- v[i].X = -v[i].X;
+ vertex1.X = -vertex1.X;
+ vertex2.X = -vertex2.X;
+ vertex3.X = -vertex3.X;
+ normal = core::plane3dSIMDf(vertex1, vertex2, vertex3).getNormal();
};
if (_params.writerFlags & IAssetWriter::EWPF_WRITE_RIGHT_HANDED)
@@ -137,11 +144,10 @@ inline void writeFacesBinary(asset::ICPUMeshBuffer* buffer, const bool& noIndice
flipVectors();
}
- const core::plane3dSIMDf plane(v[0], v[1], v[2]);
- file->write(&plane, 12);
- file->write(v+0, 12);
- file->write(v+1, 12);
- file->write(v+2, 12);
+ file->write(&normal, 12);
+ file->write(&vertex1, 12);
+ file->write(&vertex2, 12);
+ file->write(&vertex3, 12);
file->write(&color, 2); // saving color using non-standard VisCAM/SolidView trick
}
}

original_message: Fix on bin CSTLWriting, forgot XD