After becoming fed up with the traditional process of importing 3D models into GameMaker: Studio, I decided to write an addon for Blender which would allow direct export of 3D data to GameMaker – eliminating the need for weird middleware or slow/clunky import scripts. You can download this addon below, find instructions for how to use it, and this is where I will post all future updates to this project.
Here is the most up-to-date version of the addon (last updated July 16, 2017): Blender addon script 1.5.9
Download the script, then open up Blender and go to File > User Preferences, click the Addons tab at the top, then click Install from File.
Once the script is installed, find it in your list of addons (type “gamemaker” in the search box, or click the Import-Export button tab to the left), and tick the small box on the right to enable it. Click Save User Settings and close the window.
Now you’re ready to start exporting models to GameMaker: Studio!
When you’ve got your 3D model ready to export, select it, then click File > Export > GameMaker 3D (.txt).
Next you’ll see the standard Blender save dialog, but it’ll have some new options specific to the GameMaker export addon in the panel on the left.
There are a number of formats and model types to choose from now – here is a brief explanation of what each of the settings does:
The desired output format of the model. Basically, how you want your output data formatted.
- GML Script – The model will be output as a self-contained GML script, which can be added to your game as a script that you call to load your model. The script will return the new model’s id.
- GameMaker Model – The model will be output in GameMaker’s built-in model format, and can be loaded to your game using d3d_model_load().
- Raw Vertex Data – The model will be output as a list of vertex data, which follows this format: x, y, z, x normal, y normal, z normal, uv x, uv y. Each line is a vertex, and as with the other models, the number and order of vertices will depend on the model type you select in the next dropdown.
The type/style of the exported model.
- Triangle List – The model is written as a list of its triangles.
- Line List – The model is written as a list of vertex pairs, one pair for each of its edges.
- Point List – The vertex data is written as a list of points, one for each vertex.
Whether or not to apply any modifiers that might be on the object before exporting it. Generally, it’s a good idea to keep this on, because otherwise the exported model could differ from what you’re seeing in Blender.
Rotate X by 90
If you happened to create your model with the wrong orientation, or you imported it from a 3D app that uses Y as up (as opposed to Z) then this is a quick way to fix that in the exported model. It will rotate the model 90 degrees on the X axis.
Mirror on Y Axis
In Blender, the 3D space is oriented Z-up – but if you look at how X and Y are oriented, you’ll notice that Y runs positive in the opposite direction of how it would in a GameMaker game that is also Z-up. Therefore, if your model isn’t symmetrical, it will get mirrored going from Blender to GameMaker. This option flips the exported model by mirroring it on the Y axis.
Flip UV Vertically
Similar to the issue mentioned above, Blender’s UV coordinates also run opposite to GameMaker’s on the Y axis, so you either need to flip the UV coordinates (which is what this option does) or flip your texture map.
If your game uses a 3D scale that is different from Blender, you can use this option to scale the exported models, without having to work on models that are uncomfortably large or small, and without having to depend on scaling objects in GameMaker as you draw them, which often seems to cause the object’s normals to appear incorrect.
Make Coordinates Relative
This option will only appear if you are exporting the model as a GML script. If enabled, it will add some extra variables to the script that lets you transform/translate the model when you call the model script in your game. This can be useful if you want to add multiple copies of the object to your game, but in different places, and don’t want to perform the transform/translation at runtime.
Once you’ve chosen an appropriate path, filename, and the settings you want, click Export for GameMaker. The script will output a text file and your export will be ready to bring into GameMaker!
Depending on which model format you chose, there will be different ways to get your exported model into GameMaker at this point. If you chose GameMaker Model or GML Script, you can follow the instructions below to get your model data into GameMaler. If you exported the model as raw vertex data, it will be up to you to consider how you want to import (and utilize) the data.
Importing a GameMaker Model
This is the easiest way to get your model into a GameMaker project.
Just call the d3d_model_load() function and point it to your model. Optionally, you may want to add the model file to your Included Files in the resource tree, so it always gets packaged with your game. You can also change the filename and/or extension to something else – GameMaker: Studio doesn’t care what extension the file has, as long as the data inside the file remains intact.
Importing a GML Script
If you’d rather have your models reside in your project as scripts (or, perhaps, you want to do some further manual tweaking of your model in GameMaker’s script editor), you can use the GML Script option.
Open the text file the addon created and select everything there, then create a new script in your GameMaker project, name it something appropriate, and paste the model data into the script.
Now just call the script when you’d like to load up your model, and store the returned model id to use later for drawing, etc. Your script will have a few more arguments to it if you chose the Make Coordinates Relative option when you exported your model.
While this Blender addon tries to help alleviate a lot of the problems with importing 3D objects to GameMaker from other 3D applications, there are still a number of things to be aware of to ensure that the best results. Here are a few tips that might help you:
- Make sure your object is oriented around the world origin (0, 0, 0) in Blender exactly how you want it to be in the game – this will be your object’s default rotational axis. Additionally, make sure your object is rotated and scaled properly to your game’s setup.
- It’s a good idea to apply your object’s location, rotation, and scale before exporting. You can do this by selecting your object, then pressing CTRL+A, then applying each of these properties. This will move the object’s origin to 0, 0, 0, and also normalize the object’s scale and rotation.
- The Edge Split modifier can give you more control over how your object’s normals appear in GameMaker. You can read more about using it here.
- Don’t forget to set up your object’s UV’s, if you’re planning on drawing it with a texture applied. Blender has many tools to help you do this, which you can read about here.
- Although this addon is built in a way that it should never perform any permanent, destructive operations on your models, always be sure to save your work in Blender before exporting, just in case
Although this addon has reached a pretty good place in terms of features, there’s always more to add. Currently, I’d like to add support for GameMaker Studio 2/vertex buffers, but that’s all that’s on my list. If you have any feature requests or bug reports, please get in touch and let me know!
Additionally, you’re welcome to add your own functionality, which should be relatively easy thanks to Blender’s Python scripting system. If you make any big improvements or additions that you think I might like to see, please drop me a note.
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.
- Added proper changelog!
- Fixed a scripting error with UV coordinates when exporting in GameMaker Model format
- Re-wrote many parts of the script, removed lots of old code and outdated comments
- Added the ability to export to GameMaker Model and Raw Vertex Data formats
- Added the ability to export linelists and pointlists
- Fixed an error that prevented models from being triangulated after modifiers were applied
- Renamed some of the functions to (hopefully) be a bit more obvious about what they do
- Changed the name of the script in the Export menu
- Changed the button label in the export dialog
- Small change to the name of the script in the Export menu
- Updated tracker URL
- Moved and re-wrote some functions to happen at better places in the order of operations
- Added an option for exporting the object with relative coordinates
- Further cleanup of various parts of the script
- Removed some redundant code
- Reformatted some indentation
- Initial release