#Converting from Unity to Godot - Mesh Generation

1 messages · Page 1 of 1 (latest)

stoic umbra
#

Hi! I am trying to implement my own terrain generation system that I can shape to my liking, and am following a tutorial to lay out the mesh generation part of the system. However, the tutorial I want to use is designed for Unity. I have been able to convert it pretty well so far, however I don't have much experience with Godot's tools for creating meshes. What would be the best way to convert this function to GDscript? I know I am probably creating an Arraymesh, and that this will go into a MeshInstance, but I am not sure where to go from there.

dusky pond
#

The ArrayMesh API functions are for procedural mesh creation. You can do everything with them manually. The class documentation has also basic script examples how to do it. For the very basic mesh you only need the Mesh.ARRAY_VERTEX populated. Everything else is just "common knowledge" of mesh creation that you can look up on the internet so has mostly no specific documentation in Godot. You still will find plenty of script examples online for Godot or also can look at the source code for the importers and mesh related classes that uses the same under the hood. They all call the add_surface_from_arrays() function that you can search for.

#

The SurfaceTool class is a helper that has convenience functions to create meshes and converts the input later to an ArrayMesh. E.g. it has functions to calculate normals or tangents, or do indexing or optimize the vertex order for caches, if you dont want to do all this manually. E.g. to replace the Unity mesh.RecalculateNormals() you would use the SurfaceTool generate normals and tangents functions instead.

#

The MeshDataTool also exists but is just a wrapper when for some reasons people dont want to work with direct ArrayMesh arrays. It is not very useful outside of that as you can do everything with the ArrayMesh the same way and sometimes also far more efficient.

stoic umbra
#

Ok I got the mesh to generate with a surface tool so can spit out its own normals. However, it doesn't respond to lighting properly? Shown is a marching cube sphere next to a smaller, normal sphere. For some reason the marching cube mesh's response to light is inverted?