godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.09k stars 69 forks source link

Merge/batch different meshes at import-time #901

Open Zireael07 opened 4 years ago

Zireael07 commented 4 years ago

Describe the project you are working on: 3d racing game

Describe the problem or limitation you are having in your project: Collada files import as several meshes instead of one.

Describe the feature / enhancement and how it helps to overcome the problem or limitation: An option to merge meshes.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: It could be an import-time switch, but a more generic solution (preferably exposed to GDScript so that I could merge already imported assets/scenes via tool scripts) would also be necessary.

If this enhancement will not be used often, can it be worked around with a few lines of script?: Nope

Is there a reason why this should be core and not an add-on in the asset library?: Import-time switch cannot be done via an add-on. There was an asset that claimed to do the generic kind, but it crashed on Collada imported meshes, it only worked for Godot primitives.

Original issue: https://github.com/godotengine/godot/issues/7844

fire commented 4 years ago

I have a custom_module for this https://github.com/godot-extended-libraries/scene_merge/tree/master. Please review. It's not in the Godot Engine pipeline for submission, but you know how to ping me on Discord.

Zireael07 commented 4 years ago

I didn't consider custom modules, thanks for the ping - IIRC they became easier to use with a very recent PR, didn't they?

aaronfranke commented 4 years ago

Why can't this be done in Blender or another 3D graphics application before creating the collada file?

fire commented 4 years ago

The closest attempts are either proprietary or don’t work.

https://www.rizom-lab.com/ One draw call tech.

https://github.com/Grim-es/material-combiner-addon This doesn’t work.

There is a unity tool to bake avatars to one mesh, but I only have pictures that it exists. Can't find the git repo. It relies on the flattening materials to a square and render via the camera.

Microsoft’ Simplygon and Unreal Engine’s voxel lod tools exist too.

The closest viable project to contribute is Blender’s GPL plugin. I prefer mit for remixing.

My plan is to chain merging -> mesh tri decimation -> export to gltf or fbx inside of Godot. The ui is already being worked on Concept Graph.

https://github.com/HungryProton/concept_graph

The described pipeline works manually.

Thanks

Zireael07 commented 4 years ago

There is a unity tool to bake avatars

In case it wasn't clear, I was thinking of static meshes, not characters.

@fire: Unity has a built-in function: https://docs.unity3d.com/ScriptReference/Mesh.CombineMeshes.html

An open-source asset: https://github.com/mogoson/MeshCombiner (and at least one more on the asset store that I once used, but can't remember the name of)

@aaronfranke: In many cases, the assets are gotten from elsewhere (asset stores, Blender Kit, free sites like turbosquid) and a programmer cannot be expected to know his or her way around Blender (I have used Blender a bit, but I wouldn't even know where to start looking).

fire commented 4 years ago

This is also a requirement for hierarchal lods in Godot Engine. The idea behind that is you combine arbitrary clusters of meshes and then decimate.

This is not needed for lod imposters though.

fire commented 4 years ago

Since this was repeatedly mentioned:

https://github.com/michaeldegroot/cats-blender-plugin/blob/bb382b1028b2ee1f4a49aa4890b6052352db377f/tools/atlas.py#L418

The cats plugin requires you to install https://github.com/Grim-es/material-combiner-addon and I had trouble getting meshes to merge. It might be me though.

pererikbergman commented 4 years ago

I see a need for merge meshes as well. As far as I understand there is only one way to regenerate the NavigationMesh by calling create_from_mesh, but you can only add one mesh. If I dynamically need to generate the level at runtime it would be so good to have this feature.

Lexpartizan commented 4 years ago

I wrote a simple function on a script that can merge the meshinstance array into one. I'm not sure about performance and so on, but it seems to work for simple meshes with one uv, tangents, and vertices. If it would be fast and would be a part of the engine, in C++, perhaps it would make sense to merge static objects for the sake of reducing the number drawcalls. I would like to consult and ask if such a function makes sense for merging into a single collision shapes grid? CombineMeshes.zip

lawnjelly commented 3 years ago

Available at runtime in https://github.com/godotengine/godot/pull/46130. If there's interest I can try and make this available standalone (maybe in a second PR).

Zireael07 commented 3 years ago

A second PR, pretty please? I know the portal occlusion has taken you quite some time so let's not hold it up further...

fire commented 2 years ago

Both #3673 and this #901 are the same. Crosslinking.

lawnjelly commented 2 years ago

Ah forgot this, for basic functionality it just needs binding two existing functions potentially:

bool MeshInstance::is_mergeable_with(const MeshInstance &p_other);
bool MeshInstance::create_by_merging(Vector<MeshInstance *> p_list);

The latter one might need tweaking slightly as the binding requirements for gdscript can be a bit fiddly. These are the functions used in portals for merging meshes. It's pretty basic, and probably not hugely tested, but is a start and can be improved.

If that worked we could look at any UI improvements that could be made to make it easier for users.

I've also currently been banditing this for LOD development so you can do deduplication + simplification + vertex cache optimization at the same time, but that may be better as a separate function call.