Skip to content

Commit 787212f

Browse files
author
devsh
committed
split off the AABB from the Position View range
1 parent 1f06c53 commit 787212f

File tree

14 files changed

+109
-27
lines changed

14 files changed

+109
-27
lines changed

examples_tests

include/nbl/asset/ICPUGeometryCollection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class NBL_API2 ICPUGeometryCollection : public IAsset, public IGeometryCollectio
5151
}
5252

5353
//
54-
inline bool setAABB(const IGeometryBase::SAABBStorage& aabb)
54+
inline bool setAABB(const decltype(base_t::m_aabb)& aabb)
5555
{
5656
if (isMutable())
5757
{

include/nbl/asset/ICPUPolygonGeometry.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class NBL_API2 ICPUPolygonGeometry final : public IPolygonGeometry<ICPUBuffer>
3434
retval->m_positionView = m_positionView.clone(nextDepth);
3535
retval->m_jointOBBView = m_jointOBBView.clone(nextDepth);
3636
retval->m_indexView = m_indexView.clone(nextDepth);
37+
retval->m_aabb = m_aabb;
3738
retval->m_jointWeightViews.reserve(m_jointWeightViews.size());
3839
for (const auto& pair : m_jointWeightViews)
3940
retval->m_jointWeightViews.push_back({
@@ -96,6 +97,22 @@ class NBL_API2 ICPUPolygonGeometry final : public IPolygonGeometry<ICPUBuffer>
9697
return false;
9798
}
9899

100+
//
101+
template<typename Visitor>
102+
inline void visitAABB(Visitor&& visitor) const {return base_t::visitAABB(std::forward<Visitor>(visitor));}
103+
template<typename Visitor>
104+
inline bool visitAABB(Visitor&& visitor)
105+
{
106+
if (isMutable())
107+
{
108+
getAABBStorage().visit(getAABBFormat(),std::forward<Visitor>(visitor));
109+
return true;
110+
}
111+
return false;
112+
}
113+
template<typename Scalar>
114+
inline bool setAABB(const hlsl::shapes::AABB<3,Scalar>& aabb) {return visitAABB([&aabb](auto&& ref)->void{ref=aabb;});}
115+
99116
//
100117
inline bool setJointCount(const uint32_t count)
101118
{

include/nbl/asset/IGeometry.h

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class IGeometryBase : public virtual core::IReferenceCounted
4747
U8_NORM,
4848
S8,
4949
S8_NORM,
50+
Count,
5051
BitCount=4
5152
};
5253
//
@@ -155,6 +156,11 @@ class IGeometryBase : public virtual core::IReferenceCounted
155156
const_cast<SAABBStorage*>(this)->visit(format,std::forward<Visitor>(visitor));
156157
}
157158

159+
inline void reset(const EAABBFormat format)
160+
{
161+
visit(format,[](auto& aabb)->void{aabb = aabb.create();});
162+
}
163+
158164
hlsl::shapes::AABB<4,hlsl::float64_t> f64 = hlsl::shapes::AABB<4,hlsl::float64_t>::create();
159165
hlsl::shapes::AABB<4,uint64_t> u64;
160166
hlsl::shapes::AABB<4,int64_t> s64;
@@ -206,30 +212,23 @@ class IGeometryBase : public virtual core::IReferenceCounted
206212

207213
//
208214
template<typename Visitor>
209-
inline void visitAABB(Visitor&& visitor) {encodedDataRange.visit(rangeFormat,std::forward<Visitor>(visitor));}
215+
inline void visitRange(Visitor&& visitor) {encodedDataRange.visit(rangeFormat,std::forward<Visitor>(visitor));}
210216
template<typename Visitor>
211-
inline void visitAABB(Visitor&& visitor) const {encodedDataRange.visit(rangeFormat,std::forward<Visitor>(visitor));}
217+
inline void visitRange(Visitor&& visitor) const {encodedDataRange.visit(rangeFormat,std::forward<Visitor>(visitor));}
212218

213219
//
214-
inline void resetRange(const EAABBFormat newFormat)
215-
{
216-
rangeFormat = newFormat;
217-
auto tmp = [](auto& aabb)->void{aabb = aabb.create();};
218-
visitAABB(tmp);
219-
}
220-
inline void resetRange() {resetRange(rangeFormat);}
220+
inline void resetRange() {encodedDataRange.reset(rangeFormat);}
221221

222222
//
223223
template<typename AABB>
224224
inline AABB getRange() const
225225
{
226226
AABB retval = AABB::create();
227-
auto tmp = [&retval](const auto& aabb)->void
227+
visitRange([&retval](const auto& aabb)->void
228228
{
229229
retval.minVx = aabb.minVx;
230230
retval.maxVx = aabb.maxVx;
231-
};
232-
visitAABB(tmp);
231+
});
233232
return retval;
234233
}
235234

@@ -245,11 +244,23 @@ class IGeometryBase : public virtual core::IReferenceCounted
245244
};
246245

247246
virtual EAABBFormat getAABBFormat() const = 0;
248-
virtual const SAABBStorage& getAABB() const = 0;
247+
virtual const SAABBStorage& getAABBStorage() const = 0;
249248
template<typename Visitor>
250249
inline void visitAABB(Visitor&& visitor) const
251250
{
252-
getAABB().visit(getAABBFormat(),std::forward<Visitor>(visitor));
251+
getAABBStorage().visit(getAABBFormat(),std::forward<Visitor>(visitor));
252+
}
253+
//
254+
template<typename AABB>
255+
inline AABB getAABB() const
256+
{
257+
auto retval = AABB::create();
258+
visitAABB([&retval](const auto& aabb)->void
259+
{
260+
retval.minVx = aabb.minVx;
261+
retval.maxVx = aabb.maxVx;
262+
});
263+
return retval;
253264
}
254265

255266
protected:
@@ -278,6 +289,9 @@ class IGeometry : public std::conditional_t<std::is_same_v<BufferType,ICPUBuffer
278289
return true;
279290
}
280291

292+
//
293+
inline IGeometryBase::EAABBFormat getAABBFormat() const override final {return m_positionView.composed.rangeFormat;}
294+
281295
struct SDataView
282296
{
283297
inline operator bool() const {return src && composed;}
@@ -488,7 +502,7 @@ struct blake3_hasher::update_impl<asset::IGeometryBase::SDataViewBase,Dummy>
488502
hasher << input.stride;
489503
hasher << input.format;
490504
hasher << input.rangeFormat;
491-
input.visitAABB([&hasher](auto& aabb)->void{hasher.update(&aabb,sizeof(aabb));});
505+
input.visitRange([&hasher](auto& aabb)->void{hasher.update(&aabb,sizeof(aabb));});
492506
}
493507
};
494508
}

include/nbl/asset/IGeometryCollection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class NBL_API2 IGeometryCollection : public virtual core::IReferenceCounted
116116

117117

118118
// For the entire collection, as always it should NOT include any geometry which is affected by a joint.
119-
IGeometryBase::SAABBStorage m_aabb;
119+
hlsl::shapes::AABB<3,hlsl::float64_t> m_aabb;
120120
SDataView m_inverseBindPoseView = {};
121121
// The AABBs gathered from all geometries (optional) and are in "bone-space" so there's no need for OBB option,
122122
// joint influence is usually aligned to the covariance matrix of geometry affected by it.

include/nbl/asset/IPolygonGeometry.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ class IPolygonGeometry : public IIndexableGeometry<BufferType>, public IPolygonG
160160
inline EPrimitiveType getPrimitiveType() const override final {return PrimitiveType;}
161161

162162
//
163-
inline IGeometryBase::EAABBFormat getAABBFormat() const override final {return base_t::m_positionView.composed.rangeFormat;}
164-
inline const IGeometryBase::SAABBStorage& getAABB() const override final {return base_t::m_positionView.composed.encodedDataRange;}
163+
inline const IGeometryBase::SAABBStorage& getAABBStorage() const override final {return m_aabb;}
165164

166165
//
167166
inline uint64_t getVertexReferenceCount() const {return base_t::getIndexView() ? base_t::getIndexCount():base_t::m_positionView.getElementCount();}
@@ -261,6 +260,8 @@ class IPolygonGeometry : public IIndexableGeometry<BufferType>, public IPolygonG
261260
return true;
262261
}
263262

263+
//
264+
IGeometryBase::SAABBStorage m_aabb = {};
264265
//
265266
core::vector<SJointWeight> m_jointWeightViews = {};
266267
//

include/nbl/asset/utils/CGeometryManipulator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class NBL_API2 CGeometryManipulator
4040
aabb.addPoint(pt);
4141
}
4242
};
43-
IGeometryBase::SDataViewBase tmp = {};
44-
tmp.resetRange(view.composed.rangeFormat);
45-
tmp.visitAABB(addToAABB);
43+
IGeometryBase::SDataViewBase tmp = view.composed;
44+
tmp.resetRange();
45+
tmp.visitRange(addToAABB);
4646
return tmp.encodedDataRange;
4747
}
4848

include/nbl/asset/utils/CPolygonGeometryManipulator.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ class NBL_API2 CPolygonGeometryManipulator
6060
recomputeRange(view);
6161
}
6262

63+
//
64+
static inline IGeometryBase::SAABBStorage computeAABB(const ICPUPolygonGeometry* geo)
65+
{
66+
if (!geo || !geo->getPositionView() || geo->getPositionView().composed.rangeFormat>=IGeometryBase::EAABBFormat::Count)
67+
return {};
68+
// the AABB shall be the same format as the Position View's range Format
69+
IGeometryBase::SAABBStorage retval;
70+
//if (geo->getIndexView() || geo->isSkinned())
71+
{
72+
// TODO: kevinyu
73+
}
74+
//else
75+
retval = geo->getPositionView().composed.encodedDataRange;
76+
return retval;
77+
}
78+
static inline void recomputeAABB(const ICPUPolygonGeometry* geo)
79+
{
80+
if (geo->isMutable())
81+
const_cast<IGeometryBase::SAABBStorage&>(geo->getAABBStorage()) = computeAABB(geo);
82+
}
83+
6384
//! Comparison methods
6485
enum E_ERROR_METRIC
6586
{

include/nbl/builtin/hlsl/shapes/aabb.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ struct AABB
3838
maxVx = hlsl::max<point_t>(pt,maxVx);
3939
}
4040
//
41-
point_t getExtent()
41+
point_t getExtent() NBL_CONST_MEMBER_FUNC
4242
{
4343
return maxVx - minVx;
4444
}
4545

4646
//
47-
Scalar getVolume()
47+
Scalar getVolume() NBL_CONST_MEMBER_FUNC
4848
{
4949
const point_t extent = getExtent();
5050
return extent.x * extent.y * extent.z;
5151
}
5252

5353
// returns the corner of the AABB which has the most positive dot product
54-
point_t getFarthestPointInFront(const point_t planeNormal)
54+
point_t getFarthestPointInFront(const point_t planeNormal) NBL_CONST_MEMBER_FUNC
5555
{
5656
return hlsl::mix(maxVx,minVx,planeNormal < promote<point_t>(0.f));
5757
}

include/nbl/video/IGPUPolygonGeometry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class IGPUPolygonGeometry final : public asset::IPolygonGeometry<const IGPUBuffe
2626
SDataView jointOBBView = {};
2727
SDataView indexView = {};
2828
const IIndexingCallback* indexing = nullptr;
29+
asset::IGeometryBase::SAABBStorage aabb = {};
2930
SDataView normalView = {};
3031
std::span<const SJointWeight> jointWeightViews = {};
3132
std::span<const SDataView> auxAttributeViews = {};
@@ -39,6 +40,7 @@ class IGPUPolygonGeometry final : public asset::IPolygonGeometry<const IGPUBuffe
3940
retval->m_jointOBBView = params.jointOBBView;
4041
retval->m_indexView = params.indexView;
4142
retval->m_indexing = params.indexing;
43+
retval->m_aabb = params.aabb;
4244
if (params.jointCount)
4345
retval->m_jointWeightViews.insert(retval->m_jointWeightViews.begin(),params.jointWeightViews.begin(),params.jointWeightViews.end());
4446
retval->m_normalView = params.normalView;

0 commit comments

Comments
 (0)