Skip to content
Open
25 changes: 25 additions & 0 deletions include/nbl/asset/utils/COBBGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

// Copyright (C) 2018-2023 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h

#ifndef _NBL_ASSET_C_OBB_GENERATOR_H_INCLUDED_
#define _NBL_ASSET_C_OBB_GENERATOR_H_INCLUDED_

#include "nbl/asset/utils/CPolygonGeometryManipulator.h"
#include "nbl/builtin/hlsl/shapes/obb.hlsl"

namespace nbl::asset
{
class COBBGenerator
{
public:
Comment on lines +14 to +16

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation


using VertexCollection = CPolygonGeometryManipulator::VertexCollection;

static hlsl::shapes::OBB<> compute(const VertexCollection& vertices);

};
}

#endif
21 changes: 21 additions & 0 deletions include/nbl/asset/utils/CPolygonGeometryManipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "nbl/asset/ICPUPolygonGeometry.h"
#include "nbl/asset/utils/CGeometryManipulator.h"
#include "nbl/asset/utils/CSmoothNormalGenerator.h"
#include "nbl/builtin/hlsl/shapes/obb.hlsl"

namespace nbl::asset
{
Expand Down Expand Up @@ -231,6 +232,26 @@ class NBL_API2 CPolygonGeometryManipulator
EEM_COUNT
};

struct VertexCollection
{
using FetchFn = std::function<hlsl::float32_t3(size_t vertexIndex)>;
FetchFn fetch;
Comment on lines +237 to +238

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is always runtime polymorphic (wont specialize nicely based on a lambda), VertexCollection should be templated, the default template arg can be std::function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw I don't think all the OBB stuff should be nested inside CPolygonGeometryManipulator

size_t size;

static auto fromSpan(std::span<const hlsl::float32_t3> vertices) -> VertexCollection
{
return VertexCollection{
.fetch = [data = vertices.data()](size_t vertexIndex)-> hlsl::float32_t3
{
return data[vertexIndex];
},
.size = vertices.size()
};
}
Comment on lines +241 to +250

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a different template instantiation of VertexCollection


hlsl::float32_t3 operator[](size_t index) const { return fetch(index); }
};
static hlsl::shapes::OBB<3, hlsl::float32_t> calculateOBB(const VertexCollection& vertexCollection);
static core::smart_refctd_ptr<ICPUPolygonGeometry> createUnweldedList(const ICPUPolygonGeometry* inGeo);

using SSNGVertexData = CSmoothNormalGenerator::VertexData;
Expand Down
1 change: 1 addition & 0 deletions include/nbl/builtin/hlsl/shapes/aabb.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct AABB
point_t maxVx;
};


namespace util
{
namespace impl
Expand Down
42 changes: 42 additions & 0 deletions include/nbl/builtin/hlsl/shapes/obb.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2018-2023 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#ifndef _NBL_BUILTIN_HLSL_SHAPES_OBB_INCLUDED_
#define _NBL_BUILTIN_HLSL_SHAPES_OBB_INCLUDED_

namespace nbl
{
namespace hlsl
{
namespace shapes
{

template<int16_t D=3, typename Scalar=float32_t>
struct OBB
{
using scalar_t = Scalar;
using point_t = vector<Scalar,D>;

static OBB createAxisAligned(point_t mid, point_t len)
{
OBB ret;
ret.mid = mid;
ret.ext = len * 0.5f;
for (auto dim_i = 0; dim_i < D; dim_i++)
{
ret.axes[dim_i] = point_t(0);
ret.axes[dim_i][dim_i] = 1;
}
return ret;
}

point_t mid;
std::array<point_t, D> axes;
point_t ext;
Comment on lines +33 to +35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a matrix<float32_t,D,D+1> instead

@karimsayedre which OBB is more useful for you in general, the one that transforms a [0,1]^3 or [-1,1]^3 obb ?

};

}
}
}

#endif
2 changes: 2 additions & 0 deletions include/nbl/ext/DebugDraw/CDrawAABB.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ namespace nbl::ext::debug_draw
return transform;
}

static hlsl::float32_t3x4 getTransformFromOBB(const hlsl::shapes::OBB<3, float>& aabb);

protected:
struct ConstructorParams
{
Expand Down
1 change: 1 addition & 0 deletions src/nbl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ set(NBL_ASSET_SOURCES
# Meshes
asset/utils/CForsythVertexCacheOptimizer.cpp
asset/utils/CSmoothNormalGenerator.cpp
asset/utils/COBBGenerator.cpp
asset/utils/CGeometryCreator.cpp
asset/utils/CPolygonGeometryManipulator.cpp
asset/utils/COverdrawPolygonGeometryOptimizer.cpp
Expand Down
Loading
Loading