Welcome to TerraForge, a Rust-based terrain engine designed for high-performance and scalable terrain generation and manipulation. TerraForge leverages advanced algorithms and parallel processing to generate and triangulate vast terrains efficiently.
TerraForge is built to handle large-scale terrain generation using a Fibonacci sphere algorithm for point distribution and Delaunay triangulation for mesh generation. It is optimized for performance with multi-threaded processing, making it suitable for real-time applications and large datasets.
To use TerraForge, you need to have Rust installed. You can add TerraForge to your project by including it in your Cargo.toml
file:
[dependencies]
spade = "1.9.2" # Add the spade library for Delaunay triangulation
terraforge = { git = "https://github.com/yourusername/terraforge.git" } # Replace with your repo URL
TerraForge provides a function to perform Delaunay triangulation on a set of 3D points. The triangulation function projects the points onto a 2D plane for processing.
use terraforge::perform_triangulation;
fn main() {
let points = vec![
(0.0, 0.0, 0.0),
(1.0, 0.0, 0.0),
(0.0, 1.0, 0.0),
(1.0, 1.0, 0.0),
];
match perform_triangulation(points) {
Ok(triangulation) => println!("Triangulation successful!"),
Err(e) => println!("Error during triangulation: {:?}", e),
}
}
TerraForge includes a function to generate points on a sphere using the Fibonacci lattice method. This is useful for creating evenly distributed points over a spherical surface, ideal for terrain generation on planetary scales.
use terraforge::generate_fibonacci_sphere;
fn main() {
let num_samples = 1000;
let min_latitude = -90.0;
let max_latitude = 90.0;
let min_longitude = -180.0;
let max_longitude = 180.0;
let seed = 0.5;
match generate_fibonacci_sphere(num_samples, min_latitude, max_latitude, min_longitude, max_longitude, seed) {
Ok(points) => {
println!("Generated points:");
for point in points {
println!("{:?}", point);
}
},
Err(e) => println!("Error generating points: {:?}", e),
}
}
We welcome contributions to TerraForge! Whether it's reporting bugs, improving documentation, or contributing code, your help is appreciated.
Please ensure your code adheres to the existing style and passes all tests.
TerraForge is licensed under the MIT License. See the LICENSE file for more details.
Thank you for using TerraForge! If you have any questions or feedback, feel free to open an issue on our GitHub repository.
This Rust library generates evenly spaced Voronoi diagrams on a sphere using the Fibonacci spiral method. It's designed to create hexagon-like regions of nearly uniform size across the surface of a sphere, which can be useful for various applications such as planet generation, geographic data analysis, or spherical tessellation.
The library uses the following key concepts:
The library is implemented in Rust and uses the following main components:
fibonacci_point
: Generates a single point on the Fibonacci spiral.generate_fibonacci_sphere
: Creates a set of points distributed on a sphere using the Fibonacci spiral method.create_spherical_voronoi
: Constructs the Voronoi diagram from the generated points.stereographic_projection
and inverse_stereographic_projection
: Handle the mapping between 3D spherical coordinates and 2D planar coordinates.calculate_spherical_circumcenter
: Computes the center of a spherical triangle, used for Voronoi cell centers.print_voronoi_edges
: Outputs the Voronoi diagram edges for visualization.To use this library in your Rust project:
Cargo.toml
:[dependencies]
spherical_voronoi = { git = "https://github.com/yourusername/spherical_voronoi.git" }
use spherical_voronoi::{generate_fibonacci_sphere, create_spherical_voronoi, print_voronoi_edges};
fn main() -> std::io::Result<()> {
let num_samples = 1000;
let jitter = 0.1;
let points = generate_fibonacci_sphere(num_samples, jitter)?;
let triangulation = create_spherical_voronoi(points);
print_voronoi_edges(&triangulation)?;
println!("Voronoi edges have been written to voronoi_edges.txt");
Ok(())
}
This will generate a set of points on a sphere, create a Voronoi diagram, and write the edges to a file named voronoi_edges.txt
in a format suitable for visualization in tools such as Unreal Engine.
You can adjust the following parameters to customize the output:
num_samples
: Increase for more detailed tessellation (more Voronoi cells).jitter
: Adjust between 0.0 and 1.0 to control the randomness of point placement.The library generates two files:
output.txt
: Contains the list of generated points and the time taken to generate them.voronoi_edges.txt
: Contains the edges of the Voronoi diagram in a format suitable for visualization.This library depends on the following Rust crates:
spade
: For Delaunay triangulationrand
: For random number generationrayon
: For parallel processingEnsure these dependencies are included in your Cargo.toml
file.
[dependencies]
spade = "1.8.2"
rand = "0.8.5"
rayon = "1.5.1"