99
1010#include " nbl/asset/ICPUPolygonGeometry.h"
1111#include " nbl/asset/utils/CGeometryManipulator.h"
12+ #include " nbl/asset/utils/CSmoothNormalGenerator.h"
1213
1314namespace nbl ::asset
1415{
@@ -17,17 +18,6 @@ namespace nbl::asset
1718class NBL_API2 CPolygonGeometryManipulator
1819{
1920 public:
20- // vertex data needed for CSmoothNormalGenerator
21- struct SSNGVertexData
22- {
23- uint32_t index; // offset of the vertex into index buffer
24- uint32_t hash; //
25- float wage; // angle wage of the vertex
26- hlsl::float32_t3 position; // position of the vertex in 3D space
27- hlsl::float32_t3 parentTriangleFaceNormal; //
28- };
29-
30- using VxCmpFunction = std::function<bool (const SSNGVertexData&, const SSNGVertexData&, const ICPUPolygonGeometry*)>;
3121
3222 static inline void recomputeContentHashes (ICPUPolygonGeometry* geo)
3323 {
@@ -243,11 +233,14 @@ class NBL_API2 CPolygonGeometryManipulator
243233
244234 static core::smart_refctd_ptr<ICPUPolygonGeometry> createUnweldedList (const ICPUPolygonGeometry* inGeo);
245235
236+ using SSNGVertexData = CSmoothNormalGenerator::VertexData;
237+ using SSNGVxCmpFunction = CSmoothNormalGenerator::VxCmpFunction;
238+
246239 static core::smart_refctd_ptr<ICPUPolygonGeometry> createSmoothVertexNormal (const ICPUPolygonGeometry* inbuffer, bool enableWelding = false , float epsilon = 1 .525e-5f ,
247- VxCmpFunction vxcmp = [](const CPolygonGeometryManipulator:: SSNGVertexData& v0, const CPolygonGeometryManipulator:: SSNGVertexData& v1, const ICPUPolygonGeometry* buffer)
240+ SSNGVxCmpFunction vxcmp = [](const SSNGVertexData& v0, const SSNGVertexData& v1, const ICPUPolygonGeometry* buffer)
248241 {
249- static constexpr float cosOf45Deg = 0 .70710678118f ;
250- return dot (v0.parentTriangleFaceNormal , v1.parentTriangleFaceNormal ) > cosOf45Deg;
242+ constexpr float cosOf45Deg = 0 .70710678118f ;
243+ return dot (normalize ( v0.weightedNormal ), normalize ( v1.weightedNormal ) ) > cosOf45Deg;
251244 });
252245
253246#if 0 // TODO: REDO
@@ -277,14 +270,14 @@ class NBL_API2 CPolygonGeometryManipulator
277270 };
278271 typedef std::function<bool(const IMeshManipulator::SSNGVertexData&, const IMeshManipulator::SSNGVertexData&, ICPUMeshBuffer*)> VxCmpFunction;
279272
280- //! Compares two attributes of floating point types in accordance with passed error metric.
281- /**
282- @param _a First attribute.
283- @param _b Second attribute.
284- @param _cpa Component count.
285- @param _errMetric Error metric info.
286- */
287- static inline bool compareFloatingPointAttribute(const core::vectorSIMDf& _a, const core::vectorSIMDf& _b, size_t _cpa, const SErrorMetric& _errMetric)
273+ //! Compares two attributes of floating point types in accordance with passed error metric.
274+ /**
275+ @param _a First attribute.
276+ @param _b Second attribute.
277+ @param _cpa Component count.
278+ @param _errMetric Error metric info.
279+ */
280+ static inline bool compareFloatingPointAttribute(const core::vectorSIMDf& _a, const core::vectorSIMDf& _b, size_t _cpa, const SErrorMetric& _errMetric)
288281 {
289282 using ErrorF_t = core::vectorSIMDf(*)(core::vectorSIMDf, core::vectorSIMDf);
290283
@@ -365,41 +358,41 @@ class NBL_API2 CPolygonGeometryManipulator
365358 }
366359
367360
368- //! Swaps the index buffer for a new index buffer with invalid triangles removed.
369- /**
370- Invalid triangle is such consisting of two or more same indices.
371- @param _input Input index buffer.
372- @param _idxType Type of indices in the index buffer.
373- @returns New index buffer or nullptr if input indices were of unknown type or _input was nullptr.
374- */
375- static void filterInvalidTriangles(ICPUMeshBuffer* _input);
376-
377- //! Creates index buffer from input converting it to indices for line list primitives. Input is assumed to be indices for line strip.
378- /**
379- @param _input Input index buffer's data.
380- @param _idxCount Index count.
381- @param _inIndexType Type of input index buffer data (32bit or 16bit).
382- @param _outIndexType Type of output index buffer data (32bit or 16bit).
383- */
384- static core::smart_refctd_ptr<ICPUBuffer> idxBufferFromLineStripsToLines(const void* _input, uint32_t& _idxCount, E_INDEX_TYPE _inIndexType, E_INDEX_TYPE _outIndexType);
385-
386- //! Creates index buffer from input converting it to indices for triangle list primitives. Input is assumed to be indices for triangle strip.
387- /**
388- @param _input Input index buffer's data.
389- @param _idxCount Index count.
390- @param _inIndexType Type of input index buffer data (32bit or 16bit).
391- @param _outIndexType Type of output index buffer data (32bit or 16bit).
392- */
393- static core::smart_refctd_ptr<ICPUBuffer> idxBufferFromTriangleStripsToTriangles(const void* _input, uint32_t& _idxCount, E_INDEX_TYPE _inIndexType, E_INDEX_TYPE _outIndexType);
394-
395- //! Creates index buffer from input converting it to indices for triangle list primitives. Input is assumed to be indices for triangle fan.
396- /**
397- @param _input Input index buffer's data.
398- @param _idxCount Index count.
399- @param _inIndexType Type of input index buffer data (32bit or 16bit).
400- @param _outIndexType Type of output index buffer data (32bit or 16bit).
401- */
402- static core::smart_refctd_ptr<ICPUBuffer> idxBufferFromTrianglesFanToTriangles(const void* _input, uint32_t& _idxCount, E_INDEX_TYPE _inIndexType, E_INDEX_TYPE _outIndexType);
361+ //! Swaps the index buffer for a new index buffer with invalid triangles removed.
362+ /**
363+ Invalid triangle is such consisting of two or more same indices.
364+ @param _input Input index buffer.
365+ @param _idxType Type of indices in the index buffer.
366+ @returns New index buffer or nullptr if input indices were of unknown type or _input was nullptr.
367+ */
368+ static void filterInvalidTriangles(ICPUMeshBuffer* _input);
369+
370+ //! Creates index buffer from input converting it to indices for line list primitives. Input is assumed to be indices for line strip.
371+ /**
372+ @param _input Input index buffer's data.
373+ @param _idxCount Index count.
374+ @param _inIndexType Type of input index buffer data (32bit or 16bit).
375+ @param _outIndexType Type of output index buffer data (32bit or 16bit).
376+ */
377+ static core::smart_refctd_ptr<ICPUBuffer> idxBufferFromLineStripsToLines(const void* _input, uint32_t& _idxCount, E_INDEX_TYPE _inIndexType, E_INDEX_TYPE _outIndexType);
378+
379+ //! Creates index buffer from input converting it to indices for triangle list primitives. Input is assumed to be indices for triangle strip.
380+ /**
381+ @param _input Input index buffer's data.
382+ @param _idxCount Index count.
383+ @param _inIndexType Type of input index buffer data (32bit or 16bit).
384+ @param _outIndexType Type of output index buffer data (32bit or 16bit).
385+ */
386+ static core::smart_refctd_ptr<ICPUBuffer> idxBufferFromTriangleStripsToTriangles(const void* _input, uint32_t& _idxCount, E_INDEX_TYPE _inIndexType, E_INDEX_TYPE _outIndexType);
387+
388+ //! Creates index buffer from input converting it to indices for triangle list primitives. Input is assumed to be indices for triangle fan.
389+ /**
390+ @param _input Input index buffer's data.
391+ @param _idxCount Index count.
392+ @param _inIndexType Type of input index buffer data (32bit or 16bit).
393+ @param _outIndexType Type of output index buffer data (32bit or 16bit).
394+ */
395+ static core::smart_refctd_ptr<ICPUBuffer> idxBufferFromTrianglesFanToTriangles(const void* _input, uint32_t& _idxCount, E_INDEX_TYPE _inIndexType, E_INDEX_TYPE _outIndexType);
403396
404397 //!
405398 static inline std::array<uint32_t,3u> getTriangleIndices(const ICPUMeshBuffer* mb, uint32_t triangleIx)
@@ -635,7 +628,7 @@ class NBL_API2 CPolygonGeometryManipulator
635628
636629 //! Creates a copy of a mesh with vertices welded
637630 /** \param mesh Input mesh
638- \param errMetrics Array of size EVAI_COUNT. Describes error metric for each vertex attribute (used if attribute is of floating point or normalized type).
631+ \param errMetrics Array of size EVAI_COUNT. Describes error metric for each vertex attribute (used if attribute is of floating point or normalized type).
639632 \param tolerance The threshold for vertex comparisons.
640633 \return Mesh without redundant vertices. */
641634 static core::smart_refctd_ptr<ICPUMeshBuffer> createMeshBufferWelded(ICPUMeshBuffer *inbuffer, const SErrorMetric* errMetrics, const bool& optimIndexType = true, const bool& makeNewMesh = false);
@@ -653,12 +646,12 @@ class NBL_API2 CPolygonGeometryManipulator
653646 */
654647 static void requantizeMeshBuffer(ICPUMeshBuffer* _meshbuffer, const SErrorMetric* _errMetric);
655648
656- //! Creates a 32bit index buffer for a mesh with primitive types changed to list types
657- /**#
649+ //! Creates a 32bit index buffer for a mesh with primitive types changed to list types
650+ /**#
658651 @param _newPrimitiveType
659- @param _begin non-const iterator to beginning of meshbuffer range
660- @param _end non-const iterator to ending of meshbuffer range
661- */
652+ @param _begin non-const iterator to beginning of meshbuffer range
653+ @param _end non-const iterator to ending of meshbuffer range
654+ */
662655 template<typename Iterator>
663656 static inline void homogenizePrimitiveTypeAndIndices(Iterator _begin, Iterator _end, const E_PRIMITIVE_TOPOLOGY _newPrimitiveType, const E_INDEX_TYPE outIndexType = EIT_32BIT)
664657 {
0 commit comments