@@ -84,79 +84,6 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CSmoothNormalGenerator::calculateNor
8484 return smoothPolygon;
8585}
8686
87- CSmoothNormalGenerator::VertexHashMap::VertexHashMap (size_t _vertexCount, uint32_t _hashTableMaxSize, float _cellSize) :
88- m_sorter (createSorter(_vertexCount)),
89- m_hashTableMaxSize (_hashTableMaxSize),
90- m_cellSize (_cellSize)
91- {
92- assert ((core::isPoT (m_hashTableMaxSize)));
93-
94- m_vertices.reserve (_vertexCount);
95- }
96-
97- uint32_t CSmoothNormalGenerator::VertexHashMap::hash (const CPolygonGeometryManipulator::SSNGVertexData & vertex) const
98- {
99- const hlsl::float32_t3 position = vertex.position / m_cellSize;
100-
101- return ((static_cast <uint32_t >(position.x ) * primeNumber1) ^
102- (static_cast <uint32_t >(position.y ) * primeNumber2) ^
103- (static_cast <uint32_t >(position.z ) * primeNumber3))& (m_hashTableMaxSize - 1 );
104- }
105-
106- uint32_t CSmoothNormalGenerator::VertexHashMap::hash (const hlsl::uint32_t3& position) const
107- {
108- return ((position.x * primeNumber1) ^
109- (position.y * primeNumber2) ^
110- (position.z * primeNumber3))& (m_hashTableMaxSize - 1 );
111- }
112-
113- void CSmoothNormalGenerator::VertexHashMap::add (CPolygonGeometryManipulator::SSNGVertexData && vertex)
114- {
115- vertex.hash = hash (vertex);
116- m_vertices.push_back (vertex);
117- }
118-
119- CSmoothNormalGenerator::VertexHashMap::BucketBounds CSmoothNormalGenerator::VertexHashMap::getBucketBoundsByHash (uint32_t hash)
120- {
121- if (hash == invalidHash)
122- return { m_vertices.end (), m_vertices.end () };
123-
124- const auto skipListBound = std::visit ([&](auto & sorter)
125- {
126- auto hashBound = sorter.getHashBound (hash);
127- return std::pair<collection_t ::iterator, collection_t ::iterator>(m_vertices.begin () + hashBound.first , m_vertices.begin () + hashBound.second );
128- }, m_sorter);
129-
130- auto begin = std::lower_bound (skipListBound.first , skipListBound.second , hash);
131- auto end = std::upper_bound (skipListBound.first , skipListBound.second , hash);
132-
133- // bucket missing
134- if (begin == m_vertices.end ())
135- return { m_vertices.end (), m_vertices.end () };
136-
137- // bucket missing
138- if (begin->hash != hash)
139- return { m_vertices.end (), m_vertices.end () };
140-
141- return { begin, end };
142- }
143-
144- void CSmoothNormalGenerator::VertexHashMap::validate ()
145- {
146- const auto oldSize = m_vertices.size ();
147- m_vertices.resize (oldSize*2u );
148- // TODO: maybe use counting sort (or big radix) and use the histogram directly for the m_buckets
149- auto finalSortedOutput = std::visit ( [&](auto & sorter) { return sorter (m_vertices.data (), m_vertices.data () + oldSize, oldSize, KeyAccessor ()); },m_sorter );
150- // TODO: optimize out the erase
151- if (finalSortedOutput != m_vertices.data ())
152- m_vertices.erase (m_vertices.begin (), m_vertices.begin () + oldSize);
153- else
154- m_vertices.resize (oldSize);
155-
156- // TODO: are `m_buckets` even begin USED!?
157- uint16_t prevHash = m_vertices[0 ].hash ;
158- core::vector<CPolygonGeometryManipulator::SSNGVertexData>::iterator prevBegin = m_vertices.begin ();
159- }
16087
16188CSmoothNormalGenerator::VertexHashMap CSmoothNormalGenerator::setupData (const asset::ICPUPolygonGeometry* polygon, float epsilon)
16289{
@@ -243,56 +170,6 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CSmoothNormalGenerator::processConne
243170 return outPolygon;
244171}
245172
246- uint8_t CSmoothNormalGenerator::VertexHashMap::getNeighboringCellHashes (uint32_t * outNeighbours, const CPolygonGeometryManipulator::SSNGVertexData& vertex)
247- {
248- hlsl::float32_t3 cellFloatCoord = floor (vertex.position / m_cellSize - hlsl::float32_t3 (0 .5f ));
249- hlsl::uint32_t3 neighbor = hlsl::uint32_t3 (static_cast <uint32_t >(cellFloatCoord.x ), static_cast <uint32_t >(cellFloatCoord.y ), static_cast <uint32_t >(cellFloatCoord.z ));
250-
251- uint8_t neighbourCount = 0 ;
252-
253- // left bottom near
254- outNeighbours[neighbourCount] = hash (neighbor);
255- neighbourCount++;
256-
257- auto addUniqueNeighbour = [&neighbourCount, outNeighbours](uint32_t hashVal)
258- {
259- if (std::find (outNeighbours, outNeighbours + neighbourCount, hashVal) != outNeighbours + neighbourCount)
260- {
261- outNeighbours[neighbourCount] = hashVal;
262- neighbourCount++;
263- }
264- };
265-
266- // right bottom near
267- neighbor = neighbor + hlsl::uint32_t3 (1 , 0 , 0 );
268- addUniqueNeighbour (hash (neighbor));
269-
270- // right bottom far
271- neighbor = neighbor + hlsl::uint32_t3 (0 , 0 , 1 );
272- addUniqueNeighbour (hash (neighbor));
273-
274- // left bottom far
275- neighbor = neighbor - hlsl::uint32_t3 (1 , 0 , 0 );
276- addUniqueNeighbour (hash (neighbor));
277-
278- // left top far
279- neighbor = neighbor + hlsl::uint32_t3 (0 , 1 , 0 );
280- addUniqueNeighbour (hash (neighbor));
281-
282- // right top far
283- neighbor = neighbor + hlsl::uint32_t3 (1 , 0 , 0 );
284- addUniqueNeighbour (hash (neighbor));
285-
286- // righ top near
287- neighbor = neighbor - hlsl::uint32_t3 (0 , 0 , 1 );
288- addUniqueNeighbour (hash (neighbor));
289-
290- // left top near
291- neighbor = neighbor - hlsl::uint32_t3 (1 , 0 , 0 );
292- addUniqueNeighbour (hash (neighbor));
293-
294- return neighbourCount;
295- }
296173
297174core::smart_refctd_ptr<ICPUPolygonGeometry> CSmoothNormalGenerator::weldVertices (const ICPUPolygonGeometry* polygon, VertexHashMap& vertices, float epsilon)
298175{
0 commit comments