feat: fucking hell yeah (it works) dont look at commit time pls

This commit is contained in:
2024-04-23 04:59:20 +02:00
parent 98cf2e8369
commit 00776b92d3
7 changed files with 114 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
[package]
name = "noise"
name = "nodes-noise"
version = "0.1.0"
authors = ["Max Richter <jim-x@web.de>"]
edition = "2018"
@@ -23,6 +23,7 @@ serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.4"
console_error_panic_hook = { version = "0.1.7", optional = true }
web-sys = { version = "0.3.69", features = ["console"] }
noise = "0.9.0"
[dev-dependencies]
wasm-bindgen-test = "0.3.34"

View File

@@ -16,6 +16,9 @@
"type": "float",
"min": 0.1,
"max": 100
},
"seed": {
"type": "seed"
}
}
}

View File

@@ -1,14 +1,46 @@
use macros::include_definition_file;
use utils::{concat_args, get_args, log};
use noise::{core::open_simplex::open_simplex_2d, permutationtable::PermutationTable, Vector2};
use utils::{
concat_args, decode_float, encode_float, evaluate_float, get_args, log, set_panic_hook,
};
use wasm_bindgen::prelude::*;
include_definition_file!("src/input.json");
#[rustfmt::skip]
#[wasm_bindgen]
pub fn execute(input: &[i32]) -> Vec<i32> {
set_panic_hook();
let args = get_args(input);
let plants = get_args(args[0]);
log!("noise plants: {:?}", plants);
concat_args(vec![plants[0].to_vec()])
let scale = evaluate_float(args[1]);
let strength = evaluate_float(args[2]);
let seed = args[3][0];
let hasher = PermutationTable::new(seed as u32);
log!("scale: {}, strength: {}, seed: {}", scale, strength, seed);
let output: Vec<Vec<i32>> = plants
.iter()
.map(|p| {
let mut plant = p.to_vec();
log!("plant: {:?}", plant);
let points = (plant.len() - 5) / 4;
for i in 0..points {
let a = i as f64 / (points - 1) as f64;
let px = Vector2::new(0.0, a * scale as f64);
let pz = Vector2::new(a * scale as f64, 0.0);
let nx = open_simplex_2d(px, &hasher) as f32 * strength * 0.1;
let nz = open_simplex_2d(pz, &hasher) as f32 * strength * 0.1;
plant[3 + i * 4] = encode_float(decode_float(plant[3 + i * 4]) + nx);
plant[5 + i * 4] = encode_float(decode_float(plant[5 + i * 4]) + nz);
}
plant
})
.collect();
concat_args(output.iter().map(|v| v.as_slice()).collect())
}

View File

@@ -35,10 +35,10 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
if arg_type == 0 {
// this is stem
let stem = &arg[2..arg.len() - 2];
let stem = &arg[3..arg.len() - 2];
output.push(arg.to_vec());
log!("stem: {:?}", stem);
let geometry = extrude_path(stem, resolution);
log!("geometry: {:?}", geometry);
output.push(geometry);
} else if arg_type == 1 {
// this is geometry