SHARE
TWEET

Untitled

a guest Jan 16th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //m_LOD == 10 in the beginning
  2.      //m_RawVerts - array of 3d Vector filled with values from vertex buffer.
  3.  
  4.      void DecreaseLOD()
  5.      {
  6.          m_LOD--;
  7.          if(m_LOD<1)m_LOD=1;
  8.          RebuildGeometry();
  9.      }
  10.  
  11.      void IncreaseLOD()
  12.      {
  13.          m_LOD++;
  14.          if(m_LOD>10)m_LOD=10;
  15.          RebuildGeometry();
  16.      }
  17.  
  18.      void RebuildGeometry()
  19.      {    
  20.          void* vertexRawData = new byte[m_VertexBufferSize];        
  21.          void* indexRawData = new DWORD[m_IndexCount];
  22.          auto context = mp_D3D->mp_Context;    
  23.  
  24.          D3D11_MAPPED_SUBRESOURCE data;
  25.          ZeroMemory(&data,sizeof(D3D11_MAPPED_SUBRESOURCE));
  26.  
  27.          context->Map(mp_VertexBuffer->mp_buffer,0,D3D11_MAP_READ,0,&data);
  28.          memcpy(vertexRawData,data.pData,m_VertexBufferSize);
  29.          context->Unmap(mp_VertexBuffer->mp_buffer,0);            
  30.  
  31.          context->Map(mp_IndexBuffer->mp_buffer,0,D3D11_MAP_READ,0,&data);
  32.          memcpy(indexRawData,data.pData,m_IndexBufferSize);
  33.          context->Unmap(mp_IndexBuffer->mp_buffer,0);
  34.  
  35.          DWORD* dwI = (DWORD*)indexRawData;
  36.  
  37.          int sz = (m_VertexStride/sizeof(float));//size of vertex element
  38.  
  39.          //algorithm must be here.
  40.          std::vector<Vector3d> vertices;
  41.          int i = 0;
  42.          for(int j = 0; j < m_VertexCount; j++)
  43.          {
  44.              float x1 = (((float*)vertexRawData)[0+i]);
  45.              float y1 = (((float*)vertexRawData)[1+i]);
  46.              float z1 = (((float*)vertexRawData)[2+i]);
  47.              Vector3d lv = Vector3d(x1,y1,z1);            
  48.  
  49.              //my useless attempts
  50.              if(j+m_LOD+1<m_RawVerts.size())
  51.              {
  52.                  float v1 = VECTORHELPER::Distance(m_RawVerts[dwI[j]],m_RawVerts[dwI[j+m_LOD]]);
  53.                  float v2 = VECTORHELPER::Distance(m_RawVerts[dwI[j]],m_RawVerts[dwI[j+m_LOD+1]]);  
  54.  
  55.                  if(v1>v2)
  56.                      lv = m_RawVerts[dwI[j+1]];
  57.                  else
  58.                      if(v2<v1)
  59.                          lv = m_RawVerts[dwI[j+2]];
  60.              }    
  61.  
  62.              (((float*)vertexRawData)[0+i]) = lv.x;
  63.              (((float*)vertexRawData)[1+i]) = lv.y;
  64.              (((float*)vertexRawData)[2+i]) = lv.z;
  65.  
  66.              i+=sz;//pass others vertex format values without change    
  67.          }  
  68.  
  69.          for(int j = 0; j < m_IndexCount; j++)
  70.          {
  71.              //indices ?
  72.          }
  73.  
  74.          //set vertexes to device
  75.          UpdateVertexes(vertexRawData,mp_VertexBuffer->getSize());            
  76.  
  77.          delete[] vertexRawData;
  78.          delete[] indexRawData;
  79.      }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top