| @@ -0,0 +1,4 @@ | |||||
| /target | |||||
| Cargo.lock | |||||
| /.import | |||||
| /.mono | |||||
| @@ -0,0 +1,12 @@ | |||||
| [package] | |||||
| name = "marching_cubes" | |||||
| version = "0.1.0" | |||||
| authors = ["Isabelle Lesko <me@izzabelle.dev>"] | |||||
| edition = "2018" | |||||
| [lib] | |||||
| crate-type = ["cdylib"] | |||||
| [dependencies] | |||||
| gdnative = "0.9.3" | |||||
| cgmath = "0.18.0" | |||||
| @@ -0,0 +1,9 @@ | |||||
| [gd_scene load_steps=2 format=2] | |||||
| [ext_resource path="res://PointGenerator.gdns" type="Script" id=1] | |||||
| [node name="RootNode" type="Spatial"] | |||||
| [node name="PointGenerator" type="Node" parent="."] | |||||
| [node name="PointsRoot" type="Spatial" parent="."] | |||||
| @@ -0,0 +1,7 @@ | |||||
| [gd_resource type="Environment" load_steps=2 format=2] | |||||
| [sub_resource type="ProceduralSky" id=1] | |||||
| [resource] | |||||
| background_mode = 2 | |||||
| background_sky = SubResource( 1 ) | |||||
| @@ -0,0 +1,34 @@ | |||||
| [remap] | |||||
| importer="texture" | |||||
| type="StreamTexture" | |||||
| path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" | |||||
| metadata={ | |||||
| "vram_texture": false | |||||
| } | |||||
| [deps] | |||||
| source_file="res://icon.png" | |||||
| dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] | |||||
| [params] | |||||
| compress/mode=0 | |||||
| compress/lossy_quality=0.7 | |||||
| compress/hdr_mode=0 | |||||
| compress/bptc_ldr=0 | |||||
| compress/normal_map=0 | |||||
| flags/repeat=0 | |||||
| flags/filter=true | |||||
| flags/mipmaps=false | |||||
| flags/anisotropic=false | |||||
| flags/srgb=2 | |||||
| process/fix_alpha_border=true | |||||
| process/premult_alpha=false | |||||
| process/HDR_as_SRGB=false | |||||
| process/invert_color=false | |||||
| stream=false | |||||
| size_limit=0 | |||||
| detect_3d=true | |||||
| svg/scale=1.0 | |||||
| @@ -0,0 +1,24 @@ | |||||
| ; Engine configuration file. | |||||
| ; It's best edited using the editor UI and not directly, | |||||
| ; since the parameters that go here are not all obvious. | |||||
| ; | |||||
| ; Format: | |||||
| ; [section] ; section goes between [] | |||||
| ; param=value ; assign values to parameters | |||||
| config_version=4 | |||||
| _global_script_classes=[ ] | |||||
| _global_script_class_icons={ | |||||
| } | |||||
| [application] | |||||
| config/name="Marching Cubes" | |||||
| run/main_scene="res://Main.tscn" | |||||
| config/icon="res://icon.png" | |||||
| [rendering] | |||||
| environment/default_environment="res://default_env.tres" | |||||
| @@ -0,0 +1,11 @@ | |||||
| // namespacing | |||||
| use gdnative::prelude::*; | |||||
| // modules | |||||
| mod point_gen; | |||||
| // register classes to godot lib | |||||
| fn init(handle: InitHandle) { | |||||
| handle.add_class::<point_gen::PointGenerator>() | |||||
| } | |||||
| godot_init!(init); | |||||
| @@ -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"); | |||||
| } | |||||
| } | |||||