浏览代码

initial commit

master
Isabelle L. 4 年前
当前提交
87d85027d3
共有 9 个文件被更改,包括 173 次插入0 次删除
  1. +4
    -0
      .gitignore
  2. +12
    -0
      Cargo.toml
  3. +9
    -0
      Main.tscn
  4. +7
    -0
      default_env.tres
  5. 二进制
      icon.png
  6. +34
    -0
      icon.png.import
  7. +24
    -0
      project.godot
  8. +11
    -0
      src/lib.rs
  9. +72
    -0
      src/point_gen.rs

+ 4
- 0
.gitignore 查看文件

@@ -0,0 +1,4 @@
/target
Cargo.lock
/.import
/.mono

+ 12
- 0
Cargo.toml 查看文件

@@ -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"

+ 9
- 0
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="."]

+ 7
- 0
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 )

二进制
icon.png 查看文件

之前 之后
宽度: 64  |  高度: 64  |  大小: 3.2 KiB

+ 34
- 0
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

+ 24
- 0
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"

+ 11
- 0
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::<point_gen::PointGenerator>()
}
godot_init!(init);

+ 72
- 0
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<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");
}
}

正在加载...
取消
保存