最近我已經開始使用MonoGame並開始學習3D遊戲編程,下面是關於如何添加3D模型的一些在線教程我得到了下面的代碼,應該顯示一個3d立方體和照相機我控制平移周圍:無法加載MonoCube資產作爲非內容文件
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);
}
}
的問題是,當我嘗試啓動遊戲,我得到以下錯誤:
型Microsoft.Xna的」未處理的異常.Framework.Content.ContentLoadException'發生在MonoGame.Framework.dll 附加信息:不能將MonoCube資產加載爲非內容文件!
而我不知道問題是什麼,管道有模型的.dae文件和png,並且生成良好,內容管道.mgcb文件位於Content文件夾內,因此不是問題,我知道,我會很感激任何和所有的幫助,因爲我現在在這方面虧本。