feat: some shut
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "triangle"
|
||||
name = "template"
|
||||
version = "0.1.0"
|
||||
authors = ["Max Richter <jim-x@web.de>"]
|
||||
edition = "2018"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "wasm-pack build --release --out-name index --no-default-features",
|
||||
"dev": "cargo watch -s 'pnpm build'"
|
||||
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
|
||||
}
|
||||
}
|
||||
|
||||
18
nodes/max/plantarium/random/src/definition.json
Normal file
18
nodes/max/plantarium/random/src/definition.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"outputs": [
|
||||
"float"
|
||||
],
|
||||
"inputs": {
|
||||
"min": {
|
||||
"type": "float",
|
||||
"value": 2
|
||||
},
|
||||
"max": {
|
||||
"type": "float",
|
||||
"value": 2
|
||||
},
|
||||
"seed": {
|
||||
"type": "seed"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,22 @@
|
||||
use macros::define_node;
|
||||
use macros::include_definition_file;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
define_node!(
|
||||
r#"{
|
||||
"outputs": ["float"],
|
||||
"inputs": {
|
||||
"min": { "type": "float", "value": 2 },
|
||||
"max": { "type": "float", "value": 2 },
|
||||
"seed": { "type": "seed" }
|
||||
}
|
||||
}"#
|
||||
);
|
||||
include_definition_file!("src/definition.json");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(args: &[i32]) -> Vec<i32> {
|
||||
// let min: String;
|
||||
// if var_min.is_string() {
|
||||
// min = unwrap_string(var_min);
|
||||
// } else {
|
||||
// min = unwrap_int(var_min).to_string();
|
||||
// }
|
||||
//
|
||||
// let max: String;
|
||||
// if var_max.is_string() {
|
||||
// max = unwrap_string(var_max);
|
||||
// } else {
|
||||
// max = unwrap_int(var_max).to_string();
|
||||
// }
|
||||
//
|
||||
// let seed: String;
|
||||
// if var_seed.is_string() {
|
||||
// seed = unwrap_string(var_seed);
|
||||
// } else {
|
||||
// seed = unwrap_int(var_seed).to_string();
|
||||
// }
|
||||
//
|
||||
// log(&format!("min: {}, max: {}, seed: {}", min, max, seed));
|
||||
//
|
||||
// // Interpolate strings into JSON format
|
||||
// let json_string = format!(
|
||||
// r#"{{"__type": "random", "min": {}, "max": {}, "seed": {}}}"#,
|
||||
// min, max, seed
|
||||
// );
|
||||
let mut result = Vec::with_capacity(args.len() + 7);
|
||||
result.push(0);
|
||||
result.push(1);
|
||||
result.push(0); // encoding the [ bracket
|
||||
result.push(args[1] + 1);
|
||||
|
||||
// json_string
|
||||
vec![1, args[0]]
|
||||
result.push(1); // adding the node-type, random: 0
|
||||
result.extend_from_slice(&args[2..]);
|
||||
|
||||
result.push(1);
|
||||
result.push(1); // closing bracket
|
||||
result.push(1);
|
||||
result.push(1); // closing bracket
|
||||
result
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
let a = i as f32 / (res_curve - 1) as f32;
|
||||
path_p[i * 4] = origin[0] + (a * 8.0).sin() * 0.2;
|
||||
path_p[i * 4 + 1] = origin[1] + a * length;
|
||||
path_p[i * 4 + 2] = origin[2] + 0.0;
|
||||
path_p[i * 4 + 2] = origin[2] + ((a + 2.0) * 8.0).sin() * 0.2;
|
||||
path_p[i * 4 + 3] = thickness * (1.0 - a);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "wasm-pack build --release --out-name index --no-default-features",
|
||||
"dev": "cargo watch -s 'pnpm build'"
|
||||
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use macros::include_definition_file;
|
||||
use utils::{decode_float, encode_float, wrap_arg};
|
||||
use utils::{decode_float, encode_float, evaluate_arg, evaluate_float, get_args, wrap_arg};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::console;
|
||||
|
||||
@@ -9,11 +9,15 @@ include_definition_file!("src/input.json");
|
||||
#[wasm_bindgen]
|
||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
|
||||
let size = input[2];
|
||||
let decoded = decode_float(input[2]);
|
||||
utils::set_panic_hook();
|
||||
|
||||
let args = get_args(input);
|
||||
|
||||
let size = evaluate_arg(args[0]);
|
||||
let decoded = decode_float(size);
|
||||
let negative_size = encode_float(-decoded);
|
||||
|
||||
console::log_1(&format!("WASM(triangle): input: {:?} -> {}", input, decoded).into());
|
||||
console::log_1(&format!("WASM(triangle): input: {:?} -> {}", args[0],decoded).into());
|
||||
|
||||
// [[1,3, x, y, z, x, y,z,x,y,z]];
|
||||
wrap_arg(&[
|
||||
@@ -22,8 +26,6 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
1, // 1 face
|
||||
// this are the indeces for the face
|
||||
0, 2, 1,
|
||||
// this is the normal for the single face 1065353216 == 1.0f encoded is i32
|
||||
0, 1065353216, 0,
|
||||
//
|
||||
negative_size, // x -> point 1
|
||||
0, // y
|
||||
@@ -36,6 +38,10 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||
0, // x -> point 3
|
||||
0, // y
|
||||
size, // z
|
||||
// this is the normal for the single face 1065353216 == 1.0f encoded is i32
|
||||
0, 1065353216, 0,
|
||||
0, 1065353216, 0,
|
||||
0, 1065353216, 0,
|
||||
])
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "wasm-pack build --release --out-name index --no-default-features",
|
||||
"dev": "cargo watch -s 'pnpm build'"
|
||||
"dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user