-
Notifications
You must be signed in to change notification settings - Fork 65
Fix polygon manipulator aabb computation #903
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,20 +61,48 @@ class NBL_API2 CPolygonGeometryManipulator | |
} | ||
|
||
// | ||
static inline IGeometryBase::SAABBStorage computeAABB(const ICPUPolygonGeometry* geo) | ||
{ | ||
if (!geo || !geo->getPositionView() || geo->getPositionView().composed.rangeFormat>=IGeometryBase::EAABBFormat::Count) | ||
return {}; | ||
// the AABB shall be the same format as the Position View's range Format | ||
IGeometryBase::SAABBStorage retval; | ||
//if (geo->getIndexView() || geo->isSkinned()) | ||
{ | ||
// TODO: kevinyu | ||
} | ||
//else | ||
retval = geo->getPositionView().composed.encodedDataRange; | ||
return retval; | ||
} | ||
static inline IGeometryBase::SAABBStorage computeAABB(const ICPUPolygonGeometry* geo) | ||
{ | ||
if (!geo || !geo->getPositionView() || geo->getPositionView().composed.rangeFormat>=IGeometryBase::EAABBFormat::Count) | ||
return {}; | ||
// the AABB shall be the same format as the Position View's range Format | ||
if (geo->getIndexView() || geo->isSkinned()) | ||
{ | ||
auto addToAABB = [&](auto& aabb)->void | ||
{ | ||
using aabb_t = std::remove_reference_t<decltype(aabb)>; | ||
for (auto i = 0; i != geo->getIndexView().getElementCount(); i++) | ||
{ | ||
uint32_t vertex_i; | ||
const auto indexBuffer = geo->getIndexView().getPointer(); | ||
switch (geo->getIndexType()) | ||
{ | ||
case EIT_16BIT: | ||
vertex_i = reinterpret_cast<const uint16_t*>(indexBuffer)[i]; | ||
break; | ||
case EIT_32BIT: | ||
vertex_i = reinterpret_cast<const uint32_t*>(indexBuffer)[i]; | ||
break; | ||
default: | ||
assert(false); | ||
break; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its better to pack up the whole this way you avoid dealing with the switch and different inted buffer decodes at every index There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. outdated |
||
typename aabb_t::point_t pt; | ||
geo->getPositionView().decodeElement(vertex_i, pt); | ||
aabb.addPoint(pt); | ||
} | ||
}; | ||
IGeometryBase::SDataViewBase tmp = geo->getPositionView().composed; | ||
tmp.resetRange(); | ||
tmp.visitRange(addToAABB); | ||
return tmp.encodedDataRange; | ||
} | ||
else | ||
{ | ||
return geo->getPositionView().composed.encodedDataRange; | ||
} | ||
} | ||
|
||
static inline void recomputeAABB(const ICPUPolygonGeometry* geo) | ||
{ | ||
if (geo->isMutable()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is meant to be for Graphics Pipelines, use non-index-view specific methods (
decodeElement
like a normal view) to decode indices (this way you'll be able to support int8 indicesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.