Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post Posted: December 8th, 2017, 11:11 pm 
 

Joined: December 7th, 2017, 2:27 pm
Posts: 1
okey , i finaly managed to create some directx11 framework like thing . ( actually it is dirty compilation of tutorials vs vs )( especially chili framework helped a lot thnks bro )

anyway i figure out to export human readable mesh data from blender (dae , obj )
and the problem occurs in here:

after i read vertex , normal , tex coordinates
i simply make an unindexed array of meshes like this

example code:

struct MeshData
{
XMFLOAT3 Pos;
XMFLOAT3 Norm;
XMFLOAT2 Tex;
};


//*****
// read data from file
//*****


std::vector<MeshData > vertexDat;

for(int i = 0 ; i < indexSize ; i++)
{
MeshData tmp;
tmp.Pos = posArray[pos_indices[i]]; // pos x , y , z
tmp.Norm = normalArray[norm_indices[i]]; // norm x , y , z
tmp.Tex = textureArray[tex_indices[i]]; // texx w ,s

vertexDat.emplace_back(tmp); // stored per vertex data
}

this dang thing actually works but it doesn't makes sense because that makes my all draw calls unindexed so is there a problem ? Or what should i do ?

in some sphere models i compared all generated vertex data to each other and only 30 - 40
vertex data is same in 3k vertex count...

im lost help :? and sorry for shit tier eng :mrgreen:


Top 
 Profile  
Reply with quote  
 Post Posted: December 9th, 2017, 3:13 am 
 

Joined: November 30th, 2013, 7:40 pm
Posts: 656
Location: Merville, British Columbia Canada
Are you creating both index and vertex buffers ? If i understand your problem you need indexes for your vertexDat ?.
Code:
// create container to hold indices
std::vector<int> indices;// for index buffer
for(int i = 0 ; i < indexSize ; i++)
{
MeshData tmp;
tmp.Pos = posArray[pos_indices[i]]; // pos x , y , z
tmp.Norm = normalArray[norm_indices[i]]; // norm x , y , z
tmp.Tex = textureArray[tex_indices[i]]; // texx w ,s

vertexDat.emplace_back(tmp); // stored per vertex data
indices.push_back(i);
}

Create an ID3D11Buffer VBuffer with vertexData;
Create an ID3D11Buffer IBuffer with indices;
on your render function you'd use something like this
Code:
HRESULT TerrainShader::Render(ID3D11DeviceContext * context, ID3D11Buffer * VBuffer, ID3D11Buffer * IBuffer, const UINT vertStructInBytes, const int indexCount, const std::vector<ID3D11ShaderResourceView*> textures)
{
UINT offset = 0;
   context->IASetVertexBuffers(0, 1, &VBuffer, &vertStructInBytes, &offset);
   context->IASetIndexBuffer(IBuffer, DXGI_FORMAT_R32_UINT, 0);
   context->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
   context->PSSetConstantBuffers(0, 1, &ShaderFactory::ConstFogLightBuffers[ShaderFactory::CB_light]);
   for (int i = 0; i<textures.size(); i++)
      context->PSSetShaderResources(i, 1, &textures[i]);

   int bufferNumber = 0;
//ShaderFactory::ConstMatrixBuffers holds view,projection and object matricies
   context->VSSetConstantBuffers(bufferNumber, 3, ShaderFactory::ConstMatrixBuffers);

   bufferNumber = 3;
   context->VSSetConstantBuffers(bufferNumber, 1, &ShaderFactory::ConstFogLightBuffers[ShaderFactory::CB_fog]);
   context->IASetInputLayout(m_inputLayout);
   context->VSSetShader(m_vertexShader, NULL, 0);
   context->PSSetShader(m_pixelShader, NULL, 0);
   context->PSSetSamplers(0, 1, &m_sampler);
   context->DrawIndexed(indexCount, 0, 0);
   return S_OK;
}

_________________
Curiosity killed the cat, satisfaction brought him back


Top 
 Profile  
Reply with quote  
 Post Posted: December 9th, 2017, 6:49 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2970
Location: Oklahoma, United States
Yeah, as MrGodin shows, once you have all your vertex data matched up with each other in order, you'd just use the index of the for loop to create your index buffer. The reason this method works is you are creating a triangle and giving it three consecutive indices.

The mismatch in say on disk and in memory vertex counts is usually the fact that shared vertices on disk are referenced in the faces (objfile -f ) as the same index. So for instance 6 adjacent triangles can share the same vertex so there might be 1/6th as many in the obj file as is when loaded into memory. A cube has 8 vertices, 24 normals and 14 texcoords if mapped and the edges of the cube are hard edges. When you get load the triangles that make up that cube, you get 36 position, 36 normals, and 36 texcoords, in other words, 36 individual vertices.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 3 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron