feat: add snapToGrid and showGrid settings
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use macros::include_definition_file;
|
||||
use utils::{evaluate_arg, get_args};
|
||||
use utils::{evaluate_int, get_args};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::console;
|
||||
|
||||
@@ -11,8 +11,8 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
|
||||
let args = get_args(input);
|
||||
|
||||
let value_encoded = evaluate_arg(args[0]);
|
||||
let length = evaluate_arg(args[1]) as usize;
|
||||
let value_encoded = evaluate_int(args[0]);
|
||||
let length = evaluate_int(args[1]) as usize;
|
||||
|
||||
console::log_1(&format!("WASM(array): input: {:?} -> {:?}", args, value_encoded).into());
|
||||
|
||||
|
||||
@@ -5,17 +5,13 @@ include_definition_file!("src/input.json");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(args: &[i32]) -> Vec<i32> {
|
||||
let mut result = Vec::with_capacity(args.len() + 7);
|
||||
result.push(0);
|
||||
result.push(1);
|
||||
let mut result = Vec::with_capacity(args.len() + 3);
|
||||
result.push(0); // encoding the [ bracket
|
||||
result.push(args[1] + 1);
|
||||
|
||||
result.push(0); // adding the node-type, math: 0
|
||||
result.extend_from_slice(&args[2..]);
|
||||
|
||||
result.push(1);
|
||||
result.push(1); // closing bracket
|
||||
result.push(1);
|
||||
result.push(1); // closing bracket
|
||||
result
|
||||
|
||||
6
nodes/max/plantarium/noise/.gitignore
vendored
Normal file
6
nodes/max/plantarium/noise/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
bin/
|
||||
pkg/
|
||||
wasm-pack.log
|
||||
28
nodes/max/plantarium/noise/Cargo.toml
Normal file
28
nodes/max/plantarium/noise/Cargo.toml
Normal file
@@ -0,0 +1,28 @@
|
||||
[package]
|
||||
name = "noise"
|
||||
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/noise/package.json
Normal file
6
nodes/max/plantarium/noise/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'"
|
||||
}
|
||||
}
|
||||
21
nodes/max/plantarium/noise/src/input.json
Normal file
21
nodes/max/plantarium/noise/src/input.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"id": "max/plantarium/noise",
|
||||
"outputs": [
|
||||
"plant"
|
||||
],
|
||||
"inputs": {
|
||||
"plant": {
|
||||
"type": "plant"
|
||||
},
|
||||
"scale": {
|
||||
"type": "float",
|
||||
"min": 0.1,
|
||||
"max": 100
|
||||
},
|
||||
"strength": {
|
||||
"type": "float",
|
||||
"min": 0.1,
|
||||
"max": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
14
nodes/max/plantarium/noise/src/lib.rs
Normal file
14
nodes/max/plantarium/noise/src/lib.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use macros::include_definition_file;
|
||||
use utils::{concat_args, get_args, log};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
include_definition_file!("src/input.json");
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
let args = get_args(input);
|
||||
let plants = get_args(args[0]);
|
||||
log!("noise plants: {:?}", plants);
|
||||
concat_args(vec![plants[0].to_vec()])
|
||||
}
|
||||
13
nodes/max/plantarium/noise/tests/web.rs
Normal file
13
nodes/max/plantarium/noise/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,7 +1,7 @@
|
||||
use glam::{Mat4, Vec3};
|
||||
use macros::include_definition_file;
|
||||
use utils::{
|
||||
concat_args, evaluate_arg,
|
||||
concat_args, evaluate_int,
|
||||
geometry::{extrude_path, transform_geometry},
|
||||
get_args, log,
|
||||
};
|
||||
@@ -10,13 +10,17 @@ use wasm_bindgen::prelude::*;
|
||||
include_definition_file!("src/inputs.json");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(input: Vec<i32>) -> Vec<i32> {
|
||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
utils::set_panic_hook();
|
||||
|
||||
let args = get_args(input.as_slice());
|
||||
log!("output input: {:?}", input);
|
||||
|
||||
let args = get_args(input);
|
||||
|
||||
log!("output args: {:?}", args);
|
||||
|
||||
let inputs = get_args(args[0]);
|
||||
let resolution = evaluate_arg(args[1]) as usize;
|
||||
let resolution = evaluate_int(args[1]) as usize;
|
||||
|
||||
log!("inputs: {}, resolution: {}", inputs.len(), resolution);
|
||||
|
||||
@@ -26,13 +30,19 @@ pub fn execute(input: Vec<i32>) -> Vec<i32> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if arg[2] == 0 {
|
||||
let arg_type = arg[0];
|
||||
|
||||
log!("arg: {:?}", arg);
|
||||
|
||||
if arg_type == 0 {
|
||||
// this is stem
|
||||
let _arg = &arg[3..];
|
||||
let mut geometry = extrude_path(_arg, resolution);
|
||||
let matrix = Mat4::from_translation(Vec3::new(0.0, 0.0, 0.0));
|
||||
geometry = transform_geometry(geometry, matrix);
|
||||
output.push(geometry);
|
||||
} else if arg[2] == 1 {
|
||||
} else if arg_type == 1 {
|
||||
// this is geometry
|
||||
output.push(arg.to_vec());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use macros::include_definition_file;
|
||||
use utils::{evaluate_arg, evaluate_float, evaluate_vec3, get_args, set_panic_hook, wrap_arg};
|
||||
use utils::{evaluate_float, evaluate_int, evaluate_vec3, get_args, log, set_panic_hook, wrap_arg};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
include_definition_file!("src/input.json");
|
||||
@@ -10,22 +10,30 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
|
||||
let args = get_args(input);
|
||||
|
||||
log!("node-stem: {:?}", args);
|
||||
|
||||
let origin = evaluate_vec3(args[0]);
|
||||
let length = evaluate_float(args[1]);
|
||||
let thickness = evaluate_float(args[2]);
|
||||
let res_curve = evaluate_arg(args[3]) as usize;
|
||||
let res_curve = evaluate_int(args[3]) as usize;
|
||||
|
||||
let mut path: Vec<i32> = vec![0; res_curve * 4 + 1];
|
||||
path.resize(res_curve * 4 + 1, 0);
|
||||
log!("origin: {:?}", origin);
|
||||
|
||||
let slice = &mut path[1..];
|
||||
let amount_points = res_curve * 4;
|
||||
// +4 for opening and closing brackets and +1 node-type
|
||||
let output_size = amount_points + 5;
|
||||
|
||||
let mut path: Vec<i32> = vec![0; output_size];
|
||||
path[0] = 0; // encode opening bracket
|
||||
path[1] = res_curve as i32 * 4 + 4; // encode opening bracket
|
||||
path[2] = 0; // encode node-type, stem: 0
|
||||
path[output_size - 2] = 1; // encode closing bracket
|
||||
path[output_size - 1] = 1; // encode closing bracket
|
||||
|
||||
let slice = &mut path[3..output_size - 2];
|
||||
|
||||
// Unsafe code to transmute the i32 slice to an f32 slice
|
||||
let path_p: &mut [f32] = unsafe {
|
||||
// Ensure that the length of the slice is a multiple of 4
|
||||
assert_eq!(slice.len() % 4, 0);
|
||||
|
||||
// Transmute the i32 slice to an f32 slice
|
||||
std::slice::from_raw_parts_mut(slice.as_ptr() as *mut f32, slice.len())
|
||||
};
|
||||
|
||||
@@ -37,5 +45,7 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
path_p[i * 4 + 3] = thickness * (1.0 - a);
|
||||
}
|
||||
|
||||
wrap_arg(&path)
|
||||
log!("res: {:?}", path);
|
||||
|
||||
path
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use macros::include_definition_file;
|
||||
use utils::{decode_float, encode_float, evaluate_arg, get_args, wrap_arg};
|
||||
use utils::{decode_float, encode_float, evaluate_int, get_args, wrap_arg};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::console;
|
||||
|
||||
@@ -13,7 +13,7 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
|
||||
let args = get_args(input);
|
||||
|
||||
let size = evaluate_arg(args[0]);
|
||||
let size = evaluate_int(args[0]);
|
||||
let decoded = decode_float(size);
|
||||
let negative_size = encode_float(-decoded);
|
||||
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
use macros::include_definition_file;
|
||||
use utils::log;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
include_definition_file!("src/input.json");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(args: &[i32]) -> Vec<i32> {
|
||||
let mut result = Vec::with_capacity(args.len() + 2);
|
||||
result.push(0); // encoding the [ bracket
|
||||
result.push(args[1]);
|
||||
|
||||
result.extend_from_slice(&args[2..]);
|
||||
|
||||
result.push(1);
|
||||
result.push(1); // closing bracket
|
||||
|
||||
log!("WASM(vec3): res {:?}", result);
|
||||
result
|
||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
input.to_vec()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user