irrlicht/source/Irrlicht/CGLTFMeshFileLoader.h
jordan4ibanez f8f10248b4 Package glTF spec docs with comments
* git --CRUSH

And try to make this line the same

Now undo my gitignore nonsense

Hail mary

Move these functions to the top

More documentation

Add some serious documentation

Move this to the top

Readability & documentation

Add some documentation

Add spec documentation

Make this more more complex to make it less complex

Move this up & document

Make this more readable for me

Document and make this more readable

Move this out of the way and document it

Update CGLTFMeshFileLoader.cpp

Documentation

Document

Update CGLTFMeshFileLoader.cpp

Document

Move entry point to bottom

Part 5

Part 4

Part 3

Part 2

Allman -> OTBS (readability for me)

Consolidate

Remove unneeded function

These files are annoying

* fix #1

* fix 2

* indentation

* Remove redundant function

* Remove redundant function

* add trailing new line

* Stop an interesting build error with a template

* Code reduction

* Document bytestride

* Add more detail to chain hierarchy

* Dump this huge vscode thing in here for no reason

* Document 3 more functions

* Document copyTcoords

* Dump in (incorrect) scale documentation for node

* Add a readable description

* Fix incorrect getScale

* Add update based on context of function

* Add documentation, fix another one

* Document another

* Document another

* And document another

* Document this nice function

* Bolt in some future use documentation

* Add highlighting for IDE

* Just shovel on more docs to this

* 2 more comments

* I think that's all of them

* Add some wild west debuggin

* And then update this comment

* Bolt on isAccessorNormalized()

* Bolt in an absolute hack job to test

* Now clean this mess up and give josiah ref material

* Fix Josiah's request for scale

* Fix josiah request

* Fix josiah request .vscode

Fix indentation

Fix indentation

Fix indentation

* Unfix getScale()

again
2024-04-18 07:34:49 -05:00

146 lines
3.6 KiB
C++

#ifndef __C_GLTF_MESH_FILE_LOADER_INCLUDED__
#define __C_GLTF_MESH_FILE_LOADER_INCLUDED__
#include "IAnimatedMesh.h"
#include "IMeshLoader.h"
#include "IReadFile.h"
#include "irrTypes.h"
#include "path.h"
#include "S3DVertex.h"
#include "SMesh.h"
#include "vector2d.h"
#include "vector3d.h"
#include <tiny_gltf.h>
#include <cstddef>
#include <vector>
namespace irr
{
namespace scene
{
class CGLTFMeshFileLoader : public IMeshLoader
{
public:
CGLTFMeshFileLoader() noexcept;
bool isALoadableFileExtension(const io::path& filename) const override;
IAnimatedMesh* createMesh(io::IReadFile* file) override;
private:
class BufferOffset
{
public:
BufferOffset(const std::vector<unsigned char>& buf,
const std::size_t offset);
BufferOffset(const BufferOffset& other,
const std::size_t fromOffset);
unsigned char at(const std::size_t fromOffset) const;
private:
const std::vector<unsigned char>& m_buf;
std::size_t m_offset;
int m_filesize;
};
class MeshExtractor {
public:
using vertex_t = video::S3DVertex;
MeshExtractor(const tinygltf::Model& model) noexcept;
MeshExtractor(const tinygltf::Model&& model) noexcept;
/* Gets indices for the given mesh/primitive.
*
* Values are return in Irrlicht winding order.
*/
std::vector<u16> getIndices(const std::size_t meshIdx,
const std::size_t primitiveIdx) const;
std::vector<vertex_t> getVertices(std::size_t meshIdx,
const std::size_t primitiveIdx) const;
std::size_t getMeshCount() const;
std::size_t getPrimitiveCount(const std::size_t meshIdx) const;
private:
tinygltf::Model m_model;
template <typename T>
static T readPrimitive(const BufferOffset& readFrom);
static core::vector2df readVec2DF(
const BufferOffset& readFrom);
/* Read a vec3df from a buffer with transformations applied.
*
* Values are returned in Irrlicht coordinates.
*/
static core::vector3df readVec3DF(
const BufferOffset& readFrom,
const float scale);
void copyPositions(const std::size_t accessorIdx,
std::vector<vertex_t>& vertices) const;
void copyNormals(const std::size_t accessorIdx,
std::vector<vertex_t>& vertices) const;
void copyTCoords(const std::size_t accessorIdx,
std::vector<vertex_t>& vertices) const;
/* Get the scale factor from the glTF mesh information.
*
* Returns vec3(1.0, 1.0, 1.0) if no scale factor is present.
*/
float getScale() const;
std::size_t getElemCount(const std::size_t accessorIdx) const;
std::size_t getByteStride(const std::size_t accessorIdx) const;
bool isAccessorNormalized(const std::size_t accessorIdx) const;
BufferOffset getBuffer(const std::size_t accessorIdx) const;
std::size_t getIndicesAccessorIdx(const std::size_t meshIdx,
const std::size_t primitiveIdx) const;
std::size_t getPositionAccessorIdx(const std::size_t meshIdx,
const std::size_t primitiveIdx) const;
/* Get the accessor id of the normals of a primitive.
*
* -1 is returned if none are present.
*/
std::size_t getNormalAccessorIdx(const std::size_t meshIdx,
const std::size_t primitiveIdx) const;
/* Get the accessor id for the tcoords of a primitive.
*
* -1 is returned if none are present.
*/
std::size_t getTCoordAccessorIdx(const std::size_t meshIdx,
const std::size_t primitiveIdx) const;
};
void loadPrimitives(const MeshExtractor& parser, SMesh* mesh);
static bool tryParseGLTF(io::IReadFile* file,
tinygltf::Model& model);
};
} // namespace scene
} // namespace irr
#endif // __C_GLTF_MESH_FILE_LOADER_INCLUDED__