BVB Source Codes

CRYENGINE Show ForsythFaceReorderer.h Source code

Return Download CRYENGINE: download ForsythFaceReorderer.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4. #ifndef __ForsythFaceReorderer_h__
  5. #define __ForsythFaceReorderer_h__
  6.  
  7. //
  8. // Note: This implementation, in contrast to many other implementations
  9. // of the Forsyth's algorithm, does not crash when the input faces contain
  10. // duplicate indices, for example (8,3,8) or (1,1,9).
  11. //
  12. class ForsythFaceReorderer
  13. {
  14. public:
  15.         static const size_t sk_maxCacheSize = 50; // you can change it. note: making it higher will increase sizeof(*this)
  16.         static const size_t sk_minVerticesPerFace = 3;
  17.         static const size_t sk_maxVerticesPerFace = 4;
  18.  
  19.         static_assert(sk_minVerticesPerFace >= 3, "Bad min # of vertices per face");
  20.         static_assert(sk_minVerticesPerFace <= sk_maxVerticesPerFace, "Bad # of vertices per face");
  21.         static_assert(sk_maxVerticesPerFace <= sk_maxCacheSize, "Bad max cache size");
  22.  
  23. private:
  24.         typedef uint16 valency_type;
  25.         static const valency_type sk_maxValency = 0xFFFF;
  26.  
  27.         typedef int8 cachepos_type;
  28.         static const cachepos_type sk_maxCachePos = 127;
  29.  
  30.         struct Vertex
  31.         {
  32.                 uint32*       m_pFaceList;
  33.                 valency_type  m_aliveFaceCount;
  34.                 cachepos_type m_posInCache;
  35.                 float         m_score;
  36.         };
  37.  
  38.         static const size_t sk_valencyTableSize = 32;                  // note: size_t is used instead of valency_type because valency_type overflows if sk_valencyTableSize == 1 + sk_maxValency
  39.         static_assert(sk_valencyTableSize - 1 <= sk_maxValency, "Bad valency table size");
  40.  
  41.         static_assert(sk_maxCacheSize <= 1 + (size_t)sk_maxCachePos, "Max cache size is too big");
  42.  
  43.         std::vector<Vertex> m_vertices;
  44.         std::vector<uint8>  m_deadFacesBitArray;
  45.         std::vector<float>  m_faceScores;        // score of every face
  46.         std::vector<uint32> m_vertexFaceLists;   // lists with indices of faces (each vertex has own list)
  47.  
  48.         int                 m_cacheSize;
  49.         int                 m_cacheUsedSize;
  50.         uint32              m_cache[sk_maxCacheSize + sk_maxVerticesPerFace]; // +sk_maxVerticesPerFace is temporary storage for vertices of the incoming face
  51.  
  52.         float               m_scoreTable_valency[sk_valencyTableSize];
  53.         float               m_scoreTable_cachePosition[sk_maxCacheSize];
  54.  
  55. public:
  56.         ForsythFaceReorderer();
  57.  
  58.         // notes:
  59.         // 1) it's not allowed to pass same array for inVertexIndices and outVertexIndices
  60.         // 2) outFaceToOldFace is optional (pass 0 if you don't need this array filled)
  61.         bool reorderFaces(
  62.           const size_t cacheSize,
  63.           const uint verticesPerFace,
  64.           const size_t indexCount,
  65.           const uint32* const inVertexIndices,
  66.           uint32* const outVertexIndices,
  67.           uint32* const outFaceToOldFace);
  68.  
  69. private:
  70.         void   clear();
  71.         void   computeCacheScoreTable(const int verticesPerFace);
  72.         void   computeValencyScoreTable();
  73.         void   computeVertexScore(Vertex& v);
  74.         void   moveVertexToCacheTop(const uint32 vertexIndex);
  75.         void   removeFaceFromVertex(const uint32 vertexIndex, const uint32 faceIndex);
  76.         uint32 findBestFaceToAdd(uint32& faceSearchCursor) const;
  77. };
  78.  
  79. #endif
  80.  
downloadForsythFaceReorderer.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top