Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glTF loading for index types other than 16-bit #60

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ set (KOKKO_SOURCES
src/Graphics/TransformUpdateReceiver.hpp
src/Graphics/Scene.cpp
src/Graphics/Scene.hpp
src/Math/BoundingBox.cpp
src/Math/BoundingBox.hpp
src/Math/AABB.cpp
src/Math/AABB.hpp
src/Math/Frustum.hpp
src/Math/Intersect3D.cpp
src/Math/Intersect3D.hpp
Expand Down
4 changes: 1 addition & 3 deletions engine/src/Debug/DebugTextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,9 @@ void DebugTextRenderer::CreateAndUploadData()
data.vertexData = vertexData.GetData();
data.vertexDataSize = vertexData.GetCount() * sizeof(vertexData[0]);
data.vertexCount = vertexData.GetCount() / static_cast<int>(componentCount);
data.vertexBufferUsage = RenderBufferUsage::DynamicDraw;
data.indexData = indexData.GetData();
data.indexDataSize = indexData.GetCount() * sizeof(indexData[0]);
data.indexCount = static_cast<unsigned int>(indexData.GetCount());
data.indexBufferUsage = RenderBufferUsage::DynamicDraw;
data.indexCount = static_cast<uint32_t>(indexData.GetCount());

meshManager->UploadIndexed(meshId, data);

Expand Down
1 change: 0 additions & 1 deletion engine/src/Debug/DebugVectorRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ void DebugVectorRenderer::DrawLineChainScreen(size_t count, const Vec3f* points,
VertexData data;
data.vertexFormat = vertexFormatPos;
data.primitiveMode = RenderPrimitiveMode::LineStrip;
data.vertexBufferUsage = RenderBufferUsage::DynamicDraw;
data.vertexData = reinterpret_cast<const float*>(points);
data.vertexDataSize = static_cast<unsigned int>(requiredBufferSize);
data.vertexCount = static_cast<unsigned int>(count);
Expand Down
4 changes: 2 additions & 2 deletions engine/src/Graphics/TerrainQuadTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "Graphics/TerrainSystem.hpp"

#include "Math/BoundingBox.hpp"
#include "Math/AABB.hpp"
#include "Math/Frustum.hpp"
#include "Math/Intersect3D.hpp"

Expand Down Expand Up @@ -121,7 +121,7 @@ void TerrainQuadTree::RenderTile(
Vec3f tileMin = levelOrigin + Vec3f(id.x * tileWidth, terrainBottom, id.y * tileWidth);
Vec3f tileSize(tileWidth, terrainHeight, tileWidth);

BoundingBox tileBounds;
AABB tileBounds;
tileBounds.extents = tileSize * 0.5f;
tileBounds.center = tileMin + tileBounds.extents;

Expand Down
13 changes: 9 additions & 4 deletions engine/src/Math/BoundingBox.cpp → engine/src/Math/AABB.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#include "Math/BoundingBox.hpp"
#include "Math/AABB.hpp"

#include <cmath>
#include <algorithm>
#include <limits>

BoundingBox BoundingBox::Transform(const Mat4x4f& m) const
namespace kokko
{

AABB AABB::Transform(const Mat4x4f& m) const
{
Mat4x4f absm;

for (int i = 0; i < 16; ++i)
absm[i] = std::abs(m[i]);

BoundingBox result;
AABB result;

result.center = (m * Vec4f(this->center, 1.0f)).xyz();
result.extents = (absm * Vec4f(this->extents, 0.0f)).xyz();

return result;
}

void BoundingBox::UpdateToContain(unsigned int count, const Vec3f* points)
void AABB::UpdateToContain(unsigned int count, const Vec3f* points)
{
constexpr float fmax = std::numeric_limits<float>::max();
constexpr float fmin = std::numeric_limits<float>::min();
Expand All @@ -42,3 +45,5 @@ void BoundingBox::UpdateToContain(unsigned int count, const Vec3f* points)
extents = difference * 0.5f;
center = minimum + extents;
}

} // namespace kokko
9 changes: 7 additions & 2 deletions engine/src/Math/BoundingBox.hpp → engine/src/Math/AABB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
#include "Math/Vec3.hpp"
#include "Math/Mat4x4.hpp"

struct BoundingBox
namespace kokko
{

struct AABB
{
Vec3f center;
Vec3f extents;

BoundingBox Transform(const Mat4x4f& m) const;
AABB Transform(const Mat4x4f& m) const;
void UpdateToContain(unsigned int count, const Vec3f* points);
};

} // namespace kokko
Loading
Loading