Blender Addon: Export GameMaker 3D Model Script

Note: There is a new, better version of this script now, and it works with newer versions of Blender and GameMaker. You can find it here.

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.6.1

Installation

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!

Export

When you’ve got your 3D model ready to export, select it, then click File > Export > GameMaker 3D (.gml).

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:

Format

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.

Model Type

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.

Make Importable

If checked, this option adds a small amount of code to the beginning of the script which makes the file easier to directly import into GameMaker: Studio. This code defines a script name for importing and follows this format: “#define scr_[filename]” followed by two line breaks.

Apply Modifiers

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.

Scale

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!

Import

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.

Tips

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 UVs, 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.

Further Development

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.

Changelog

1.6.1

  • Added an option for script output: “Make Importable”, which adds the script name at the beginning of the file, to allow the script to import directly into GameMaker: Studio
  • Changed the default extension for output back to .gml
  • Removed old code and cleaned up some of the imported Python libraries

1.5.9

  • Added proper changelog!
  • Fixed a scripting error with UV coordinates when exporting in GameMaker Model format

1.5.8

  • 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

1.4.6

  • Small change to the name of the script in the Export menu
  • Updated tracker URL

1.4.5

  • 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

1.3.0

  • Removed some redundant code
  • Reformatted some indentation

1.1.0

  • Initial release

Add-on for:

  • blender 2.79+
Download

52 Comments

  • epicguy474 says:

    when i try to do this the export menu’s thing is gray and i cant use it. Anyone got a fix?

    • Martin says:

      Hi epicguy – make sure that the model you’re trying to export is selected, and that it is a mesh. You may need to convert it to a mesh prior to exporting it if it contains live text, curves, nurbs, etc. Just make sure to keep a copy of it somewhere else, as converting it to a mesh may destroy some editing capabilities.

  • AX says:

    Well,
    first thing I don

  • Lynn says:

    I’m confused; how do I download it because when I click on it, it opens a new window and has the scripting in it? Do I save ‘as link’ or something? Nonetheless, thank you for creating this…now I just need to figure out how to download it.

    • P. says:

      Changing the name of the file from “.txt” to “.py” worked for me

    • Christopher M Rosa says:

      how do i download this????????????????????????????????????????????????!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! i just get a window with a bunch of text

  • Lynn says:

    Is there a way you can make a video of this because as I’m trying to ‘export’ my object, I’m not able to select the ‘Game Maker 3D Model Script(.txt)’ option and I don’t know what I did wrong.

  • Ashish says:

    My quesrion is that who to setting game maker 3d model script (txt).

  • Dax says:

    Hi Martin. Firstly, thank you for the script. I’m a complete newbie to 3D with GameMaker. I’m using MagicVoxel to export an OBJ into Blender, which includes colour materials. Can you tell me, if I use your script, will the information in the .txt file it creates include this colour information?

    • Hi Dax – I took a look at MagicaVoxel, and it *should* work as long as you use the PNG file it exports as your texture in GameMaker.

      You’ll have to resize it to be a square, though. Luckily, you can do this in GameMaker, if you import the image and then open it in GameMaker’s image editor. Just hit Transform > Stretch… and then uncheck Keep Aspect Ratio, change the height to 256 pixels, and set the quality to Poor.

    • Martin says:

      Hi Dax! After investigating MagicaVoxel, I’d say yes, you should be able to do this – just use the PNG that MagicaVoxel exports with your model as the texture in GameMaker.

      You’ll need to resize it to be a square 256×256, but luckily you can do this in GameMaker’s image editor relatively easily. Just load up the image into GameMaker and open it in the built-in editor. Then go to Transform > Stretch… and uncheck Keep Aspect Ratio, change the height to 256 pixels, and set the quality to Poor.

  • Dax says:

    Thanks for the reply Martin. So, just to clarify, MagicaVoxel outputs the following files:

    model.obj
    model.mtl
    model.png

    Blender will use your script and product a .txt file.
    I can copy and paste this .txt file into a script in GameMaker and display the model (without colour)

    To get colour on my 3D model you’re saying resize the model.png to 256×256 and import it into GameMaker
    Can you explain how to link model.png to my 3D model in Gamemaker? Do I need some sort of extra file like a UV Map?

    Sorry for the newbie questions, but I’ve never done it before ;-)

    • Dax says:

      ignore my silly comments – it worked!!! Resized to 256×256!

      Note: I used Qubicle Voxel Editor > export OBJ

      Qubicle’s looks more like a texture map than MagicaVoxel? MagicaVoxel’s png looks more like a palette?

    • Martin says:

      Awesome!

      MagicaVoxel’s texture is actually a normal texture – it’s just set up to be 1 pixel high, with each color slot being assigned UV coordinates in the center of each appropriate pixel. Because of the way UV’s work, you can just stretch this out to be compatible with programs like GameMaker, which require textures to be square, and the UV’s will still land in the middle of each spot.

      Anyway, glad you got it working! :)

  • Dax says:

    Ah, that’s good to know. I actually love MagicVoxel – very easy to use and recommended

    • Martin says:

      Nice – I’ve only used it a few times, but I’ve been impressed. I will definitely use it if I ever have any voxel modeling projects pop up!

  • Dax says:

    Can’t thank you enough for this script Martin – saves me sooooo much time!!

  • JDoe says:

    I keep getting error location

  • JDoe says:

    error location unknown when i try to export in both d3d and txt

  • Dax says:

    Have you tried specifying exactly where you want to save the exported files? For example I had to tell it to save to my documents folder

  • Dax says:

    In addition to selecting say My Documents as a location to save to, fill in the box below with your own filename

  • JDoe says:

    yes i did but still won’t save i;m using blender v2.70 if that helps

    • Martin says:

      One more update to this issue – someone else had a similar problem, and the solution was to create a new Blend file and append the file with your models, then try exporting again. Not sure what the problem is yet, but this helped another person, so I figured it’d be worth mentioning here. Good luck!

  • Dax says:

    in case it helps, my Blender is 2.77

  • Terrence says:

    Hi, Martin!
    I’m finding a bit of trouble in the rendering portion of the 3D object, which my subsequently label my problem as a Game Maker problem that can easily be remedied, with help. My problem is, when attempting to draw the 3D model in-game, it doesn’t show up! Here are the steps I’d taken before meeting this problem:

    1) I went through the process of opening a .OBJ model in Blender, using the addon to export the model as a .txt file, and copying the script included in the .txt file to a script in my game.
    2) (This may very well be where my limited knowledge of 3D in GM:Studio got the best of me) I called the script in a code box in the Create event of the object that I chose to render the model. To call the script I simply typed out the name of the script (in this case it’s “model_build_tree();”) and that was all I kept in the object’s Create event.
    3) I went to the object’s Draw event, placed a code box, and typed out d3d_model_draw(temp,x,y,0,global.texture_tree) (I have a solid green texture saved as “global.texture_tree”, this for sure isn’t the problem) and left the draw event at that. I already have d3d started and everything for the room of my game, as I am able to see 3d blocks I’d previously made. So at this point, I placed the object, with only two lines of code (one in the Create event, and one in the Draw event) into my room.
    4) I ran the game, and in my room I could only see the 3D blocks I had placed previously, no 3D model of a tree anywhere to be seen.

    There is a very good chance that I missed a step setting up the script to actually render the 3D model in game, so I’d like you to enlighten my on whatever else I need to add to the coding of my game to get the model to show up, if you don’t mind, that is! Thank you in advance!

  • Azurexis says:

    Thank you so fucking much man!!! This helped me a lot! <3 <3 <3
    This is so much more easy than converting .obj to something and in the end it's still shit!
    This is easy, fast, clean and very effective! THANK YOU!

  • Mike says:

    Shocker. Fresh installed Blender 2.78. Fresh installed this add-on. Imported an obj. Tried to export and what do you know: about four errors in the traceback. Shame…

  • Some of the triangles of my model disappears when exporting to GameMaker format…

  • Erdrick The Hero says:

    Martin – Thanks for the script! So far, I’m finding it to be pretty useful, but I’ve hit a bit of a snag: When importing my model into GameMaker, I am able to display the model perfectly fine in a solid color, but when applying the texture, it appears as if my UV map is completely ignored, and the texture is just fit randomly onto the geometry. Now, I’ve only just started modelling for games (my previous modelling experience was for technical and architectural drawing, and it wasn’t ever necessary to apply a texture via UV map), so it’s possible that I’m misunderstanding something – but the texture fits my model fine in Blender. Any hints as to why this is occurring?

  • The script works really well for the model, but regardless of the uvmapping and texture file the model is a solid black in gamemaker. GMmodelfix repairs this problem but that makes it useless to use the script in the first place… I’m using gamemaker version 1.2.1130 and blender version 2.74.

  • SuitMeUpRed says:

    I tried the script but this 3d is really new to me..
    After i load my object, do i have to draw it (i probably do i mean it’s invisible), and if so, how?

    Sorry for my dumb comment!
    Thanks in advance <3

  • Jordan Vigay says:

    This is so awesome, been using it for ages and it works great, only criticism (and i don’t know if this can be fixed) is that it splits all the faces into triangles and messes up the gamemaker built in lighting, which works per face

  • Installing the script appears to work fine, but when I try to export I get this error: https://i.imgur.com/yVVuOdd.png

    (Using Blender 2.79b. Has something changed?)

    I really hope someone can help me resolve this, it looks like it can save me a lot of time.

  • Christopher M Rosa says:

    How do you even download this fucking addon

  • Christian Price says:

    I was wondering if it’s possible to import a game maker model into blender? Each time I try to do it a get an error reading “Report: Undefined type| Finish importing”

    • Martin says:

      Hi Christian – sorry for the extremely late reply. You could do this, but you’d have to write a plugin for Blender that would import the model (or one for GameMaker that exports it).

      The data is all there, it just needs to be converted to a format that Blender can read!

  • Daniel says:

    I am having issues with the normals using this exporter. Even if i just create a simple cube the normals are all over the place, not even just on the wrong side, but even faces with the same orientation having different normals. Is there a way to fix this, I have been comparing my attempts to the default game maker cube but it doesnt work with lighting.

    Thanks in advance!

    • Daniel says:

      Oh and i should maybe add that using edgespit has a weird effect, basically if i have a sun in GM shining top down (birds eye perspective) it appears that the top edge of the models are lit (e.g. not the ones facing the camera, but the ones actually facing upwards). Might be a Y/Z translation issue somewhere.

  • condealeAle says:

    Hi, any update about the script?

  • Lolar says:

    Please add support for the latest blender. Thanks!

1 Trackback or Pingback

Leave a Reply to Erdrick The Hero Cancel reply

Note: Your name will appear alongside your comment. Your email address will not be published. Comments that include links will need to be manually approved before they appear on the page.