P
Pixelrobin
Guest
NOTE: This is for the BETA version of GMS 2, and things might change over time. Also, the script is not at all finished yet, but usable under certain circumstances. I will be uploading new versions and editing this post to accommodate them accordingly.
NOTE 2: I am considering making some stuff for the marketplace at a small price at one point... more deatils later I guess.
NOTE 2: I am considering making some stuff for the marketplace at a small price at one point... more deatils later I guess.
Thanks to Michael's post, I was able to take Martin Crownover's script and edit it to make some progress on a script to export 3D models from Blender for use in Gamemaker Studio 2. I thought I would release it early so people can mess around with it and offer feedback as development continues.
Currently, as 3D models or included files aren't supported, this exports a txt file as a script. You will need to open the file and copy/paste the contents in a new script within your project. Also, vertex colors and custom properties aren't supported yet either, it just defaults to white.
Downloads
Blender plugin script
Example GMS2 project
Installation and Exporting
First and foremost, I highly recommend reading Michael's guide mentioned above. This assumes that you have complete knowledge of what was written there. This also assumes you're familiar with blender and it's interface. Then, follow the guide on Martin's blog mentioned above to install the plugin into blender and export to a Gamemaker script. Things from there are pretty much the same here. However, there are a few things to note:
- I added the export option to flip z coords for use when the Camera's up vector is (0, 0, 1). If you are following Michael's guide, leave this on.
- The "alternate script format" export option is currently broken, don't use it. I need to figure out how to edit a vertex buffer after creating it initially.
- I added the export option to flip z coords for use when the Camera's up vector is (0, 0, 1). If you are following Michael's guide, leave this on.
- The "alternate script format" export option is currently broken, don't use it. I need to figure out how to edit a vertex buffer after creating it initially.
Using this in your game
I assume you know what the code is doing in these steps, if not, read Michael's guide.
1. Remember not to use the alternate script format option yet. Uncheck it if it is checked.
2. Create a script called 'model' and copy the contents of the exported file into it.
3. If you have a texture and a model with uv mapping, create a sprite with it called 'spr_texture'
3. Create an object called obj_model, use the following code in the create event:
4. In the same object, put this code in the draw event, if you don't have a texture and didn't create a sprite texture, replace 'sprite_get_texture( spr_texture, 0 )' with '-1'
5. Follow Michael's guide to setup the 3D scene and camera, (Step 1 in that post) and set up matrices to transform your models (Step 3).
If you followed everything correctly, you should see your shiny 3D model in your game. If you don't, you might need to reverse the normals or scale it to a size more appropriate for the camera.
1. Remember not to use the alternate script format option yet. Uncheck it if it is checked.
2. Create a script called 'model' and copy the contents of the exported file into it.
3. If you have a texture and a model with uv mapping, create a sprite with it called 'spr_texture'
3. Create an object called obj_model, use the following code in the create event:
Code:
// Create the format
// MAKE SURE THIS IS IN THE SAME ORDER!!
// I will add support for other orders and custom attributes later
vertex_format_begin();
vertex_format_add_position_3d();
vertex_format_add_normal();
vertex_format_add_color();
vertex_format_add_textcoord();
format = vertex_format_end();
// Create the vertex buffer using the script 'model' and store it in the variable 'v_buffer'
v_buffer = model( format );
Code:
// Draw the buffer
vertex_submit( v_buffer, pr_trianglelist, sprite_get_texture( spr_texture, 0 ) );
If you followed everything correctly, you should see your shiny 3D model in your game. If you don't, you might need to reverse the normals or scale it to a size more appropriate for the camera.
Changelog
11/20: Initial post
I'm willing to help with questions below if you have any! I will make a better guide later too. I need to sleep for now.
Last edited by a moderator: