在Monogame中无需内容管道即可加载.FBX文件

问题描述

我想知道是否有一种方法可以在不使用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;
    }

解决方法

所以我设法使用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());
    }