feat: add active node settings
This commit is contained in:
@@ -17,14 +17,14 @@
|
||||
"min": 0.1,
|
||||
"max": 100
|
||||
},
|
||||
"seed": {
|
||||
"type": "seed"
|
||||
},
|
||||
"fixBottom": {
|
||||
"type": "float",
|
||||
"hidden": true,
|
||||
"min": 0,
|
||||
"max": 1
|
||||
},
|
||||
"seed": {
|
||||
"type": "seed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ use wasm_bindgen::prelude::*;
|
||||
|
||||
include_definition_file!("src/input.json");
|
||||
|
||||
fn lerp(a: f32, b: f32, t: f32) -> f32 {
|
||||
a + t * (b - a)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
set_panic_hook();
|
||||
@@ -16,10 +20,23 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
let plants = get_args(args[0]);
|
||||
let scale = evaluate_float(args[1]);
|
||||
let strength = evaluate_float(args[2]);
|
||||
let seed = args[3][0];
|
||||
let _fix_bottom = evaluate_float(args[3]);
|
||||
let fix_bottom = if _fix_bottom.is_finite() {
|
||||
_fix_bottom
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
let seed = args[4][0];
|
||||
|
||||
let hasher = PermutationTable::new(seed as u32);
|
||||
log!("scale: {}, strength: {}, seed: {}", scale, strength, seed);
|
||||
log!(
|
||||
"scale: {}, strength: {}, fix_bottom: {}, seed: {}",
|
||||
scale,
|
||||
strength,
|
||||
fix_bottom,
|
||||
seed
|
||||
);
|
||||
|
||||
let output: Vec<Vec<i32>> = plants
|
||||
.iter()
|
||||
@@ -33,8 +50,14 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
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 * a as f32;
|
||||
let nz = open_simplex_2d(pz, &hasher) as f32 * strength * 0.1 * a as f32;
|
||||
let nx = open_simplex_2d(px, &hasher) as f32
|
||||
* strength
|
||||
* 0.1
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
let nz = open_simplex_2d(pz, &hasher) as f32
|
||||
* strength
|
||||
* 0.1
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
"outputs": [],
|
||||
"inputs": {
|
||||
"input": {
|
||||
"type": [
|
||||
"plant",
|
||||
"model"
|
||||
],
|
||||
"type": "plant",
|
||||
"external": true
|
||||
},
|
||||
"resolution_circle": {
|
||||
|
||||
Reference in New Issue
Block a user