SimpleMesh game component and x2swm

I've uploaded a SimpleMesh game component to use on conjunction with x2swm.

Instructions are here: http://astaroth.beatbuggy.net:8080/Images/XNAMagic/SimpleMesh_GameComponent_rm.jpg

Download it here:

http://astaroth.beatbuggy.net:8080/Downloads/SimpleMesh_GameComponent.zip

Instructions:

1) Add the game component to your project.

2) Drag the component onto your game designer.

3) Set the mesh path and mesh name. (i.e media\\ , Dwarf.swm)

4) Put the DrawComponents() call in whichever effect pass you wish.

This works for n swm batches.

It will continue to work if the texture is missing.

Here is the latest x2swm:

http://astaroth.beatbuggy.net:8080/Downloads/x2swm_1_0_0_3.zip




Answer this question

SimpleMesh game component and x2swm

  • Kevin Southern

    Updated to use IGraphicsService, so you dont have to edit your game manually. If you just got this, you can probably discard my last post.

  • ncazanav

    I forget to mention something, to hook up the graphics component to the SimplMesh component, you will have to edit your primarygamecomponent.designer.cs and to something like:

    this.SimpleMesh.Device = this.graphics;



  • Michael Ruminer

    Thats the help I've been using but so far no luck getting it working.

    -Greg.

  • MadMojo1

    Well I did all the things you said...and put a break point at the end of the simplemesh draw method, and it hits it...so I'm not sure what I'm doing wrong. I named the meshpath and meshfile correctly (if not it gives the iofilenotfound error), and I'm using a mesh from Spacewar, since I thought maybe I had a problem with the X to SWM conversion....I tried using a shader instead of BasicEffect as well, still no luck. I know it's not my card or software setup or anything like that, since I've already rendered a cube with texture and lighting. I think I have everything else I need to know as far as making a simple game goes, this is my only stumbling block now -- getting a mesh inside to work with. I really don't want to create stuff triangle by triangle in code -- keeping track of triangle vertices and points in a cube is my head is taxing enough :)

    At any rate, thanks for taking the time to look at the code and point that stuff out -- every piece of advice helps.

  • foomunchoo

    I've followed the instructions here and can't get them to work. I'm not new to programming, been using C# since Beta in 2000. I'm new to the rest of it. I bought Truespace 5.2 thinking I could create some models and use them in a game. I have my model coverted to swm but nothing happens when I follow the rest of this. Just a blank blue screen.

  • Markus Fritz

    Thanks for releasing this and your help

    I'm still trying to get it working but here's a few things I've discovered so far that may help others get it working.

    First thing to do is create a new blank XNA Game project. Create a new folder for your mesh and texture and name it appropriately, such as content or media. Add your mesh and texture to the folder in solution explorer.

    Select the mesh and the texture and set their properties to be copy always - this will ensure they are moved to your release/debug folder when you build.

    Step 1 - you must unzip SimpleMesh_GameComponent.zip and add the 2 files - SimpleMesh.cs and SimpleMesh.Designer.cs to your new project.

    Next you must build your project.

    Now if you look in your toolbox you should see a SimpleMesh component.

    Step 2 - Drag the SimpleMesh component from the toolbox onto your game designer form, should already be a graphics component on there.

    Step 3 - Click the SimpleMesh component and then in the properties window you can set the mesh path and name.

    The path is relative to the .exe and you must escape slashes so if you called your folder content you will set it to be content\\

    The mesh name is the name of your mesh for example box.swm

    Step 4 - Before your mesh will render you need to setup an effect around the DrawComponents() call.

    I'm currently trying to use the simple.fx effect from the XNA How to apply an effect example.

    I've added a shaders folder containing the effect to my project and set it to copy always.

    I've setup world, projection and view matrices and added an effect pass containing the DrawComponents() call but so far have been unable to get my mesh displaying. I'm sure I'm close and will post the source once I've got it working.

    Hope this is useful to someone,

    -Greg.

  • stswordman

    You could either do it with BasicEffect or get your own efect going.

    See:

    ms-help://MS.VSExpressCC.v80/MS.VSIPCC.v80/MS.XNAFX.1033/XNA/Apply_an_Effect.htm



  • JohnGalt

    pRtkL xLr8r wrote:
    I can't get this to work either. I've followed the directions, but nothing is rendered. Does this look right Here is my code:

    using System;
    using System.Collections.Generic;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Components;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Storage;

    namespace Meshtest
    {
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    partial class Game1 : Microsoft.Xna.Framework.Game
    {
    public Game1()
    {
    InitializeComponent();
    }

    protected override void Update()
    {
    // The time since Update was called last
    float elapsed = (float)ElapsedTime.TotalSeconds;

    // TODO: Add your game logic here

    // Let the GameComponents update
    UpdateComponents();
    }

    protected override void Draw()
    {
    // Make sure we have a valid device
    if (!graphics.EnsureDevice())
    return;

    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
    graphics.GraphicsDevice.BeginScene();

    // TODO: Add your drawing code here
    BasicEffect effect = new BasicEffect(graphics.GraphicsDevice, null);

    //lighting
    effect.Alpha = 1.0f;
    effect.DiffuseColor = new Vector3(0.72f, 0.72f, 0.72f);
    effect.AmbientColor = new Vector3(0.2f, 0.2f, 0.2f);
    effect.SpecularColor = new Vector3(0.25f, 0.25f, 0.25f);
    effect.SpecularPower = 0.5f;
    effect.AmbientLightColor = new Vector3(0.25f, 0.25f, 0.25f);
    effect.DirectionalLight0.Enable = true;
    effect.DirectionalLight0.DiffuseColor = Vector3.One;
    effect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(1.0f, -1.0f, 1.0f));
    effect.DirectionalLight0.SpecularColor = Vector3.One;
    effect.DirectionalLight1.Enable = true;
    effect.DirectionalLight1.DiffuseColor = new Vector3(0.8f, 0.8f, 0.8f);
    effect.DirectionalLight1.Direction = Vector3.Normalize(new Vector3(-1.0f, 1.0f, -1.0f));
    effect.DirectionalLight1.SpecularColor = new Vector3(0.5f, 0.5f, 0.5f);
    effect.LightingEnable = true;

    //coordinate transformations
    Matrix world = Matrix.CreateTranslation(new Vector3(0.0f, 0.0f, 0.0f));
    Matrix view = Matrix.CreateLookAt(new Vector3(2.0f, 2.0f, 3.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
    Matrix projection = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4.0f, // 2 PI Radians is 360 degrees, so this is 45 degrees
    (float)this.Window.ClientWidth / (float)this.Window.ClientHeight, 1.0f, 100.0f);

    effect.Projection = projection;
    effect.World = world;
    effect.View = view;
    // Let the GameComponents draw

    graphics.GraphicsDevice.RenderState.CullMode =
    CullMode.CullClockwiseFace;
    effect.Begin(EffectStateOptions.Default);
    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
    {
    pass.Begin();
    effect.CommitChanges();
    DrawComponents();
    pass.End();
    }
    effect.End();


    graphics.GraphicsDevice.EndScene();
    graphics.GraphicsDevice.Present();
    }
    }
    }

    There are sever problems with this.

    1) you should create the basic effect only once, and make it a member of this class.

    2) You are looking at 0,0,0, trying moving the camera back i.e (0,1,10) and setting a target of (0,1,9)

    3) set your near plane a little closer 1 unit is pretty large (try 0.1), also try making the far plane alot bigger

    4) you shouldnt need the commit changes mid pass, unless you change something in the effect

    Other than that it really depends on your model, its dimensions etc.

    Also put a breakpoint the SimpleMesh draw method, is it called



  • Mike Stall - MSFT

    I can't get this to work either. I've followed the directions, but nothing is rendered. Does this look right Here is my code:

    using System;
    using System.Collections.Generic;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Components;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Storage;

    namespace Meshtest
    {
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    partial class Game1 : Microsoft.Xna.Framework.Game
    {
    public Game1()
    {
    InitializeComponent();
    }

    protected override void Update()
    {
    // The time since Update was called last
    float elapsed = (float)ElapsedTime.TotalSeconds;

    // TODO: Add your game logic here

    // Let the GameComponents update
    UpdateComponents();
    }

    protected override void Draw()
    {
    // Make sure we have a valid device
    if (!graphics.EnsureDevice())
    return;

    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
    graphics.GraphicsDevice.BeginScene();

    // TODO: Add your drawing code here
    BasicEffect effect = new BasicEffect(graphics.GraphicsDevice, null);

    //lighting
    effect.Alpha = 1.0f;
    effect.DiffuseColor = new Vector3(0.72f, 0.72f, 0.72f);
    effect.AmbientColor = new Vector3(0.2f, 0.2f, 0.2f);
    effect.SpecularColor = new Vector3(0.25f, 0.25f, 0.25f);
    effect.SpecularPower = 0.5f;
    effect.AmbientLightColor = new Vector3(0.25f, 0.25f, 0.25f);
    effect.DirectionalLight0.Enable = true;
    effect.DirectionalLight0.DiffuseColor = Vector3.One;
    effect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(1.0f, -1.0f, 1.0f));
    effect.DirectionalLight0.SpecularColor = Vector3.One;
    effect.DirectionalLight1.Enable = true;
    effect.DirectionalLight1.DiffuseColor = new Vector3(0.8f, 0.8f, 0.8f);
    effect.DirectionalLight1.Direction = Vector3.Normalize(new Vector3(-1.0f, 1.0f, -1.0f));
    effect.DirectionalLight1.SpecularColor = new Vector3(0.5f, 0.5f, 0.5f);
    effect.LightingEnable = true;

    //coordinate transformations
    Matrix world = Matrix.CreateTranslation(new Vector3(0.0f, 0.0f, 0.0f));
    Matrix view = Matrix.CreateLookAt(new Vector3(2.0f, 2.0f, 3.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
    Matrix projection = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4.0f, // 2 PI Radians is 360 degrees, so this is 45 degrees
    (float)this.Window.ClientWidth / (float)this.Window.ClientHeight, 1.0f, 100.0f);

    effect.Projection = projection;
    effect.World = world;
    effect.View = view;
    // Let the GameComponents draw

    graphics.GraphicsDevice.RenderState.CullMode =
    CullMode.CullClockwiseFace;
    effect.Begin(EffectStateOptions.Default);
    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
    {
    pass.Begin();
    effect.CommitChanges();
    DrawComponents();
    pass.End();
    }
    effect.End();


    graphics.GraphicsDevice.EndScene();
    graphics.GraphicsDevice.Present();
    }
    }
    }


  • AlucardHellSing

    Assuming you are actually rendering the mesh correctly I could guess it to be one of these things:

    Your not transforming verts correctly in vertex shader world (optional) * view * projection.

    The positions are simply not in the view frustum (could be behind you, or even far away).

    Double check your scale, is the model too small to see, or are you inside it

    Hope that helps.



  • sticksnap

    Ah ok, are you not signed into windows live messenger Or just appearing offline

  • cwest

    Great work again!

  • SimpleMesh game component and x2swm