feat: add benchmark settings panel
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 1m59s

This commit is contained in:
2024-05-01 23:05:04 +02:00
parent 8bf2958e1d
commit d9afec5bf6
39 changed files with 1253 additions and 741 deletions

View File

@@ -9,13 +9,13 @@
},
"strength": {
"type": "float",
"min": 0.1,
"min": 0,
"max": 1
},
"curviness": {
"type": "float",
"hidden": true,
"min": 0.1,
"min": 0,
"max": 1
},
"depth": {

View File

@@ -1,8 +1,9 @@
use glam::Vec3;
use macros::include_definition_file;
use utils::{
concat_args, evaluate_float, evaluate_int, geometry::wrap_path_mut, log, reset_call_count,
set_panic_hook, split_args,
concat_args, evaluate_float, evaluate_int,
geometry::{wrap_path, wrap_path_mut},
log, reset_call_count, set_panic_hook, split_args,
};
use wasm_bindgen::prelude::*;
@@ -34,58 +35,64 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let output: Vec<Vec<i32>> = plants
.iter()
.map(|_path_data| {
let mut path_data = _path_data.to_vec();
let path_data = _path_data.to_vec();
if path_data[2] != 0 || path_data[3] < (max_depth - depth + 1) {
return path_data;
}
let path = wrap_path_mut(&mut path_data);
let path = wrap_path(&path_data);
let mut output_data = path_data.clone();
let output = wrap_path_mut(&mut output_data);
let mut offset_vec = Vec3::ZERO;
for i in 1..path.length {
// let alpha = i as f32 / (path.length - 1) as f32;
let start_index = (i - 1) * 4;
let end_index = start_index + 4;
let original_length = path.get_length();
for i in 0..path.length - 1 {
let alpha = i as f32 / (path.length - 1) as f32;
let start_index = i * 4;
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]);
let end_point = Vec3::from_slice(&path.points[start_index + 4..start_index + 7]);
let length = (end_point - start_point).length();
let direction = end_point - start_point;
let normalised = (end_point - start_point).normalize();
let strength = evaluate_float(args[1]);
let down_point = Vec3::new(0.0, -length * strength, 0.0);
let length = direction.length();
let curviness = evaluate_float(args[2]);
let strength =
evaluate_float(args[1]) / curviness.max(0.0001) * evaluate_float(args[1]);
let mut mid_point = lerp_vec3(
normalised,
down_point,
curviness * (i as f32 / path.length as f32).sqrt(),
log!(
"length: {}, curviness: {}, strength: {}",
length,
curviness,
strength
);
let down_point = Vec3::new(0.0, -length * strength, 0.0);
let mut mid_point = lerp_vec3(direction, down_point, curviness * alpha.sqrt());
if mid_point[0] == 0.0 && mid_point[2] == 0.0 {
mid_point[0] += 0.0001;
mid_point[2] += 0.0001;
}
mid_point = mid_point.normalize();
mid_point *= length;
// Correct midpoint length
mid_point *= mid_point.length() / length;
let final_end_point = start_point + mid_point;
let offset_end_point = end_point + offset_vec;
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];
output.points[start_index + 4] = offset_end_point[0];
output.points[start_index + 5] = offset_end_point[1];
output.points[start_index + 6] = offset_end_point[2];
let offset = final_end_point - end_point;
offset_vec += offset;
offset_vec += final_end_point - end_point;
}
path_data
log!("length: {} final: {}", original_length, output.get_length());
output_data
})
.collect();

View File

@@ -1,4 +1,3 @@
use glam::Vec3;
use macros::include_definition_file;
use noise::{HybridMulti, MultiFractal, NoiseFn, OpenSimplex};
use utils::{
@@ -66,15 +65,7 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
let path = wrap_path_mut(&mut path_data);
let p0 = Vec3::new(path.points[0], path.points[1], path.points[2]);
let p2 = Vec3::new(
path.points[path.length * 4 - 3],
path.points[path.length * 4 - 2],
path.points[path.length * 4 - 1],
);
let length = (p2 - p0).length() as f64;
let length = path.get_length() as f64;
for i in 0..path.length {
let a = i as f64 / (path.length - 1) as f64;