Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How to clone a mesh in DX11?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 steven166   Members   -  Reputation: 234

Like
0Likes
Like

Posted 10 October 2012 - 05:50 AM

I want to clone a mesh in DX11, then modify the vertex structure like adding some information for each vertex and render. But I have no idea how to do it in DX11? in DX9, we can use clone function but in DX11, how to do it?

Anybody helps me, please? thanks in advanced.

Sponsor:

#2 MJP   Moderators   -  Reputation: 11589

Like
2Likes
Like

Posted 10 October 2012 - 01:13 PM

I assume that when you say "DX9", you're talking about the ID3DXMesh class? I'm not sure what you're using now for managing your meshes, but cloning a mesh is pretty simple:
  • Make sure that you have the original mesh data available in CPU memory. If you already loaded it into a vertex buffer, you can copy it to a staging buffer and Map that to get a pointer to the data.
  • Allocate enough CPU memory to fit however many vertices you have, using the new vertex layout
  • For each element in the new vertex layout, check if that element exists in the old layout. If it exists, store the byte offset of the element in the old layout. If it doesn't exist, store some value indicating that it doesn't exist (for instance, you could use -1). You can store this all in an array or std::vector containing one integer per new vertex element.
  • Loop over all vertices. For each vertex, loop over your table of offsets that you built in the previous step. If the the element exists in the old layout, copy the data from the old vertex data to the new vertex data using the offset that you stored. When you're done with all elements, advance your pointers to the vertex data by the strides so that they point to the start of the next vertex
  • Create a vertex buffer with the new vertex data


#3 steven166   Members   -  Reputation: 234

Like
0Likes
Like

Posted 10 October 2012 - 08:51 PM

Thank you.

#4 steven166   Members   -  Reputation: 234

Like
0Likes
Like

Posted 11 October 2012 - 07:09 AM

I can iterate through all vertices, but how can I know which vertex belongs to the same triangle in DX11? because in DX9 we can loop over all triangles, then use the index buffer and vertex buffer to modify it such as add an incremental primitive's ID into 3l vertices which belongs to the same triangle in a mesh.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS