Skip to content

Commit 5af4a9b

Browse files
author
kevyuu
committed
Move SSNGVertexData and VxCmpFunction to CSmoothNormalGenerator
1 parent c580d72 commit 5af4a9b

File tree

4 files changed

+39
-37
lines changed

4 files changed

+39
-37
lines changed

include/nbl/asset/utils/CPolygonGeometryManipulator.h

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "nbl/asset/ICPUPolygonGeometry.h"
1111
#include "nbl/asset/utils/CGeometryManipulator.h"
12+
#include "nbl/asset/utils/CSmoothNormalGenerator.h"
1213
#include "nbl/asset/utils/CVertexHashGrid.h"
1314

1415
namespace nbl::asset
@@ -19,33 +20,6 @@ class NBL_API2 CPolygonGeometryManipulator
1920
{
2021
public:
2122

22-
struct SSNGVertexData
23-
{
24-
uint32_t index; //offset of the vertex into index buffer
25-
// TODO: check whether separating hash and position into its own vector or even rehash the position everytime we need will result in VertexHashGrid become faster.
26-
uint32_t hash;
27-
hlsl::float32_t3 weightedNormal;
28-
hlsl::float32_t3 position; //position of the vertex in 3D space
29-
30-
hlsl::float32_t3 getPosition() const
31-
{
32-
return position;
33-
}
34-
35-
void setHash(uint32_t hash)
36-
{
37-
this->hash = hash;
38-
}
39-
40-
uint32_t getHash() const
41-
{
42-
return hash;
43-
};
44-
45-
};
46-
47-
using VxCmpFunction = std::function<bool(const SSNGVertexData&, const SSNGVertexData&, const ICPUPolygonGeometry*)>;
48-
4923
static inline void recomputeContentHashes(ICPUPolygonGeometry* geo)
5024
{
5125
if (!geo)
@@ -260,8 +234,9 @@ class NBL_API2 CPolygonGeometryManipulator
260234

261235
static core::smart_refctd_ptr<ICPUPolygonGeometry> createUnweldedList(const ICPUPolygonGeometry* inGeo);
262236

237+
using SSNGVxCmpFunction = CSmoothNormalGenerator::VxCmpFunction;
263238
static core::smart_refctd_ptr<ICPUPolygonGeometry> createSmoothVertexNormal(const ICPUPolygonGeometry* inbuffer, bool enableWelding = false, float epsilon = 1.525e-5f,
264-
VxCmpFunction vxcmp = [](const CPolygonGeometryManipulator::SSNGVertexData& v0, const CPolygonGeometryManipulator::SSNGVertexData& v1, const ICPUPolygonGeometry* buffer)
239+
SSNGVxCmpFunction vxcmp = [](const CSmoothNormalGenerator::SSNGVertexData& v0, const CSmoothNormalGenerator::SSNGVertexData& v1, const ICPUPolygonGeometry* buffer)
265240
{
266241
static constexpr float cosOf45Deg = 0.70710678118f;
267242
return dot(normalize(v0.weightedNormal),normalize(v1.weightedNormal)) > cosOf45Deg;

src/nbl/asset/utils/CPolygonGeometryManipulator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CPolygonGeometryManipulator::createU
136136
return outGeometry;
137137
}
138138

139-
core::smart_refctd_ptr<ICPUPolygonGeometry> CPolygonGeometryManipulator::createSmoothVertexNormal(const ICPUPolygonGeometry* inPolygon, bool enableWelding, float epsilon, VxCmpFunction vxcmp)
139+
core::smart_refctd_ptr<ICPUPolygonGeometry> CPolygonGeometryManipulator::createSmoothVertexNormal(const ICPUPolygonGeometry* inPolygon, bool enableWelding, float epsilon, SSNGVxCmpFunction vxcmp)
140140
{
141141
if (!inPolygon)
142142
{

src/nbl/asset/utils/CSmoothNormalGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ namespace nbl
1313
{
1414
namespace asset
1515
{
16-
static bool operator<(uint32_t lhs, const CPolygonGeometryManipulator::SSNGVertexData& rhs)
16+
static bool operator<(uint32_t lhs, const CSmoothNormalGenerator::SSNGVertexData& rhs)
1717
{
1818
return lhs < rhs.hash;
1919
}
2020

21-
static bool operator<(const CPolygonGeometryManipulator::SSNGVertexData& lhs, uint32_t rhs)
21+
static bool operator<(const CSmoothNormalGenerator::SSNGVertexData& lhs, uint32_t rhs)
2222
{
2323
return lhs.hash < rhs;
2424
}
@@ -29,7 +29,7 @@ static bool compareVertexPosition(const hlsl::float32_t3& a, const hlsl::float32
2929
return (difference.x <= epsilon && difference.y <= epsilon && difference.z <= epsilon);
3030
}
3131

32-
CSmoothNormalGenerator::Result CSmoothNormalGenerator::calculateNormals(const asset::ICPUPolygonGeometry* polygon, float epsilon, CPolygonGeometryManipulator::VxCmpFunction vxcmp)
32+
CSmoothNormalGenerator::Result CSmoothNormalGenerator::calculateNormals(const asset::ICPUPolygonGeometry* polygon, float epsilon, VxCmpFunction vxcmp)
3333
{
3434
VertexHashMap vertexHashMap = setupData(polygon, epsilon);
3535
const auto smoothPolygon = processConnectedVertices(polygon, vertexHashMap, epsilon,vxcmp);
@@ -67,7 +67,7 @@ CSmoothNormalGenerator::VertexHashMap CSmoothNormalGenerator::setupData(const as
6767
return vertices;
6868
}
6969

70-
core::smart_refctd_ptr<ICPUPolygonGeometry> CSmoothNormalGenerator::processConnectedVertices(const asset::ICPUPolygonGeometry* polygon, VertexHashMap& vertexHashMap, float epsilon, CPolygonGeometryManipulator::VxCmpFunction vxcmp)
70+
core::smart_refctd_ptr<ICPUPolygonGeometry> CSmoothNormalGenerator::processConnectedVertices(const asset::ICPUPolygonGeometry* polygon, VertexHashMap& vertexHashMap, float epsilon, VxCmpFunction vxcmp)
7171
{
7272
auto outPolygon = core::move_and_static_cast<ICPUPolygonGeometry>(polygon->clone(0u));
7373
static constexpr auto NormalFormat = EF_R32G32B32_SFLOAT;

src/nbl/asset/utils/CSmoothNormalGenerator.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#ifndef _NBL_ASSET_C_SMOOTH_NORMAL_GENERATOR_H_INCLUDED_
55
#define _NBL_ASSET_C_SMOOTH_NORMAL_GENERATOR_H_INCLUDED_
66

7+
#include "nbl/asset/utils/CVertexHashGrid.h"
78

8-
#include "nbl/asset/utils/CPolygonGeometryManipulator.h"
99

1010
namespace nbl::asset
1111
{
@@ -16,19 +16,46 @@ class CSmoothNormalGenerator
1616
CSmoothNormalGenerator() = delete;
1717
~CSmoothNormalGenerator() = delete;
1818

19-
using VertexHashMap = CVertexHashGrid<CPolygonGeometryManipulator::SSNGVertexData>;
19+
struct SSNGVertexData
20+
{
21+
uint32_t index; //offset of the vertex into index buffer
22+
// TODO: check whether separating hash and position into its own vector or even rehash the position everytime we need will result in VertexHashGrid become faster.
23+
uint32_t hash;
24+
hlsl::float32_t3 weightedNormal;
25+
hlsl::float32_t3 position; //position of the vertex in 3D space
26+
27+
hlsl::float32_t3 getPosition() const
28+
{
29+
return position;
30+
}
31+
32+
void setHash(uint32_t hash)
33+
{
34+
this->hash = hash;
35+
}
36+
37+
uint32_t getHash() const
38+
{
39+
return hash;
40+
};
41+
42+
};
43+
44+
using VxCmpFunction = std::function<bool(const SSNGVertexData&, const SSNGVertexData&, const ICPUPolygonGeometry*)>;
45+
46+
using VertexHashMap = CVertexHashGrid<SSNGVertexData>;
2047

2148
struct Result
2249
{
2350
VertexHashMap vertexHashGrid;
2451
core::smart_refctd_ptr<ICPUPolygonGeometry> geom;
2552
};
26-
static Result calculateNormals(const ICPUPolygonGeometry* polygon, float epsilon, CPolygonGeometryManipulator::VxCmpFunction function);
53+
static Result calculateNormals(const ICPUPolygonGeometry* polygon, float epsilon, VxCmpFunction function);
2754

2855
private:
2956

3057
static VertexHashMap setupData(const ICPUPolygonGeometry* polygon, float epsilon);
31-
static core::smart_refctd_ptr<ICPUPolygonGeometry> processConnectedVertices(const ICPUPolygonGeometry* polygon, VertexHashMap& vertices, float epsilon, CPolygonGeometryManipulator::VxCmpFunction vxcmp);
58+
static core::smart_refctd_ptr<ICPUPolygonGeometry> processConnectedVertices(const ICPUPolygonGeometry* polygon, VertexHashMap& vertices, float epsilon, VxCmpFunction vxcmp);
3259
};
3360

3461
}

0 commit comments

Comments
 (0)