Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge/batch different meshes at import-time #901

Open
Zireael07 opened this issue May 26, 2020 · 13 comments
Open

Merge/batch different meshes at import-time #901

Zireael07 opened this issue May 26, 2020 · 13 comments

Comments

@Zireael07
Copy link

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: godotengine/godot#7844

@fire
Copy link
Member

fire commented May 26, 2020

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
Copy link
Author

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
Copy link
Member

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

@fire
Copy link
Member

fire commented May 26, 2020

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
Copy link
Author

Zireael07 commented May 26, 2020

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
Copy link
Member

fire commented May 26, 2020

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
Copy link
Member

fire commented May 26, 2020

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
Copy link

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
Copy link

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

@Calinou Calinou changed the title Merge/batch meshes Merge/batch different meshes at import-time Dec 1, 2020
@lawnjelly
Copy link
Member

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

@Zireael07
Copy link
Author

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
Copy link
Member

fire commented Jan 5, 2022

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

@lawnjelly
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants