Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

edwinnie

from TriFans to Indexed TriLists...

This topic is 5482 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

ok! i am trying to upgrade my vertex buffer of trifans to an index buffer of indexed tri-lists. the situation is this: 1) i have a mesh that has a number of surfaces. 2) each surface may not have the same number of vertices. 3) each surface''s vertices are arranged in tri-fans initially. 4) some surfaces have indices and so the vertices in these surfaces are arranged in tri-lists. now to arrange everything into one vertex buffer and index buffer:
//---------------------------------------------------

//for each mesh, it has an array of Surfaces pointers

//---------------------------------------------------

DWORD totalVertexCount = 0;
for(int i=0; i<SurfaceCount; i++)
{
     int surfaceVertexCount = Surfaces[i]->VertexCount;

     //------------------------

     //build subset information

     //------------------------

     D3DXATTRIBUTERANGE attr;
     attr.AttribId    = i;
     attr.VertexStart = totalVertexCount;
     attr.VertexCount = surfaceVertexCount;
     attr.FaceStart   = i;
     attr.FaceCount   = 1;
	
     //-------------------------------

     //every node stores a single mesh

     //and its attributes

     //-------------------------------

     node->subsets.push_back(attr);

     totalVertexCount += surfaceVertexCount;
}
hopefully this makes some sense so far... next, i created an empty vertex buffer and did all the memcpy...etc now to create the index buffer:
//----------------------

//some working variables

//----------------------

int totalIndexCount = (totalVertexCount - 2) * 3;
int num_bytes = totalIndexCount * sizeof(USHORT);

//-------------------------------------

//create the index buffer for this node

//-------------------------------------

device->CreateIndexBuffer( num_bytes, 
		           0, 
			   D3DFMT_INDEX16, 
		           D3DPOOL_MANAGED, 
			   &node->indices, 
			   NULL );

//--------------------------------

//lock indexbuffer

//the portion below is not correct

//--------------------------------

USHORT* indices = NULL;
USHORT* p = indices;
hr = node->indices->Lock(0, 0, (void**)&indices, 0);
		

//-----------------------

//for all mesh''s surfaces

//-----------------------

for(int k=0;  k<SurfaceCount;  k++)
{
      //--------------------------------------------

      //for each triangle(each vertex has 3 indices)

      //012, 123, 234, ...

      //--------------------------------------------

      for(int j=0; j<cmesh->Surfaces[k]->VertexCount; j++)
      {
	   *p++ = node->subsets[k].VertexStart + j;
	   *p++ = node->subsets[k].VertexStart + j + 1;
	   *p++ = node->subsets[k].VertexStart + j + 2;
      }
}
hr = node->indices->Unlock();
well... thats so far i have for the conversion, it seems that i might be missing something here, i do know that each surface may have indices as well, and thats one more area i am particularly confused of how to handle it. but before that, i am pretty sure that the above codes have some errors(coz i kept crashing), so i am wondering if anyone out there who has done the same thing and would like to share how you did it. thx alot fer reading! edwinz

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!