Jump to content
  • Advertisement
Sign in to follow this  
mysigninname

XNA interface - CustomVerts

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

I get a

CustomVertex.VertexMultiTexture' does not implement interface member 'Microsoft.Xna.Framework.Graphics.IVertexType.VertexDeclaration'

From the following code;



namespace Stuff_mk1
{
public class CustomVertex
{




public struct VertexMultiTexture : IVertexType
{
public Vector3 position;
public Vector2 uv;
public Vector3 normal;
public Vector4 texWeights;

public VertexMultiTexture(Vector3 pos, Vector2 texCoord, Vector3 norm, Vector4 texWeight)
{
position = pos;
uv = texCoord;
normal = norm;
texWeights = texWeight;
}





}



public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration
(

new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
new VertexElement(32, VertexElementFormat.Vector4, VertexElementUsage.BlendWeight, 0)


);















}
}







How do i implement IvertexType.VertexDeclaration, and what does that really mean?
Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
The IVertexType requires you to implement a property called VertexDeclaration which returns (strangely enough) a VertexDeclaration that describes your vertex.

The vertex structs provided by XNA implement this interface explicitly, meaning that VertexDeclaration cannot be accessed from an instance of the vertex class unless explicitly cast as an IVertexType. Instead, XNA relies on the the static property VertexDeclaration that it implements on each vertex type. This property is reflected and used whenever you see code that passes the type of a vertex struct to a method.


public struct VertexPosition : IVertexType
{
public readonly Vector3 Position;

public VertexPosition(Vector3 position)
{
Position = position;
}

public static VertexDeclaration VertexDeclaration
{
get { //create vertex declaration here }
}

VertexDeclaration IVertex.VertexDeclaration
{
get { return VertexDeclaration; }
}
}

Share this post


Link to post
Share on other sites
Thanks! Problem solvered. It's very cool making your own format. :)



The IVertexType requires you to implement a property called VertexDeclaration which returns (strangely enough) a VertexDeclaration that describes your vertex.

The vertex structs provided by XNA implement this interface explicitly, meaning that VertexDeclaration cannot be accessed from an instance of the vertex class unless explicitly cast as an IVertexType. Instead, XNA relies on the the static property VertexDeclaration that it implements on each vertex type. This property is reflected and used whenever you see code that passes the type of a vertex struct to a method.


public struct VertexPosition : IVertexType
{
public readonly Vector3 Position;

public VertexPosition(Vector3 position)
{
Position = position;
}

public static VertexDeclaration VertexDeclaration
{
get { //create vertex declaration here }
}

VertexDeclaration IVertex.VertexDeclaration
{
get { return VertexDeclaration; }
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!