Add loader flags, CBufferLoaderBIN and first flipping around X axie
MODIFY
include/irr/asset/IAssetLoader.h
include/irr/asset/IAssetLoader.h
@@ -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

MODIFY
source/Irrlicht/CMakeLists.txt
source/Irrlicht/CMakeLists.txt
@@ -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

ADD
src/irr/asset/CBufferLoaderBIN.cpp
+#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

ADD
src/irr/asset/CBufferLoaderBIN.h
+// 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);
+ };
+ }
+}

MODIFY
src/irr/asset/CSTLMeshFileLoader.cpp
src/irr/asset/CSTLMeshFileLoader.cpp
@@ -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)

Add loader flags, CBufferLoaderBIN and first flipping around X axie