Eric van Feggelen

Hello guys,

I've loaded a mesh from an .x file, and I want the coordinates of some of the vertices. The object is a big bowl, and I need the selection of vertices around the edge of the bowl, that way I can render something such as water in the object.

How do you suggest I'd do something like this


Re: XNA Framework Reading vertex data from assets



These will of course be the untransformed coordinates.

Re: XNA Framework Reading vertex data from assets

Eric van Feggelen


I kinda figured that out, and the untransformed coordinates are exactly what I need. I can simply transform them in the same way I would do to the mesh. But how will I know which vertex is where What to I need to do to find that out Which util should I use to investigate the .X file

That was the question i meant!

Re: XNA Framework Reading vertex data from assets

Inaki Ayucar

Do you mean how to know which polygon a vertex belongs

Meshes are normally divided into parts, usually for using different materials. Each part has a bunch of polygons in it, and each polygon has its vertices.

You need to access the Index Buffer in addition to the vertex buffer, which will tell you what vertices are forming each polygon. It has 3 vertex indices for each triangle, so the index buffer has NumTriangles * 3 entries. For example (IB = IndexBuffer)

IB[0] = index of vertex 0 of triangle 0

IB[1] = index of vertex 1 of triangle 0

IB[2] = index of vertex 2 of triangle 0

IB[3] = index of vertex 0 of triangle 1

IB[4] = index of vertex 1 of triangle 1

IB[5] = index of vertex 2 of triangle 1

and so on...

You can check some tutorials about handling all the geometry info of a model here:

Im completing a Custom Content Processor that stores all the info you need about your models. Ií»ll post it later today.

Hope this helps.

Re: XNA Framework Reading vertex data from assets


Well you could tag the polygons associated with those vertices as a separate material when you create the model in your 3D modeling software, and then when you export it as an X-file this should cause those polygons to have their own unique Attribute Group ID within the X-file, which will cause those polygons to become a separate ModelMeshPart within the Model.Meshes[].MeshParts[] collection. You can then use the ModelMeshPart.StartIndex property to find the starting index within the Model.Meshes[].IndexBuffer for the vertices associated with that ModelMeshPart. You then can use the indices from the index buffer to read the appropriate vertices from the vertex buffer. After that, you'll probably need to write a little method in your game to have the GPU draw each of the vertices one by one as points as described here:

As it draws each point one by one, pausing between each one, you can have it tell you the index or coordinates of the associated point, and you can write down the relevant information when the points you are interested in are drawn. It's a bit of a laborious manual process, but you only have to do it once.

However actually it may be simpler to get the coordinates of the vertices using the 3D modeling software you used to create the model with and just write them down from there.

Re: XNA Framework Reading vertex data from assets

Eric van Feggelen


Thanks for the responses, i think the quickest solution to finding the right vertices would be to render them as a PointList. I'm going to trace the vertices in the vertexbuffer by clicking on the points in the app, and stepping into debugmode to find the same vertex data to know where they are located.

If i'd want to do something like this very often, is there a 3d format that allows me to label vertices so I can find them at runtime in Direct3d

Re: XNA Framework Reading vertex data from assets


It's not an issue of format, as the X-file format supports custom templates where you could store the data. However you'd have to create your own model content processor to read this custom data. There is no industry standard method for storing this sort of information as far as I know. It would probably be easier to make use of the scripting capabilities that most 3D modeling packages have and write a script to create a metadata file that contains the information about a given model that you are interested in, and then create an importer in your game to read in the information from this file.

Re: XNA Framework Reading vertex data from assets

Shawn Hargreaves - MSFT

I would rethink your problem and do this a different way.

Build your bowl as one mesh, and then in the same file, create a second mesh that represents the the skin on the surface, where you want to draw your water.

That way you can just render the bowl mesh as one thing, and examine or render the other mesh to obtain whatever data or effects you need. Don't mess around trying to extract only a subset of vertices from a single big mesh, just split things up however you need them while you are building the artwork.