I’m discovering how procedural mesh generation works with Godot and I can’t modify a mesh without having to remove all the surfaces, modify them and then put them back.
Is this normal operation or is it possible to just add vertices and indexes of triangles without having to rebuild everything each time?
For example, I have a curve to which I add points as I move along it. I draw a line (Mesh.PrimitiveType.LineStrip) to visualize the curve and add points as I go. can’t I just add the new vertices without having to copy the surface, modify it, call “ClearSurfaces()” and then “AddSurfaceFromArrays(Mesh.PrimitiveType.LineStrip, modifiedSurface)”?
This example is relatively inexpensive and works very well, but I will soon tackle more complex geometries and I would like to start by understanding what is possible and what is not.
I’m not complaining, I’m just trying to understand the limitations in order to adapt my code accordingly and be as optimized as possible. And I may have missed something while digging through the documentation and doing my tests.
The RenderingServer API has specific functions to update an attribute/skin/vertex region of a mesh instead of the entire mesh. That is a very advanced use as you need to provide the correct stride in the byte array but it is an option.
That only goes for updates on an already created surface with its fixed size. If you need to change the size of the mesh all the rendering arrays need to be resized so at that point you really can just clear the surface and do it from scratch.
I have already gone through the documentation extensively and looked at all the accessible methods, but the explanations are not always clear or not precise enough for certain scenarios.
But the link may be useful to those who pass here without reading the doc first.
After some reflexion and research I think the method "RenderingServer.MeshSurfaceUpdateVertexRegion would be usefull in my case to have a fixed number of vertexs and triangle indexes and just changing their values without having to clear and recreate all the surface?
But the source code is totally alien to me when the implementation say :
public static void MeshSurfaceUpdateVertexRegion(
Rid mesh,
int surface,
int offset,
byte data)
{
NativeCalls.godot_icall_4_898(RenderingServer.MethodBind57, GodotObject.GetPtr((GodotObject) RenderingServer.Singleton), mesh, surface, offset, data);
}
I understand that “MethodBind57” is some sort of method pointer but I don’t know how to find what it point to, to read the code of that method.
I’m using C# by the way but I understand C++ if I have to read the source code in that langage.
is there a place where I can learn how to use this kind of functions ?
I have to change the Vector3 values of the vertexs and the indexes of the triangles.
The idea is to procedurally generate a mesh along a curve and replace old parts by new one so the new vertexs wil be triangulated with the previously modified region etc…
what bugs me is how can I get or create the byte data and does this function only update the position of vertexs or the data contains all the attributes like color, normals, etc ?
I will continue searching but if you can enlight me I will be very gratfull.
If you convert a C# function name to snake_case you get 99% of the time the GDScript or C++ function name that you can search in the docs or source code.
The byte array that you need to create for the mesh region update is basically a sliced mesh array of what you use for the mesh surface creation just for that stride section that you want to update on the mesh.