feat: add path_geometry data
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m21s
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m21s
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "max/plantarium/box",
|
||||
"outputs": [
|
||||
"model"
|
||||
"geometry"
|
||||
],
|
||||
"inputs": {
|
||||
"size": {
|
||||
|
||||
6
nodes/max/plantarium/branches/.gitignore
vendored
Normal file
6
nodes/max/plantarium/branches/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
bin/
|
||||
pkg/
|
||||
wasm-pack.log
|
||||
28
nodes/max/plantarium/branches/Cargo.toml
Normal file
28
nodes/max/plantarium/branches/Cargo.toml
Normal file
@@ -0,0 +1,28 @@
|
||||
[package]
|
||||
name = "template"
|
||||
version = "0.1.0"
|
||||
authors = ["Max Richter <jim-x@web.de>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[features]
|
||||
default = ["console_error_panic_hook"]
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2.84"
|
||||
|
||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||
# logging them with `console.error`. This is great for development, but requires
|
||||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
||||
# code size when deploying.
|
||||
utils = { version = "0.1.0", path = "../../../../packages/utils" }
|
||||
macros = { version = "0.1.0", path = "../../../../packages/macros" }
|
||||
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"] }
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.34"
|
||||
6
nodes/max/plantarium/branches/package.json
Normal file
6
nodes/max/plantarium/branches/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "wasm-pack build --release --out-name index --no-default-features",
|
||||
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
|
||||
}
|
||||
}
|
||||
70
nodes/max/plantarium/branches/src/input.json
Normal file
70
nodes/max/plantarium/branches/src/input.json
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"id": "max/plantarium/branches",
|
||||
"outputs": [
|
||||
"path"
|
||||
],
|
||||
"inputs": {
|
||||
"plant": {
|
||||
"type": "path",
|
||||
"external": true
|
||||
},
|
||||
"length": {
|
||||
"type": "float",
|
||||
"min": 0,
|
||||
"max": 3,
|
||||
"step": 0.05,
|
||||
"value": 0.8
|
||||
},
|
||||
"thiccness": {
|
||||
"type": "float",
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.01,
|
||||
"value": 0.8
|
||||
},
|
||||
"offsetSingle": {
|
||||
"type": "float",
|
||||
"min": 0,
|
||||
"hidden": true,
|
||||
"max": 1,
|
||||
"step": 0.01,
|
||||
"value": 0.5
|
||||
},
|
||||
"lowestBranch": {
|
||||
"type": "float",
|
||||
"hidden": true,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.01,
|
||||
"value": 0.2
|
||||
},
|
||||
"highestBranch": {
|
||||
"type": "float",
|
||||
"hidden": true,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.01,
|
||||
"value": 1
|
||||
},
|
||||
"depth": {
|
||||
"type": "float",
|
||||
"hidden": true,
|
||||
"min": 1,
|
||||
"value": 1,
|
||||
"description": "On how many layern of branches should we place branches."
|
||||
},
|
||||
"amount": {
|
||||
"type": "integer",
|
||||
"min": 0,
|
||||
"max": 64,
|
||||
"value": 10
|
||||
},
|
||||
"resolution_curve": {
|
||||
"type": "integer",
|
||||
"value": 32,
|
||||
"min": 3,
|
||||
"max": 64,
|
||||
"setting": "resolution.curve"
|
||||
}
|
||||
}
|
||||
}
|
||||
18
nodes/max/plantarium/branches/src/lib.rs
Normal file
18
nodes/max/plantarium/branches/src/lib.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use macros::include_definition_file;
|
||||
use utils::{concat_args, decode_float, encode_float, get_args, set_panic_hook, wrap_arg};
|
||||
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 paths = get_args(args[0]);
|
||||
|
||||
concat_args(paths)
|
||||
}
|
||||
13
nodes/max/plantarium/branches/tests/web.rs
Normal file
13
nodes/max/plantarium/branches/tests/web.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
//! Test suite for the Web and headless browsers.
|
||||
|
||||
#![cfg(target_arch = "wasm32")]
|
||||
|
||||
extern crate wasm_bindgen_test;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
wasm_bindgen_test_configure!(run_in_browser);
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn pass() {
|
||||
assert_eq!(1 + 1, 2);
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"id": "max/plantarium/noise",
|
||||
"outputs": [
|
||||
"plant"
|
||||
"path"
|
||||
],
|
||||
"inputs": {
|
||||
"plant": {
|
||||
"type": "plant"
|
||||
"type": "path"
|
||||
},
|
||||
"scale": {
|
||||
"type": "float",
|
||||
|
||||
@@ -2,7 +2,7 @@ use glam::Vec3;
|
||||
use macros::include_definition_file;
|
||||
use noise::{core::open_simplex::open_simplex_2d, permutationtable::PermutationTable, Vector2};
|
||||
use utils::{
|
||||
concat_args, decode_float, encode_float, evaluate_float, evaluate_vec3, get_args, log,
|
||||
concat_args, evaluate_float, evaluate_vec3, geometry::wrap_path, get_args, reset_call_count,
|
||||
set_panic_hook,
|
||||
};
|
||||
use wasm_bindgen::prelude::*;
|
||||
@@ -17,62 +17,46 @@ fn lerp(a: f32, b: f32, t: f32) -> f32 {
|
||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
set_panic_hook();
|
||||
|
||||
reset_call_count();
|
||||
|
||||
let args = get_args(input);
|
||||
|
||||
let plants = get_args(args[0]);
|
||||
let scale = (evaluate_float(args[1]) * 0.1) as f64;
|
||||
let strength = evaluate_float(args[2]);
|
||||
let _fix_bottom = evaluate_float(args[3]);
|
||||
let fix_bottom = if _fix_bottom.is_finite() {
|
||||
_fix_bottom
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let fix_bottom = evaluate_float(args[3]);
|
||||
|
||||
let seed = args[4][0];
|
||||
|
||||
let directional_strength = evaluate_vec3(args[5]);
|
||||
|
||||
let hasher = PermutationTable::new(seed as u32);
|
||||
log!(
|
||||
"scale: {}, strength: {}, fix_bottom: {}, seed: {}, directional: {:?}",
|
||||
scale,
|
||||
strength,
|
||||
fix_bottom,
|
||||
seed,
|
||||
directional_strength
|
||||
);
|
||||
|
||||
let output: Vec<Vec<i32>> = plants
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(j, p)| {
|
||||
let mut plant = p.to_vec();
|
||||
.map(|(j, _path_data)| {
|
||||
let mut path_data = _path_data.to_vec();
|
||||
|
||||
log!("plant: {:?}", plant);
|
||||
// if this is not a path don't modify it
|
||||
if path_data[2] != 0 {
|
||||
return path_data;
|
||||
}
|
||||
|
||||
let points = (plant.len() - 5) / 4;
|
||||
let path = wrap_path(&mut path_data);
|
||||
|
||||
let p0 = Vec3::new(
|
||||
decode_float(plant[3]),
|
||||
decode_float(plant[4]),
|
||||
decode_float(plant[5]),
|
||||
);
|
||||
let p0 = Vec3::new(path.points[0], path.points[1], path.points[2]);
|
||||
|
||||
let p2 = Vec3::new(
|
||||
decode_float(plant[plant.len() - 6]),
|
||||
decode_float(plant[plant.len() - 5]),
|
||||
decode_float(plant[plant.len() - 4]),
|
||||
path.points[path.length * 4 - 3],
|
||||
path.points[path.length * 4 - 2],
|
||||
path.points[path.length * 4 - 1],
|
||||
);
|
||||
// .... x, y, z, w, 1, 1
|
||||
// -4 -3 -2 -1
|
||||
|
||||
let length = (p2 - p0).length() as f64;
|
||||
|
||||
log!("p0: {:?} p1: {:?} length: {}", p0, p2, length);
|
||||
|
||||
for i in 0..points {
|
||||
let a = i as f64 / (points - 1) as f64;
|
||||
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);
|
||||
@@ -96,14 +80,13 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
* directional_strength[2]
|
||||
* lerp(1.0, a as f32, fix_bottom);
|
||||
|
||||
plant[3 + i * 4] = encode_float(decode_float(plant[3 + i * 4]) + nx);
|
||||
plant[4 + i * 4] = encode_float(decode_float(plant[4 + i * 4]) + ny);
|
||||
plant[5 + i * 4] = encode_float(decode_float(plant[5 + i * 4]) + nz);
|
||||
path.points[i * 4] += nx;
|
||||
path.points[i * 4 + 1] += ny;
|
||||
path.points[i * 4 + 2] += nz;
|
||||
}
|
||||
|
||||
plant
|
||||
path_data
|
||||
})
|
||||
.collect();
|
||||
|
||||
concat_args(output.iter().map(|v| v.as_slice()).collect())
|
||||
concat_args(output.iter().map(|x| x.as_slice()).collect())
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
"outputs": [],
|
||||
"inputs": {
|
||||
"input": {
|
||||
"type": "plant",
|
||||
"type": "path",
|
||||
"accepts": [
|
||||
"geometry"
|
||||
],
|
||||
"external": true
|
||||
},
|
||||
"resolution_circle": {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
use macros::include_definition_file;
|
||||
use utils::{concat_args, evaluate_int, geometry::extrude_path, get_args, log};
|
||||
use utils::{
|
||||
concat_args, evaluate_int,
|
||||
geometry::{extrude_path, wrap_path},
|
||||
get_args, log,
|
||||
};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
include_definition_file!("src/inputs.json");
|
||||
@@ -10,30 +14,25 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
|
||||
let args = get_args(input);
|
||||
|
||||
log!("output args: {:?}", args);
|
||||
|
||||
let inputs = get_args(args[0]);
|
||||
|
||||
log!("output inputs: {:?}", inputs);
|
||||
|
||||
let resolution = evaluate_int(args[1]) as usize;
|
||||
|
||||
log!("output inputs: {:?}", inputs);
|
||||
log!("inputs: {}, resolution: {}", inputs.len(), resolution);
|
||||
|
||||
let mut output: Vec<Vec<i32>> = Vec::new();
|
||||
for arg in inputs {
|
||||
if arg.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let arg_type = arg[2];
|
||||
log!("arg_type: {}, \n {:?}", arg_type, arg,);
|
||||
|
||||
if arg_type == 0 {
|
||||
// this is stem
|
||||
let stem = &arg[3..arg.len() - 2];
|
||||
output.push(arg.to_vec());
|
||||
log!("stem: {:?}", stem);
|
||||
let geometry = extrude_path(stem, resolution);
|
||||
// this is path
|
||||
let mut vec = arg.to_vec();
|
||||
output.push(vec.clone());
|
||||
let path_data = wrap_path(&mut vec);
|
||||
log!("{:?}", path_data);
|
||||
let geometry = extrude_path(path_data, resolution);
|
||||
output.push(geometry);
|
||||
} else if arg_type == 1 {
|
||||
// this is geometry
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "max/plantarium/stem",
|
||||
"outputs": [
|
||||
"plant"
|
||||
"path"
|
||||
],
|
||||
"inputs": {
|
||||
"origin": {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use macros::include_definition_file;
|
||||
use utils::{
|
||||
evaluate_float, evaluate_int, evaluate_vec3, get_args, log, reset_call_count, set_panic_hook,
|
||||
evaluate_float, evaluate_int, evaluate_vec3,
|
||||
geometry::{create_multiple_paths, wrap_multiple_paths},
|
||||
get_args, log, reset_call_count, set_panic_hook,
|
||||
};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
@@ -14,60 +16,31 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
|
||||
let args = get_args(input);
|
||||
|
||||
let amount = evaluate_int(args[1]) as usize;
|
||||
let path_resolution = evaluate_int(args[4]) as usize;
|
||||
|
||||
log!("stem args: {:?}", args);
|
||||
|
||||
let amount = evaluate_int(args[1]) as usize;
|
||||
let res_curve = evaluate_int(args[4]) as usize;
|
||||
let mut stem_data = create_multiple_paths(amount, path_resolution, 1);
|
||||
|
||||
log!("STEM: amount: {} res_curve: {}", amount, res_curve);
|
||||
|
||||
// 4 extra for opening and closing brackets
|
||||
// and each stem has 5 extra for opening and closing brackets and node-type
|
||||
let output_size = 4 + amount * (res_curve * 4 + 5);
|
||||
|
||||
let mut path: Vec<i32> = vec![0; output_size];
|
||||
path[0] = 0; // encode opening bracket
|
||||
path[1] = 1; // encode opening bracket
|
||||
path[output_size - 2] = 1; // encode closing bracket
|
||||
path[output_size - 1] = 1; // encode closing bracket
|
||||
|
||||
for i in 0..amount {
|
||||
let start_index = 2 + i * (res_curve * 4 + 5);
|
||||
let end_index = 2 + (i + 1) * (res_curve * 4 + 5);
|
||||
let mut stems = wrap_multiple_paths(&mut stem_data);
|
||||
|
||||
for stem in stems.iter_mut() {
|
||||
let origin = evaluate_vec3(args[0]);
|
||||
let length = evaluate_float(args[2]);
|
||||
let thickness = evaluate_float(args[3]);
|
||||
let amount_points = stem.points.len() / 4;
|
||||
|
||||
log!(
|
||||
"STEM {i}: origin: {:?} length: {} thickness: {}",
|
||||
origin,
|
||||
length,
|
||||
thickness
|
||||
);
|
||||
|
||||
path[start_index] = 0; // encode opening bracket
|
||||
path[start_index + 1] = res_curve as i32 * 4 + 2; // encode opening bracket
|
||||
path[start_index + 2] = 0; // encode node-type, stem: 0
|
||||
|
||||
path[end_index - 2] = 1; // encode closing bracket
|
||||
path[end_index - 1] = 1; // encode closing bracket
|
||||
|
||||
let path_slice = &mut path[3 + start_index..end_index - 2];
|
||||
|
||||
let path_p: &mut [f32] = unsafe {
|
||||
assert_eq!(path_slice.len() % 4, 0);
|
||||
std::slice::from_raw_parts_mut(path_slice.as_ptr() as *mut f32, path_slice.len())
|
||||
};
|
||||
|
||||
for i in 0..res_curve {
|
||||
let a = i as f32 / (res_curve - 1) as f32;
|
||||
path_p[i * 4] = origin[0];
|
||||
path_p[i * 4 + 1] = origin[1] + a * length;
|
||||
path_p[i * 4 + 2] = origin[2];
|
||||
path_p[i * 4 + 3] = thickness * (1.0 - a);
|
||||
for i in 0..amount_points {
|
||||
let a = i as f32 / (path_resolution - 1) as f32;
|
||||
stem.points[i * 4] = origin[0];
|
||||
stem.points[i * 4 + 1] = origin[1] + a * length;
|
||||
stem.points[i * 4 + 2] = origin[2];
|
||||
stem.points[i * 4 + 3] = thickness * (1.0 - a);
|
||||
}
|
||||
}
|
||||
|
||||
path
|
||||
log!("stem_data: {:?}", stem_data);
|
||||
|
||||
stem_data
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "max/plantarium/triangle",
|
||||
"outputs": [
|
||||
"model"
|
||||
"geometry"
|
||||
],
|
||||
"inputs": {
|
||||
"size": {
|
||||
|
||||
Reference in New Issue
Block a user