Reputation: 47
recently I have taken up MonoGame and starting out with learning 3D games programming, following some online tutorials on how to add 3d models I got the following code made that should display a 3d cube and a camera I control to pan around it:
public class Game1 : Game
{
GraphicsDeviceManager graphics;
Vector3 camTarget;
Vector3 camPosition;
Matrix projectionMatrix;
Matrix viewMatrix;
Matrix worldMatrix;
Model model;
// orbit
bool orbit;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
camTarget = new Vector3(0f, 0f, 0f);
camPosition = new Vector3(0f, 0f, -100f);
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f), GraphicsDevice.DisplayMode.AspectRatio, 1f, 1000f);
viewMatrix = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);
worldMatrix = Matrix.CreateWorld(camTarget, Vector3.Forward, Vector3.Up);
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
model = Content.Load<Model>("MonoCube");
// TODO: use this.Content to load your game content here
}
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
camPosition.X -= 1f;
// remove this to create a rotation
camTarget.X -= 1f;
}
if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
camPosition.X += 1f;
// remove this to create a rotation
camTarget.X += 1f;
}
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
camPosition.Y -= 1f;
// remove this to create a rotation
camTarget.Y -= 1f;
}
if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
camPosition.Y += 1f;
// remove this to create a rotation
camTarget.Y += 1f;
}
if (Keyboard.GetState().IsKeyDown(Keys.OemPlus))
{
camPosition.X += 1f;
// remove this to create a rotation
}
if (Keyboard.GetState().IsKeyDown(Keys.OemMinus))
{
camPosition.X -= 1f;
// remove this to create a rotation
}
if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
orbit = !orbit;
}
if (orbit)
{
Matrix rotationMatrix = Matrix.CreateRotationY(MathHelper.ToRadians(1f));
camPosition = Vector3.Transform(camPosition, rotationMatrix);
}
viewMatrix = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
foreach(ModelMesh mesh in model.Meshes)
{
foreach(BasicEffect effect in mesh.Effects)
{
effect.View = viewMatrix;
effect.World = worldMatrix;
effect.Projection = projectionMatrix;
//mesh.Draw();
}
mesh.Draw();
}
base.Draw(gameTime);
}
}
The issue is that when I try and start the game, I get the following error:
An unhandled exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in MonoGame.Framework.dll Additional information: Could not load MonoCube asset as a non-content file!
And I can not figure out what the issue is, the pipeline has the .dae file and the png for the model and builds fine, the content pipeline .mgcb file is within the Content folder so that isn't the issue that I know of, I would really appreciate any and all help as I am at a loss right now over this.
Upvotes: 0
Views: 230
Reputation: 441
You could try using an XNB file to make sure it's nothing wrong with the loading. Microsoft has a few examples, this was the first one that popped up for me: http://xbox.create.msdn.com/en-US/education/catalog/lab/marble_maze
Might be a stupid suggestion but make sure the compiled content files are located in the Content folder for the main project and not the content project.
What platform are you targeting? Haven't used monogame for a while but previously you couldn't use Spritefont's compiled for windows on ios and vice versa. Look at the options for your .dae file in the content project.
Upvotes: 1