Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions include/nbl/asset/utils/CPolygonGeometryManipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,61 @@ class NBL_API2 CPolygonGeometryManipulator
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())
if (geo->getIndexView() || geo->isSkinned())
{
// TODO: kevinyu
std::unordered_set<uint32_t> jointNodeIndexes = {};
if (geo->isSkinned())
{
for (const auto& jointWeight : geo->getJointWeightViews())
{
for (auto vertex_i = 0u; vertex_i < jointWeight.indices.getElementCount(); vertex_i++)
{
hlsl::vector<uint32_t, 1> index;
hlsl::vector<hlsl::float32_t, 1> weight;
jointWeight.indices.decodeElement(vertex_i, index);
jointWeight.weights.decodeElement(vertex_i, weight);
if (weight.x != 0.f)
jointNodeIndexes.insert(index.x);
}
}
}

auto addToAABB = [&](auto& aabb)->void
{
using aabb_t = std::remove_reference_t<decltype(aabb)>;
if (geo->getIndexView())
{
for (auto index_i = 0u; index_i != geo->getIndexView().getElementCount(); index_i++)
{
hlsl::vector<uint32_t, 1> vertex_i;
geo->getIndexView().decodeElement(index_i, vertex_i);
if (geo->isSkinned() && jointNodeIndexes.contains(vertex_i.x)) continue;
typename aabb_t::point_t pt;
geo->getPositionView().decodeElement(vertex_i.x, pt);
aabb.addPoint(pt);
}
} else
{
for (auto vertex_i = 0u; vertex_i != geo->getPositionView().getElementCount(); vertex_i++)
{
if (geo->isSkinned() && jointNodeIndexes.contains(vertex_i)) continue;
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;
}
//else
retval = geo->getPositionView().composed.encodedDataRange;
return retval;
}

static inline void recomputeAABB(const ICPUPolygonGeometry* geo)
{
if (geo->isMutable())
Expand Down
Loading