Make CSTL and COBJ Loaders flipping work
MODIFY
src/irr/asset/COBJMeshFileLoader.cpp
src/irr/asset/COBJMeshFileLoader.cpp
@@ -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);
}

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

MODIFY
src/irr/asset/CPLYMeshFileLoader.h
src/irr/asset/CPLYMeshFileLoader.h
@@ -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
-

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

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

Make CSTL and COBJ Loaders flipping work