Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions include/nbl/asset/IPolygonGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class IPolygonGeometry : public IIndexableGeometry<BufferType>, public IPolygonG
// SoA instead of AoS, first component is the first bone influece, etc.
struct SJointWeight
{
static const size_t JOINT_COUNT_PER_VERTEX = 4;

// one thing this doesn't check is whether every vertex has a weight and index
inline operator bool() const {return indices && isIntegerFormat(indices.composed.format) && weights && weights.composed.isFormatted() && indices.getElementCount()==weights.getElementCount();}

Expand Down
59 changes: 52 additions & 7 deletions include/nbl/asset/utils/CPolygonGeometryManipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,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
auto isVertexSkinned = [](const ICPUPolygonGeometry* geo, uint64_t vertex_i)
{
if (!geo->isSkinned()) return false;
constexpr auto jointCountPerVertex = ICPUPolygonGeometry::SJointWeight::JOINT_COUNT_PER_VERTEX;
for (auto& weightView : geo->getJointWeightViews())
{
for (auto weight_i = 0u; weight_i < jointCountPerVertex; weight_i++)
{
hlsl::vector<hlsl::float32_t, 1> weight;
weightView.weights.decodeElement(jointCountPerVertex * vertex_i + weight_i, weight);
if (weight.x != 0.f) 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