Skip to content

Commit 9412472

Browse files
author
devsh
committed
move CGeometryManipulator to CGeometryManipulator.h
1 parent 60f1f3e commit 9412472

File tree

2 files changed

+63
-45
lines changed

2 files changed

+63
-45
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_ASSET_C_GEOMETRY_MANIPULATOR_H_INCLUDED_
5+
#define _NBL_ASSET_C_GEOMETRY_MANIPULATOR_H_INCLUDED_
6+
7+
8+
#include "nbl/core/declarations.h"
9+
10+
#include "nbl/asset/ICPUPolygonGeometry.h"
11+
#include "nbl/asset/utils/CQuantNormalCache.h"
12+
#include "nbl/asset/utils/CQuantQuaternionCache.h"
13+
14+
namespace nbl::asset
15+
{
16+
17+
class NBL_API2 CGeometryManipulator
18+
{
19+
public:
20+
static inline void recomputeContentHash(const IGeometry<ICPUBuffer>::SDataView& view)
21+
{
22+
if (!view)
23+
return;
24+
view.src.buffer->setContentHash(view.src.buffer->computeContentHash());
25+
}
26+
27+
static inline IGeometryBase::SAABBStorage computeRange(const IGeometry<ICPUBuffer>::SDataView& view)
28+
{
29+
if (!view || !view.composed.isFormatted())
30+
return {};
31+
auto it = reinterpret_cast<char*>(view.src.buffer->getPointer())+view.src.offset;
32+
const auto end = it+view.src.actualSize();
33+
auto addToAABB = [&](auto& aabb)->void
34+
{
35+
using aabb_t = std::remove_reference_t<decltype(aabb)>;
36+
for (auto i=0; i!=view.getElementCount(); i++)
37+
{
38+
typename aabb_t::point_t pt;
39+
view.decodeElement(i,pt);
40+
aabb.addPoint(pt);
41+
}
42+
};
43+
IGeometryBase::SDataViewBase tmp = {};
44+
tmp.resetRange(view.composed.rangeFormat);
45+
tmp.visitAABB(addToAABB);
46+
return tmp.encodedDataRange;
47+
}
48+
49+
static inline void recomputeRange(IGeometry<ICPUBuffer>::SDataView& view, const bool deduceRangeFormat=true)
50+
{
51+
if (!view || !view.composed.isFormatted())
52+
return;
53+
if (deduceRangeFormat)
54+
view.composed.rangeFormat = IGeometryBase::getMatchingAABBFormat(view.composed.format);
55+
view.composed.encodedDataRange = computeRange(view);
56+
}
57+
};
58+
59+
// TODO: Utility in another header for GeometryCollection to compute AABBs, deal with skins (joints), etc.
60+
61+
} // end namespace nbl::asset
62+
#endif

include/nbl/asset/utils/CPolygonGeometryManipulator.h

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,13 @@
88
#include "nbl/core/declarations.h"
99

1010
#include "nbl/asset/ICPUPolygonGeometry.h"
11+
#include "nbl/asset/utils/CGeometryManipulator.h"
1112
#include "nbl/asset/utils/CQuantNormalCache.h"
1213
#include "nbl/asset/utils/CQuantQuaternionCache.h"
1314

1415
namespace nbl::asset
1516
{
1617

17-
// TODO: move to its own header!
18-
class NBL_API2 CGeometryManipulator
19-
{
20-
public:
21-
static inline void recomputeContentHash(const IGeometry<ICPUBuffer>::SDataView& view)
22-
{
23-
if (!view)
24-
return;
25-
view.src.buffer->setContentHash(view.src.buffer->computeContentHash());
26-
}
27-
28-
static inline IGeometryBase::SAABBStorage computeRange(const IGeometry<ICPUBuffer>::SDataView& view)
29-
{
30-
if (!view || !view.composed.isFormatted())
31-
return {};
32-
auto it = reinterpret_cast<char*>(view.src.buffer->getPointer())+view.src.offset;
33-
const auto end = it+view.src.actualSize();
34-
auto addToAABB = [&](auto& aabb)->void
35-
{
36-
using aabb_t = std::remove_reference_t<decltype(aabb)>;
37-
for (auto i=0; i!=view.getElementCount(); i++)
38-
{
39-
typename aabb_t::point_t pt;
40-
view.decodeElement(i,pt);
41-
aabb.addPoint(pt);
42-
}
43-
};
44-
IGeometryBase::SDataViewBase tmp = {};
45-
tmp.resetRange(view.composed.rangeFormat);
46-
tmp.visitAABB(addToAABB);
47-
return tmp.encodedDataRange;
48-
}
49-
50-
static inline void recomputeRange(IGeometry<ICPUBuffer>::SDataView& view, const bool deduceRangeFormat=true)
51-
{
52-
if (!view || !view.composed.isFormatted())
53-
return;
54-
if (deduceRangeFormat)
55-
view.composed.rangeFormat = IGeometryBase::getMatchingAABBFormat(view.composed.format);
56-
view.composed.encodedDataRange = computeRange(view);
57-
}
58-
};
59-
6018
//! An interface for easy manipulation of polygon geometries.
6119
class NBL_API2 CPolygonGeometryManipulator
6220
{
@@ -778,7 +736,5 @@ class CMeshManipulator : public IMeshManipulator
778736
};
779737
#endif
780738

781-
// TODO: Utility in another header for GeometryCollection to compute AABBs, deal with skins (joints), etc.
782-
783739
} // end namespace nbl::asset
784740
#endif

0 commit comments

Comments
 (0)