As I discussed in a recent blog post, after becoming fed up with the traditional process of importing 3D models into GameMaker, I decided to write an addon for Blender which would allow me to go directly from 3D design to GameMaker itself, with no need for middleware that doesn’t meet all of my needs, modelers that aren’t full-featured, or clunky import scripts. Rather than go into all of that again here, I’d simply like to present the script itself, and a short tutorial on how to use it.
First, the script! Get it here: io_export_gamemaker3d_1_4_6.py
Note: If you’re looking for a script which will output models directly to GameMaker’s internal model format, I’ve made one for that too, which you can find here.
Installation for this script works just like any other Blender addon – namely, you download it and save it somewhere, then open up Blender, go to File > User Preferences…, click the Addons tab at the top, then click the button at the bottom of the window that says Install from File…
Once the script is installed, click the Import-Export button on the left side of the window to help find it, and then tick the small box to the right to enable it. If you don’t want to have to do this every time you start Blender, click the Save User Settings button at the bottom left of the window. Close the User Preferences window, and you’re ready to start exporting!
Once you’ve got a model built that you’re ready to export to GameMaker, there are a few final steps you’ll want to take to ensure that things turn out the way you want. Make sure you read over these before you export your object.
First, make sure the object is oriented around the origin exactly how you want it to be in the game. Consider the world origin in Blender (0, 0, 0) to be the pivot point for your model, and orient it accordingly.
Second, make sure the object is rotated and scaled properly. Again, make it exactly as you want it to be in its default state in the game.
Once you’ve got everything positioned correctly, make sure you’re in Object mode and in a 3D view, click Object > Apply > Rotation & Scale. Then click Object > Apply > Location. These options are also available by hitting CTRL+A. This will move the object’s axis to the origin, and will reset the rotation and scaling to match how the object is currently oriented.
Another thing you might want to do is add an Edge Split modifier to your model. This will allow you to have absolute control over how the normals of your model translate into GameMaker, and I highly recommend it. With this modifier enabled, you can mark edges on your model that are to be sharp or not however you like. It’s way better than just hoping the edges turn out looking right based on their default smoothing angles.
Finally (and also optionally) get the object’s UV map set up how you like it, for texturing. The export script will not include UV coordinates if your object doesn’t have a UV map attached.
You can find the new GameMaker Model Script export in the File > Export menu. And though I’ve never had any major problems here, I recommend saving your work before exporting, just in case.
Select your object and then launch the script. You’ll be met with a (hopefully) familiar file-picker dialog, with a few options on the lower left side. The default settings should be fine, but you can tweak them if necessary. Most should be pretty self-explanatory.
Make sure not to overwrite anything you’d like to keep, and hit Export to finalize. As long as nothing horribly wrong happened, you should now have a new text file with GML in it!
Open up this text file and copy the contents into a new script in GameMaker. Obviously, you can make changes to it to suit your needs, but by default, when you call the script it will create the new model and then return the model’s resource ID. You can then use this to draw the model, or once you’re done with it, destroy it.
I have a few small ideas for options to add to the export process, and of course, if you need to add anything to the script yourself, it’s there for you to do so. If you make any major changes that you feel like I should know about (or if you find any bugs) please get in touch and let me know!
This script was built from an open source script originally written by Jeff LaMarche. I have contacted Jeff and he has indicated that he requires no credit or compensation for utilizing his script in this way. You can view the original script’s license here.