Sign in to follow this  

reading in obj to dx Mesh

This topic is 3459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im planning on creating class to read in objs and then create some sort of mesh object to store them in. Ive been looking through the Dx documentation and have come up with a few interfaces, the first being
HRESULT D3DXCreateMesh(
  DWORD NumFaces,
  DWORD NumVertices,
  DWORD Options,
  CONST LPD3DVERTEXELEMENT9 * pDeclaration,
  LPDIRECT3DDEVICE9 pD3DDevice,
  LPD3DXMESH * ppMesh
);

My only issue with this, is that i wont be able to create subsets, say if one mesh has different material properties for different parts i then saw
HRESULT CreateVertexBuffer(
  UINT Length,
  DWORD Usage,
  DWORD FVF,
  D3DPOOL Pool,
  IDirect3DVertexBuffer9** ppVertexBuffer,
  HANDLE* pSharedHandle
);

HRESULT CreateIndexBuffer(
  UINT Length,
  DWORD Usage,
  D3DFORMAT Format,
  D3DPOOL Pool,
  IDirect3DIndexBuffer9** ppIndexBuffer,
  HANDLE* pSharedHandle
);

But i still see no way of setting up subsets, from the it id3dsbasemesh interface it says The subset that is specified by AttribId will be rendered by the IDirect3DDevice9::DrawIndexedPrimitive method, using the D3DPT_TRIANGLELIST primitive type, so an index buffer must be properly initialized.
An attribute table is used to identify areas of the mesh that need to be drawn with different textures, render states, materials, and so on. In addition, the application can use the attribute table to hide portions of a mesh by not drawing a given attribute identifier (AttribId) when drawing the frame.
so does this mean, that if i want to create subsets and render them, i have ro do somthing like.
//render cubes
create a single vertex/index buffers storing a single mesh of 2 cubes
distinguish start and end index value of each cube

set cube1 material and texture
HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, cube1size, cube1IndexStart, cube1faceCount));


set cube2 material and texture
HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, cube2size, cube2IndexStart, cube2faceCount));


but obviously with nicer code, that works with vectors or somthing

Share this post


Link to post
Share on other sites
You can use D3DXCreateMesh to load all the vertices, normals, etc., for your object. You have to keep track of which faces have which materials and textures.

Get the mesh's attribute table and fill it with an attribute number for each face corresponding to which material/texture set you want to use for that face. Load the attribute table back into the mesh.

For efficency, you'll want to optimize the mesh. You can use OptimizeInPlace with the D3DXMESHOPT_ATTRSORT option and probably D3DXMESHOPT_VERTEXCACHE. Be sure to generate and use the adjacency table with OptimizeInPlace.

To render:

for(int i=0; i<numAttribues; i++)
{
device->SetMaterial(yourMatTable[i].MatD3D);
device->SetTexture(yourMatTable[i].texture); // or whereever you store the texture pointer for material group i
mesh->DrawSubset(i);
}

That's pretty much it.


Share this post


Link to post
Share on other sites

This topic is 3459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this