Skip to content
Merged
Changes from 6 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
56 changes: 50 additions & 6 deletions include/nbl/asset/utils/CPolygonGeometryManipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,59 @@ 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
auto isVertexSkinned = [](const ICPUPolygonGeometry* geo, uint64_t vertex_i)
{
if (!geo->isSkinned()) return false;
const auto& jointWeightView = geo->getJointWeightViews()[vertex_i];
for (auto weight_i = 0u; weight_i < jointWeightView.weights.getElementCount(); weight_i++)
{
hlsl::vector<hlsl::float32_t, 1> weight;
jointWeightView.weights.decodeElement(vertex_i, weight);
auto hasWeight = false;
if (weight.x != 0.f) hasWeight = true;
if (hasWeight) return true;
}
return false;
};

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 (isVertexSkinned(geo, 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 (isVertexSkinned(geo, 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