Correct CSTL x flipping, add flipping in COBJMeshFileLoader
MODIFY
src/irr/asset/COBJMeshFileLoader.cpp
src/irr/asset/COBJMeshFileLoader.cpp
@@ -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);
}

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

Correct CSTL x flipping, add flipping in COBJMeshFileLoader