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

Planet terrain #278

Merged

Conversation

Capital-Asterisk
Copy link
Contributor

@Capital-Asterisk Capital-Asterisk commented May 9, 2024

This PR works on the incomplete planet terrain generator 'planeta' in src/planet-a.

Planet terrain is created by first managing a "Skeleton." The Skeleton is a triangle mesh that uses int64 coordinates, able to represent large planets. Each triangle is subdividable into 4 more triangles (triforce style), forming a quad tree of triangles (vertices are shared and handled accordingly).

High detail triangle grid meshes (called 'chunks') can then be created, copying coordinated from the skeleton triangles. This can be used for rendering or physics colliders. This is currently not yet implemented.

Certain invariants constrain the skeleton in such a way that generated meshes are completely closed and seamless (a manifold mesh). This allows it to work well with vertex shaders with displacement, such as ocean waves.

I'm thinking of making an infographic as part of the docs, to help describe some of the inner workings.

Terrain test scenario

New test scenario! This uses the existing camera controls to move around a 3D scene, containing a single 'planet' which subdivides and increases in detail when close to the camera's target (the green wireframe cube). A chunk mesh of the entire planet is managed in the background (there's no code that sends it to the GPU yet). Every 10 seconds, The mesh is exported is exported as an .obj file to the current directory, where it can be viewed with 3d modelling software like Blender.

Important non-planet related changes:

  • Add ArrayView2DWrapper - wraps an ArrayView for a cleaner interface
  • Add has_value member function for StrongID
  • Add id_utils.h - MaybeNewId and RefCountStatus
  • Add math_int64.h - some generic int64-related math functions
  • Add minimum distance variable to CameraController
  • Fix horrible bug related to drawing materials - there was an std::vector that just kept growing non-stop

🐦 --- 🌐

fun fact: The 'a' in planet-a refers to it being the first planet implementation, as if there was going to be a 'b'. The letter was never incremented even after a major rewrite. It might as well just be "planeta" as the Spanish or Filipino word for planet.

# Conflicts:
#	src/planet-a/SubdivTriangleMesh.cpp
#	src/planet-a/icosahedron.cpp
#	src/testapp/sessions/vehicles_machines.cpp
src/osp/core/id_utils.h Fixed Show fixed Hide fixed
src/planet-a/chunk_utils.h Fixed Show fixed Hide fixed
src/planet-a/chunk_utils.h Fixed Show fixed Hide fixed
src/planet-a/skeleton.h Fixed Show fixed Hide fixed
src/planet-a/skeleton.h Fixed Show fixed Hide fixed
src/planet-a/skeleton.h Fixed Show fixed Hide fixed
src/planet-a/skeleton_subdiv.h Fixed Show fixed Hide fixed
src/planet-a/skeleton_subdiv.h Fixed Show fixed Hide fixed
src/planet-a/skeleton_subdiv.h Fixed Show fixed Hide fixed
src/testapp/sessions/terrain.h Fixed Show fixed Hide fixed
src/planet-a/chunk_generate.cpp Fixed Show fixed Hide fixed
src/planet-a/skeleton.cpp Fixed Show fixed Hide fixed
}

/**
* @brief Anger the address sanitizer for invalid array views / spans / similar containers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to make the address sanitizer mad on purpose?

What were you using this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's cases where I had an array view that exists, and I wanted to assert that it points to valid memory. There's no uses of it right now, but at the time it was actually quite helpful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting.

In windows there's actually a OS api to let you explicitly check that at runtime.

No idea how to go about doing it in linux though.

src/osp/core/math_int64.h Outdated Show resolved Hide resolved
print("inline constexpr std::array<float, 10> const gc_icoTowerOverHorizonVsSubdiv\n"
+ "{\n"
+ " " + ", ".join(nstr_float(edge_length) for edge_length in tower_heights) + "\n"
+ "};\n")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting the existence of this python script. The icosahedron stuff here use to be calculated at runtime, but only with doubles and implementation-defined std::sqrt. Precalculating all this with much much higher precision is a far more practical

@Capital-Asterisk Capital-Asterisk marked this pull request as ready for review May 17, 2024 01:36
@Capital-Asterisk
Copy link
Contributor Author

@Capital-Asterisk Capital-Asterisk merged commit a5c4ea4 into TheOpenSpaceProgram:master May 22, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants