minetest/source/Irrlicht/CGLTFMeshFileLoader.cpp

489 lines
15 KiB
C++
Raw Normal View History

#include "CGLTFMeshFileLoader.h"
#include "CMeshBuffer.h"
#include "coreutil.h"
#include "IAnimatedMesh.h"
2023-10-08 19:33:24 +02:00
#include "ILogger.h"
#include "IReadFile.h"
#include "irrTypes.h"
2023-10-08 19:33:24 +02:00
#include "os.h"
#include "path.h"
#include "S3DVertex.h"
#include "SAnimatedMesh.h"
#include "SColor.h"
#include "SMesh.h"
#include "vector3d.h"
#include <cstddef>
#include <cstring>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <utility>
#include <variant>
#include <vector>
/* Notes on the coordinate system.
*
* glTF uses a right-handed coordinate system where +Z is the
* front-facing axis, and Irrlicht uses a left-handed coordinate
* system where -Z is the front-facing axis.
* We convert between them by reflecting the mesh across the X axis.
* Doing this correctly requires negating the Z coordinate on
* vertex positions and normals, and reversing the winding order
* of the vertex indices.
*/
namespace irr {
2022-11-07 01:00:42 +01:00
namespace scene {
CGLTFMeshFileLoader::BufferOffset::BufferOffset(
const std::vector<unsigned char>& buf,
const std::size_t offset)
: m_buf(buf)
, m_offset(offset)
{
}
CGLTFMeshFileLoader::BufferOffset::BufferOffset(
const CGLTFMeshFileLoader::BufferOffset& other,
const std::size_t fromOffset)
: m_buf(other.m_buf)
, m_offset(other.m_offset + fromOffset)
{
}
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
2023-12-01 23:10:01 +01:00
/**
* Get a raw unsigned char (ubyte) from a buffer offset.
*/
unsigned char CGLTFMeshFileLoader::BufferOffset::at(
const std::size_t fromOffset) const
{
return m_buf.at(m_offset + fromOffset);
}
CGLTFMeshFileLoader::CGLTFMeshFileLoader() noexcept
2022-11-10 20:58:28 +01:00
{
}
2022-11-10 20:58:28 +01:00
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
2023-12-01 23:10:01 +01:00
/**
* The most basic portion of the code base. This tells irllicht if this file has a .gltf extension.
*/
bool CGLTFMeshFileLoader::isALoadableFileExtension(
const io::path& filename) const
2022-11-10 20:58:28 +01:00
{
return core::hasFileExtension(filename, "gltf");
}
2022-11-10 20:58:28 +01:00
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
2023-12-01 23:10:01 +01:00
/**
* Entry point into loading a GLTF model.
*/
IAnimatedMesh* CGLTFMeshFileLoader::createMesh(io::IReadFile* file)
2022-11-10 20:58:28 +01:00
{
if (file->getSize() <= 0) {
return nullptr;
}
std::optional<tiniergltf::GlTF> model = tryParseGLTF(file);
if (!model.has_value()) {
return nullptr;
}
if (!(model->buffers.has_value()
&& model->bufferViews.has_value()
&& model->accessors.has_value()
&& model->meshes.has_value()
&& model->nodes.has_value())) {
return nullptr;
}
MeshExtractor parser(std::move(model.value()));
2023-05-17 23:47:02 +02:00
SMesh* baseMesh(new SMesh {});
loadPrimitives(parser, baseMesh);
2022-11-10 20:58:28 +01:00
SAnimatedMesh* animatedMesh(new SAnimatedMesh {});
animatedMesh->addMesh(baseMesh);
baseMesh->drop();
return animatedMesh;
}
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
2023-12-01 23:10:01 +01:00
/**
* Load up the rawest form of the model. The vertex positions and indices.
* 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::loadPrimitives(
const MeshExtractor& parser,
SMesh* mesh)
{
2023-05-18 00:19:57 +02:00
for (std::size_t i = 0; i < parser.getMeshCount(); ++i) {
for (std::size_t j = 0; j < parser.getPrimitiveCount(i); ++j) {
auto indices = parser.getIndices(i, j);
auto vertices = parser.getVertices(i, j);
2023-05-17 23:47:02 +02:00
SMeshBuffer* meshbuf(new SMeshBuffer {});
2023-05-18 00:19:57 +02:00
meshbuf->append(vertices.data(), vertices.size(),
2023-05-17 23:47:02 +02:00
indices.data(), indices.size());
mesh->addMeshBuffer(meshbuf);
meshbuf->drop();
2023-05-17 23:47:02 +02:00
}
}
2022-11-10 20:58:28 +01:00
}
2023-05-18 14:01:43 +02:00
CGLTFMeshFileLoader::MeshExtractor::MeshExtractor(
const tiniergltf::GlTF& model) noexcept
: m_model(model)
{
}
2023-05-18 14:01:43 +02:00
CGLTFMeshFileLoader::MeshExtractor::MeshExtractor(
const tiniergltf::GlTF&& model) noexcept
: m_model(model)
{
}
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
2023-12-01 23:10:01 +01:00
/**
* Extracts GLTF mesh indices into the irrlicht model.
*/
2023-05-18 14:01:43 +02:00
std::vector<u16> CGLTFMeshFileLoader::MeshExtractor::getIndices(
2023-05-18 13:41:36 +02:00
const std::size_t meshIdx,
const std::size_t primitiveIdx) const
{
// FIXME this need not exist. What do we do if it doesn't?
2023-05-18 14:33:04 +02:00
const auto accessorIdx = getIndicesAccessorIdx(meshIdx, primitiveIdx);
const auto& buf = getBuffer(accessorIdx.value());
// FIXME check accessor type (which could also be u8 or u32).
2023-05-17 23:47:02 +02:00
std::vector<u16> indices{};
const auto count = getElemCount(accessorIdx.value());
2023-05-17 23:47:02 +02:00
for (std::size_t i = 0; i < count; ++i) {
std::size_t elemIdx = count - i - 1;
indices.push_back(readPrimitive<u16>(
BufferOffset(buf, elemIdx * sizeof(u16))));
}
2023-05-17 23:47:02 +02:00
return indices;
}
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
2023-12-01 23:10:01 +01:00
/**
* Create a vector of video::S3DVertex (model data) from a mesh & primitive index.
*/
2023-05-18 14:01:43 +02:00
std::vector<video::S3DVertex> CGLTFMeshFileLoader::MeshExtractor::getVertices(
2023-05-18 13:41:36 +02:00
const std::size_t meshIdx,
const std::size_t primitiveIdx) const
{
2023-05-18 14:33:04 +02:00
const auto positionAccessorIdx = getPositionAccessorIdx(
meshIdx, primitiveIdx);
std::vector<vertex_t> vertices{};
vertices.resize(getElemCount(positionAccessorIdx));
copyPositions(positionAccessorIdx, vertices);
const auto normalAccessorIdx = getNormalAccessorIdx(
meshIdx, primitiveIdx);
if (normalAccessorIdx.has_value()) {
copyNormals(normalAccessorIdx.value(), vertices);
}
2023-05-18 14:33:04 +02:00
const auto tCoordAccessorIdx = getTCoordAccessorIdx(
meshIdx, primitiveIdx);
if (tCoordAccessorIdx.has_value()) {
copyTCoords(tCoordAccessorIdx.value(), vertices);
}
2023-05-18 00:19:57 +02:00
return vertices;
}
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
2023-12-01 23:10:01 +01:00
/**
* Get the amount of meshes that a model contains.
*/
2023-05-18 14:01:43 +02:00
std::size_t CGLTFMeshFileLoader::MeshExtractor::getMeshCount() const
2023-05-17 23:47:02 +02:00
{
return m_model.meshes->size();
2023-05-17 23:47:02 +02:00
}
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
2023-12-01 23:10:01 +01:00
/**
* Get the amount of primitives that a mesh in a model contains.
*/
2023-05-18 14:01:43 +02:00
std::size_t CGLTFMeshFileLoader::MeshExtractor::getPrimitiveCount(
2023-05-18 13:41:36 +02:00
const std::size_t meshIdx) const
2023-05-17 23:47:02 +02:00
{
return m_model.meshes->at(meshIdx).primitives.size();
2023-05-17 23:47:02 +02:00
}
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
2023-12-01 23:10:01 +01:00
/**
* Templated buffer reader. Based on type width.
* This is specifically used to build upon to read more complex data types.
* It is also used raw to read arrays directly.
* Basically we're using the width of the type to infer
* how big of a gap we have from the beginning of the buffer.
*/
template <typename T>
2023-05-18 14:01:43 +02:00
T CGLTFMeshFileLoader::MeshExtractor::readPrimitive(
const BufferOffset& readFrom)
2022-11-12 14:01:56 +01:00
{
2022-11-10 20:58:28 +01:00
unsigned char d[sizeof(T)]{};
for (std::size_t i = 0; i < sizeof(T); ++i) {
d[i] = readFrom.at(i);
}
T dest;
std::memcpy(&dest, d, sizeof(dest));
return dest;
}
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
2023-12-01 23:10:01 +01:00
/**
* Read a vector2df from a buffer at an offset.
* @return vec2 core::Vector2df
*/
2023-05-18 14:01:43 +02:00
core::vector2df CGLTFMeshFileLoader::MeshExtractor::readVec2DF(
const CGLTFMeshFileLoader::BufferOffset& readFrom)
2022-11-12 14:01:56 +01:00
{
return core::vector2df(readPrimitive<float>(readFrom),
readPrimitive<float>(BufferOffset(readFrom, sizeof(float))));
2022-11-12 14:01:56 +01:00
}
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
2023-12-01 23:10:01 +01:00
/**
* Read a vector3df from a buffer at an offset.
* @return vec3 core::Vector3df
*/
2023-05-18 14:01:43 +02:00
core::vector3df CGLTFMeshFileLoader::MeshExtractor::readVec3DF(
const BufferOffset& readFrom,
const core::vector3df scale = {1.0f,1.0f,1.0f})
2022-11-12 14:01:56 +01:00
{
2022-11-07 01:00:42 +01:00
return core::vector3df(
scale.X * readPrimitive<float>(readFrom),
scale.Y * readPrimitive<float>(BufferOffset(readFrom, sizeof(float))),
-scale.Z * readPrimitive<float>(BufferOffset(readFrom, 2 *
sizeof(float))));
2022-11-10 20:58:28 +01:00
}
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
2023-12-01 23:10:01 +01:00
/**
* Streams vertex positions raw data into usable buffer via reference.
* Buffer: ref Vector<video::S3DVertex>
*/
2023-05-18 14:01:43 +02:00
void CGLTFMeshFileLoader::MeshExtractor::copyPositions(
2023-05-18 14:33:04 +02:00
const std::size_t accessorIdx,
std::vector<vertex_t>& vertices) const
2022-11-10 20:58:28 +01:00
{
2023-05-18 14:33:04 +02:00
const auto& buffer = getBuffer(accessorIdx);
const auto count = getElemCount(accessorIdx);
const auto byteStride = getByteStride(accessorIdx);
for (std::size_t i = 0; i < count; i++) {
2023-05-18 14:33:04 +02:00
const auto v = readVec3DF(BufferOffset(buffer,
(byteStride * i)), getScale());
2023-05-18 14:33:04 +02:00
vertices[i].Pos = v;
2022-11-12 14:01:56 +01:00
}
}
2022-11-12 00:37:21 +01:00
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
2023-12-01 23:10:01 +01:00
/**
* Streams normals raw data into usable buffer via reference.
* Buffer: ref Vector<video::S3DVertex>
*/
2023-05-18 14:01:43 +02:00
void CGLTFMeshFileLoader::MeshExtractor::copyNormals(
2023-05-18 14:33:04 +02:00
const std::size_t accessorIdx,
std::vector<vertex_t>& vertices) const
2022-11-12 14:43:44 +01:00
{
2023-05-18 14:33:04 +02:00
const auto& buffer = getBuffer(accessorIdx);
const auto count = getElemCount(accessorIdx);
for (std::size_t i = 0; i < count; i++) {
2023-05-18 14:33:04 +02:00
const auto n = readVec3DF(BufferOffset(buffer,
3 * sizeof(float) * i));
vertices[i].Normal = n;
2022-11-12 14:43:44 +01:00
}
}
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
2023-12-01 23:10:01 +01:00
/**
* Streams texture coordinate raw data into usable buffer via reference.
* Buffer: ref Vector<video::S3DVertex>
*/
2023-05-18 14:01:43 +02:00
void CGLTFMeshFileLoader::MeshExtractor::copyTCoords(
2023-05-18 14:33:04 +02:00
const std::size_t accessorIdx,
std::vector<vertex_t>& vertices) const
2022-11-12 14:01:56 +01:00
{
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
2023-12-01 23:10:01 +01:00
2023-05-18 14:33:04 +02:00
const auto& buffer = getBuffer(accessorIdx);
const auto count = getElemCount(accessorIdx);
for (std::size_t i = 0; i < count; ++i) {
2023-05-18 14:33:04 +02:00
const auto t = readVec2DF(BufferOffset(buffer,
2 * sizeof(float) * i));
vertices[i].TCoords = t;
2022-11-12 14:01:56 +01:00
}
}
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
2023-12-01 23:10:01 +01:00
/**
* Gets the scale of a model's node via a reference Vector3df.
* Documentation: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-node
* Type: number[3] (tinygltf: vector<double>)
* Required: NO
* @returns: core::vector2df
*/
core::vector3df CGLTFMeshFileLoader::MeshExtractor::getScale() const
2022-11-12 14:01:56 +01:00
{
core::vector3df buffer{1.0f,1.0f,1.0f};
// FIXME this just checks the first node
const auto &node = m_model.nodes->at(0);
// FIXME this does not take the matrix into account
// (fix: properly map glTF -> Irrlicht node hierarchy)
if (std::holds_alternative<tiniergltf::Node::TRS>(node.transform)) {
const auto &trs = std::get<tiniergltf::Node::TRS>(node.transform);
buffer.X = static_cast<float>(trs.scale[0]);
buffer.Y = static_cast<float>(trs.scale[1]);
buffer.Z = static_cast<float>(trs.scale[2]);
2022-11-12 00:37:21 +01:00
}
return buffer;
2022-11-07 01:00:42 +01:00
}
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
2023-12-01 23:10:01 +01:00
/**
* The number of elements referenced by this accessor, not to be confused with the number of bytes or number of components.
* Documentation: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_accessor_count
* Type: Integer
* Required: YES
*/
2023-05-18 14:01:43 +02:00
std::size_t CGLTFMeshFileLoader::MeshExtractor::getElemCount(
2023-05-18 13:41:36 +02:00
const std::size_t accessorIdx) const
2023-05-17 23:47:02 +02:00
{
return m_model.accessors->at(accessorIdx).count;
2023-05-17 23:47:02 +02:00
}
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
2023-12-01 23:10:01 +01:00
/**
* The stride, in bytes, between vertex attributes.
* When this is not defined, data is tightly packed.
* When two or more accessors use the same buffer view, this field MUST be defined.
* Documentation: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_bufferview_bytestride
* Required: NO
*/
std::size_t CGLTFMeshFileLoader::MeshExtractor::getByteStride(
const std::size_t accessorIdx) const
{
const auto& accessor = m_model.accessors->at(accessorIdx);
// FIXME this does not work with sparse / zero-initialized accessors
const auto& view = m_model.bufferViews->at(accessor.bufferView.value());
return view.byteStride.value_or(accessor.elementSize());
}
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
2023-12-01 23:10:01 +01:00
/**
* Specifies whether integer data values are normalized (true) to [0, 1] (for unsigned types)
* or to [-1, 1] (for signed types) when they are accessed. This property MUST NOT be set to
* true for accessors with FLOAT or UNSIGNED_INT component type.
* Documentation: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_accessor_normalized
* Required: NO
*/
bool CGLTFMeshFileLoader::MeshExtractor::isAccessorNormalized(
const std::size_t accessorIdx) const
{
const auto& accessor = m_model.accessors->at(accessorIdx);
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
2023-12-01 23:10:01 +01:00
return accessor.normalized;
}
/**
* Walk through the complex chain of the model to extract the required buffer.
* Accessor -> BufferView -> Buffer
*/
2023-05-18 14:01:43 +02:00
CGLTFMeshFileLoader::BufferOffset CGLTFMeshFileLoader::MeshExtractor::getBuffer(
2023-05-18 13:41:36 +02:00
const std::size_t accessorIdx) const
2023-05-17 23:47:02 +02:00
{
const auto& accessor = m_model.accessors->at(accessorIdx);
// FIXME this does not work with sparse / zero-initialized accessors
const auto& view = m_model.bufferViews->at(accessor.bufferView.value());
const auto& buffer = m_model.buffers->at(view.buffer);
2023-05-17 23:47:02 +02:00
return BufferOffset(buffer.data, view.byteOffset);
}
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
2023-12-01 23:10:01 +01:00
/**
* The index of the accessor that contains the vertex indices.
* When this is undefined, the primitive defines non-indexed geometry.
* When defined, the accessor MUST have SCALAR type and an unsigned integer component type.
* Documentation: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_mesh_primitive_indices
* Type: Integer
* Required: NO
*/
std::optional<std::size_t> CGLTFMeshFileLoader::MeshExtractor::getIndicesAccessorIdx(
2023-05-18 13:41:36 +02:00
const std::size_t meshIdx,
const std::size_t primitiveIdx) const
2023-05-17 23:47:02 +02:00
{
return m_model.meshes->at(meshIdx).primitives[primitiveIdx].indices;
2023-05-17 23:47:02 +02:00
}
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
2023-12-01 23:10:01 +01:00
/**
* The index of the accessor that contains the POSITIONs.
* Documentation: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview
* Type: VEC3 (Float)
* ! Required: YES (Appears so, needs another pair of eyes to research.)
* Second pair of eyes says: "When positions are not specified, client implementations SHOULD skip primitives rendering"
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
2023-12-01 23:10:01 +01:00
*/
2023-05-18 14:01:43 +02:00
std::size_t CGLTFMeshFileLoader::MeshExtractor::getPositionAccessorIdx(
2023-05-18 13:41:36 +02:00
const std::size_t meshIdx,
const std::size_t primitiveIdx) const
2023-05-18 00:19:57 +02:00
{
// FIXME position-less primitives should be skipped.
return m_model.meshes->at(meshIdx).primitives[primitiveIdx]
.attributes.position.value();
2023-05-18 00:19:57 +02:00
}
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
2023-12-01 23:10:01 +01:00
/**
* The index of the accessor that contains the NORMALs.
* Documentation: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview
* Type: VEC3 (Float)
* ! Required: NO (Appears to not be, needs another pair of eyes to research.)
*/
std::optional<std::size_t> CGLTFMeshFileLoader::MeshExtractor::getNormalAccessorIdx(
2023-05-18 14:33:04 +02:00
const std::size_t meshIdx,
const std::size_t primitiveIdx) const
{
return m_model.meshes->at(meshIdx).primitives[primitiveIdx].attributes.normal;
2023-05-18 14:33:04 +02:00
}
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
2023-12-01 23:10:01 +01:00
/**
* The index of the accessor that contains the TEXCOORDs.
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
2023-12-01 23:10:01 +01:00
* Documentation: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview
* Type: VEC3 (Float)
* ! Required: YES (Appears so, needs another pair of eyes to research.)
*/
std::optional<std::size_t> CGLTFMeshFileLoader::MeshExtractor::getTCoordAccessorIdx(
2023-05-18 14:33:04 +02:00
const std::size_t meshIdx,
const std::size_t primitiveIdx) const
{
const auto& texcoords = m_model.meshes->at(meshIdx).primitives[primitiveIdx].attributes.texcoord;
if (!texcoords.has_value())
return std::nullopt;
return texcoords->at(0);
2023-05-18 14:33:04 +02:00
}
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
2023-12-01 23:10:01 +01:00
/**
* This is where the actual model's GLTF file is loaded and parsed by tiniergltf.
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
2023-12-01 23:10:01 +01:00
*/
std::optional<tiniergltf::GlTF> CGLTFMeshFileLoader::tryParseGLTF(io::IReadFile* file)
{
auto size = file->getSize();
auto buf = std::make_unique<char[]>(size + 1);
file->read(buf.get(), size);
// We probably don't need this, but add it just to be sure.
buf[size] = '\0';
Json::CharReaderBuilder builder;
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
Json::Value json;
JSONCPP_STRING err;
if (!reader->parse(buf.get(), buf.get() + size, &json, &err)) {
return std::nullopt;
}
try {
return tiniergltf::GlTF(json);
} catch (const std::runtime_error &e) {
return std::nullopt;
} catch (const std::out_of_range &e) {
return std::nullopt;
}
}
2022-11-10 20:58:28 +01:00
} // namespace scene
} // namespace irr