godotengine / godot-blender-exporter

Addon for Blender to directly export to a Godot Scene
GNU General Public License v2.0
1.15k stars 123 forks source link

request: option to export to a .mesh file #77

Closed fracteed closed 5 years ago

fracteed commented 6 years ago

First up, this is fantastic work that you guys are doing, much appreciated!

Was wondering if it is possible to get an option to export a mesh from Blender directly to a .mesh file (with uv's, vertex colors and poly selections). It would be a very useful option in several scenarios. I am making a game that uses large sets of .mesh files to procedurally populate my levels. Currently I export to obj and convert this manually to a .mesh file from Godot. Being able to do this directly from Blender would be a massive time saver.

Also, if you are doing a low poly game and texturing via vertex colors all you would need is the .mesh file straight from Blender into Godot, without worrying about any conversion of an .escn file. This can reduce a lot of clutter in a project.

Additionally, when using a texturing workflow between Blender-Substance Painter-Godot, it would be nice to just export a .mesh and obj file from Blender. Then I can texture in Painter using the obj file, export my pbr maps directly into my godot file structure. Then it is just a matter of adding in the .mesh file direct from Blender and I have all I need for a static model. Once again without having an intermediary file format to clutter up my project folder structure (which is important when you start getting hundreds of models piling up in your project).

The .escn approach you are currently using is perfect for exporting large scenes and animated models from Blender, but for single static models (which usually comprises the majority of a game), direct .mesh export would be wonderful!

Jason0214 commented 6 years ago

From the perspective of software, it is not appropriate to have two different outputs for this addon, as all the code are based on the structure of escn file. If .mesh is useful, it is more reasonable to have another addon dedicated to exporting .mesh file (after my quick search on google, it seems there are already several existed ones)

As I don't have much game developing experience, it may be better to have other people take a look at this issue

CC @sdfgeoff

sdfgeoff commented 6 years ago

A quick test shows that .mesh files are binary files (and so aren't something easy to output from this exporter). However, tres files are something that should be relatively easy to create using the code in this exporter.

So, what may be possible is to export the meshes separate files during export (eg as meshname.tres). This could be useful for other resources as well (eg cycles materials), so I'll have a think about how feasible this is. PR's welcome.....


I'm sure you get this a lot (if I recall from other discussions on github), but:

... without having an intermediary file format to clutter up my project folder structure (which is important when you start getting hundreds of models piling up in your project).

Use more folders? Having a "models" folder is (almost always) a terrible idea. Separate levels and characters from your main "core"?

The .escn approach you are currently using is perfect for exporting large scenes and animated models from Blender, but for single static models (which usually comprises the majority of a game), direct .mesh export would be wonderful!

Actually, it works well for single small models as well. In one current project, we have a couple 3d tilesets/kits, each object a different blend file. They are then assembled into a level inside Godot. The collision geometry, materials, etc. are all handled by the exporter, so there is a single escn file per object - no need to assemble the mesh, material and collision geometry from separate resource files by hand.

But I do see that there would be a benefit from exporting some resources separately, particularly when you want to re-use resources across multiple scenes.

fracteed commented 6 years ago

@sdfgeoff thanks for your reply. Sure, export to .tres would be fine as well, if there is a way to do it. There are several instances where it is good to have just the mesh data. As I mentioned earlier I am instancing .mesh files (which could also be .tres) directly into mesh instances via script to create procedural levels. I don't ever deal with these directly in the Godot viewport and they are procedurally textured. Granted, that is possibly a unique usage.

My folder structure is very organised, but I have folders that may have 70 .mesh files for various parts of my city. These are instanced via script, so it makes sense to have related meshes in the one folder. If they also had the intermediary format (escn or obj) plus the .import file you suddenly have 3 times as many files to sift through, when Godot is only really needing its native .mesh file. I guess that some of us still somewhat prefer the old 2.1 workflow where you explicitly convert files into the native Godot formats. Of course there are advantages to the current auto convert method :)

Also, if you are using Substance Painter to do your texturing, the workflow becomes more convoluted. The steps would be: you need to export obj from Blender/import obj and texture in Painter/export maps from Painter/import maps and assemble material in Blender/export escn from Blender/import into Godot.

If you could spit out a .tres file from Blender, the workflow would be... export obj and tres from blender/import obj to Painter/export maps from Painter into Godot/assemble material in Godot using maps and tres file. There also tends to be lots of redoing of textures in Painter, so it is a quick export out of Painter and save over the exisitng maps in Godot.

sdfgeoff commented 6 years ago

I'm a person who likes automation, so I enjoy the fact that I can completely ignore, well, just about everything. So I never work with the escn directly either! I work with blend files, and use a build system to turn them into escn, and godot automatically turns those into it's own format for me. Fantastic: once you've configured the import settings, you can just edit the blend file and forget that godot doesn't work with blend files directly. No need to version control anything except the blend files.

For this reason, the godot-blender-exporter can search for matching existing godot materials, so you don't have to re-assemble the materials in blender or assign them via inherited scene. In our project we have simple placeholder materials in blender (the names have to match). So with my workflow, it would be:

1) Give material in blender a sensible name. 2) Export to obj for substance painter. 3) Create material in godot with same name as the one in blender.

Now, every time you run the build system or export the model from blender, your model inside godot will be assigned the the right material. If you just change the maps, no need to re-export because they're external files anyway.


But hey, that's just different workflows. I don't mean to turn this issue into a workflow discussion, so I will say: I do see there being reasons why you may want to export only certain resources from blender.

The major problem is how to present it to the user. Exporting from blender almost always is a matter of exporting the whole scene, or exporting objects complete with everything. I can't think of a way to present to the user a way to export a mesh (because while an object has a mesh, a mesh is not an object). Similarly for other resources such as materials. How do you "select" what materials to export? Do you just export all of them all the time? Of course, the other option is to export everything to separate files, but then a single blend file would turn into several dozen resources on even a primitive scene.....

fracteed commented 6 years ago

Yeah, workflow tends to be a very personal thing, so I guess I prefer the opposite, in that I like to be very granular and manual with my asset workflow. I like to have total control over what assets go into what folders, naming conventions and how scene hierarchies are setup ,etc. I know it is a slower approach, but it has served me well. Most people probably prefer the automated workflow and there can be a time and place for both approaches.

As mentioned, the main reason I need just the mesh data (currently using .mesh format, but .tres would also work) is that I am instancing in all my meshes via gdscript so I need to have directly access the native Godot mesh formats. Each city and interior can be potentially chosen for hundreds of individual meshes that are in specified folders. It all works well, but the thing that slows me down is having to import into Godot as an obj and then convert to a .mesh file. When I want to edit a file I then have to do this again, which can get tedious.

To put it into perspective, here is a snippet from one of the cities, that is assembled via script from about 80 meshes and procedurally textured (no uv's):

https://www.youtube.com/watch?v=tYCk9pn1QU0

What would be ideal for me is to be able to select a mesh in Blender and in the export tab, just export that single mesh to a .tres file (just the mesh with uvs, poly selections, and vertex colors). I don't need any materials or textures attached.

Admittedly, I got off topic in my previous post with discussion about Substance Painter, since the quickest way is actually just to export a gltf2 file straight out of Painter into Godot. I had gotten used to a specific workflow that existed before Godot and Painter had gltf2 support. Also Godot gltf2 had been a bit buggy (which has probably been rectified), so I just stuck with my obj workflow which has always been solid for me.

reduz commented 6 years ago

You can already tell Godot to generate mesh files as separate files on import, by the way.

Jason0214 commented 5 years ago

As reduz mentioned, when import escn godot, there is options to separate mesh files, so it is solved for now.