Confusion about model's vertexbuffer and indexbuffer

倖福魔咒の 提交于 2019-12-13 03:44:56

问题


I have a model file containing multiple meshes (ie: a tree, a car, ...) that is used as a static background for our game. My goal is to store the model's vertices and indices as two buffers and assign these buffers to the GPU. However, I'm a bit confused on the way to go.

This Riemer's XNA Tutorial states that the model itself has a one big vertexbuffer and one big indexbuffer containing informations of all its meshes (and meshparts), but it doesn't seem possible to access these buffers. However, it is possible to access the ModelMeshParts' buffers, but I can't concatenate all of them into a single buffer.

My guess would be to extend the model processor to store the model vertices and indices in arrays at runtime. Is there an easier way to do so, since Riemer says that those buffers are already defined? I'm confused about that statement.

Thank you for answering.


回答1:


Actually, there is only 1 vertex buffer and 1 index buffer for the entire model. The Vertex buffer that is exposed in any ModelMeshPart is the entire model's vertex buffer and it is the same buffer that is exposed in any other MMPs. No need to concatenate them, the entire buffer is in each MMP.

Each MMP has its own start index of that buffer and each MMP has its own variable that describes the number of vertices that are consecutive from the start index that are used for that particular MMP.

So in this diagram of the model's VB, ModelMesh[1]->ModelMeshPart[1] has a start index of 300 and its number of vertices is 75. So this way, when drawing the MMP, the device knows to use only those few vertices of the entire VB.



来源:https://stackoverflow.com/questions/14512385/confusion-about-models-vertexbuffer-and-indexbuffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!