BVB Source Codes

CRYENGINE Show IndexedMesh.cpp Source code

Return Download CRYENGINE: download IndexedMesh.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   IndexedMesh.cpp
  5. //  Created:     28/5/2001 by Vladimir Kajalin
  6. ////////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "StdAfx.h"
  9.  
  10. #include "IndexedMesh.h"
  11. #include "MeshCompiler/MeshCompiler.h"
  12.  
  13. DEFINE_INTRUSIVE_LINKED_LIST(CIndexedMesh)
  14.  
  15. CIndexedMesh::CIndexedMesh()
  16. {
  17. }
  18.  
  19. CIndexedMesh::~CIndexedMesh()
  20. {
  21. }
  22.  
  23. void CIndexedMesh::GetMemoryUsage(ICrySizer* pSizer) const
  24. {
  25.         pSizer->AddObject(this, sizeof(*this));
  26.         CMesh::GetMemoryUsage(pSizer);
  27. }
  28.  
  29. void CIndexedMesh::RestoreFacesFromIndices()
  30. {
  31.         const int indexCount = GetIndexCount();
  32.         SetFaceCount(indexCount / 3);
  33.         memset(m_pFaces, 0, GetFaceCount() * sizeof(m_pFaces[0]));
  34.  
  35.         int nFaceId = 0;
  36.         for (int i = 0; i < indexCount; i += 3)
  37.         {
  38.                 if (m_pIndices[i] != (vtx_idx) - 1)  // deleted faces have -1 here
  39.                 {
  40.                         for (int v = 0; v < 3; ++v)
  41.                         {
  42.                                 assert((int)m_pIndices[i + v] < GetVertexCount());
  43.                                 m_pFaces[nFaceId].v[v] = m_pIndices[i + v];
  44.                         }
  45.                         ++nFaceId;
  46.                 }
  47.         }
  48.  
  49.         SetFaceCount(nFaceId);
  50. }
  51.  
  52. #if CRY_PLATFORM_WINDOWS
  53. void CIndexedMesh::Optimize(const char* szComment) PREFAST_SUPPRESS_WARNING(6262) //function uses > 32k stack space
  54. {
  55.         mesh_compiler::CMeshCompiler meshCompiler;
  56.  
  57.         if (szComment)
  58.         {
  59.                 // mesh_compiler::MESH_COMPILE_OPTIMIZE is a bit expensive so we show a warning if it's used at run time
  60.                 Warning("CIndexedMesh::Optimize is called at run time by %s", szComment);
  61.         }
  62.  
  63.         if (!meshCompiler.Compile(*this, (mesh_compiler::MESH_COMPILE_TANGENTS | mesh_compiler::MESH_COMPILE_OPTIMIZE)))
  64.         {
  65.                 Warning("CIndexedMesh::Optimize failed: %s", meshCompiler.GetLastError());
  66.         }
  67. }
  68. #endif
  69.  
  70. void CIndexedMesh::CalcBBox()
  71. {
  72.         const int vertexCount = GetVertexCount();
  73.  
  74.         if (vertexCount == 0 || !m_pPositions)
  75.         {
  76.                 m_bbox = AABB(Vec3(0, 0, 0), Vec3(0, 0, 0));
  77.                 return;
  78.         }
  79.  
  80.         assert(m_pPositionsF16 == 0);
  81.  
  82.         m_bbox.Reset();
  83.  
  84.         const int faceCount = GetFaceCount();
  85.  
  86.         if (faceCount > 0)
  87.         {
  88.                 for (int i = 0; i < faceCount; ++i)
  89.                 {
  90.                         for (int v = 0; v < 3; ++v)
  91.                         {
  92.                                 const int nIndex = m_pFaces[i].v[v];
  93.                                 assert(nIndex >= 0 && nIndex < vertexCount);
  94.                                 m_bbox.Add(m_pPositions[nIndex]);
  95.                         }
  96.                 }
  97.         }
  98.         else
  99.         {
  100.                 const int indexCount = GetIndexCount();
  101.  
  102.                 for (int i = 0; i < indexCount; ++i)
  103.                 {
  104.                         m_bbox.Add(m_pPositions[m_pIndices[i]]);
  105.                 }
  106.         }
  107. }
  108.  
downloadIndexedMesh.cpp 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