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

Alternate mesh quad diagonals for symmetrical grid #421

Open
Radivarig opened this issue Jul 16, 2024 · 2 comments
Open

Alternate mesh quad diagonals for symmetrical grid #421

Radivarig opened this issue Jul 16, 2024 · 2 comments
Labels
enhancement New feature or request idea Just an idea, may or may not be implemented
Milestone

Comments

@Radivarig
Copy link

Description

Alternating diagonals would allow symmetrical deformations and reduce the zigzag triangle spikes.

terrain_alternating_quad_diagonals

@tool
extends MeshInstance3D

@export_group("Click to generate")
@export var generate: bool:
    set(value):
        if value:
            _generate_grid()

@export var size = Vector2i(10, 10)

func _ready():
    _generate_grid()

func _generate_grid():
    if mesh:
        mesh = null

    var immediate_mesh = ImmediateMesh.new()
    immediate_mesh.surface_begin(Mesh.PRIMITIVE_TRIANGLES)

    for x in range(size.x):
        for y in range(size.y):
            var top_left = Vector3(x, 0, y + 1)
            var top_right = Vector3(x + 1, 0, y + 1)
            var bottom_left = Vector3(x, 0, y)
            var bottom_right = Vector3(x + 1, 0, y)

            if (x + y) % 2 == 0:
                immediate_mesh.surface_add_vertex(bottom_left)
                immediate_mesh.surface_add_vertex(top_right)
                immediate_mesh.surface_add_vertex(top_left)
                
                immediate_mesh.surface_add_vertex(bottom_left)
                immediate_mesh.surface_add_vertex(bottom_right)
                immediate_mesh.surface_add_vertex(top_right)
            else:
                immediate_mesh.surface_add_vertex(bottom_left)
                immediate_mesh.surface_add_vertex(bottom_right)
                immediate_mesh.surface_add_vertex(top_left)
                
                immediate_mesh.surface_add_vertex(top_left)
                immediate_mesh.surface_add_vertex(bottom_right)
                immediate_mesh.surface_add_vertex(top_right)

    immediate_mesh.surface_end()
    mesh = immediate_mesh
@TokisanGames
Copy link
Owner

TokisanGames commented Jul 16, 2024

Collision works using a HeightMapShape. The mesh is perfectly aligned with the collision shape. Your suggestion, as is, will make the collision shape and mesh be out of alignment pretty much everywhere between vertices except on flat areas. We would have to generate our own collision shape. If we did it would be after #278.

Also I intend to experiment with triangle strips and a meshless terrain. I don't believe that pattern can be made with them.

Another solution might be #228 tessellation and/or non-uniform lods. Though I do see Witcher3 uses a symmetric grid.

@TokisanGames TokisanGames added the idea Just an idea, may or may not be implemented label Jul 16, 2024
@TokisanGames TokisanGames added this to the Future milestone Jul 16, 2024
@Radivarig
Copy link
Author

Custom collisions sound great especially with a radius where chunks would spawn.

Another example is WoW terrain using the symmetric grid.

WoW symmetric grid

@TokisanGames TokisanGames added the enhancement New feature or request label Jul 26, 2024
@TokisanGames TokisanGames changed the title [Feature Request] Alternating mesh quad diagonals for symmetrical grid Alternate mesh quad diagonals for symmetrical grid Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request idea Just an idea, may or may not be implemented
Projects
Status: Future Ideas
Development

No branches or pull requests

2 participants