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

Add a way to create ArrayMesh from any Mesh resource #2249

Closed
mrjustaguy opened this issue Feb 5, 2021 · 14 comments
Closed

Add a way to create ArrayMesh from any Mesh resource #2249

mrjustaguy opened this issue Feb 5, 2021 · 14 comments

Comments

@mrjustaguy
Copy link

Describe the project you are working on

Implementing my own CSG, as the CSG provided By Godot is Buggy (When I'm done, if it proves to be better (so no more issues like godotengine/godot#43755 and godotengine/godot#41140 and any others), I'll open a Proposal to change the current implementation (as Mine is in GDScript, and I'm not good at C++ so someone would have to do translating) and/or add it to the asset library)

Describe the problem or limitation you are having in your project

CubeMesh, SphereMesh and such cannot be Turned to ArrayMesh that is required to do any sort of mesh manipulation (as well as getting UV2 for Lightmaps done)

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add a Button to turn a mesh into an ArrayMesh if it isn't one already (or isn't empty) much like the collision sibling creation is right now, that way the Primitives can easily be used for any of the ArrayMesh Specific applications.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add Convert to Array Mesh Option and add a way to call that in code

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

Yes, by using blender and exporting the primitives from there, but it's not a very fast and efficient method (compared to just having the option to do the conversion)

Is there a reason why this should be core and not an add-on in the asset library?

It's a Basic function that Godot currently doesn't have, and any addons would probably have to resolve it in some rather hacky ways

@Calinou
Copy link
Member

Calinou commented Feb 5, 2021

I'll open a Proposal to change the current implementation (as Mine is in GDScript, and I'm not good at C++ so someone would have to do translating) and/or add it to the asset library)

The Godot editor can't depend on GDScript code by design. Everything must be written in C++.

I've seen an editor plugin that could convert a CSG selection to a MeshInstance. It should be possible to achieve something similar with a MeshInstance (so you can convert a CubeMesh to an ArrayMesh). This can be done in either GDScript or C++.

@mrjustaguy
Copy link
Author

The Godot editor can't depend on GDScript code by design. Everything must be written in C++.

I know. That's why I said someone would have to Turn my GDScript Algorithms into C++ When I'm Done 😛

But we will get to that when and if/when I get the algorithms fully functional in GDScript and test it against the Currently used Godot Algorithms..

@fire
Copy link
Member

fire commented Feb 5, 2021

This is how I force csg to create a mesh. https://github.com/godotengine/godot/blob/master/modules/gltf/gltf_document.cpp#L5169

@fire
Copy link
Member

fire commented Feb 5, 2021

Do you have this as a project anywhere?

@mrjustaguy
Copy link
Author

My own attempt at implementing CSG? Only on my PC atm... Currently got as far as Separating Triangles that Do intersect with another mesh and those that don't.

@clayjohn
Copy link
Member

clayjohn commented Feb 5, 2021

Is this Proposal concerning CSGMeshes, or PrimitiveMeshes, or both?

Regarding PrimitiveMeshes, I bet we can make them just inherit from ArrayMesh instead of Mesh (and then contain proper UV2 channels as well so they can be used in baked lighting)

@mrjustaguy
Copy link
Author

It's about PrimitiveMeshes, CSG is where i've noticed the issue with the lack of ability to turn CubeMesh and SphereMesh and such into ArrayMesh for editing.

@clayjohn
Copy link
Member

clayjohn commented Feb 5, 2021

In that case, this should be very easy. We should make PrimitiveMeshs inherit from ArrayMesh. It has always bothered me that they are so similar to ArrayMeshs but are completely incompatible. It has caused a lot of confusion for users too.

@clayjohn
Copy link
Member

An update on this. Reduz explained that PrimitveMeshes were designed to be lightweight so they shouldn't inherit all the bulk that comes with the ArrayMesh.

Accordingly (for PrimitiveMeshes) we have two options:

  1. Automatically convert to ArrayMesh when unrwapping UV2s (example here
  2. Add a button to convert to ArrayMesh.

I have already implemented 1, I think it makes more sense. a "Convert to ArrayMesh" button will make no sense if the user is already using an ArrayMesh.

CSGMeshes are a whole other can of worms. I would argue that users are less likely to want to bake lighting for CSG meshes as they need to be dynamic. So I would approach them differently and perhaps add a "Bake Mesh" button that bakes the entire chain of CSG meshes into a single ArrayMesh. However, I can already foresee some problems with this approach like: what do we do about CSG nodes that have scripts attached? Or what if there are physics children to the nodes? You would only be able to bake CSG nodes that only had other CSG nodes as children (or you could choose to throw away everything that can't be baked).

@Zireael07
Copy link

+1 to a bake mesh button on a CSG chain. I have used the script version of this that was posted in one of the issues, multiple times. Anything that isn't a CSG node could just be thrown away (and this behavior called out in the tooltip.

@Calinou
Copy link
Member

Calinou commented Apr 26, 2021

I think it makes sense to provide a Convert to ArrayMesh option for primitive meshes. Maybe there should also be a method to do the same operation at run-time? I don't know if you can currently manipulate primitive meshes on the CPU at run-time (such as moving their vertices, painting their vertex colors and similar).

For CSG, we could do the following:

  • If non-CSG nodes are present when using Convert to ArrayMesh on a CSG node, move them outside the CSG node, create a MeshInstance then put those nodes as a child of the MeshInstance (keeping the initial transforms). This way, if you have nodes like lights and particles inside of your CSG structure, they can be preserved.
  • Allow converting CSG meshes non-destructively. In other words, instead of creating a MeshInstance and removing the CSG node, create a MeshInstance but hide the CSG node instead. This way, further edits can be made by the user by showing the CSG node again, removing the MeshInstance and generating a new MeshInstance non-destructively. We may want to provide two separate buttons for this, since destructive and non-destructive operations have different use cases.

@Calinou Calinou changed the title Add a way to create ArrayMesh from Any Mesh Add a way to create ArrayMesh from any Mesh resource Feb 5, 2022
@Calinou
Copy link
Member

Calinou commented Jul 19, 2023

Now that godotengine/godot#67975 is merged for UV2 on primitive meshes, are there other use cases for converting a PrimitiveMesh to an ArrayMesh?

@mrjustaguy
Copy link
Author

At this point, don't think there is any worth while reasons for this now..

@Calinou
Copy link
Member

Calinou commented Jul 20, 2023

Alright, closing then.

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

5 participants