Skip to content

Commit

Permalink
update godot-rust-script / gdext
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Jan 8, 2024
1 parent 52d99b0 commit 00d14a3
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 157 deletions.
24 changes: 15 additions & 9 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
godot = { git = "https://github.com/titannano/gdext", rev = "4ce4714" }
godot = { git = "https://github.com/titannano/gdext", rev = "e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" }
lerp = "0.4.0"
backtrace = "0.3.64"
num = "0.4.0"
rayon = "1.5.1"
itertools = "0.10.3"
num_enum = "0.7.1"

godot-rust-script = { git = "https://github.com/titannano/godot-rust-script", rev = "a2a5c018fcf0247f1d242ec2bf8a994cc975c1ee" }
godot-rust-script = { git = "https://github.com/titannano/godot-rust-script", rev = "b06f02fdbb320a3cb3cd79ad4589593aba5f4b47" }
88 changes: 44 additions & 44 deletions native/src/scripts/particles/dust_particles.rs
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
use godot_rust_script::{
godot::{
engine::{GpuParticles3D, PrimitiveMesh, StandardMaterial3D},
prelude::{godot_error, Gd},
},
godot_script_impl, GodotScript,
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>,
/// 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);
}
pub fn _ready(&mut self) {
self.set_strength(0.0);
}

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

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

let is_emitting = value > 0.0;
let is_emitting = value > 0.0;

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

if !self.base.is_emitting() {
return;
}
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 Some(mesh) = self.base.get_draw_pass_mesh(0) else {
godot_error!("Draw pass 1 does not exist!");
return;
};

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

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

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

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

material.set_proximity_fade_distance(distance as f32);
}
material.set_proximity_fade_distance(distance as f32);
}
}
Loading

0 comments on commit 00d14a3

Please sign in to comment.