Hello. I have implemented the algorithm and the shape drawing works fine. But I have no idea how to calculate the normals and UVs for each mesh. Current grid test is very unoptimized, I quickly made it for getting the textures to work. I'd appreciate any help
#Marching Cubes surface UVs and normals
16 messages · Page 1 of 1 (latest)
Thanks for sharing your code but how to run it? Main scene is not set and running grid_debug gives errors.
Awesome cube_debug 🙂
It's only supposed to work in the editor
How? AKA what should I do?
Just open either cube_debug or grid_debug scenes and change the configuration in the inspector. The cube's active vertices property controls the resulting surface
Got it 😮
I have used these stackoverflow results with my code combined in chatgpt but the resulting code didn't work. I'm confused by what they mean by "adjacent faces"
https://gamedev.stackexchange.com/a/97716
https://stackoverflow.com/a/8705469
Reading https://docs.godotengine.org/en/4.0/tutorials/3d/procedural_geometry/immediatemesh.html you have to add uv and normals before.
I see weird planes so am not sure what you need.
[edit]: your first link You can calculate normals if you have a (real) triangle by cross product (p1-p0) x (p2-p1) no?
Godot Engine documentation
Unlike the SurfaceTool or ArrayMesh, ImmediateMesh is an actual node. Being a node makes it quick to add to a scene and get visual output. It uses an OpenGL 1.x-style API like SurfaceTool, but it's...
that configuration should look like this, not sure why it's messed up on your end 😅
about the stackoverflow, what's the face's normal? Is it pointing out of the cube?
First try at calculating the normals, I get wrong result as the normal is not pointing at the correct direction
https://github.com/difof/MarchingCubesExample/blob/master/marching_cube.gd#L40
Sorry my algebra is a bit weak
That stackoverflow answer says use the normalized average normals of adjacent faces. Since for each vertex there's always two adjacent faces, I just divide the midpoint by 2 and normalize that. But it's not correct, not sure what's off

Second link partly
What is the idea ... marching cubes has triangles .. do you have some link showing the purpose?
In https://docs.godotengine.org/en/4.0/tutorials/3d/procedural_geometry/surfacetool.html they make a triangle ... can you make a debug from that? You can then use:
st.generate_normals()
st.generate_tangents()
to see it matches your expectation?
Godot Engine documentation
The SurfaceTool provides a useful interface for constructing geometry. The interface is similar to the ImmediateMesh node. You set each per-vertex attribute (e.g. normal, uv, color) and then when y...
In this coding adventure I try to understand marching cubes, and then use it to construct an endless underwater world.
If you'd like to support this channel, please consider becoming a patron here:
https://www.patreon.com/SebastianLague
Project files:
https://github.com/SebLague/Marching-Cubes
Learning resources:
http://paulbourke.net/geometr...