feat: add octaves to noise node
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m8s
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m8s
This commit is contained in:
@@ -33,8 +33,8 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
}
|
||||
|
||||
for path_data in paths.iter() {
|
||||
// if this is not a path don't modify it
|
||||
if path_data[2] != 0 || path_data[3] < (max_depth - depth) {
|
||||
// if this is not a path ignore it
|
||||
if path_data[2] != 0 || path_data[3] < (max_depth - depth + 1) {
|
||||
output.push(path_data.to_vec());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -50,38 +50,14 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
|
||||
let start_point = Vec3::from_slice(&path.points[start_index..start_index + 3]);
|
||||
let end_point = Vec3::from_slice(&path.points[end_index..end_index + 3]);
|
||||
log!("--------------------------------");
|
||||
|
||||
log!(
|
||||
"start_index: {:?} end_index: {:?} length:{}",
|
||||
start_index,
|
||||
end_index,
|
||||
path.points.len()
|
||||
);
|
||||
if start_point[0].is_nan() {
|
||||
log!("start_point is nan {:?}", path.points);
|
||||
continue;
|
||||
}
|
||||
log!("start_point: {:?}", start_point);
|
||||
log!("end_point: {:?}", end_point);
|
||||
|
||||
let length = (end_point - start_point).length();
|
||||
|
||||
let normalised = (end_point - start_point).normalize();
|
||||
|
||||
if normalised[0].is_nan() {
|
||||
log!("normalised is nan {:?}", normalised);
|
||||
continue;
|
||||
}
|
||||
|
||||
let strength = evaluate_float(args[1]);
|
||||
let down_point = Vec3::new(0.0, -length * strength, 0.0);
|
||||
|
||||
if down_point[0].is_nan() {
|
||||
log!("down_point is nan {:?}", down_point);
|
||||
continue;
|
||||
}
|
||||
|
||||
let curviness = evaluate_float(args[2]);
|
||||
|
||||
let mut mid_point = lerp_vec3(
|
||||
@@ -90,13 +66,6 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
curviness * (i as f32 / path.length as f32).sqrt(),
|
||||
);
|
||||
|
||||
if mid_point[0].is_nan() {
|
||||
log!("mid_point is nan {:?}", mid_point);
|
||||
log!("normalised: {:?}", normalised);
|
||||
log!("curviness: {:?}", curviness);
|
||||
continue;
|
||||
}
|
||||
|
||||
if mid_point[0] == 0.0 && mid_point[2] == 0.0 {
|
||||
mid_point[0] += 0.0001;
|
||||
mid_point[2] += 0.0001;
|
||||
@@ -109,11 +78,6 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
let final_end_point = start_point + mid_point;
|
||||
let offset_end_point = end_point + offset_vec;
|
||||
|
||||
if offset_end_point[0].is_nan() {
|
||||
log!("offset_end_point is nan {:?}", offset_end_point);
|
||||
continue;
|
||||
}
|
||||
|
||||
path.points[end_index] = offset_end_point[0];
|
||||
path.points[end_index + 1] = offset_end_point[1];
|
||||
path.points[end_index + 2] = offset_end_point[2];
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
},
|
||||
"fixBottom": {
|
||||
"type": "float",
|
||||
"label": "Fixate bottom of plant",
|
||||
"label": "Fix bottom of plant",
|
||||
"hidden": true,
|
||||
"value": 1.0,
|
||||
"min": 0,
|
||||
@@ -43,6 +43,13 @@
|
||||
"max": 10,
|
||||
"value": 1,
|
||||
"hidden": true
|
||||
},
|
||||
"octaves": {
|
||||
"type": "integer",
|
||||
"min": 1,
|
||||
"max": 5,
|
||||
"value": 1,
|
||||
"hidden": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use glam::Vec3;
|
||||
use macros::include_definition_file;
|
||||
use noise::{core::open_simplex::open_simplex_2d, permutationtable::PermutationTable, Vector2};
|
||||
use noise::{HybridMulti, MultiFractal, NoiseFn, OpenSimplex};
|
||||
use utils::{
|
||||
concat_args, evaluate_float, evaluate_int, evaluate_vec3, geometry::wrap_path_mut,
|
||||
reset_call_count, set_panic_hook, split_args,
|
||||
@@ -32,7 +32,14 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
|
||||
let depth = evaluate_int(args[6]);
|
||||
|
||||
let hasher = PermutationTable::new(seed as u32);
|
||||
let octaves = evaluate_int(args[7]);
|
||||
|
||||
let noise_x: HybridMulti<OpenSimplex> =
|
||||
HybridMulti::new(seed as u32 + 1).set_octaves(octaves as usize);
|
||||
let noise_y: HybridMulti<OpenSimplex> =
|
||||
HybridMulti::new(seed as u32 + 2).set_octaves(octaves as usize);
|
||||
let noise_z: HybridMulti<OpenSimplex> =
|
||||
HybridMulti::new(seed as u32 + 3).set_octaves(octaves as usize);
|
||||
|
||||
let mut max_depth = 0;
|
||||
for path_data in plants.iter() {
|
||||
@@ -72,31 +79,21 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
for i in 0..path.length {
|
||||
let a = i as f64 / (path.length - 1) as f64;
|
||||
|
||||
let px = Vector2::new(1000.0 + j as f64 + a * length * scale, a * scale as f64);
|
||||
let py = Vector2::new(2000.0 + j as f64 + a * length * scale, a * scale as f64);
|
||||
let pz = Vector2::new(3000.0 + j as f64 + a * length * scale, a * scale as f64);
|
||||
let px = j as f64 + a * length * scale;
|
||||
let py = a * scale as f64;
|
||||
|
||||
let nx = open_simplex_2d(px, &hasher) as f32
|
||||
* strength
|
||||
* 0.1
|
||||
path.points[i * 4] += noise_x.get([px, py]) as f32
|
||||
* directional_strength[0]
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
|
||||
let ny = open_simplex_2d(py, &hasher) as f32
|
||||
* strength
|
||||
* 0.1
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
path.points[i * 4 + 1] += noise_y.get([px, py]) as f32
|
||||
* directional_strength[1]
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
|
||||
let nz = open_simplex_2d(pz, &hasher) as f32
|
||||
* strength
|
||||
* 0.1
|
||||
* directional_strength[2]
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
|
||||
path.points[i * 4] += nx;
|
||||
path.points[i * 4 + 1] += ny;
|
||||
path.points[i * 4 + 2] += nz;
|
||||
path.points[i * 4 + 2] += noise_z.get([px, py]) as f32
|
||||
* directional_strength[2]
|
||||
* strength
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
}
|
||||
path_data
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user