How to properly render a FBX file?

Hi, I’m a beginner on making 3d games but been a programmer for several years, I’ve been following some guides and learned some blender to make models, I managed to make this one:

I exported it as FBX format and set the texture palette to strip path so it takes it from the same path as the model, the problem is when I try to render it in monogame it shows distorted and color washed, the position of some elements are moved (the “pine cones”) and the colors don’t match:

This is the code I’m using to render the model:

protected override void Initialize()
{
  _pine    = Content.Load<Model>("a/models/trees_pine");
}

private void DrawModel(Model model, Vector3 position)
{
  foreach (var mesh in model.Meshes)
  {
    foreach (BasicEffect effect in mesh.Effects)
    {
      effect.World = Matrix.CreateTranslation(position);
      effect.EnableDefaultLighting();
      effect.PreferPerPixelLighting = true;
      effect.Alpha = 1;
      var cameraPosition     = new Vector3(0, 12, 0);
      var cameraLookAtVector = new Vector3(0, 0, 0);
      var cameraUpVector     = Vector3.UnitZ;
      effect.View = Matrix.CreateLookAt(
        cameraPosition, cameraLookAtVector, cameraUpVector);
      float aspectRatio = GraphicsDeviceManager.PreferredBackBufferWidth /
                          GraphicsDeviceManager.PreferredBackBufferHeight;
      float fieldOfView   = MathHelper.PiOver4;
      float nearClipPlane = 1;
      float farClipPlane  = 200;

      for (var i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
      {
        effect.CurrentTechnique.Passes[i].Apply();
      }
      
      effect.Projection = Matrix.CreatePerspectiveFieldOfView(
        fieldOfView, aspectRatio, nearClipPlane, farClipPlane);
    }

    mesh.Draw();
  }
}

protected override void Draw(GameTime gameTime)
{
  GraphicsDevice.Clear(Color.CornflowerBlue);
  DrawModel(_pine, new Vector3(0, 0, 0));
}

I’ve tried opening the model on other software and it shows correctly, heres in windows’ 3d viewer:

Here’s a link to the texture and the model: Google Drive Link

What am I doing wrong? :confused:

1 Like

Not sure. Color-wise - I don’t know what it does by default with material settings so I’d proly make sure to set ambient and diffuse. I’d also make sure not to keep recalculating the matrices inside the loop - just to be more efficient. If camera changes, this could be done once per update (once in init or load before too).
As far as the scale goes - not sure what’s going on - I’d check possibility of bad aspect ratio (which should only happen if preferred isn’t matching actual - which is possible - I use PresentationParameters or Viewport to get the true results after requesting dimensions since not all dimensions are supported for full screen on all devices - safer to do check in init after - not in constructor) or scaling issues on export from Blender.
What happens if you do this?:
‘’’
Matrix world, view, proj;

    protected override void LoadContent()
    {
        pine  = Content.Load<Model>("a/models/trees_pine");

        world = Matrix.CreateTranslation(position);
        view  = Matrix.CreateLookAt(cameraPosition, cameraLookAtVector, cameraUpVector);
        proj  = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Viewport.AspectRatio, 1, 200);
        

    }

    private void DrawModel(Model model, Vector3 position)
    {
        foreach (var mesh in model.Meshes) {
            foreach (BasicEffect effect in mesh.Effects) {                    
                effect.EnableDefaultLighting();
                effect.PreferPerPixelLighting = true;
                effect.TextureEnabled         = true;  
                effect.Alpha      = 1;
                effect.View       = cam.view;
                effect.Projection = cam.proj;
                effect.AmbientLightColor = new Vector3(0.2f, 0.1f, 0.3f);
                effect.DiffuseColor      = new Vector3(0.96f, 0.98f, 0.89f);
            }

            mesh.Draw();
        }
    }

‘’’

@Roberto_Arosemena Welcome to the Community!

Very nice model you made there, just wanted to say that.

Happy Coding!

1 Like

Hmm, could be how your camera is set up giving you that stretch maybe. It looks to me like the UV mapping is off, not sure what basic effect does in the shader it’s self.

But, just so you know, I put your mesh and texture in my tutorial code, and it renders fine.

I am going to add it to my repo too, so you can have a look at the code an how it is doing the render.

I am at work at the moment, ill let you know when I have got around to updating my repo :smiley:

OK, got to do this sooner than I expected.
My MonoGame repo is here.
The specific project I created to render your model is here.

Hope this helps :slight_smile: