diff --git a/irr/src/CGLTFMeshFileLoader.cpp b/irr/src/CGLTFMeshFileLoader.cpp index 6fcf599ab..110380a17 100644 --- a/irr/src/CGLTFMeshFileLoader.cpp +++ b/irr/src/CGLTFMeshFileLoader.cpp @@ -10,7 +10,6 @@ #include "IReadFile.h" #include "matrix4.h" #include "path.h" -#include "S3DVertex.h" #include "quaternion.h" #include "vector3d.h" @@ -53,11 +52,11 @@ core::vector3df convertHandedness(const core::vector3df &p) namespace scene { -using CMFL = CGLTFMeshFileLoader; +using SelfType = CGLTFMeshFileLoader; template -CMFL::Accessor -CMFL::Accessor::sparseIndices(const tiniergltf::GlTF &model, +SelfType::Accessor +SelfType::Accessor::sparseIndices(const tiniergltf::GlTF &model, const tiniergltf::AccessorSparseIndices &indices, const std::size_t count) { @@ -67,12 +66,12 @@ CMFL::Accessor::sparseIndices(const tiniergltf::GlTF &model, const auto &buffer = model.buffers->at(view.buffer); const auto source = buffer.data.data() + view.byteOffset + indices.byteOffset; - return CMFL::Accessor(source, byteStride, count); + return SelfType::Accessor(source, byteStride, count); } template -CMFL::Accessor -CMFL::Accessor::sparseValues(const tiniergltf::GlTF &model, +SelfType::Accessor +SelfType::Accessor::sparseValues(const tiniergltf::GlTF &model, const tiniergltf::AccessorSparseValues &values, const std::size_t count, const std::size_t defaultByteStride) @@ -83,12 +82,12 @@ CMFL::Accessor::sparseValues(const tiniergltf::GlTF &model, const auto &buffer = model.buffers->at(view.buffer); const auto source = buffer.data.data() + view.byteOffset + values.byteOffset; - return CMFL::Accessor(source, byteStride, count); + return SelfType::Accessor(source, byteStride, count); } template -CMFL::Accessor -CMFL::Accessor::base(const tiniergltf::GlTF &model, std::size_t accessorIdx) +SelfType::Accessor +SelfType::Accessor::base(const tiniergltf::GlTF &model, std::size_t accessorIdx) { const auto &accessor = model.accessors->at(accessorIdx); @@ -106,8 +105,8 @@ CMFL::Accessor::base(const tiniergltf::GlTF &model, std::size_t accessorIdx) } template -CMFL::Accessor -CMFL::Accessor::make(const tiniergltf::GlTF &model, std::size_t accessorIdx) +SelfType::Accessor +SelfType::Accessor::make(const tiniergltf::GlTF &model, std::size_t accessorIdx) { const auto &accessor = model.accessors->at(accessorIdx); if (accessor.componentType != getComponentType() || accessor.type != getType()) @@ -152,37 +151,37 @@ CMFL::Accessor::make(const tiniergltf::GlTF &model, std::size_t accessorIdx) return base; } -#define ACCESSOR_TYPES(T, U, V) \ - template <> \ - constexpr tiniergltf::Accessor::Type CMFL::Accessor::getType() \ - { \ - return tiniergltf::Accessor::Type::U; \ - } \ - template <> \ - constexpr tiniergltf::Accessor::ComponentType CMFL::Accessor::getComponentType() \ - { \ - return tiniergltf::Accessor::ComponentType::V; \ +#define ACCESSOR_TYPES(T, U, V) \ + template <> \ + constexpr tiniergltf::Accessor::Type SelfType::Accessor::getType() \ + { \ + return tiniergltf::Accessor::Type::U; \ + } \ + template <> \ + constexpr tiniergltf::Accessor::ComponentType SelfType::Accessor::getComponentType() \ + { \ + return tiniergltf::Accessor::ComponentType::V; \ } -#define VEC_ACCESSOR_TYPES(T, U, n) \ - template <> \ - constexpr tiniergltf::Accessor::Type CMFL::Accessor>::getType() \ - { \ - return tiniergltf::Accessor::Type::VEC##n; \ - } \ - template <> \ - constexpr tiniergltf::Accessor::ComponentType CMFL::Accessor>::getComponentType() \ - { \ - return tiniergltf::Accessor::ComponentType::U; \ - } \ - template <> \ - std::array CMFL::rawget(const void *ptr) \ - { \ - const T *tptr = reinterpret_cast(ptr); \ - std::array res; \ - for (u8 i = 0; i < n; ++i) \ - res[i] = rawget(tptr + i); \ - return res; \ +#define VEC_ACCESSOR_TYPES(T, U, n) \ + template <> \ + constexpr tiniergltf::Accessor::Type SelfType::Accessor>::getType() \ + { \ + return tiniergltf::Accessor::Type::VEC##n; \ + } \ + template <> \ + constexpr tiniergltf::Accessor::ComponentType SelfType::Accessor>::getComponentType() \ + { \ + return tiniergltf::Accessor::ComponentType::U; \ + } \ + template <> \ + std::array SelfType::rawget(const void *ptr) \ + { \ + const T *tptr = reinterpret_cast(ptr); \ + std::array res; \ + for (u8 i = 0; i < n; ++i) \ + res[i] = rawget(tptr + i); \ + return res; \ } #define ACCESSOR_PRIMITIVE(T, U) \ @@ -199,7 +198,7 @@ ACCESSOR_PRIMITIVE(u32, UNSIGNED_INT) ACCESSOR_TYPES(core::vector3df, VEC3, FLOAT) template -T CMFL::Accessor::get(std::size_t i) const +T SelfType::Accessor::get(std::size_t i) const { // Buffer-based accessor: Read directly from the buffer. if (std::holds_alternative(source)) { @@ -226,7 +225,7 @@ static inline bool isBigEndian() } template -T CMFL::rawget(const void *ptr) +T SelfType::rawget(const void *ptr) { if (!isBigEndian()) return *reinterpret_cast(ptr); @@ -244,7 +243,7 @@ T CMFL::rawget(const void *ptr) // Note that these "more specialized templates" should win. template <> -core::matrix4 CMFL::rawget(const void *ptr) +core::matrix4 SelfType::rawget(const void *ptr) { const f32 *fptr = reinterpret_cast(ptr); f32 M[16]; @@ -257,7 +256,7 @@ core::matrix4 CMFL::rawget(const void *ptr) } template <> -core::vector3df CMFL::rawget(const void *ptr) +core::vector3df SelfType::rawget(const void *ptr) { const f32 *fptr = reinterpret_cast(ptr); return core::vector3df( @@ -267,7 +266,7 @@ core::vector3df CMFL::rawget(const void *ptr) } template <> -core::quaternion CMFL::rawget(const void *ptr) +core::quaternion SelfType::rawget(const void *ptr) { const f32 *fptr = reinterpret_cast(ptr); return core::quaternion( @@ -278,8 +277,8 @@ core::quaternion CMFL::rawget(const void *ptr) } template -CMFL::NormalizedValuesAccessor -CMFL::createNormalizedValuesAccessor( +SelfType::NormalizedValuesAccessor +SelfType::createNormalizedValuesAccessor( const tiniergltf::GlTF &model, const std::size_t accessorIdx) { @@ -297,7 +296,7 @@ CMFL::createNormalizedValuesAccessor( } template -std::array CMFL::getNormalizedValues( +std::array SelfType::getNormalizedValues( const NormalizedValuesAccessor &accessor, const std::size_t i) { @@ -320,14 +319,10 @@ std::array CMFL::getNormalizedValues( return values; } -CGLTFMeshFileLoader::CGLTFMeshFileLoader() noexcept -{ -} - /** * The most basic portion of the code base. This tells irllicht if this file has a .gltf extension. */ -bool CGLTFMeshFileLoader::isALoadableFileExtension( +bool SelfType::isALoadableFileExtension( const io::path& filename) const { return core::hasFileExtension(filename, "gltf"); @@ -336,7 +331,7 @@ bool CGLTFMeshFileLoader::isALoadableFileExtension( /** * Entry point into loading a GLTF model. */ -IAnimatedMesh* CGLTFMeshFileLoader::createMesh(io::IReadFile* file) +IAnimatedMesh* SelfType::createMesh(io::IReadFile* file) { if (file->getSize() <= 0) { return nullptr; @@ -403,7 +398,7 @@ static std::vector generateIndices(const std::size_t nVerts) * Documentation: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes * If material is undefined, then a default material MUST be used. */ -void CGLTFMeshFileLoader::MeshExtractor::loadMesh( +void SelfType::MeshExtractor::loadMesh( const std::size_t meshIdx, ISkinnedMesh::SJoint *parent) const { @@ -475,7 +470,7 @@ static core::matrix4 loadTransform(std::optional isChild(m_gltf_model.nodes->size()); for (const auto &node : *m_gltf_model.nodes) { @@ -519,7 +514,7 @@ void CGLTFMeshFileLoader::MeshExtractor::loadNodes() const /** * Extracts GLTF mesh indices. */ -std::optional> CMFL::MeshExtractor::getIndices( +std::optional> SelfType::MeshExtractor::getIndices( const std::size_t meshIdx, const std::size_t primitiveIdx) const { @@ -573,7 +568,7 @@ std::optional> CMFL::MeshExtractor::getIndices( /** * Create a vector of video::S3DVertex (model data) from a mesh & primitive index. */ -std::optional> CMFL::MeshExtractor::getVertices( +std::optional> SelfType::MeshExtractor::getVertices( const std::size_t meshIdx, const std::size_t primitiveIdx) const { @@ -607,7 +602,7 @@ std::optional> CMFL::MeshExtractor::getVertices( /** * Get the amount of meshes that a model contains. */ -std::size_t CGLTFMeshFileLoader::MeshExtractor::getMeshCount() const +std::size_t SelfType::MeshExtractor::getMeshCount() const { return m_gltf_model.meshes->size(); } @@ -615,7 +610,7 @@ std::size_t CGLTFMeshFileLoader::MeshExtractor::getMeshCount() const /** * Get the amount of primitives that a mesh in a model contains. */ -std::size_t CGLTFMeshFileLoader::MeshExtractor::getPrimitiveCount( +std::size_t SelfType::MeshExtractor::getPrimitiveCount( const std::size_t meshIdx) const { return m_gltf_model.meshes->at(meshIdx).primitives.size(); @@ -625,7 +620,7 @@ std::size_t CGLTFMeshFileLoader::MeshExtractor::getPrimitiveCount( * Streams vertex positions raw data into usable buffer via reference. * Buffer: ref Vector */ -void CGLTFMeshFileLoader::MeshExtractor::copyPositions( +void SelfType::MeshExtractor::copyPositions( const std::size_t accessorIdx, std::vector& vertices) const { @@ -639,7 +634,7 @@ void CGLTFMeshFileLoader::MeshExtractor::copyPositions( * Streams normals raw data into usable buffer via reference. * Buffer: ref Vector */ -void CGLTFMeshFileLoader::MeshExtractor::copyNormals( +void SelfType::MeshExtractor::copyNormals( const std::size_t accessorIdx, std::vector& vertices) const { @@ -653,7 +648,7 @@ void CGLTFMeshFileLoader::MeshExtractor::copyNormals( * Streams texture coordinate raw data into usable buffer via reference. * Buffer: ref Vector */ -void CGLTFMeshFileLoader::MeshExtractor::copyTCoords( +void SelfType::MeshExtractor::copyTCoords( const std::size_t accessorIdx, std::vector& vertices) const { @@ -668,7 +663,7 @@ void CGLTFMeshFileLoader::MeshExtractor::copyTCoords( /** * This is where the actual model's GLTF file is loaded and parsed by tiniergltf. */ -std::optional CGLTFMeshFileLoader::tryParseGLTF(io::IReadFile* file) +std::optional SelfType::tryParseGLTF(io::IReadFile* file) { auto size = file->getSize(); auto buf = std::make_unique(size + 1); diff --git a/irr/src/CGLTFMeshFileLoader.h b/irr/src/CGLTFMeshFileLoader.h index eac480317..d0fb298c1 100644 --- a/irr/src/CGLTFMeshFileLoader.h +++ b/irr/src/CGLTFMeshFileLoader.h @@ -26,7 +26,7 @@ namespace scene class CGLTFMeshFileLoader : public IMeshLoader { public: - CGLTFMeshFileLoader() noexcept; + CGLTFMeshFileLoader() noexcept {}; bool isALoadableFileExtension(const io::path& filename) const override;