Jump to content
  • Advertisement


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


from TriFans to Indexed TriLists...

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


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

     //every node stores a single mesh

     //and its attributes



     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, 
			   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

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!