Skip to content

Commit

Permalink
Introduce Godot Rust Script
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Nov 22, 2023
1 parent 3ed6cc5 commit b4d992e
Show file tree
Hide file tree
Showing 14 changed files with 1,605 additions and 42 deletions.
896 changes: 877 additions & 19 deletions native/Cargo.lock

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[workspace]
resolver = "2"

members = [
"scripts",
]

[workspace.dependencies]
godot-rust-script = { git = "https://github.com/titannano/godot-rust-script", rev = "80b730c24e8488bc2e9c973c794006305d7d2c0d" }

[package]
name = "native"
version = "0.4.0"
Expand All @@ -7,9 +17,14 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
godot = { git = "https://github.com/godot-rust/gdext", rev = "b4e6fd6c9c23e0fd3a124c2893a9592c861ab780" }
godot = { git = "https://github.com/titannano/gdext", rev = "a5d17342b7b47e8af652a6a733f497c468bbd59a" }
lerp = "0.4.0"
backtrace = "0.3.64"
num = "0.4.0"
rayon = "1.5.1"
itertools = "0.10.3"
godot-rust-script = { workspace = true, features = ["runtime"] }
hot-lib-reloader = "0.6.5"
scripts = { path = "./scripts" }
lazy_static = "1.4.0"
process_path = "0.1.4"
12 changes: 12 additions & 0 deletions native/scripts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "scripts"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["dylib", "rlib"]

[dependencies]
godot-rust-script = { workspace = true, features = ["scripts"] }
backtrace = "0.3.64"
num_enum = "0.7.1"
5 changes: 5 additions & 0 deletions native/scripts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod particles;
mod scene_object_registry;
mod spawner;

godot_rust_script::setup_library!();
68 changes: 68 additions & 0 deletions native/scripts/src/particles/dust_particles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use godot_rust_script::{
godot::{
engine::{GpuParticles3D, PrimitiveMesh, StandardMaterial3D},
prelude::{godot_error, Gd},
},
godot_script_impl, GodotScript,
};

/// Dust Particle behavior for a particle system.
/// This is used for the rotor effects
#[derive(GodotScript, Debug)]
#[script(base = GpuParticles3D)]
struct DustParticles {
/// The strength of the emitted dust.
/// This is used for the rotor effects
/**
* This is more documentation
* please read it carefully
*/
#[prop(get = Self::strength, set = Self::set_strength)]
#[export(range(min = 0.1, max = 1.5, step = 0.05))]
strength: f64,
base: Gd<GpuParticles3D>,
}

#[godot_script_impl]
impl DustParticles {
pub fn _ready(&mut self) {
self.set_strength(0.0);
}

/// get effect strength
pub fn strength(&self) -> f64 {
self.strength
}

pub fn set_strength(&mut self, value: f64) {
self.strength = value;

let is_emitting = value > 0.0;

if self.base.is_emitting() != is_emitting {
self.base.set_emitting(is_emitting);
}

if !self.base.is_emitting() {
return;
}

let Some(mesh) = self.base.get_draw_pass_mesh(1) else {
godot_error!("Draw pass 1 does not exist!");
return;
};

let mesh: Gd<PrimitiveMesh> = mesh.cast();

let Some(material) = mesh.get_material() else {
godot_error!("mesh has no material!");
return;
};

let mut material: Gd<StandardMaterial3D> = material.cast();

let distance = (100.0 * (1.0 - value)).max(2.0);

material.set_proximity_fade_distance(distance as f32);
}
}
1 change: 1 addition & 0 deletions native/scripts/src/particles/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod dust_particles;
Loading

0 comments on commit b4d992e

Please sign in to comment.