【问题标题】:Loading .FBX file without Content Pipeline in Monogame在 Monogame 中加载没有内容管道的 .FBX 文件
【发布时间】:2020-09-12 07:08:49
【问题描述】:

我想知道是否有一种方法可以在不使用 monogame 内容管道的情况下将仅包含一个立方体的简单 .fbx 文件加载到我的游戏中。这是我目前拥有的代码,但我想基本上摆脱文件为 .xnb 的要求

    public static Model LoadModel(string model)
    {
        Model outModel = null;
        // If model is already in memory, reference that instead of having to load it again
        if (Loaded3DModels.ContainsKey(model))
        {
            Loaded3DModels.TryGetValue(model, out outModel);
        }
        else
        {
            if (File.Exists(Game.gameWindow.Content.RootDirectory + "/" + model + ".fbx"))
            {
                outModel = Game.gameWindow.Content.Load<Model>(model + ".fbx");
                Loaded3DModels.Add(model, outModel);
            }
            else
            {
                Debug.LogError("The Model \"" + model + ".fbx\" does not exist!", true, 2);
            }
        }

        return outModel;
    }

【问题讨论】:

  • Monogame 内容管道是在您的游戏中加载内容所必需的。虽然通过快速搜索,您可以找到一些解决方法。

标签: c# model 3d xna monogame


【解决方案1】:

所以我设法使用 AssImp 加载网格,然后将其“转换”为 Monogame 可以渲染的东西

    public Renderer3DComponent(Mesh mesh)
    {
        // Set up material
        Material = new BasicEffect(Game.graphics.GraphicsDevice);
        Material.Alpha = 1;
        Material.VertexColorEnabled = true;
        Material.LightingEnabled = false;

        // Tris
        for (int i = mesh.VertexCount - 1; i >= 0; i--)
        {
            var Vert = mesh.Vertices[i];
            Verts.Add(new VertexPositionColor(new Vector3(Vert.X, Vert.Y, Vert.Z), Color.White));
        }

        // Buffer
        Buffer = new VertexBuffer(Game.graphics.GraphicsDevice, typeof(VertexPositionColor), Verts.Count, BufferUsage.WriteOnly);
        Buffer.SetData(Verts.ToArray());
    }

【讨论】:

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