Skip to content

Commit

Permalink
Fix gltf static mesh loading issues (minetest#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 and JosiahWI committed Apr 18, 2024
1 parent 0faf132 commit 036b40a
Show file tree
Hide file tree
Showing 7 changed files with 463 additions and 110 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Expand Up @@ -23,3 +23,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
26 changes: 25 additions & 1 deletion include/SSkinMeshBuffer.h
Expand Up @@ -301,7 +301,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");

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

0 comments on commit 036b40a

Please sign in to comment.