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.


Dynamically Create ModelMesh (MeshContent->ModelMesh)


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
1 reply to this topic

#1 Lloydg   Members   -  Reputation: 114

Like
0Likes
Like

Posted 03 October 2012 - 04:02 AM

I am having a problem, I want to Dynamically Create a ModelMesh at runtime rather then loading a file.

	    public static ModelMesh BuildMesh(String name)
	    {
		    MeshBuilder builder = MeshBuilder.StartMesh(name);
		    // build the mesh
		    MeshContent finishedMesh = builder.FinishMesh();
		   
		    return finishedMesh as a ModelMesh?
	    }

But I don't know how to convert a MeshContent to a ModelMesh?
Does anyone have an idea?

Thanks

Sponsor:

#2 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 05 October 2012 - 04:35 PM

Hi there, MeshBuilder is a part of the content pipeline, which depends on MsBuild. And due the way in which the mechanism works, it is only supposed to be used within the content pipeline (or a pipeline extension library), the information that MeshBuilder creates is intended for either the built in model processor, or your own custom processor. If you wish to be able to build the equivalent of the functionality ModelMesh provides, you may have to do this yourself, however there are plenty of tutorials on the internet that will show you how to do this.

Just incase this is new to you, here is a quick checklist for achieving this:

- Create an array of vertices (VertexPositionColor is one, but you can use other presets, and even create your own type).
- Create an array of indices for faces, it's normal to have them in multiples of 3, and each index refers to a vertex.
- In your draw call, call one of the appropriate Draw... methods, here's a quick example:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace FastTriExample
{
	public class Game1 : Game
	{
		GraphicsDeviceManager graphics;
		VertexBuffer vbo;
		BasicEffect shader;

		public Game1()
		{
			graphics = new GraphicsDeviceManager(this);
			Content.RootDirectory = "Content";
		}

		protected override void LoadContent()
		{
			vbo = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 3, BufferUsage.WriteOnly);
			vbo.SetData<VertexPositionColor>(new VertexPositionColor[]{
				new VertexPositionColor(Vector3.Up, Color.White),
				new VertexPositionColor(Vector3.Down + Vector3.Right, Color.Blue),
				new VertexPositionColor(Vector3.Down + Vector3.Left, Color.Red)
			});
			float aspectRatio = GraphicsDevice.Viewport.AspectRatio;
			shader = new BasicEffect(GraphicsDevice);
			shader.World = Matrix.CreateScale(0.5f);
			shader.View = Matrix.CreateLookAt(Vector3.Backward, Vector3.Zero, Vector3.Up);
			shader.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, aspectRatio, 0.1f, 2);
		}

		protected override void Draw(GameTime gameTime)
		{
			GraphicsDevice.Clear(Color.CornflowerBlue);
			shader.CurrentTechnique.Passes[0].Apply();
			GraphicsDevice.SetVertexBuffer(vbo);
			GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
		}

	}
}

Have fun!

Edited by AmzBee, 05 October 2012 - 04:37 PM.

We are now on Tumblr, so please come and check out our site! 

 

http://xpod-games.com





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