Hi all,
I created a class that wraps MonoGame importers / processors and allow loading models, sounds, effects and other assets without building them as XNB.
Why though?
My personal reason is that I want to allow players to easily mod the game, and having XNB files is a small barrier in the way.
How to use?
Its a bit hacky so I didn’t do a NuGet package, just grab the code from gist and add it to your project, and make sure you install the MonoGame.Framework.Content.Pipeline and MonoGame.Framework.XXX NuGet packages.
Here’s a usage example:
Model myRawModel = AssetsLoader.LoadModel("someModel.obj"); // or .x, or .fbx
Warning
For building effects you need external dll, and for spritefonts you need to have the font installed. Personally I don’t use it for effects and spritefonts, these I do build upfront and use the compiled file.
I do something similar for the same reason. I want Players to be able to modify my game. I have 3 different Asset Managers, Sound, Images, and Music. They allow me to cache those assets and reuse them on any game object that I need.
I haven’t delved into 3D stuff yet as my preference is 2D games, so I don’t have a 3D asset manager.
I just took a small look and I did not tested this so far, but it looks interesting. Thanks for sharing!
Just a couple of questions:
Does that mean that the end-user don’t need any external binaries (like we know from the MGCB.exe for example), so that he just can use the raw files and your game converts it into a usable format?
Can you somehow still use the ContentManger to load this stuff, or do you need to manage that by yourself (disposing content etc).
Hi @BlizzCrafter , thanks
I forgot how much MG is fun and have a great community so it’s good to be back!
You need the MonoGame content pipeline dll and its dependencies (assimp and such I suppose). So it probably won’t work on anything that’s not desktop but as long as you ship the dlls you should be good, with the exception of spritefont and effects I mentioned in the original post. Personally I’m OK with having to build spritefonts and effects upfront, my modding focus is on models, texture and sounds.
You can use the ContentManger alongside this class, but they don’t integrate together. From looking at MG code it looks like the content manager can only get input from compiled xnb files, but I may have missed something.
Also I didn’t really do anything on regard of cleanups. When my project gets more advanced I will start handle these things.
As you can see it’s all a bit raw, which is why I posted it as gist and not nuget
Maybe by the end of my project it will have a more proper and robust nuget for those of us with xnbphobia
Yeah, shipping the dlls shouldn’t be a license problem at least. I needed to take a deeper look for my sandbox application and all the neccessary dlls are licensed like this:
Microsoft Public License (Ms-PL)
Microsoft Permissive License (Ms-PL) v1.1
MIT
FreeImage Public License
In the moment i’m just shipping them together with the MGCB.exe and call it to generate the XNB files dynamically.
But I also created the project MonoGame.RuntimeBuilder which is basically a wrapper for the MGCB and gives you easy control over it during runtime.
Maybe this is also interesting for you. Feel free to take a look if you want.
I also thought about an extra application package (SDK) on the Steam platform which developers could dynamically install if they want mod-support on this platform. This would be the easiest one I think and it would also have the benefit that the developers wouldn’t need to ship the whole libraries for the MGCB. But I have the feeling that we need an extra MonoGame-Steam-Account for this so that it is official and trustworthy. On the other hand this solution only works on Steam then.
However, it’s nice to see other efforts on this to make mod-support for games and applications using MonoGame easier
Ah I didn’t consider licensing yet because I’m building something that might be open source and is still experimental. But good point.
Cool project, the advantage of your approach is that you can pre-build everything in addition and so people only need the content dlls if they want modding, unlike my approach which requires all the dlls (and being desktop) regardless.
I hope the awesome people behind MG will address this issue and provide some built-in way to handle raw assets (besides textures) . I know its a deviation from the XNA style and APIs MG is based on, but it can be implemented as a side addon dll and not as part of the core dlls.
Cool! I’ve been thinking about doing something like this… Instead of bundling everything in the content proj, I’d like to host images etc. in blob storage, pull down via http and load into a game.
Would this code be useful for something like that?
Yeah but depending on what exactly you need, you may not need it. For example textures and songs are super easy to load from file so you don’t really need my code for that (nor the extra dlls it add).
I suggest going over the code and see which assets you need and if I have a method for that and how much its complicated. IMO the majority of the “meat” there is loading models.
Nice I was looking to do textures and sounds, but your solution gave me even more. About to start a new monogame project and I need this functionality. I am building an in-game editor for building the game directly in the game itself. I started it in Bevy, but I just realized I am fighting the compiler constantly and Bevy really wants to be a 3d engine when I am building 2D games, so it is harder than it should be to get pixel perfect pixel art. This code is the missing piece that will allow me to port my existing code to C#/Monogame and not lose functionality I had in Bevy. I want to prioritize speed of development. Ideally, I want to be able to hit save on a texture, have a file watcher see the change and update existing texture or add if new, without having to ever stop the game/editor. I think I can pull this off with your examples, which should make for great dev workflow. Thanks for the code!