【问题标题】:Could not load MonoCube asset as a non-content file无法将 MonoCube 资产加载为非内容文件
【发布时间】:2015-10-06 21:24:28
【问题描述】:

最近我开始学习 MonoGame 并开始学习 3D 游戏编程,遵循一些关于如何添加 3d 模型的在线教程,我编写了以下代码,该代码应该显示一个 3d 立方体和一个我控制的用于平移它的相机:

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);
    }
}

问题是当我尝试启动游戏时,我收到以下错误:

MonoGame.Framework.dll 中出现“Microsoft.Xna.Framework.Content.ContentLoadException”类型的未处理异常 附加信息:无法将 MonoCube 资源加载为非内容文件!

我无法弄清楚问题是什么,管道有模型的 .dae 文件和 png 并且构建良好,内容管道 .mgcb 文件位于 Content 文件夹中,所以这不是问题我知道,我真的很感激任何和所有的帮助,因为我现在对此感到不知所措。

【问题讨论】:

    标签: c# 3d xna pipeline monogame


    【解决方案1】:

    您可以尝试使用 XNB 文件来确保加载没有问题。微软有几个例子,这是第一个出现在我面前的例子: http://xbox.create.msdn.com/en-US/education/catalog/lab/marble_maze

    这可能是一个愚蠢的建议,但请确保编译后的内容文件位于主项目的 Content 文件夹中,而不是位于内容项目的文件夹中。

    您的目标是什么平台?有一段时间没用过monogame了,但以前你不能在ios上使用Spritefont为windows编译的,反之亦然。查看内容项目中 .dae 文件的选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多