Coder Social home page Coder Social logo

blender-to-gmstudio / blender-gms-vtx-buffer Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 2.0 170 KB

Generic Blender exporter for GameMaker that exports highly customizable vertex formats

Home Page: https://github.com/bartteunis/blender-gms-vbx

Python 100.00%
blender python gamemaker-studio-2 blender-addon gamemaker

blender-gms-vtx-buffer's Introduction

Blender to GameMaker Vertex Buffer Exporter

This exporter can be used to export all kinds of vertex formats.

Description

  • Generates a file with vertex buffer contents
  • Applies transforms & modifiers
  • Generates an accompanying JSON file that describes all exported content
  • Features:
    • Customizable vertex format, allowing for:
      • Static geometry batches
      • Dynamic geometry batches (mesh data + offset per mesh/object in json file)
      • Batched morphs
    • Morphs & per-frame stuff, including interpolation
    • Basic export of any material/shader properties

Installing the plugin in Blender

  • In Blender, go to Edit > Preferences
  • Go to tab Add-ons and select Install from File...
  • Select the zip file blender-gms-vtx-buffer-v1.0.13.zip and confirm (the filename will be different for another version of the exporter)
  • Tick the checkbox next to Import-Export: Export GameMaker Vertex Buffer
  • Click Save User Settings
  • The plugin is now ready to be used

Installing presets

Preset files are Python files (.py) that contain an operator preset's code. These files need to placed in the right directory for the operator to detect them. To install a new preset:

  • Navigate to %USERPROFILE%\AppData\Roaming\Blender Foundation\Blender\2.82\scripts\presets\operator
  • Create a new directory with the name export_scene.gms_vtx_buffer. This is the bl_idname of the operator.
  • Place the preset file in this directory The included presets can be installed from the add-on's preferences

Usage

In Blender

  • Select one or more objects that you want to export
  • Export using an existing export preset or create your own configuration

In GameMaker

  • Load the file as a buffer using buffer_load.
  • Define the vertex format, either in the code editor or load it from the JON file.
  • Create a vertex buffer from the buffer using the created vertex format.
  • Create a shader with vertex attributes that correspond to the vertex format.
  • Draw the model using the shader.

To export the vertex format, tick Export Object Data. This generates an additional .json file which contains a description of the vertex format. The format description can be found under the key blmod/mesh_data/format.

The add-on does not currently come with any code for GameMaker. Many examples will be added to and explained in the wiki.

Advanced

More info and examples can be found in the wiki: https://github.com/blender-to-gmstudio/blender-gms-vtx-buffer/wiki

Creating vertex formats

See the wiki on defining vertex formats.

blender-gms-vtx-buffer's People

Contributors

bartteunis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

blender-gms-vtx-buffer's Issues

Error on exporting via the Python console

line 177, in export
    for i, obj in enumerate(mesh_selection): obj.batch_index = i   # Guarantee a predictable batch index
AttributeError: 'Object' object has no attribute 'batch_index'

This occurred with this call:
bpy.ops.export_scene.gms_vtx_buffer(filepath="C:/Users/bart_/Desktop/test.vbx",selection_only=True,vertex_format=[],reverse_loop=True,export_mesh_data=True,export_json_data=False,export_images=False)

Export to glTF format?

The file format currently in use by the exporter looks a lot like glTF.
It'd be a good thing to standardize this exporter's format further to be prepared for the future.
There is no use keeping a custom file "json+binary" format when an industry standard exists.
Only the contents of the JSON file will need to be modified. The binary data remains the same.

Although this isn't high on the priority list, it's definitely something to seriously consider.

Fix vertex color export

It appears that vertex colors in Blender might now stored in a different property, since a recent release.
Find out if anything needs to be changed in the exporter and change it if that is the case.

Add an option to export a header/footer that can store a bit of metadata

  • Will allow for some 'MESH' object metadata to be written to file in a structured format
  • The export of the header/footer should make use of the same features/functions that are used by the vertex attribute export (e.g. define format and pre-processing function)
  • Important things to consider are, for example, len(mesh.vertices); If the model is first triangulated then this should write the final number of vertices after triangulation.
  • Add a nice panel on the exporter's file properties that makes it easy to set up this header/footer and that makes it possible to include this info in export presets. Layout should be similar to the vertex format attribute list.
  • This will allow basic support for BBMOD: at least BBMOD_Mesh and potentially BBMOD_Model
  • It will likely also allow basic support for SMF (no animation)

Change file browser file filter when setting a different extension

With the new custom file extension setting it is now possible to export mesh data to file names with a different extension. This isn't reflected in the file filter.

Figure out a way to change the file filter upon changing the custom file extension export option.

Automatically install export presets on install of the add-on

If you currently want to install export presets you first have to navigate to %APPDATA%\Blender Foundation\Blender\3.4\scripts\presets\operator\export_scene.gms_vtx_buffer, which means installing presets is something fully manual.

Ideally this works without any need for the user to navigate to that folder. Include some setting or button in the addon's preferences to enable a quick and easy installation to the included presets.

Rework completely for Blender 2.8 using packages

The existing Blender plugins have a nice file structure, using python packages.
With that, it appears that the nested class approach is not the right one.

Rework the code completely.

Examples can be found in obj, fbx, ... importers and exporters.

Blender 4 compatibility

Check if there have been any changes to Blender's bpy API and change what's needed/required.

"Current" frame always exports the animation's start frame

Ideally selecting "Current" frame should export the frame that is currently active (bpy.context.scene.frame_current).
"All" should export all frames, either from the start frame or from the current frame (and then wrap from end frame to start frame). It could be an option whether to use the current frame or the start frame.

Truncate return value of conversion function to format length

As an example, Material.diffuse_color has 4 components.
Drop the alpha component if format string is 'fff' or 'BBB'
Same for positions, keep (x, y) if format string is 'ff' or 'BB' or 'ii'.
Etc. etc.

The way it works now is not intuitive at all and also crashes the exporter.

Support collection instances (recursively)

Add support for collection instances in the exporter, possibly as an export option. All meshlike items inside the collection instance should be added to the list of meshes to export and transformed if Apply Transforms is enabled.
This should make it substantially easier to export large world models that have collection instances in them. Important to treat every individual collection instance as a single entity (i.e. for purposes of batch export).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.