purpose of the existence and freakin collada/obj files -help

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
orchaosis
Posts: 1
Joined: December 7th, 2017, 2:27 pm

purpose of the existence and freakin collada/obj files -help

Post by orchaosis » December 8th, 2017, 11:11 pm

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]; // pos x , y , z
tmp.Norm = normalArray[norm_indices]; // norm x , y , z
tmp.Tex = textureArray[tex_indices]; // 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:

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: purpose of the existence and freakin collada/obj files -

Post by MrGodin » December 9th, 2017, 3:13 am

Are you creating both index and vertex buffers ? If i understand your problem you need indexes for your vertexDat ?.

Code: Select all

// 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: Select all

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

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: purpose of the existence and freakin collada/obj files -

Post by albinopapa » December 9th, 2017, 6:49 am

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

Post Reply