Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Fix gltf static mesh loading issues (#14)
Browse files Browse the repository at this point in the history
* Support u8 / u32 indices

* Skip primitives without vertices

* Add support for non-indexed geometry & skipping primitives

* Fix possible memory leak on error

* Use SSkinnedMesh

* Check indices

* Properly mirror node hierarchy

* Update .gitignore

* Reorder includes

* Add some throws for logic errors

* Fix non-indexed geometry winding order, add unit test

* Address code review comments

* Add matrix transform unit test
  • Loading branch information
appgurueu authored Apr 15, 2024
1 parent 1320fc9 commit 3484a6b
Show file tree
Hide file tree
Showing 7 changed files with 462 additions and 112 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ scripts/glext.h

# vscode cmake plugin
build/*

# vscode clangd plugin
.cache
compile_commands.json

# build dependencies
_deps

# autogenerated test-related files
**/CTestTestfile.cmake
Testing
DartConfiguration.tcl
27 changes: 24 additions & 3 deletions include/SSkinMeshBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,31 @@ struct SSkinMeshBuffer : public IMeshBuffer
}

//! append the vertices and indices to the current buffer
void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override {}
void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override {
if (vertices == getVertices())
throw std::logic_error("can't append own vertices");

//! append the meshbuffer to the current buffer
void append(const IMeshBuffer* const other) override {}
if (VertexType != video::EVT_STANDARD)
throw std::logic_error("invalid vertex type");

const u32 prevVertexCount = getVertexCount();

Vertices_Standard.reallocate(prevVertexCount + numVertices);
for (u32 i=0; i < numVertices; ++i) {
Vertices_Standard.push_back(static_cast<const video::S3DVertex* const>(vertices)[i]);
BoundingBox.addInternalPoint(static_cast<const video::S3DVertex* const>(vertices)[i].Pos);
}

Indices.reallocate(getIndexCount() + numIndices);
for (u32 i=0; i < numIndices; ++i) {
Indices.push_back(indices[i] + prevVertexCount);
}
}

//! NOT IMPLEMENTED YET: append the meshbuffer to the current buffer
void append(const IMeshBuffer* const other) override {
throw std::logic_error("not implemented yet");
}

//! get the current hardware mapping hint for vertex buffers
E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const override
Expand Down
Loading

0 comments on commit 3484a6b

Please sign in to comment.