Graphics Blender to GameMaker:Studio Exporter

Bart

WiseBart
Blender to GameMaker:Studio Exporter (current release v1.0.5)
Note to the moderators viewing this topic: I spoke with @Nocturne about this and got approval to put it here

Introduction

After quite a few years I am happy to announce the updated version of my Blender exporter add-on that I posted on the old forums. (yeah, it's been a while)
The exporter now works with Blender 2.8 and also has a compatibility version for Blender versions below 2.8 (currently not entirely up-to-date).

This add-on is entirely free to use and I hope it can make life quite a bit easier for anyone who wants to use 3D models from Blender in GameMaker.
At least that's the goal I had when I started developing this for my own use a couple of years ago.

The add-on itself does not come with any code for GameMaker but I'm going to make an extensive example project to show a couple of interesting vertex formats from basic to advanced (passthrough, basic vertex formats, static batches, dynamic batches, morph animations, "tiny" vertex formats, texture atlas/group, ...)
I'm also planning to add documentation to the wiki, although this will be more focused on the Blender side.

Features
  • Highly customizable vertex format: many properties can be added, including tangents, bitangents, all types of normals (vertex, loop and face), vertex group indices, vertex weights, ...
  • Choose the format to write to the buffer and optionally execute a "pre-processing" function to modify the value that's being written.
  • Write interpolated values for attributes up to 1 frame back in time (this could be increased, but it takes a lot of memory) - for e.g. morph animations
  • Presets so you don't have to do that configuration all over again
  • Hopefully a few more in the not too distant future, see the issues list for more info

Importing in GameMaker:Studio

The exporter generates a .vbx file that contains the (vertex) buffer data and a .json file with some additional info on the data.
Both are optional, so you can choose to export vertex buffer data and/or metadata.

The code to import from a file is the following:
GML:
var buffer = buffer_load("vertex_data.vbx");
vertex_buffer = vertex_create_buffer_from_buffer(buffer, vertex_format);
vertex_freeze(vertex_buffer);
You can define the vertex format yourself in gml if you know what format you used to export from Blender.
A description of the vertex format is also added to the .json file.
I currently don't have "standard" gml code to read it. That may get added later.

Example Project

Blender Exporter Examples YYZ

This is an early work in progress. More examples will be added when I find the time.

(To open the .blend file straight from the IDE, right-click and select Open Externally)

Setup
  1. Download the addon as a zip file from the GitHub repository
  2. Open up Blender and navigate to Edit > Preferences
  3. In Preferences, under Add-ons, click Install... and select the zip file (Blender installs addons directly from zip files)
  4. The addon now appears in the list and the only thing left is to tick the checkbox next to the name to enable it in Blender
In the end, it should look like this:



Introduction to defining vertex formats

The main feature of this add-on is the ability to define custom vertex formats.
Since these are quite customizable this can easily get pretty complex.
Because of that, here's a short introduction to this:

The vertex format that the exporter uses is defined under Mesh Data:



The leftmost dropdown allows you to select the source for the data. This can be the vertex, the face, the material, the uv or another property in the list.
The one next to it contains the properties at that source and is updated dynamically. Some types of properties are filtered out, such as strings and enums.
For example, Mesh Vertex contains the following properties:



The next two inputs may not be obvious at first sight.
Fmt defines the format to be written for this property, the full list for that can be found under Format Characters in the Python docs.
When you select the property to be used in the second column this will automatically be updated based on the metadata in Blender.
When one or more asterisks * are shown it means the add-on doesn't know what type to make of it.

You can override this suggestion by replacing it with your own format string.
In practice, you'll probably use one of these:
  • f: a single 32 bit float
  • i: a single signed int (32 bit)
  • ?: a boolean as a byte (perhaps the most confusing one)
The dropdown to the right of the format, Func, allows you to select a "pre-processing" function before the value is converted to binary format.

In the end, basically, per property/per line of the vertex format, the exporter does this:

Get value of property > Pre-processing function if not None > Conversion to format

A couple of functions are provided already but you can add your own to the file conversions.py in the add-on's directory.

The Int input can be changed from 0 to 1 and is the number of frames to go back when exporting multiple frames. It basically means "take the value of this property at index [frame-i]" and allows for interpolation of properties for e.g. morph animations.

Known bugs/Issues/Improvements/Feedback

These can be found under Issues in the repository on GitHub.

If you encounter any bugs, feel free to let me know here or add an issue to the list.

Also any other feedback on this add-on is more than welcome!
 
Last edited:

Bart

WiseBart
Updated the add-on to version 1.0.3 which has a couple of important bugfixes and useability improvements:
  • Vertex colors are now actually included (they could be selected but weren't written)
  • Selection is properly filtered
  • Sequences are now truncated to the length of the format string. So this means you can now e.g. create 2D (x, y) values from a 3D (x, y, z) by simply changing the format from 'fff' to 'ff'. No need to write a custom function for this.
  • Passthrough preset now has reverse looping through triangle indices set by default, since in GM you'll probably invert y. Also, texture uv's v is inverted (1-v).
  • A couple of important bugfixes
The example project is now also up! (currently no GMS 2.3 yet)
It contains the first very basic examples that show how to define and import a variety of vertex formats for static models, including very basic shaders showing how to work with them and the exporter presets used to export them.
 

Bart

WiseBart
Hi! Thanks for trying out the addon.
For some reason I can't open the attachment you posted so can't have a further look at it at the moment.
Could you post it again? Then I'll check to see what's wrong.
 

rayloi

Member
Hi! Thanks for trying out the addon.
For some reason I can't open the attachment you posted so can't have a further look at it at the moment.
Could you post it again? Then I'll check to see what's wrong.
"scripts\addons\blender-gms-vtx-buffer-1.0.4 " not work

rename to" scripts\addons\blender-gms-vtx-buffer "is work

i fixed ;)
 

Attachments

Bart

WiseBart
Ah, alright, nice! But that's an odd one. It shouldn't require fixing in the first place :)
How did you install the add-on? From the zip file?
 

Bart

WiseBart
Ah, you found that one, too :)
The Blender to SMF is a work in progress, animations aren't working properly yet. I'm still looking into that.
But the code is public already so anyone who wants to can use it.
 

Bart

WiseBart
It's on hold at the moment but I plan to resume work on it soon.
The main difficulty with that export are all the coordinate system conversions that need to happen when going from Blender to SMF.
Still waiting for the 'Eureka' moment there.

I can definitely add an animation example to the current example project.
I'll see if I can get it done soon.
 

Bart

WiseBart
Fixed a bug with the triangulation that caused the vertices of triangles in morph animations to jump from one position to another between frames.
The current version of the add-on with this bug fixed is now version 1.0.5.

I also updated the example project with two new examples: dynamic batching and morph animations.
The example project also comes with new presets for the exporter. These can be used as a basis for similar exports (tinier vertex formats, added normals, tangents, bitangents, ...).
 
Last edited:
Top