Model Render Issues

Hi, I’m quite new to Monogame and I’m having an issue rendering the 3D model I made in Blender and I would really appreciate any help. I exported my model as a dae file and converted it to fbx using an fbx converter. The fbx file renders fine in Microsoft’s 3D viewer and other software (albeit with the brick texture missing) but when I try to draw it in Monogame it doesn’t render properly. Thanks

]
Model in Blender


Model in 3D Viewer

Model in Monogame

Why don’t you directly export to .FBX?

Or for that matter .X?

Hi, when I tried to export directly to fbx I got the same issue so I used dae and converted it to see if it was a problem with the export from blender or the import into monogame

Try .X [DirectX Model Format .X]

:anchor: T22795 Export to the DirectX Model Format (.x) (blender.org)

EDIT

You should be able to import this with the pipeline without converting to xnb

EDIT

This is amusing to see…

Something a little more recent…

wow… DirectX export used to be on the internal list… whattttt…

I guess try loading the model in 2.79 and see if the DirectX export works that way…

I will try 2.79 and see if the add-on is there

for anyone wondering…

Index of /release/Blender2.79/

Confirmed present:

I suppose one could try importing that .py file to the new version?

attempting to confirm this…

Imported but does not show up on the export list…

Hi, I’m sorry, I’m quite new to monogame, but I’ve managed to export as a directx file and I’ve loaded into monogame via the pipeline but when I try to draw it I’m getting an error at mesh.Draw() code (System.InvalidOperationException
HResult=0x80131509
Message=An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0.
Source=MonoGame.Framework
StackTrace:
at Microsoft.Xna.Framework.Graphics.InputLayoutCache.GetOrCreate(VertexBufferBindings vertexBuffers)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState(Boolean applyShaders)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.ApplyState(Boolean applyShaders)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
at Microsoft.Xna.Framework.Graphics.ModelMesh.Draw()
at Game1.Avatar.Draw(Matrix viewMatrix, Matrix projectionMatrix) ) Does directx not work with meshes? thanks

If you add three backticks ` [Usually above the tab key before the 1 key on UK keyboard layouts, potentially the same on US keyboards]

[image source but I have cropped it https://miro.medium.com/max/8136/1*yAvZYz1LTPpX0qRAoeR_cg.png]
image

Your code can be beautified like so:

(System.InvalidOperationException
HResult=0x80131509
Message=An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0.
Source=MonoGame.Framework
StackTrace:
at Microsoft.Xna.Framework.Graphics.InputLayoutCache.GetOrCreate(VertexBufferBindings vertexBuffers)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState(Boolean applyShaders)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.ApplyState(Boolean applyShaders)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
at Microsoft.Xna.Framework.Graphics.ModelMesh.Draw()
at Game1.Avatar.Draw(Matrix viewMatrix, Matrix projectionMatrix) )
[/quote]

(System.InvalidOperationException
HResult=0x80131509
Message=An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0.
Source=MonoGame.Framework
StackTrace:
at Microsoft.Xna.Framework.Graphics.InputLayoutCache.GetOrCreate(VertexBufferBindings vertexBuffers)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState(Boolean applyShaders)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.ApplyState(Boolean applyShaders)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
at Microsoft.Xna.Framework.Graphics.ModelMesh.Draw()
at Game1.Avatar.Draw(Matrix viewMatrix, Matrix projectionMatrix) ) 

Remember to add three backticks again at the end of the code block to close it…

EDIT

And I just found an issue in doing it right lol

BACKTICKS
CODE BLOCK
BACKTICKS

NOT

BACKTICKS
CODEBLOCK BACKTICKS

The closing backticks must be on a new line… just like the opening backticks

EDIT

Can you try .obj format?

Ok, I’ve redone that below. Do you happen to know how to fix the error? Many thanks

System.InvalidOperationException
  HResult=0x80131509
  Message=An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0.
  Source=MonoGame.Framework
  StackTrace:
   at Microsoft.Xna.Framework.Graphics.InputLayoutCache.GetOrCreate(VertexBufferBindings vertexBuffers)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState(Boolean applyShaders)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.ApplyState(Boolean applyShaders)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType primitiveType, Int32 baseVertex, Int32 startIndex, Int32 primitiveCount)
   at Microsoft.Xna.Framework.Graphics.ModelMesh.Draw()
   at Game1.Avatar.Draw(Matrix viewMatrix, Matrix projectionMatrix) in C:\Users\emmaj\OneDrive - Cardinal Newman College\Computer Science\NEA\Game1\Game1\Avatar.cs:line 49
   at Game1.Game1.Draw(GameTime gameTime) in C:\Users\emmaj\OneDrive - Cardinal Newman College\Computer Science\NEA\Game1\Game1\Game1.cs:line 113
   at Microsoft.Xna.Framework.Game.DoDraw(GameTime gameTime)
   at Microsoft.Xna.Framework.Game.Tick()
   at MonoGame.Framework.WinFormsGameWindow.TickOnIdle(Object sender, EventArgs e)
   at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at MonoGame.Framework.WinFormsGameWindow.RunLoop()
   at MonoGame.Framework.WinFormsGamePlatform.RunLoop()
   at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
   at Microsoft.Xna.Framework.Game.Run()
   at Game1.Program.Main() in C:\Users\emmaj\OneDrive - Cardinal Newman College\Computer Science\NEA\Game1\Game1\Program.cs:line 18

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
SharpDXException: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

Did you try importing with the MGCB as well or directly?

Try .obj

Another thing that springs to mind, have you tried using MilkShape3D?

Did you play with the exporter parameters?

Try this combination:

I just used the pipeline tool, I haven’t tried MGCB.
Tried using .obj and got a similar result to using .fbx
I’m wondering if its a problem with the model itself as I’ve loaded other models into the game with no issue. I used blender’s archimesh add on so I don’t know if that’s messed it up.
Screenshot 2022-04-12 162724
Using .obj

1 Like

I was going to ask about the mesh buildup next lol

Try not using that and see what happens…

For simple models like this, I highly recommend MilkShape3D

Though, buying it is another matter, it can take a day to a few weeks before orders are processed…

chUmbaLum sOft (milkshape3d.com)

EDIT

See the export parameter post above…

I’ll try rebuilding the model without using the archimesh add on and get back to you. Thanks so much

1 Like

Before I forget,

Hi @Emma , Welcome to the Community!

Happy Coding!

Also posting this to avoid a double post warning on your reply box lol

EDIT

There is a trial for 30 days…

image

image

EDIT

OH

SV_Position0 is the shader thing… try using the HiDef instead of Reach profile as well…

What is your shader setup?

Also, the export is still an issue btw…

Thanks for your help. I remade the model without using the archimesh add on and now it works exporting with fbx. It hasn’t got the brick texture with it, I think because I used the nodes in blender’s shader tab to make that so I’m trying to figure out how to bake that and then get that into the pipeline with the model :smile:

1 Like

Try the MilkShape3D trial and find a guide/video on texture mapping, you might find the same for Blender and try that instead.

Keep going!

Hi Emma, I was having similar issues with Blender models not displaying properly in monogame but working fine in 3Dviewer. For me, the issue was that I had not applied the scale in blender prior to exporting as FBX. Not sure if you are still having issues. If you are, hope this helps.

2 Likes