If at all possible, can you move your processing to build time
At build time, you can make use of Microsoft.Xna.Framework.Content.Pipeline.Graphics.VertexContent and the various channel properties and such.
One other option is to parse the VertexElement[] for the vertex structure and then treat the vertex array as a byte[] and use pointers and the offsets and size that you've parsed from the VertexElement[]. The initial parsing of the VertexElement[] takes a little effort but then you could wrap that in adaptor classes that make accessing the elements easy.
Cheers,
Leaf.
Mark Flamer wrote:
I may be overlooking something basic. I have only been programing for 6mo (noob). I have a base geometry class that all my geometry types inherit from. I diddn't want to restrict these classes to using a paticular vertex type. So I used generics to store my vertices. I am also working on a system for batching draw calls based on texture, effect, primative type ect. I want this class to be able to use any type of vertex for sorting. Does that make sense
You can do something like that :
/// <summary>
/// <para>Custom vertex typesfor ground.</para>
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct ObjectVertex
{
/// <summary>
/// <para>Vertex position on X-axis.</para>
/// </summary>
[VertexProperty(VertexPropertyType.X)]
public float X;
/// <summary>
/// <para>Vertex position on Y-axis.</para>
/// </summary>
[VertexProperty(VertexPropertyType.Y)]
public float Y;
/// <summary>
/// <para>Vertex position on Z-axis.</para>
/// </summary>
[VertexProperty(VertexPropertyType.Z)]
public float Z;
[...]
}
The attribute specifie the description of the propertie. Then explore your vertex type to find wich kind of member you want.
Type type = typeof(T);
for(int i = 0 ; i < type.GetFields().Length ; i++)
{
FieldInfo fi = type.GetFields()
;
if (fi.GetCustomAttributes(typeof(VertexProperty), false).Length == 0)
continue;
VertexProperty attr = (VertexProperty)fi.GetCustomAttributes(typeof(VertexProperty), false)[0];
if (attr.PropertyType == VertexPropertyType.X)
indexX = i;
if (attr.PropertyType == VertexPropertyType.Y)
indexY = i;
if (attr.PropertyType == VertexPropertyType.Z)
indexZ = i;
if (attr.PropertyType == VertexPropertyType.Format)
indexFormat = i;
}
I have a code that run on it here. I juste make 3 instruction to create a MRM :
ProgressiveMesh<ObjectVertex> mesh = new ProgressiveMesh<ObjectVertex>(vertices, ints, null);
mesh.Load(this._device);
this.mesh.Render();
Even if i dont know the type of the vertices array i gived to the constructor my render method know that Format, and my compurtings method can extract position from each vertices to build a ProgressiveMesh. How with Attributes :)
Sure. But why does any of this code need to modify the position values in these vertices
I was hoping to avoid making seperate draw calls for each object that has a different WVP matrix when they are static and don't change from frame to frame. My solution (hopefully) is to seperate my static geometry and pre-transform the vertices before combining into one static vertex buffer. Then I only have to make a few calls. The pre-transformation of the vertices is where this question came from.