0
\$\begingroup\$

I am trying to draw a 3D cube on the screen, using MonoGame. The cube was created in Blender and exported as an fbx file. The following is what the cube looks like in VS when opened in the editor:

enter image description here

And this is what it looks like when displayed on screen:

enter image description here

From the research that I've done so far, I believe that I need to apply a texture. I couldn't see any way to do this in Blender, or in the Content Pipeline Tool, and so I tried the following when drawing the effect:

effect.Texture = _texture;
effect.TextureEnabled = true;

When I run this, I get a runtime error:

An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0, NORMAL0, COLOR0.

Clearly I'm missing a key part of this puzzle; please can somebody point me in the right direction.

\$\endgroup\$
5
\$\begingroup\$

1. Creating textured model in Blender
First, add a new texture by going to texture panel on the right. Select type "Image or Movie", click "Open" and locate your texture file.
enter image description here

Then, move your mouse to the 3d view, press Tab to select the default cube, then press "U" and select Unwrap. enter image description here
Go to UV Image Editor: enter image description here
and select the texture: enter image description here
At this point, the cube should be textured and you can verify that by changing viewport shading to texture: enter image description here
Now export the model as FBX file (all settings should be on default). When you open the model now in Visual Studio, the texture should also be visible. enter image description here 2. Converting the model
Download Autodesk FBX 2013.3 Converter (http://usa.autodesk.com/adsk/servlet/pc/item?siteID=123112&id=22694909)
In the converter, add your fbx file, change the destination folder to the same one where your current file is (otherwise it creates a subfolder) and rename destination file so that it isn't same. Then press Convert. enter image description here
Now open the Monogame pipeline tool and import both the converted model and the texture:enter image description here 3. Rendering the cube
I believe that your rendering code would now work, but to be sure, there is a simple code needed to render it properly:

public class Game1 : Game
{
    GraphicsDeviceManager graphics;     
    private Model model;

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

    protected override void LoadContent()
    {           
        model = Content.Load<Model>("Model1");
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        foreach (ModelMesh mesh in model.Meshes)
        {              
            foreach (BasicEffect effect in mesh.Effects)
            {

                effect.World = Matrix.CreateTranslation(new Vector3(0, 0, 0));
                effect.View = Matrix.CreateLookAt(new Vector3(5,5, 5), Vector3.Zero, Vector3.Up);
                effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), 1.6f, 0.1f, 10000.0f);
                effect.EnableDefaultLighting();
            }

            mesh.Draw();
        }

        base.Draw(gameTime);
    }
}

enter image description here

\$\endgroup\$
  • \$\begingroup\$ This works flawlessly on the default cube - however, when I try the same process using this object (opengameart.org/content/scoutship), for example, it doesn't allow me to do the UV Unwrap. \$\endgroup\$ – Paul Michaels Aug 17 '15 at 7:26
  • \$\begingroup\$ I just tested it with the spaceship and there was no problem. So you can't see the option to unwrap, or is there some kind of error? \$\endgroup\$ – Martin Ciz Aug 17 '15 at 7:58
  • \$\begingroup\$ Can't see the option \$\endgroup\$ – Paul Michaels Aug 17 '15 at 8:14
  • \$\begingroup\$ Is it only this one that's missing or some others from the UV mapping menu as well? Are you in edit mode and not object mode? \$\endgroup\$ – Martin Ciz Aug 17 '15 at 8:27
  • \$\begingroup\$ It is definitely in edit mode, but the only options available are: Smart UV project, Lightmap Pack and Follow Active Quads; the other options are there, but ghosted. \$\endgroup\$ – Paul Michaels Aug 18 '15 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.