SeaPeaMe
SeaPeaMe

Reputation: 109

Loading .FBX file without Content Pipeline in Monogame

I was wondering if there was a way to load a simple .fbx file with just a cube into my game without using the monogame content pipeline. Here's the code I have currently, but I want to essentially just get rid of the requirement for the file to be .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;
    }

Upvotes: 0

Views: 544

Answers (1)

SeaPeaMe
SeaPeaMe

Reputation: 109

So I managed to use AssImp to load a mesh, and then "Convert" it to something Monogame could render

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

Upvotes: 1

Related Questions