@@ -65,16 +65,61 @@ class NBL_API2 CPolygonGeometryManipulator
6565 {
6666 if (!geo || !geo->getPositionView () || geo->getPositionView ().composed .rangeFormat >=IGeometryBase::EAABBFormat::Count)
6767 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())
68+
69+ if (geo->getIndexView () || geo->isSkinned ())
7170 {
72- // TODO: kevinyu
71+ const auto jointViewCount = geo->getJointWeightViews ().size ();
72+ auto isVertexSkinned = [&jointViewCount](const ICPUPolygonGeometry* geo, uint64_t vertex_i)
73+ {
74+ if (!geo->isSkinned ()) return false ;
75+ for (auto weightView_i = 0u ; weightView_i < jointViewCount; weightView_i++)
76+ {
77+ const auto & weightView = geo->getJointWeightViews ()[weightView_i];
78+ hlsl::float32_t4 weight;
79+ weightView.weights .decodeElement (vertex_i, weight);
80+ for (auto channel_i = 0 ; channel_i < getFormatChannelCount (weightView.weights .composed .format ); channel_i++)
81+ if (weight[channel_i] > 0 .f )
82+ return true ;
83+ }
84+ return false ;
85+ };
86+
87+ auto addToAABB = [&](auto & aabb)->void
88+ {
89+ using aabb_t = std::remove_reference_t <decltype (aabb)>;
90+ if (geo->getIndexView ())
91+ {
92+ for (auto index_i = 0u ; index_i != geo->getIndexView ().getElementCount (); index_i++)
93+ {
94+ hlsl::vector<uint32_t , 1 > vertex_i;
95+ geo->getIndexView ().decodeElement (index_i, vertex_i);
96+ if (isVertexSkinned (geo, vertex_i.x )) continue ;
97+ typename aabb_t ::point_t pt;
98+ geo->getPositionView ().decodeElement (vertex_i.x , pt);
99+ aabb.addPoint (pt);
100+ }
101+ } else
102+ {
103+ for (auto vertex_i = 0u ; vertex_i != geo->getPositionView ().getElementCount (); vertex_i++)
104+ {
105+ if (isVertexSkinned (geo, vertex_i)) continue ;
106+ typename aabb_t ::point_t pt;
107+ geo->getPositionView ().decodeElement (vertex_i, pt);
108+ aabb.addPoint (pt);
109+ }
110+ }
111+ };
112+ IGeometryBase::SDataViewBase tmp = geo->getPositionView ().composed ;
113+ tmp.resetRange ();
114+ tmp.visitRange (addToAABB);
115+ return tmp.encodedDataRange ;
116+ }
117+ else
118+ {
119+ return geo->getPositionView ().composed .encodedDataRange ;
73120 }
74- // else
75- retval = geo->getPositionView ().composed .encodedDataRange ;
76- return retval;
77121 }
122+
78123 static inline void recomputeAABB (const ICPUPolygonGeometry* geo)
79124 {
80125 if (geo->isMutable ())
0 commit comments