commit 87d85027d3904e35df78c2f227d3345364a307a3 Author: Isabelle Lesko Date: Sun Mar 28 12:46:41 2021 -0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9510a41 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target +Cargo.lock +/.import +/.mono \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8dc4ce8 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "marching_cubes" +version = "0.1.0" +authors = ["Isabelle Lesko "] +edition = "2018" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +gdnative = "0.9.3" +cgmath = "0.18.0" diff --git a/Main.tscn b/Main.tscn new file mode 100644 index 0000000..578beda --- /dev/null +++ b/Main.tscn @@ -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="."] diff --git a/default_env.tres b/default_env.tres new file mode 100644 index 0000000..20207a4 --- /dev/null +++ b/default_env.tres @@ -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 ) diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..c98fbb6 Binary files /dev/null and b/icon.png differ diff --git a/icon.png.import b/icon.png.import new file mode 100644 index 0000000..96cbf46 --- /dev/null +++ b/icon.png.import @@ -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 diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..1ec6757 --- /dev/null +++ b/project.godot @@ -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" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..450079c --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,11 @@ +// namespacing +use gdnative::prelude::*; + +// modules +mod point_gen; + +// register classes to godot lib +fn init(handle: InitHandle) { + handle.add_class::() +} +godot_init!(init); diff --git a/src/point_gen.rs b/src/point_gen.rs new file mode 100644 index 0000000..e47c630 --- /dev/null +++ b/src/point_gen.rs @@ -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, 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"); + } +}