|
|
@@ -0,0 +1,72 @@ |
|
|
|
use cgmath::Vector3; |
|
|
|
use gdnative::api::OpenSimplexNoise; |
|
|
|
use gdnative::prelude::*; |
|
|
|
use std::collections::HashMap; |
|
|
|
|
|
|
|
// structure to represent the point data generator class |
|
|
|
#[derive(NativeClass)] |
|
|
|
#[inherit(Node)] |
|
|
|
pub struct PointGenerator { |
|
|
|
// exported fields |
|
|
|
#[property] |
|
|
|
pub width: i64, |
|
|
|
#[property] |
|
|
|
pub height: i64, |
|
|
|
#[property] |
|
|
|
pub depth: i64, |
|
|
|
#[property] |
|
|
|
pub noise_seed: i64, |
|
|
|
#[property] |
|
|
|
pub noise_octaves: i64, |
|
|
|
#[property] |
|
|
|
pub noise_peroid: f64, |
|
|
|
#[property] |
|
|
|
pub noise_persistence: f64, |
|
|
|
|
|
|
|
// internal fields |
|
|
|
_point_map: HashMap<Vector3<i64>, f64>, |
|
|
|
} |
|
|
|
|
|
|
|
#[methods] |
|
|
|
impl PointGenerator { |
|
|
|
// basic constructor |
|
|
|
fn new(_owner: &Node) -> Self { |
|
|
|
PointGenerator { |
|
|
|
// exported fields |
|
|
|
width: 0, |
|
|
|
height: 0, |
|
|
|
depth: 0, |
|
|
|
noise_seed: 691337420, |
|
|
|
noise_octaves: 4, |
|
|
|
noise_peroid: 20.0, |
|
|
|
noise_persistence: 0.8, |
|
|
|
// internal fields |
|
|
|
_point_map: HashMap::new(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn generate_points(&mut self) { |
|
|
|
let rng = OpenSimplexNoise::new(); |
|
|
|
|
|
|
|
rng.set_seed(self.noise_seed); |
|
|
|
rng.set_octaves(self.noise_octaves); |
|
|
|
rng.set_period(self.noise_peroid); |
|
|
|
rng.set_persistence(self.noise_persistence); |
|
|
|
|
|
|
|
for x in 0..(self.width) { |
|
|
|
for z in 0..(self.depth) { |
|
|
|
for y in 0..(self.height) { |
|
|
|
let noise_value = rng.get_noise_3d(x as f64, y as f64, z as f64); |
|
|
|
self._point_map.insert(Vector3::new(x, y, z), noise_value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// called on the node being instatiated |
|
|
|
#[export] |
|
|
|
fn _ready(&mut self, _owner: &Node) { |
|
|
|
self.generate_points(); |
|
|
|
godot_print!("generated points"); |
|
|
|
} |
|
|
|
} |